summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Watkins <daniel.watkins@canonical.com>2019-03-04 22:36:07 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-03-04 22:36:07 +0000
commit109772c2e9066f5ae53aa2806c4bb4a2ab6f4bff (patch)
tree838b2ab736e92a1ea9003ad5b73b9e5c284e29b0
parent5352dd99eb2937b4eaaaf596b40ad7ca69d87f64 (diff)
downloadcloud-init-git-109772c2e9066f5ae53aa2806c4bb4a2ab6f4bff.tar.gz
clean: correctly determine the path for excluding seed directory
Previously, init.paths.cloud_dir has a trailing slash, which meant that "/var/lib/cloud//seed" was being compared to "/var/lib/cloud/seed" and (of course), never matching. In this commit, switch to using os.path.join to avoid this case (and update the tests to catch it in future). LP: #1818571
-rw-r--r--cloudinit/cmd/clean.py3
-rw-r--r--cloudinit/cmd/tests/test_clean.py3
2 files changed, 4 insertions, 2 deletions
diff --git a/cloudinit/cmd/clean.py b/cloudinit/cmd/clean.py
index 28ee7b84..30e49de0 100644
--- a/cloudinit/cmd/clean.py
+++ b/cloudinit/cmd/clean.py
@@ -62,8 +62,9 @@ def remove_artifacts(remove_logs, remove_seed=False):
if not os.path.isdir(init.paths.cloud_dir):
return 0 # Artifacts dir already cleaned
+ seed_path = os.path.join(init.paths.cloud_dir, 'seed')
for path in glob.glob('%s/*' % init.paths.cloud_dir):
- if path == '%s/seed' % init.paths.cloud_dir and not remove_seed:
+ if path == seed_path and not remove_seed:
continue
try:
if os.path.isdir(path) and not is_link(path):
diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py
index 15c3294e..f092ab3d 100644
--- a/cloudinit/cmd/tests/test_clean.py
+++ b/cloudinit/cmd/tests/test_clean.py
@@ -22,7 +22,8 @@ class TestClean(CiTestCase):
class FakeInit(object):
cfg = {'def_log_file': self.log1,
'output': {'all': '|tee -a {0}'.format(self.log2)}}
- paths = mypaths(cloud_dir=self.artifact_dir)
+ # Ensure cloud_dir has a trailing slash, to match real behaviour
+ paths = mypaths(cloud_dir='{}/'.format(self.artifact_dir))
def __init__(self, ds_deps):
pass