From fac4a31df358c882bb68a90888619ca75d59dd11 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Thu, 15 Mar 2018 11:19:34 +0100 Subject: [PATCH] Generate symlinks during tests Having symlinks pointing to /opt/file in the repo is a bit ugly. It further even breaks use cases like synchronize from executor to node due to fixed safe path checking. Instead we can generate them during test execution based on the test fixture content. Change-Id: I917aad6e99f13798f3a44c56d49e74aef460236a --- tests/base.py | 21 +++++++------------ .../roles/assemble-test/files/dir-symlink/one | 2 +- .../roles/assemble-test/files/symlink | 2 +- .../roles/copy-test/files/dir-symlink/symlink | 2 +- .../playbooks/roles/copy-test/files/symlink | 2 +- .../roles/includevars-test/vars/symlink.yaml | 2 +- .../double-symlink-sidekick | 2 +- .../vars/dir-symlink/two.yaml | 2 +- .../vars/dir/sub/recursive-link | 2 +- .../vars/double-symlink-sidekick/vars.yaml | 2 +- .../roles/includevarsdir-test/vars/symlink | 2 +- .../playbooks/roles/patch-test/files/symlink | 2 +- .../playbooks/roles/script-test/files/symlink | 2 +- .../roles/template-test/templates/symlink | 2 +- .../roles/unarchive-test/files/symlink | 2 +- 15 files changed, 22 insertions(+), 27 deletions(-) mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/dir-symlink/one mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/symlink mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/dir-symlink/symlink mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/symlink mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevars-test/vars/symlink.yaml mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-double-symlink/double-symlink-sidekick mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-symlink/two.yaml mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir/sub/recursive-link mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/double-symlink-sidekick/vars.yaml mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/symlink mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/patch-test/files/symlink mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/script-test/files/symlink mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/template-test/templates/symlink mode change 120000 => 100644 tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/unarchive-test/files/symlink diff --git a/tests/base.py b/tests/base.py index abf2879888..a9b7d21827 100755 --- a/tests/base.py +++ b/tests/base.py @@ -2407,24 +2407,19 @@ class ZuulTestCase(BaseTestCase): files = {} 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: test_tree_filepath = os.path.join(dirpath, filename) common_path = os.path.commonprefix([test_tree_filepath, source_path]) relative_filepath = test_tree_filepath[len(common_path) + 1:] - if os.path.islink(test_tree_filepath): - content = SymLink(os.readlink(test_tree_filepath)) - else: - with open(test_tree_filepath, 'rb') as f: - content = f.read() + with open(test_tree_filepath, 'rb') as f: + content = f.read() + # dynamically create symlinks if the content is of the form + # symlink: + match = re.match(b'symlink: ([^\s]+)', content) + if match: + content = SymLink(match.group(1)) + files[relative_filepath] = content self.addCommitToRepo(project, 'add content from fixture', files, branch='master', tag='init') diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/dir-symlink/one b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/dir-symlink/one deleted file mode 120000 index e5576ba045..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/dir-symlink/one +++ /dev/null @@ -1 +0,0 @@ -/opt/file \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/dir-symlink/one b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/dir-symlink/one new file mode 100644 index 0000000000..33e34a8325 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/dir-symlink/one @@ -0,0 +1 @@ +symlink: /opt/file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/symlink deleted file mode 120000 index 6a29f1c515..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/assemble \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/symlink new file mode 100644 index 0000000000..2b1ef2c456 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/assemble-test/files/symlink @@ -0,0 +1 @@ +symlink: /opt/assemble diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/dir-symlink/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/dir-symlink/symlink deleted file mode 120000 index 22d2e57bc0..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/dir-symlink/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/dir \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/dir-symlink/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/dir-symlink/symlink new file mode 100644 index 0000000000..b21f8f8173 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/dir-symlink/symlink @@ -0,0 +1 @@ +symlink: /opt/dir diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/symlink deleted file mode 120000 index e5576ba045..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/file \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/symlink new file mode 100644 index 0000000000..33e34a8325 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/copy-test/files/symlink @@ -0,0 +1 @@ +symlink: /opt/file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevars-test/vars/symlink.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevars-test/vars/symlink.yaml deleted file mode 120000 index 99a91abada..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevars-test/vars/symlink.yaml +++ /dev/null @@ -1 +0,0 @@ -/opt/vars.yaml \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevars-test/vars/symlink.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevars-test/vars/symlink.yaml new file mode 100644 index 0000000000..a0b14fc6a4 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevars-test/vars/symlink.yaml @@ -0,0 +1 @@ +symlink: /opt/vars.yaml diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-double-symlink/double-symlink-sidekick b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-double-symlink/double-symlink-sidekick deleted file mode 120000 index 7037b32406..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-double-symlink/double-symlink-sidekick +++ /dev/null @@ -1 +0,0 @@ -../double-symlink-sidekick \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-double-symlink/double-symlink-sidekick b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-double-symlink/double-symlink-sidekick new file mode 100644 index 0000000000..62583effab --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-double-symlink/double-symlink-sidekick @@ -0,0 +1 @@ +symlink: ../double-symlink-sidekick diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-symlink/two.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-symlink/two.yaml deleted file mode 120000 index 99a91abada..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-symlink/two.yaml +++ /dev/null @@ -1 +0,0 @@ -/opt/vars.yaml \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-symlink/two.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-symlink/two.yaml new file mode 100644 index 0000000000..a0b14fc6a4 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir-symlink/two.yaml @@ -0,0 +1 @@ +symlink: /opt/vars.yaml diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir/sub/recursive-link b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir/sub/recursive-link deleted file mode 120000 index a96aa0ea9d..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir/sub/recursive-link +++ /dev/null @@ -1 +0,0 @@ -.. \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir/sub/recursive-link b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir/sub/recursive-link new file mode 100644 index 0000000000..4777594220 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/dir/sub/recursive-link @@ -0,0 +1 @@ +symlink: .. diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/double-symlink-sidekick/vars.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/double-symlink-sidekick/vars.yaml deleted file mode 120000 index 99a91abada..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/double-symlink-sidekick/vars.yaml +++ /dev/null @@ -1 +0,0 @@ -/opt/vars.yaml \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/double-symlink-sidekick/vars.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/double-symlink-sidekick/vars.yaml new file mode 100644 index 0000000000..a0b14fc6a4 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/double-symlink-sidekick/vars.yaml @@ -0,0 +1 @@ +symlink: /opt/vars.yaml diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/symlink deleted file mode 120000 index e9b7d22784..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/vars \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/symlink new file mode 100644 index 0000000000..5ec4b036d0 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/includevarsdir-test/vars/symlink @@ -0,0 +1 @@ +symlink: /opt/vars diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/patch-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/patch-test/files/symlink deleted file mode 120000 index a126395256..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/patch-test/files/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/patch \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/patch-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/patch-test/files/symlink new file mode 100644 index 0000000000..159669522d --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/patch-test/files/symlink @@ -0,0 +1 @@ +symlink: /opt/patch diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/script-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/script-test/files/symlink deleted file mode 120000 index ca30538411..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/script-test/files/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/script.sh \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/script-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/script-test/files/symlink new file mode 100644 index 0000000000..8bc5f44067 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/script-test/files/symlink @@ -0,0 +1 @@ +symlink: /opt/script.sh diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/template-test/templates/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/template-test/templates/symlink deleted file mode 120000 index e5576ba045..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/template-test/templates/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/file \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/template-test/templates/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/template-test/templates/symlink new file mode 100644 index 0000000000..33e34a8325 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/template-test/templates/symlink @@ -0,0 +1 @@ +symlink: /opt/file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/unarchive-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/unarchive-test/files/symlink deleted file mode 120000 index 29ab2be92d..0000000000 --- a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/unarchive-test/files/symlink +++ /dev/null @@ -1 +0,0 @@ -/opt/archive.tar \ No newline at end of file diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/unarchive-test/files/symlink b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/unarchive-test/files/symlink new file mode 100644 index 0000000000..1b179b22c4 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/roles/unarchive-test/files/symlink @@ -0,0 +1 @@ +symlink: /opt/archive.tar