#307 Remove whole mock directory in /var/lib
Merged 4 years ago by lsedlar. Opened 4 years ago by lsedlar.
lsedlar/odcs cleanup-mock-files  into  master

@@ -154,7 +154,7 @@ 

  

  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 @@ 

      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):

@@ -168,14 +168,14 @@ 

  

          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 @@ 

  

          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"))

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.

rebased onto 0fb85fd

4 years ago

Pull-Request has been merged by lsedlar

4 years ago