Merge "Generate symlinks during tests"

This commit is contained in:
Zuul 2018-03-16 02:54:39 +00:00 committed by Gerrit Code Review
commit cb4b10f517
15 changed files with 22 additions and 27 deletions

View File

@ -2407,24 +2407,19 @@ class ZuulTestCase(BaseTestCase):
files = {} files = {}
for (dirpath, dirnames, filenames) in os.walk(source_path): for (dirpath, dirnames, filenames) in os.walk(source_path):
# Note: In case a symlink points to an already existing directory
# os.walk includes that in the dirnames list. In order to properly
# copy these links, just add them to the filenames list.
for dirname in dirnames:
test_tree_filepath = os.path.join(dirpath, dirname)
if os.path.islink(test_tree_filepath):
filenames.append(dirname)
for filename in filenames: for filename in filenames:
test_tree_filepath = os.path.join(dirpath, filename) test_tree_filepath = os.path.join(dirpath, filename)
common_path = os.path.commonprefix([test_tree_filepath, common_path = os.path.commonprefix([test_tree_filepath,
source_path]) source_path])
relative_filepath = test_tree_filepath[len(common_path) + 1:] relative_filepath = test_tree_filepath[len(common_path) + 1:]
if os.path.islink(test_tree_filepath): with open(test_tree_filepath, 'rb') as f:
content = SymLink(os.readlink(test_tree_filepath)) content = f.read()
else: # dynamically create symlinks if the content is of the form
with open(test_tree_filepath, 'rb') as f: # symlink: <target>
content = f.read() match = re.match(b'symlink: ([^\s]+)', content)
if match:
content = SymLink(match.group(1))
files[relative_filepath] = content files[relative_filepath] = content
self.addCommitToRepo(project, 'add content from fixture', self.addCommitToRepo(project, 'add content from fixture',
files, branch='master', tag='init') files, branch='master', tag='init')

View File

@ -0,0 +1 @@
symlink: /opt/assemble

View File

@ -0,0 +1 @@
symlink: /opt/file

View File

@ -0,0 +1 @@
symlink: /opt/patch

View File

@ -0,0 +1 @@
symlink: /opt/script.sh

View File

@ -0,0 +1 @@
symlink: /opt/archive.tar