1# Copyright (c) 2019 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from __future__ import print_function 6from __future__ import unicode_literals 7 8import common 9from autotest_lib.client.common_lib.global_config import global_config 10 11FROM_AFE = "FROM_AFE" 12FROM_HOST_CONFIG = "FROM_HOST_CONFIG" 13 14 15def _config(_config_override): 16 config = global_config if _config_override is None else _config_override 17 enabled = config.get_config_value( 18 'CROS', 'stable_version_config_repo_enable', type=bool, default=False 19 ) 20 return config, enabled 21 22 23def classify_board(board, _config_override=None): 24 """ 25 determine what the appropriate information source is for a given board. 26 27 @param board string -- board name 28 @param _config_override -- optional global config object 29 30 @returns FROM_AFE or FROM_HOST_CONFIG 31 """ 32 config, enabled = _config(_config_override) 33 if enabled: 34 boards = config.get_config_value( 35 'CROS', 'stable_version_config_repo_opt_in_boards', type=list, default=[], 36 ) 37 if ':all' in boards or board in boards: 38 return FROM_HOST_CONFIG 39 return FROM_AFE 40 41 42def classify_model(model, _config_override=None): 43 """ 44 determine what the appropriate information source is for a given model. 45 46 @param board string -- board name 47 @param _config_override -- optional global config object 48 49 @returns FROM_AFE or FROM_HOST_CONFIG 50 """ 51 config, enabled = _config(_config_override) 52 if enabled: 53 models = config.get_config_value( 54 'CROS', 'stable_version_config_repo_opt_in_models', type=list, default=[], 55 ) 56 if ':all' in models or model in models: 57 return FROM_HOST_CONFIG 58 return FROM_AFE 59