From 6cc09f3c422971aa79fd0cf88864796eca133c2b Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Tue, 9 May 2023 16:03:09 -0600 Subject: tests: avoid leaks to underlying filesystem for /etc/cloud/clean.d (#2251) --- tests/unittests/cmd/test_clean.py | 47 +++++++++++++++++++++++---------------- 1 file 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 -- cgit v1.2.1