autotest: make lsb_release_content as a property for re-use.
BUG=chromium:718532
TEST=Run
host = hosts.create_host('chromeos2-row8-rack4-host16.cros')
host.get_release_version()
host.get_release_version() (run it twice to test whether self.run
is called again)
Change-Id: Ida4d3ff22be2cde49c2379281abf053f1e75b5bd
Reviewed-on: https://chromium-review.googlesource.com/502736
Commit-Ready: Xixuan Wu <xixuan@chromium.org>
Tested-by: Xixuan Wu <xixuan@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
diff --git a/server/hosts/cros_host.py b/server/hosts/cros_host.py
index 6d6d070..bca9897 100644
--- a/server/hosts/cros_host.py
+++ b/server/hosts/cros_host.py
@@ -11,6 +11,7 @@
import common
from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib import autotemp
+from autotest_lib.client.common_lib import decorators
from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib import global_config
from autotest_lib.client.common_lib import hosts
@@ -330,6 +331,16 @@
self.plankton = None
+ @decorators.cached_property
+ def _lsb_release_content(self):
+ """Return lsb_release_content of the host.
+
+ @return the string of the content in /etc/lsb-release file
+ """
+ return self.run(
+ 'cat "%s"' % client_constants.LSB_RELEASE).stdout.strip()
+
+
def _get_cros_repair_image_name(self):
info = self.host_info_store.get()
if info.board is None:
@@ -1349,10 +1360,8 @@
@returns The version string in lsb-release, under attribute
CHROMEOS_RELEASE_VERSION.
"""
- lsb_release_content = self.run(
- 'cat "%s"' % client_constants.LSB_RELEASE).stdout.strip()
return lsbrelease_utils.get_chromeos_release_version(
- lsb_release_content=lsb_release_content)
+ lsb_release_content=self._lsb_release_content)
def verify_cros_version_label(self):