From 0fb85fdd6fa2a4e1ddc8334ff411174c329ab1b9 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Dec 13 2019 10:34:25 +0000 Subject: Remove whole mock directory in /var/lib Originally the code removed only the chroot subdirectory, leaving behind results subdir and some log files. This was all together about 300K. However these files would not be cleaned by anything. We don't need to delete the logs in /tmp/, since those are tiny and would eventually be cleaned on reboot. --- diff --git a/server/odcs/server/mock_runroot.py b/server/odcs/server/mock_runroot.py index 491f6a6..2fcf136 100644 --- a/server/odcs/server/mock_runroot.py +++ b/server/odcs/server/mock_runroot.py @@ -154,7 +154,7 @@ def rmtree_skip_mounts(rootdir, mounts, rootdir_mounts=None): def cleanup_old_runroots(): """ - Checks the /var/lib/mock diretory for old runroot chroots and remove them. + Checks the /var/lib/mock directory for old runroot chroots and remove them. Those chroots can be lost there for example when the host reboots in the middle of runroot generation or in case Pungi task gets killed for @@ -167,14 +167,14 @@ def cleanup_old_runroots(): mounts = [conf.target_dir] + conf.runroot_extra_mounts mock_root = "/var/lib/mock" for runroot_key in os.listdir(mock_root): - chroot_path = os.path.join(mock_root, runroot_key, "root") - # Skip the chroot_path if it does not exist or is not old enough. + mock_dir = os.path.join(mock_root, runroot_key) + # Skip the mock_dir if it is not old enough. try: - if os.stat(chroot_path).st_mtime > now - conf.pungi_timeout: + if os.stat(mock_dir).st_mtime > now - conf.pungi_timeout: continue except OSError: continue - rmtree_skip_mounts(chroot_path, mounts) + rmtree_skip_mounts(mock_dir, mounts) def runroot_tmp_path(runroot_key): diff --git a/server/tests/test_mock_runroot.py b/server/tests/test_mock_runroot.py index 3fbfdee..2590a32 100644 --- a/server/tests/test_mock_runroot.py +++ b/server/tests/test_mock_runroot.py @@ -168,14 +168,14 @@ class TestMockRunroot(unittest.TestCase): def mocked_stat(path): stat_result = MagicMock() - if path.endswith("/foo/root"): + if path.endswith("/foo"): # The "foo/root" is 1 day old, so should be removed. stat_result.st_mtime = time.time() - 24 * 3600 - elif path.endswith("/already-removed/root"): + elif path.endswith("/already-removed"): # The "already-removed/root" is already removed, so raise an # exception. raise OSError("No such file") - elif path.endswith("/bar/root"): + elif path.endswith("/bar"): # The "bar/root" is just 10 seconds old, so should not be # removed. stat_result.st_mtime = time.time() - 10 @@ -186,4 +186,4 @@ class TestMockRunroot(unittest.TestCase): cleanup_old_runroots() - rmtree_skip_mounts.assert_called_once_with("/var/lib/mock/foo/root", AnyStringWith("test_composes")) + rmtree_skip_mounts.assert_called_once_with("/var/lib/mock/foo", AnyStringWith("test_composes"))