← Back to team overview

curtin-dev team mailing list archive

[Merge] ~raharper/curtin:fix/add-apt-clean-update-vmtest-regex into curtin:master

 

Ryan Harper has proposed merging ~raharper/curtin:fix/add-apt-clean-update-vmtest-regex into curtin:master.

Commit message:
distro: run apt-get clean after dist-upgrade, install, upgrade operations

Some vmtest scenarios install multiple large packages which consume storage
temporarily and in some cases prevent other install operations, like creating
an initramfs, from completing successfully.  This change introduces an
apt-get clean command run after dist-upgrade, install or upgrade actions.
This will clear out the local repositiry of retrieved package files restoring
space back to the filesystem.


Requested reviews:
  curtin developers (curtin-dev)

For more details, see:
https://code.launchpad.net/~raharper/curtin/+git/curtin/+merge/390562
-- 
Your team curtin developers is requested to review the proposed merge of ~raharper/curtin:fix/add-apt-clean-update-vmtest-regex into curtin:master.
diff --git a/curtin/distro.py b/curtin/distro.py
index e2af24a..82a4dd5 100644
--- a/curtin/distro.py
+++ b/curtin/distro.py
@@ -264,7 +264,7 @@ def apt_update(target=None, env=None, force=False, comment=None,
 
 
 def run_apt_command(mode, args=None, opts=None, env=None, target=None,
-                    execute=True, allow_daemons=False):
+                    execute=True, allow_daemons=False, clean=True):
     defopts = ['--quiet', '--assume-yes',
                '--option=Dpkg::options::=--force-unsafe-io',
                '--option=Dpkg::Options::=--force-confold']
@@ -289,7 +289,11 @@ def run_apt_command(mode, args=None, opts=None, env=None, target=None,
 
     apt_update(target, env=env, comment=' '.join(cmd))
     with ChrootableTarget(target, allow_daemons=allow_daemons) as inchroot:
-        return inchroot.subp(cmd, env=env)
+        cmd_rv = inchroot.subp(cmd, env=env)
+        if clean and mode in ['dist-upgrade', 'install', 'upgrade']:
+            inchroot.subp(['apt-get', 'clean'])
+
+    return cmd_rv
 
 
 def run_yum_command(mode, args=None, opts=None, env=None, target=None,
diff --git a/tests/unittests/test_distro.py b/tests/unittests/test_distro.py
index 23c3fba..380680c 100644
--- a/tests/unittests/test_distro.py
+++ b/tests/unittests/test_distro.py
@@ -449,6 +449,7 @@ class TestSystemUpgrade(CiTestCase):
         auto_remove = apt_base + ['autoremove']
         expected_calls = [
             mock.call(apt_cmd, env=env, target=paths.target_path(target)),
+            mock.call(['apt-get', 'clean'], target=paths.target_path(target)),
             mock.call(auto_remove, env=env, target=paths.target_path(target)),
         ]
         which_calls = [mock.call('eatmydata', target=target)]

Follow ups