summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2023-05-09 16:03:09 -0600
committerGitHub <noreply@github.com>2023-05-09 17:03:09 -0500
commit6cc09f3c422971aa79fd0cf88864796eca133c2b (patch)
tree6bbb924d025b4486a619fcce487aadeb1c8c7f0c
parenta0f5279b057853528db428e1cb24f227eed9280e (diff)
downloadcloud-init-git-6cc09f3c422971aa79fd0cf88864796eca133c2b.tar.gz
tests: avoid leaks to underlying filesystem for /etc/cloud/clean.d (#2251)
-rw-r--r--tests/unittests/cmd/test_clean.py47
1 files changed, 28 insertions, 19 deletions
diff --git a/tests/unittests/cmd/test_clean.py b/tests/unittests/cmd/test_clean.py
index c5385b79..02dce7ab 100644
--- a/tests/unittests/cmd/test_clean.py
+++ b/tests/unittests/cmd/test_clean.py
@@ -123,12 +123,15 @@ class TestClean:
symlink = clean_paths.cloud_dir.join("mylink")
sym_link(dir1.strpath, symlink.strpath)
- retcode = wrap_and_call(
- "cloudinit.cmd.clean",
- {"Init": {"side_effect": init_class}},
- clean.remove_artifacts,
- remove_logs=False,
- )
+ with mock.patch.object(
+ cloudinit.settings, "CLEAN_RUNPARTS_DIR", clean_paths.clean_dir
+ ):
+ retcode = wrap_and_call(
+ "cloudinit.cmd.clean",
+ {"Init": {"side_effect": init_class}},
+ clean.remove_artifacts,
+ remove_logs=False,
+ )
assert 0 == retcode
for path in (dir1, symlink):
assert path.exists() is False, f"Unexpected {path} found"
@@ -146,12 +149,15 @@ class TestClean:
for _dir in dirs:
ensure_dir(_dir)
- retcode = wrap_and_call(
- "cloudinit.cmd.clean",
- {"Init": {"side_effect": init_class}},
- clean.remove_artifacts,
- remove_logs=False,
- )
+ with mock.patch.object(
+ cloudinit.settings, "CLEAN_RUNPARTS_DIR", clean_paths.clean_dir
+ ):
+ retcode = wrap_and_call(
+ "cloudinit.cmd.clean",
+ {"Init": {"side_effect": init_class}},
+ clean.remove_artifacts,
+ remove_logs=False,
+ )
assert 0 == retcode
for expected_dir in dirs[:2]:
assert expected_dir.exists() is True, f"Missing {expected_dir}"
@@ -171,13 +177,16 @@ class TestClean:
for _dir in dirs:
ensure_dir(_dir)
- retcode = wrap_and_call(
- "cloudinit.cmd.clean",
- {"Init": {"side_effect": init_class}},
- clean.remove_artifacts,
- remove_logs=False,
- remove_seed=True,
- )
+ with mock.patch.object(
+ cloudinit.settings, "CLEAN_RUNPARTS_DIR", clean_paths.clean_dir
+ ):
+ retcode = wrap_and_call(
+ "cloudinit.cmd.clean",
+ {"Init": {"side_effect": init_class}},
+ clean.remove_artifacts,
+ remove_logs=False,
+ remove_seed=True,
+ )
assert 0 == retcode
assert (
clean_paths.cloud_dir.exists() is True