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
diff --git a/cloudinit/cmd/clean.py b/cloudinit/cmd/clean.py
index de22f7f..28ee7b8 100644
--- a/cloudinit/cmd/clean.py
+++ b/cloudinit/cmd/clean.py
@@ -5,12 +5,13 @@
5"""Define 'clean' utility and handler as part of cloud-init commandline."""5"""Define 'clean' utility and handler as part of cloud-init commandline."""
66
7import argparse7import argparse
8import glob
8import os9import os
9import sys10import sys
1011
11from cloudinit.stages import Init12from cloudinit.stages import Init
12from cloudinit.util import (13from cloudinit.util import (
13 ProcessExecutionError, chdir, del_dir, del_file, get_config_logfiles,14 ProcessExecutionError, del_dir, del_file, get_config_logfiles,
14 is_link, subp)15 is_link, subp)
1516
1617
@@ -61,18 +62,17 @@ def remove_artifacts(remove_logs, remove_seed=False):
6162
62 if not os.path.isdir(init.paths.cloud_dir):63 if not os.path.isdir(init.paths.cloud_dir):
63 return 0 # Artifacts dir already cleaned64 return 0 # Artifacts dir already cleaned
64 with chdir(init.paths.cloud_dir):65 for path in glob.glob('%s/*' % init.paths.cloud_dir):
65 for path in os.listdir('.'):66 if path == '%s/seed' % init.paths.cloud_dir and not remove_seed:
66 if path == 'seed' and not remove_seed:67 continue
67 continue68 try:
68 try:69 if os.path.isdir(path) and not is_link(path):
69 if os.path.isdir(path) and not is_link(path):70 del_dir(path)
70 del_dir(path)71 else:
71 else:72 del_file(path)
72 del_file(path)73 except OSError as e:
73 except OSError as e:74 error('Could not remove {0}: {1}'.format(path, str(e)))
74 error('Could not remove {0}: {1}'.format(path, str(e)))75 return 1
75 return 1
76 return 076 return 0
7777
7878
diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py
index 5a3ec3b..15c3294 100644
--- a/cloudinit/cmd/tests/test_clean.py
+++ b/cloudinit/cmd/tests/test_clean.py
@@ -136,7 +136,8 @@ class TestClean(CiTestCase):
136 clean.remove_artifacts, remove_logs=False)136 clean.remove_artifacts, remove_logs=False)
137 self.assertEqual(1, retcode)137 self.assertEqual(1, retcode)
138 self.assertEqual(138 self.assertEqual(
139 'ERROR: Could not remove dir1: oops\n', m_stderr.getvalue())139 'ERROR: Could not remove %s/dir1: oops\n' % self.artifact_dir,
140 m_stderr.getvalue())
140141
141 def test_handle_clean_args_reboots(self):142 def test_handle_clean_args_reboots(self):
142 """handle_clean_args_reboots when reboot arg is provided."""143 """handle_clean_args_reboots when reboot arg is provided."""

Subscribers

People subscribed via source and target branches