autotest: cleanup transition stable_version logic in post autotest world
BUG=chromium:1068918
TEST=run repair locally
Change-Id: I0f04e6b494170d63118c4ede9d8cf7e877a11267
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2146065
Tested-by: Garry Wang <[email protected]>
Reviewed-by: Gregory Nisbet <[email protected]>
Commit-Queue: Garry Wang <[email protected]>
diff --git a/server/afe_utils.py b/server/afe_utils.py
index bcd2764..d0b65de 100644
--- a/server/afe_utils.py
+++ b/server/afe_utils.py
@@ -15,10 +15,9 @@
import urlparse
from autotest_lib.client.common_lib import global_config
+from autotest_lib.client.common_lib import error
from autotest_lib.server.cros import autoupdater
from autotest_lib.server.cros import provision
-from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
-from autotest_lib.site_utils import stable_version_classify as sv
from autotest_lib.server import site_utils as server_utils
from autotest_lib.server.cros.dynamic_suite import constants as ds_constants
from autotest_lib.server.cros.dynamic_suite import tools
@@ -33,13 +32,6 @@
from chromite.lib import remote_access
-# TODO(crbug.com/1058095) -- the autotest frontend has been turned down
-# reduce the timeouts so that we spend less time failing to contact it.
-AFE = frontend_wrappers.RetryingAFE(timeout_min=(1.0/60), delay_sec=1)
-_CROS_VERSION_MAP = AFE.get_stable_version_map(AFE.CROS_IMAGE_TYPE)
-_FIRMWARE_VERSION_MAP = AFE.get_stable_version_map(AFE.FIRMWARE_IMAGE_TYPE)
-_FAFT_VERSION_MAP = AFE.get_stable_version_map(AFE.FAFT_IMAGE_TYPE)
-
_CONFIG = global_config.global_config
ENABLE_DEVSERVER_TRIGGER_AUTO_UPDATE = _CONFIG.get_config_value(
'CROS', 'enable_devserver_trigger_auto_update', type=bool,
@@ -75,63 +67,50 @@
return "%s-release/%s" % (board, version)
-def get_stable_cros_image_name_v2(info, _config_override=None):
- if sv.classify_board(info.board, _config_override=_config_override) == sv.FROM_HOST_CONFIG:
- logging.debug("get_stable_cros_image_name_v2: board %s from host_info_store" % info.board)
- out = _format_image_name(board=info.board, version=info.cros_stable_version)
- _log_image_name(out)
- return out
- logging.debug("get_stable_cros_image_name_v2: board %s from autotest frontend" % info.board)
- return get_stable_cros_image_name(info.board)
-
-
-def get_stable_cros_image_name(board):
+def get_stable_cros_image_name_v2(host_info):
"""Retrieve the Chrome OS stable image name for a given board.
- @param board: Board to lookup.
+ @param host_info: a host_info_store object.
@returns Name of a Chrome OS image to be installed in order to
repair the given board.
"""
- return _CROS_VERSION_MAP.get_image_name(board)
+ if not host_info.cros_stable_version:
+ raise error.AutoservError("No cros stable_version found"
+ " in host_info_store.")
+
+ logging.debug("Get cros stable_version for board: %s",
+ getattr(host_info, "board", None))
+ out = _format_image_name(board=host_info.board,
+ version=host_info.cros_stable_version)
+ _log_image_name(out)
+ return out
-def get_stable_firmware_version_v2(info, _config_override=None):
- if sv.classify_model(info.model, _config_override=_config_override) == sv.FROM_HOST_CONFIG:
- logging.debug("get_stable_firmware_version_v2: model %s from host_info_store" % info.model)
- return info.firmware_stable_version
- logging.debug("get_stable_cros_image_name_v2: model %s from autotest frontend" % info.model)
- return get_stable_firmware_version(info.model)
-
-
-def get_stable_firmware_version(model):
+def get_stable_firmware_version_v2(host_info):
"""Retrieve the stable firmware version for a given model.
- @param model: Model to lookup.
+ @param host_info: a host_info_store object.
@returns A version of firmware to be installed via
`chromeos-firmwareupdate` from a repair build.
"""
- return _FIRMWARE_VERSION_MAP.get_version(model)
+ logging.debug("Get firmware stable_version for model: %s",
+ getattr(host_info, "model", None))
+ return host_info.firmware_stable_version
-def get_stable_faft_version_v2(info, _config_override=None):
- if sv.classify_board(info.board, _config_override=_config_override) == sv.FROM_HOST_CONFIG:
- logging.debug("get_stable_faft_version_v2: model %s from host_info_store" % info.model)
- return info.faft_stable_version
- logging.debug("get_stable_faft_version_v2: model %s from autotest frontend" % info.model)
- return get_stable_faft_version(info.board)
-
-
-def get_stable_faft_version(board):
+def get_stable_faft_version_v2(host_info):
"""Retrieve the stable firmware version for FAFT DUTs.
- @param board: Board to lookup.
+ @param host_info: a host_info_store object.
@returns A version of firmware to be installed in order to
repair firmware on a DUT used for FAFT testing.
"""
- return _FAFT_VERSION_MAP.get_version(board)
+ logging.debug("Get faft stable_version for model: %s",
+ getattr(host_info, "model", None))
+ return host_info.faft_stable_version
def clean_provision_labels(host):
diff --git a/server/afe_utils_unittest.py b/server/afe_utils_unittest.py
index 0afcf6e..9874de0 100644
--- a/server/afe_utils_unittest.py
+++ b/server/afe_utils_unittest.py
@@ -9,13 +9,6 @@
from autotest_lib.server import afe_utils
-class FakeConfigFromHost(object):
- def get_config_value(self, _namespace, item, **kargs):
- return {
- "stable_version_config_repo_enable": True,
- "stable_version_config_repo_opt_in_boards": ":all",
- }[item]
-
class FakeHostInfo(object):
def __init__(self, board, cros_stable_version, servo_cros_stable_version):
self._board = board
@@ -44,8 +37,7 @@
cros_stable_version="R1-2.3.4"
)
expected = "xxx-board-release/R1-2.3.4"
- config = FakeConfigFromHost()
- out = afe_utils.get_stable_cros_image_name_v2(info=host_info, _config_override=config)
+ out = afe_utils.get_stable_cros_image_name_v2(host_info=host_info)
self.assertEqual(out, expected)
diff --git a/server/hosts/cros_host.py b/server/hosts/cros_host.py
index cb42ebd..66acf8b 100644
--- a/server/hosts/cros_host.py
+++ b/server/hosts/cros_host.py
@@ -404,17 +404,18 @@
@returns: current stable cros image name for this host.
"""
- board = self.host_info_store.get().board
- if not board:
+ info = self.host_info_store.get()
+ if not info.board:
logging.warn('No board label value found. Trying to infer '
'from the host itself.')
try:
- board = self.get_board().split(':')[1]
+ info.labels.append(self.get_board())
except (error.AutoservRunError, error.AutoservSSHTimeout) as e:
logging.error('Also failed to get the board name from the DUT '
'itself. %s.', str(e))
- raise error.AutoservError('Cannot obtain repair image name.')
- return afe_utils.get_stable_cros_image_name_v2(self.host_info_store.get())
+ raise error.AutoservError('Cannot determine board of the DUT'
+ ' while getting repair image name.')
+ return afe_utils.get_stable_cros_image_name_v2(info)
def host_version_prefix(self, image):
diff --git a/site_utils/stable_version_classify.py b/site_utils/stable_version_classify.py
deleted file mode 100644
index c4dd66f..0000000
--- a/site_utils/stable_version_classify.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (c) 2019 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-from __future__ import print_function
-from __future__ import unicode_literals
-
-import common
-from autotest_lib.client.common_lib.global_config import global_config
-
-FROM_AFE = "FROM_AFE"
-FROM_HOST_CONFIG = "FROM_HOST_CONFIG"
-
-
-def _config(_config_override):
- config = global_config if _config_override is None else _config_override
- enabled = config.get_config_value(
- 'CROS', 'stable_version_config_repo_enable', type=bool, default=False
- )
- return config, enabled
-
-
-def classify_board(board, _config_override=None):
- """
- determine what the appropriate information source is for a given board.
-
- @param board string -- board name
- @param _config_override -- optional global config object
-
- @returns FROM_AFE or FROM_HOST_CONFIG
- """
- config, enabled = _config(_config_override)
- if enabled:
- boards = config.get_config_value(
- 'CROS', 'stable_version_config_repo_opt_in_boards', type=list, default=[],
- )
- if ':all' in boards or board in boards:
- return FROM_HOST_CONFIG
- return FROM_AFE
-
-
-def classify_model(model, _config_override=None):
- """
- determine what the appropriate information source is for a given model.
-
- @param board string -- board name
- @param _config_override -- optional global config object
-
- @returns FROM_AFE or FROM_HOST_CONFIG
- """
- config, enabled = _config(_config_override)
- if enabled:
- models = config.get_config_value(
- 'CROS', 'stable_version_config_repo_opt_in_models', type=list, default=[],
- )
- if ':all' in models or model in models:
- return FROM_HOST_CONFIG
- return FROM_AFE
diff --git a/site_utils/stable_version_classify_unittest.py b/site_utils/stable_version_classify_unittest.py
deleted file mode 100644
index 237f0d9..0000000
--- a/site_utils/stable_version_classify_unittest.py
+++ /dev/null
@@ -1,105 +0,0 @@
-#!/usr/bin/python2
-# Copyright (c) 2019 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-from __future__ import print_function
-from __future__ import unicode_literals
-import unittest
-import common
-from autotest_lib.site_utils import stable_version_classify as sv
-
-
-class StableVersionClassifyModelBoard(unittest.TestCase):
- """test that classify board and classify model report the
- correct information source based on the config values"""
- def test_empty_config(self):
- fc = _FakeConfig(enable=False, boards=[], models=[])
- self.assertEqual(
- sv.classify_board('xxx-board', _config_override=fc),
- sv.FROM_AFE,
- )
- self.assertEqual(
- sv.classify_model('xxx-model', _config_override=fc),
- sv.FROM_AFE
- )
-
- def test_empty_config_but_enabled(self):
- fc = _FakeConfig(enable=True, boards=[], models=[])
- self.assertEqual(
- sv.classify_board('xxx-board', _config_override=fc),
- sv.FROM_AFE,
- )
- self.assertEqual(
- sv.classify_model('xxx-model', _config_override=fc),
- sv.FROM_AFE
- )
-
- def test_just_nocturne_config(self):
- fc = _FakeConfig(enable=True, boards=[u'nocturne'], models=[u'nocturne'])
- self.assertEqual(
- sv.classify_board('xxx-board', _config_override=fc),
- sv.FROM_AFE,
- )
- self.assertEqual(
- sv.classify_model('xxx-model', _config_override=fc),
- sv.FROM_AFE,
- )
- self.assertEqual(
- sv.classify_board('nocturne', _config_override=fc),
- sv.FROM_HOST_CONFIG,
- )
- self.assertEqual(
- sv.classify_model('nocturne', _config_override=fc),
- sv.FROM_HOST_CONFIG,
- )
-
-
- def test_enable_all(self):
- fc = _FakeConfig(enable=True, boards=[u':all'], models=[u':all'])
- self.assertEqual(
- sv.classify_board('xxx-board', _config_override=fc),
- sv.FROM_HOST_CONFIG,
- )
- self.assertEqual(
- sv.classify_model('xxx-model', _config_override=fc),
- sv.FROM_HOST_CONFIG,
- )
- self.assertEqual(
- sv.classify_board('nocturne', _config_override=fc),
- sv.FROM_HOST_CONFIG,
- )
- self.assertEqual(
- sv.classify_model('nocturne', _config_override=fc),
- sv.FROM_HOST_CONFIG,
- )
-
-
-_TEXT = (type(u''), type(b''))
-
-
-class _FakeConfig(object):
- def __init__(self, boards=None, models=None, enable=None):
- assert isinstance(boards, list)
- assert isinstance(models, list)
- assert isinstance(enable, bool)
- self.boards = boards
- self.models = models
- self.enable = enable
-
- def get_config_value(self, namespace, key, type=None, default=None):
- assert isinstance(namespace, _TEXT)
- assert isinstance(key, _TEXT)
- assert namespace == 'CROS'
- if key == 'stable_version_config_repo_enable':
- return self.enable
- if key == 'stable_version_config_repo_opt_in_boards':
- return self.boards
- if key == 'stable_version_config_repo_opt_in_models':
- return self.models
- assert False, "unrecognized key %s" % key
-
-
-
-if __name__ == '__main__':
- unittest.main()