cros deploy: optimize installed package check
Avoid sshing to the DUT twice as each one is not cheap.
BUG=None
TEST=`cros deploy` with uninstalled & installed packages still work
Change-Id: I7b5ae55edf0023e731e75484b2163e4706c3823d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2651158
Reviewed-by: Jae Hoon Kim <kimjae@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 f677fcf..9f04443 100644
--- a/cli/deploy.py
+++ b/cli/deploy.py
@@ -1073,12 +1073,13 @@
if from_dut:
# On DUT, |pkg_path| is the directory which contains environment file.
environment_path = os.path.join(pkg_path, _ENVIRONMENT_FILENAME)
- result = device.run(['test', '-f', environment_path],
- check=False, encoding=None)
- if result.returncode == 1:
+ result = device.run(['bzip2', '-d', '-c', environment_path], check=False,
+ encoding=None)
+ if result.returncode:
# The package is not installed on DUT yet. Skip extracting info.
- return None, None
- result = device.run(['bzip2', '-d', '-c', environment_path], encoding=None)
+ if not result.stdout and b'No such file or directory' in result.stderr:
+ return None, None
+ result.check_returncode()
environment_content = result.output
else:
# On host, pkg_path is tbz2 file which contains environment file.