Merge ~chad.smith/cloud-init:bug/1795508-clean-no-trace-if-cwd-gets-deleted into cloud-init:master

Proposed by Chad Smith
Status: Merged
Approved by: Ryan Harper
Approved revision: e4ae4c72414130e149c9fac05f08958081acbf78
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~chad.smith/cloud-init:bug/1795508-clean-no-trace-if-cwd-gets-deleted
Merge into: cloud-init:master
Diff against target: 63 lines (+15/-14)
2 files modified
cloudinit/cmd/clean.py (+13/-13)
cloudinit/cmd/tests/test_clean.py (+2/-1)
Reviewer Review Type Date Requested Status
Ryan Harper Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+362229@code.launchpad.net

Commit message

clean: cloud-init clean should not trace when run from within cloud_dir

Avoid traceback when cloud-init clean is run from within
/var/lib/cloud/ deleted dirs.

LP: #1795508

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:26972728ee53c9942c770776cb34befe1610c43c
https://jenkins.ubuntu.com/server/job/cloud-init-ci/535/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/535/rebuild

review: Needs Fixing (continuous-integration)
e4ae4c7... by Chad Smith

clean: cloud-init clean should not trace when run from within cloud_dir

Avoid traceback when cloud-init clean is run from within
/var/lib/cloud/ deleted dirs.

LP: #1795508

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:e4ae4c72414130e149c9fac05f08958081acbf78
https://jenkins.ubuntu.com/server/job/cloud-init-ci/536/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/536/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/cmd/clean.py b/cloudinit/cmd/clean.py
2index de22f7f..28ee7b8 100644
3--- a/cloudinit/cmd/clean.py
4+++ b/cloudinit/cmd/clean.py
5@@ -5,12 +5,13 @@
6 """Define 'clean' utility and handler as part of cloud-init commandline."""
7
8 import argparse
9+import glob
10 import os
11 import sys
12
13 from cloudinit.stages import Init
14 from cloudinit.util import (
15- ProcessExecutionError, chdir, del_dir, del_file, get_config_logfiles,
16+ ProcessExecutionError, del_dir, del_file, get_config_logfiles,
17 is_link, subp)
18
19
20@@ -61,18 +62,17 @@ def remove_artifacts(remove_logs, remove_seed=False):
21
22 if not os.path.isdir(init.paths.cloud_dir):
23 return 0 # Artifacts dir already cleaned
24- with chdir(init.paths.cloud_dir):
25- for path in os.listdir('.'):
26- if path == 'seed' and not remove_seed:
27- continue
28- try:
29- if os.path.isdir(path) and not is_link(path):
30- del_dir(path)
31- else:
32- del_file(path)
33- except OSError as e:
34- error('Could not remove {0}: {1}'.format(path, str(e)))
35- return 1
36+ for path in glob.glob('%s/*' % init.paths.cloud_dir):
37+ if path == '%s/seed' % init.paths.cloud_dir and not remove_seed:
38+ continue
39+ try:
40+ if os.path.isdir(path) and not is_link(path):
41+ del_dir(path)
42+ else:
43+ del_file(path)
44+ except OSError as e:
45+ error('Could not remove {0}: {1}'.format(path, str(e)))
46+ return 1
47 return 0
48
49
50diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py
51index 5a3ec3b..15c3294 100644
52--- a/cloudinit/cmd/tests/test_clean.py
53+++ b/cloudinit/cmd/tests/test_clean.py
54@@ -136,7 +136,8 @@ class TestClean(CiTestCase):
55 clean.remove_artifacts, remove_logs=False)
56 self.assertEqual(1, retcode)
57 self.assertEqual(
58- 'ERROR: Could not remove dir1: oops\n', m_stderr.getvalue())
59+ 'ERROR: Could not remove %s/dir1: oops\n' % self.artifact_dir,
60+ m_stderr.getvalue())
61
62 def test_handle_clean_args_reboots(self):
63 """handle_clean_args_reboots when reboot arg is provided."""

Subscribers

People subscribed via source and target branches