diff options
author | Chad Smith <chad.smith@canonical.com> | 2018-01-03 12:56:22 -0700 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2018-01-03 12:56:22 -0700 |
commit | 0b5bacb1761aefa74adb79bd1683d614bdf8c998 (patch) | |
tree | 14c5afbf617570e5b48f252e2fae2551f9920f0a /cloudinit/cmd/tests/test_clean.py | |
parent | 25ddc98e8dcd37272825f7044cf4487e3ade126b (diff) | |
download | vyos-cloud-init-0b5bacb1761aefa74adb79bd1683d614bdf8c998.tar.gz vyos-cloud-init-0b5bacb1761aefa74adb79bd1683d614bdf8c998.zip |
cli: cloud-init clean handles symlinks
Fix cloud-init clean subcommand to unlink symlinks instead of calling
del_dir.
LP: #1741093
Diffstat (limited to 'cloudinit/cmd/tests/test_clean.py')
-rw-r--r-- | cloudinit/cmd/tests/test_clean.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py index 1379740b..6713af4f 100644 --- a/cloudinit/cmd/tests/test_clean.py +++ b/cloudinit/cmd/tests/test_clean.py @@ -1,7 +1,7 @@ # This file is part of cloud-init. See LICENSE file for license information. from cloudinit.cmd import clean -from cloudinit.util import ensure_dir, write_file +from cloudinit.util import ensure_dir, sym_link, write_file from cloudinit.tests.helpers import CiTestCase, wrap_and_call, mock from collections import namedtuple import os @@ -60,6 +60,23 @@ class TestClean(CiTestCase): self.assertTrue(os.path.exists(self.log2), 'Missing expected file') self.assertEqual(0, retcode) + def test_remove_artifacts_removes_unlinks_symlinks(self): + """remove_artifacts cleans artifacts dir unlinking any symlinks.""" + dir1 = os.path.join(self.artifact_dir, 'dir1') + ensure_dir(dir1) + symlink = os.path.join(self.artifact_dir, 'mylink') + sym_link(dir1, symlink) + + retcode = wrap_and_call( + 'cloudinit.cmd.clean', + {'Init': {'side_effect': self.init_class}}, + clean.remove_artifacts, remove_logs=False) + self.assertEqual(0, retcode) + for path in (dir1, symlink): + self.assertFalse( + os.path.exists(path), + 'Unexpected {0} dir'.format(path)) + def test_remove_artifacts_removes_artifacts_skipping_seed(self): """remove_artifacts cleans artifacts dir with exception of seed dir.""" dirs = [ |