Skip to content

Commit 109772c

Browse files
Daniel WatkinsServer Team CI Bot
authored andcommitted
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
1 parent 5352dd9 commit 109772c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

cloudinit/cmd/clean.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def remove_artifacts(remove_logs, remove_seed=False):
6262

6363
if not os.path.isdir(init.paths.cloud_dir):
6464
return 0 # Artifacts dir already cleaned
65+
seed_path = os.path.join(init.paths.cloud_dir, 'seed')
6566
for path in glob.glob('%s/*' % init.paths.cloud_dir):
66-
if path == '%s/seed' % init.paths.cloud_dir and not remove_seed:
67+
if path == seed_path and not remove_seed:
6768
continue
6869
try:
6970
if os.path.isdir(path) and not is_link(path):

cloudinit/cmd/tests/test_clean.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def setUp(self):
2222
class FakeInit(object):
2323
cfg = {'def_log_file': self.log1,
2424
'output': {'all': '|tee -a {0}'.format(self.log2)}}
25-
paths = mypaths(cloud_dir=self.artifact_dir)
25+
# Ensure cloud_dir has a trailing slash, to match real behaviour
26+
paths = mypaths(cloud_dir='{}/'.format(self.artifact_dir))
2627

2728
def __init__(self, ds_deps):
2829
pass

0 commit comments

Comments
 (0)