cros deploy: merge temp dir management into one ssh connection
We run two mkdir commands right after each other, so merge that into one
call to avoid making a second ssh connection.
We also run a clean up func on the sub-temp dirs even when we only emerged
one package which means the final tear down looks like:
ssh ... rm -r /usr/local/tmp/cros-deploy/tmp.Lf7Uec55tZ/portage-tmp
ssh ... rm -r /usr/local/tmp/cros-deploy/tmp.Lf7Uec55tZ
That first connection is entirely wasted time. Since we do explicitly
want to clean up the tempdir while emerging multiple packages to keep
from running out of space, merge this rm call with the initial mkdir by
using the shell aspect. For the final emerge, we rely on teardown to
do the cleaning.
BUG=brillo:985
TEST=`cros deploy` still works and uses fewer connections
TEST=`./cbuildbot/run_tests` passes
Change-Id: I600570c6beef6d0039b8d5edb3829d6103d1fdf0
Reviewed-on: https://chromium-review.googlesource.com/272731
Reviewed-by: Yiming Chen <yimingc@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/cli/deploy.py b/cli/deploy.py
index a1ae51a..14a9a18 100644
--- a/cli/deploy.py
+++ b/cli/deploy.py
@@ -771,14 +771,18 @@
pkg_name = os.path.basename(latest_pkg)
pkg_dirname = os.path.basename(os.path.dirname(latest_pkg))
pkg_dir = os.path.join(pkgroot, pkg_dirname)
- device.RunCommand(['mkdir', '-p', pkg_dir], remote_sudo=True)
+ portage_tmpdir = os.path.join(device.work_dir, 'portage-tmp')
+ # Clean out the dirs first if we had a previous emerge on the device so as to
+ # free up space for this emerge. The last emerge gets implicitly cleaned up
+ # when the device connection deletes its work_dir.
+ device.RunCommand(
+ ['rm', '-rf', pkg_dir, portage_tmpdir, '&&',
+ 'mkdir', '-p', pkg_dir, portage_tmpdir], remote_sudo=True)
# This message is read by BrilloDeployOperation.
logging.notice('Copying %s to device.', pkg_name)
device.CopyToDevice(latest_pkg, pkg_dir, remote_sudo=True)
- portage_tmpdir = os.path.join(device.work_dir, 'portage-tmp')
- device.RunCommand(['mkdir', '-p', portage_tmpdir], remote_sudo=True)
logging.info('Use portage temp dir %s', portage_tmpdir)
# This message is read by BrilloDeployOperation.
@@ -811,10 +815,6 @@
raise
else:
logging.notice('%s has been installed.', pkg_name)
- finally:
- # Free up the space for other packages.
- device.RunCommand(['rm', '-rf', portage_tmpdir, pkg_dir],
- error_code_ok=True, remote_sudo=True)
def _Unmerge(device, pkg, root):