From ba1842c02e538e52379d8f63b5bbd360ba5d78ca Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Mon, 24 Sep 2018 16:09:55 +0100 Subject: [PATCH] Tidy up collect output file names for cloned repos This patch set tidies up collect output file names for cloned repos. As an example, previously the output file could be named something like tmp5ak7409aic-clcp-security-manifests.yaml -- after this change it will be aic-clcp-security-manifests.yaml instead which is much cleaner. Pegleg "collect" looks at the last piece in a file path to determine the filename to write to: [0] This means that changing the clone path here from something like: /tmp/tmp54d13yairship-pegleg (which will result in collection output to tmp54d13yairship-pegleg.yaml) To: /tmp/tmp54d13y/airship-pegleg (which will result in collection output to airship-pegleg.yaml) [0] https://github.com/openstack/airship-pegleg/blob/2ea1a55a2de894c991a6b7084fd42fb790632cb7/pegleg/engine/site.py#L71 Change-Id: I2198e299d392e24d376ccfa53bef57fcabf0d41b --- pegleg/engine/util/git.py | 6 +++++- tests/unit/test_cli.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pegleg/engine/util/git.py b/pegleg/engine/util/git.py index b80a9f94..aafa7b15 100644 --- a/pegleg/engine/util/git.py +++ b/pegleg/engine/util/git.py @@ -157,7 +157,11 @@ def _try_git_clone(repo_url, ref=None, proxy_server=None, auth_key=None): # the name here is important as it bubbles back up to the output filename # and ensure we handle url/foo.git/ cases. prefix is 'tmp' by default. - temp_dir = tempfile.mkdtemp(suffix=repo_url.rstrip('/').split('/')[-1]) + root_temp_dir = tempfile.mkdtemp() + repo_name = repo_url.rstrip('/').split('/')[-1] + temp_dir = os.path.join(root_temp_dir, repo_name) + os.makedirs(temp_dir) + env_vars = _get_clone_env_vars(repo_url, ref, auth_key) ssh_cmd = env_vars.get('GIT_SSH_COMMAND') diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 3499983d..1bd90412 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -80,7 +80,7 @@ class TestSiteCliActions(object): assert len(collected_files) == 1 # Validates that site manifests collected from cloned repositories # are written out to sensibly named files like airship-treasuremap.yaml - assert collected_files[0].endswith("%s.yaml" % self.repo_name) + assert collected_files[0] == ("%s.yaml" % self.repo_name) def test_collect_using_local_path(self): """Validates collect action using a path to a local repo.""" @@ -103,4 +103,4 @@ class TestSiteCliActions(object): assert len(collected_files) == 1 # Validates that site manifests collected from cloned repositories # are written out to sensibly named files like airship-treasuremap.yaml - assert collected_files[0].endswith("%s.yaml" % self.repo_name) + assert collected_files[0] == ("%s.yaml" % self.repo_name)