Merge ~chad.smith/cloud-init:clean-unlink-symlinks into cloud-init:master

Proposed by Chad Smith
Status: Merged
Approved by: Chad Smith
Approved revision: 784e7c1c9195f21730f143624842cae641fe7775
Merge reported by: Chad Smith
Merged at revision: 0b5bacb1761aefa74adb79bd1683d614bdf8c998
Proposed branch: ~chad.smith/cloud-init:clean-unlink-symlinks
Merge into: cloud-init:master
Diff against target: 60 lines (+21/-3)
2 files modified
cloudinit/cmd/clean.py (+3/-2)
cloudinit/cmd/tests/test_clean.py (+18/-1)
Reviewer Review Type Date Requested Status
Chad Smith Abstain
Server Team CI bot continuous-integration Approve
Scott Moser Approve
Review via email: mp+335671@code.launchpad.net

Commit message

cli: cloud-init clean handles symlinks

Fix cloud-init clean subcommand to unlink symlinks instead of calling
del_dir.

LP: #1741093

Description of the change

cli: cloud-init clean handles symlinks

Fix cloud-init clean subcommand to unlink symlinks instead of calling
del_dir.

LP: #1741093

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

looks good, thank you.

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

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

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

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

Thank you for your merge proposal.

Your branch has been set to 'Work in progress'.
Please set the branch back to 'Needs Review' after resolving the issues below.

Thanks again,
Your friendly neighborhood cloud-init robot.

Please fix the following issues:
------------------------------
No commit message in Launchpad
------------------------------

For more information, see commit message guidelines at
https://cloudinit.readthedocs.io/en/latest/topics/hacking.html#do-these-things-for-each-feature-or-bug

review: Needs Fixing
Revision history for this message
Chad Smith (chad.smith) :
review: Abstain
Revision history for this message
Chad Smith (chad.smith) wrote :

Thank you for your merge proposal.

Your branch has been set to 'Work in progress'.
Please set the branch back to 'Needs Review' after resolving the issues below.

Thanks again,
Your friendly neighborhood cloud-init robot.

Please fix the following issues:
------------------------------
Commit message lints:
 - Expected empty line on line 2 of the commit message
------------------------------

For more information, see commit message guidelines at
https://cloudinit.readthedocs.io/en/latest/topics/hacking.html#do-these-things-for-each-feature-or-bug

review: Needs Fixing
Revision history for this message
Chad Smith (chad.smith) :
review: Abstain

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 81797b1..de22f7f 100644
3--- a/cloudinit/cmd/clean.py
4+++ b/cloudinit/cmd/clean.py
5@@ -10,7 +10,8 @@ import sys
6
7 from cloudinit.stages import Init
8 from cloudinit.util import (
9- ProcessExecutionError, chdir, del_dir, del_file, get_config_logfiles, subp)
10+ ProcessExecutionError, chdir, del_dir, del_file, get_config_logfiles,
11+ is_link, subp)
12
13
14 def error(msg):
15@@ -65,7 +66,7 @@ def remove_artifacts(remove_logs, remove_seed=False):
16 if path == 'seed' and not remove_seed:
17 continue
18 try:
19- if os.path.isdir(path):
20+ if os.path.isdir(path) and not is_link(path):
21 del_dir(path)
22 else:
23 del_file(path)
24diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py
25index 1379740..6713af4 100644
26--- a/cloudinit/cmd/tests/test_clean.py
27+++ b/cloudinit/cmd/tests/test_clean.py
28@@ -1,7 +1,7 @@
29 # This file is part of cloud-init. See LICENSE file for license information.
30
31 from cloudinit.cmd import clean
32-from cloudinit.util import ensure_dir, write_file
33+from cloudinit.util import ensure_dir, sym_link, write_file
34 from cloudinit.tests.helpers import CiTestCase, wrap_and_call, mock
35 from collections import namedtuple
36 import os
37@@ -60,6 +60,23 @@ class TestClean(CiTestCase):
38 self.assertTrue(os.path.exists(self.log2), 'Missing expected file')
39 self.assertEqual(0, retcode)
40
41+ def test_remove_artifacts_removes_unlinks_symlinks(self):
42+ """remove_artifacts cleans artifacts dir unlinking any symlinks."""
43+ dir1 = os.path.join(self.artifact_dir, 'dir1')
44+ ensure_dir(dir1)
45+ symlink = os.path.join(self.artifact_dir, 'mylink')
46+ sym_link(dir1, symlink)
47+
48+ retcode = wrap_and_call(
49+ 'cloudinit.cmd.clean',
50+ {'Init': {'side_effect': self.init_class}},
51+ clean.remove_artifacts, remove_logs=False)
52+ self.assertEqual(0, retcode)
53+ for path in (dir1, symlink):
54+ self.assertFalse(
55+ os.path.exists(path),
56+ 'Unexpected {0} dir'.format(path))
57+
58 def test_remove_artifacts_removes_artifacts_skipping_seed(self):
59 """remove_artifacts cleans artifacts dir with exception of seed dir."""
60 dirs = [

Subscribers

People subscribed via source and target branches