Commit e9b1dee3 authored by Jérome Perrin's avatar Jérome Perrin

testing/testcase: snapshot symlinks and directories

Directories were ignored by mistake, we found out that several files
that would help us diagnosing problems were missing, because we only
snapshot etc/* which did not snapshot recursive directories such as
etc/promise or etc/service.

Symlinks were copied (the target was copied), because they matched the
isfile check, but if the symlink target was not existent, this caused
errors.

Also rename _snapshot_instance_file to _copySnapshot as it is no longer
treating files only
parent fd60c32e
......@@ -390,19 +390,19 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# copy log files from standalone
for standalone_log in glob.glob(os.path.join(
cls._base_directory, 'var', 'log', '*')):
cls._snapshot_instance_file(standalone_log, name)
cls._copySnapshot(standalone_log, name)
# copy config and log files from partitions
for pattern in cls._save_instance_file_pattern_list:
for f in glob.glob(os.path.join(cls.slap.instance_directory, pattern)):
cls._snapshot_instance_file(f, name)
cls._copySnapshot(f, name)
def tearDown(self):
self._storeSnapshot(self.id())
@classmethod
def _snapshot_instance_file(cls, source_file_name, name):
"""Save a file for later inspection.
def _copySnapshot(cls, source_file_name, name):
"""Save a file, symbolic link or directory for later inspection.
The path are made relative to slapos root directory and
we keep the same directory structure.
......@@ -422,9 +422,16 @@ class SlapOSInstanceTestCase(unittest.TestCase):
relative_path)
destination_dirname = os.path.dirname(destination)
mkdir_p(destination_dirname)
if os.path.isfile(source_file_name):
if os.path.islink(source_file_name) and not os.path.exists(source_file_name):
cls.logger.debug("copy broken symlink %s as %s", source_file_name, destination)
with open(destination, 'w') as f:
f.write('broken symink to {}\n'.format(os.readlink(source_file_name)))
elif os.path.isfile(source_file_name):
cls.logger.debug("copy %s as %s", source_file_name, destination)
shutil.copy(source_file_name, destination)
elif os.path.isdir(source_file_name):
cls.logger.debug("copy directory %s as %s", source_file_name, destination)
shutil.copytree(source_file_name, destination)
# implementation methods
@classmethod
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment