blob: dcce3f52a06500fb044f438cc1ca057ac53d4d82 [file] [log] [blame]
Kevin Chenga2619dc2016-03-28 11:42:08 -07001# Copyright 2016 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
5"""This class defines the CrosHost Label class."""
6
C Shapiro05dd3222017-09-22 10:42:33 -06007import collections
Kevin Chenga2619dc2016-03-28 11:42:08 -07008import logging
Kevin Chenga2619dc2016-03-28 11:42:08 -07009import re
10
11import common
12
13from autotest_lib.client.bin import utils
Kevin Cheng80ad5732016-03-31 16:01:56 -070014from autotest_lib.client.common_lib import global_config
Kevin Chenga2619dc2016-03-28 11:42:08 -070015from autotest_lib.client.cros.audio import cras_utils
Kevin Chenga2619dc2016-03-28 11:42:08 -070016from autotest_lib.server.cros.dynamic_suite import constants as ds_constants
17from autotest_lib.server.hosts import base_label
18from autotest_lib.server.hosts import common_label
Garry Wang11b5e872020-03-11 15:14:08 -070019from autotest_lib.server.hosts import servo_constants
Kevin Cheng80ad5732016-03-31 16:01:56 -070020from autotest_lib.site_utils import hwid_lib
Otabek Kasimov40ccb972020-05-26 15:14:39 -070021from autotest_lib.site_utils.admin_audit import verifiers as audit_verify
22from autotest_lib.site_utils.admin_audit import constants as audit_const
Kevin Chenga2619dc2016-03-28 11:42:08 -070023
24# pylint: disable=missing-docstring
C Shapiro05dd3222017-09-22 10:42:33 -060025LsbOutput = collections.namedtuple('LsbOutput', ['unibuild', 'board'])
26
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -070027# fallback values if we can't contact the HWID server
28HWID_LABELS_FALLBACK = ['sku', 'phase', 'touchscreen', 'touchpad', 'variant', 'stylus']
29
Eshwar Narayan871a2c02020-02-06 11:15:24 -080030# Repair and Deploy taskName
31REPAIR_TASK_NAME = 'repair'
32DEPLOY_TASK_NAME = 'deploy'
33
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -070034
C Shapiro05dd3222017-09-22 10:42:33 -060035def _parse_lsb_output(host):
Allen Lia0c7afc2019-02-26 15:50:06 -080036 """Parses the LSB output and returns key data points for labeling.
C Shapiro05dd3222017-09-22 10:42:33 -060037
Allen Lia0c7afc2019-02-26 15:50:06 -080038 @param host: Host that the command will be executed against
39 @returns: LsbOutput with the result of parsing the /etc/lsb-release output
40 """
41 release_info = utils.parse_cmd_output('cat /etc/lsb-release',
42 run_method=host.run)
C Shapiro05dd3222017-09-22 10:42:33 -060043
Allen Lia0c7afc2019-02-26 15:50:06 -080044 unibuild = release_info.get('CHROMEOS_RELEASE_UNIBUILD') == '1'
45 return LsbOutput(unibuild, release_info['CHROMEOS_RELEASE_BOARD'])
C Shapiro05dd3222017-09-22 10:42:33 -060046
Kevin Chenga2619dc2016-03-28 11:42:08 -070047
C Shapirobe0ff8d2019-06-14 10:41:43 -060048class DeviceSkuLabel(base_label.StringPrefixLabel):
49 """Determine the correct device_sku label for the device."""
50
51 _NAME = ds_constants.DEVICE_SKU_LABEL
52
53 def generate_labels(self, host):
54 device_sku = host.host_info_store.get().device_sku
55 if device_sku:
56 return [device_sku]
57
58 mosys_cmd = 'mosys platform sku'
59 result = host.run(command=mosys_cmd, ignore_status=True)
60 if result.exit_status == 0:
61 return [result.stdout.strip()]
62
63 return []
64
Eshwar Narayan871a2c02020-02-06 11:15:24 -080065 def update_for_task(self, task_name):
66 # This label is stored in the lab config, so only deploy tasks update it
67 # or when no task name is mentioned.
68 return task_name in (DEPLOY_TASK_NAME, '')
69
C Shapirobe0ff8d2019-06-14 10:41:43 -060070
Ned Nguyene0a619d2019-07-01 15:50:23 -060071class BrandCodeLabel(base_label.StringPrefixLabel):
72 """Determine the correct brand_code (aka RLZ-code) for the device."""
73
74 _NAME = ds_constants.BRAND_CODE_LABEL
75
76 def generate_labels(self, host):
77 brand_code = host.host_info_store.get().brand_code
78 if brand_code:
79 return [brand_code]
80
Greg Edelston7cea0c42019-11-26 15:17:22 -070081 cros_config_cmd = 'cros_config / brand-code'
82 result = host.run(command=cros_config_cmd, ignore_status=True)
Ned Nguyene0a619d2019-07-01 15:50:23 -060083 if result.exit_status == 0:
84 return [result.stdout.strip()]
85
86 return []
87
88
Shijin Abrahamc09587d2020-02-14 20:46:55 -080089class BluetoothPeerLabel(base_label.StringPrefixLabel):
90 """Return the Bluetooth peer labels.
91
92 working_bluetooth_btpeer label is applied if a Raspberry Pi Bluetooth peer
93 is detected.There can be up to 4 Bluetooth peers. Labels
94 working_bluetooth_btpeer:[1-4] will be assigned depending on the number of
95 peers present.
96
97 """
98
99 _NAME = 'working_bluetooth_btpeer'
100
101 def exists(self, host):
102 return len(host._btpeer_host_list) > 0
103
104 def generate_labels(self, host):
105 labels_list = []
106 count = 1
107
108 for (btpeer, btpeer_host) in \
109 zip(host.btpeer_list, host._btpeer_host_list):
110 try:
111 # Initialize one device type to make sure the peer is working
112 bt_hid_device = btpeer.get_bluetooth_hid_mouse()
113 if bt_hid_device.CheckSerialConnection():
114 labels_list.append(str(count))
115 count += 1
116 except Exception as e:
117 logging.error('Error with initializing bt_hid_mouse on '
118 'btpeer %s %s', btpeer_host.hostname, e)
119
120 logging.info('Bluetooth Peer labels are %s', labels_list)
121 return labels_list
122
123 def update_for_task(self, task_name):
Shijin Abraham76bc1db2020-03-06 10:52:10 -0800124 # This label is stored in the state config, so only repair tasks update
125 # it or when no task name is mentioned.
126 return task_name in (REPAIR_TASK_NAME, '')
Shijin Abrahamc09587d2020-02-14 20:46:55 -0800127
Kevin Chenga2619dc2016-03-28 11:42:08 -0700128
Mary Ruthven935ebad2018-06-13 16:13:20 -0700129class Cr50Label(base_label.StringPrefixLabel):
Mary Ruthven6c462642019-09-17 19:13:36 -0700130 """Label indicating the cr50 image type."""
Mary Ruthven935ebad2018-06-13 16:13:20 -0700131
132 _NAME = 'cr50'
133
134 def __init__(self):
135 self.ver = None
136
Mary Ruthven935ebad2018-06-13 16:13:20 -0700137 def exists(self, host):
138 # Make sure the gsctool version command runs ok
139 self.ver = host.run('gsctool -a -f', ignore_status=True)
140 return self.ver.exit_status == 0
141
Mary Ruthven6c462642019-09-17 19:13:36 -0700142 def _get_version(self, region):
143 """Get the version number of the given region"""
144 return re.search(region + ' (\d+\.\d+\.\d+)', self.ver.stdout).group(1)
Mary Ruthven935ebad2018-06-13 16:13:20 -0700145
146 def generate_labels(self, host):
147 # Check the major version to determine prePVT vs PVT
Mary Ruthven6c462642019-09-17 19:13:36 -0700148 version = self._get_version('RW')
149 major_version = int(version.split('.')[1])
Mary Ruthven935ebad2018-06-13 16:13:20 -0700150 # PVT images have a odd major version prePVT have even
Mary Ruthven6c462642019-09-17 19:13:36 -0700151 return ['pvt' if (major_version % 2) else 'prepvt']
152
Xixuan Wu61b2b262020-03-06 10:09:55 -0800153 def update_for_task(self, task_name):
154 # This label is stored in the state config, so only repair tasks update
155 # it or when no task name is mentioned.
156 return task_name in (REPAIR_TASK_NAME, '')
157
Mary Ruthven6c462642019-09-17 19:13:36 -0700158
159class Cr50RWKeyidLabel(Cr50Label):
160 """Label indicating the cr50 RW version."""
161 _REGION = 'RW'
162 _NAME = 'cr50-rw-keyid'
163
164 def _get_keyid_info(self, region):
165 """Get the keyid of the given region."""
166 match = re.search('keyids:.*%s (\S+)' % region, self.ver.stdout)
167 keyid = match.group(1).rstrip(',')
168 is_prod = int(keyid, 16) & (1 << 2)
169 return [keyid, 'prod' if is_prod else 'dev']
170
171 def generate_labels(self, host):
172 """Get the key type."""
173 return self._get_keyid_info(self._REGION)
174
175
176class Cr50ROKeyidLabel(Cr50RWKeyidLabel):
177 """Label indicating the RO key type."""
178 _REGION = 'RO'
179 _NAME = 'cr50-ro-keyid'
180
181
Kevin Chenga2619dc2016-03-28 11:42:08 -0700182class ChameleonLabel(base_label.BaseLabel):
183 """Determine if a Chameleon is connected to this host."""
184
185 _NAME = 'chameleon'
186
187 def exists(self, host):
Xixuan Wu7afb54f2019-09-17 11:45:20 -0700188 # See crbug.com/1004500#2 for details.
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800189 has_chameleon = host._chameleon_host is not None
Gregory Nisbetb2f6d792019-09-11 14:30:47 -0700190 # TODO(crbug.com/995900) -- debug why chameleon label is flipping
191 try:
192 logging.info("has_chameleon %s", has_chameleon)
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800193 logging.info("_chameleon_host %s",
194 getattr(host, "_chameleon_host", "NO_ATTRIBUTE"))
195 logging.info("chameleon %s",
196 getattr(host, "chameleon", "NO_ATTRIBUTE"))
Gregory Nisbetb2f6d792019-09-11 14:30:47 -0700197 except:
198 pass
199 return has_chameleon
200
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800201 def update_for_task(self, task_name):
202 # This label is stored in the state config, so only repair tasks update
203 # it or when no task name is mentioned.
204 return task_name in (REPAIR_TASK_NAME, '')
Kevin Chenga2619dc2016-03-28 11:42:08 -0700205
206
207class ChameleonConnectionLabel(base_label.StringPrefixLabel):
208 """Return the Chameleon connection label."""
209
210 _NAME = 'chameleon'
211
212 def exists(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800213 return host._chameleon_host is not None
Joseph Hwangeac44312016-08-31 12:08:38 +0800214
Kevin Chenga2619dc2016-03-28 11:42:08 -0700215 def generate_labels(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800216 return [host.chameleon.get_label()]
Kevin Chenga2619dc2016-03-28 11:42:08 -0700217
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800218 def update_for_task(self, task_name):
219 # This label is stored in the lab config, so only deploy tasks update it
220 # or when no task name is mentioned.
221 return task_name in (DEPLOY_TASK_NAME, '')
222
Kevin Chenga2619dc2016-03-28 11:42:08 -0700223
Joseph Hwangeac44312016-08-31 12:08:38 +0800224class ChameleonPeripheralsLabel(base_label.StringPrefixLabel):
225 """Return the Chameleon peripherals labels.
226
227 The 'chameleon:bt_hid' label is applied if the bluetooth
228 classic hid device, i.e, RN-42 emulation kit, is detected.
229
230 Any peripherals plugged into the chameleon board would be
231 detected and applied proper labels in this class.
232 """
233
234 _NAME = 'chameleon'
235
236 def exists(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800237 return host._chameleon_host is not None
Joseph Hwangeac44312016-08-31 12:08:38 +0800238
239 def generate_labels(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800240 labels = []
241 try:
242 bt_hid_device = host.chameleon.get_bluetooth_hid_mouse()
243 if bt_hid_device.CheckSerialConnection():
244 labels.append('bt_hid')
245 except:
246 logging.error('Error with initializing bt_hid_mouse')
howardchung83e55272019-08-08 14:08:05 +0800247
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800248 try:
249 ble_hid_device = host.chameleon.get_ble_mouse()
250 if ble_hid_device.CheckSerialConnection():
251 labels.append('bt_ble_hid')
252 except:
253 logging.error('Error with initializing ble_hid_mouse')
howardchung83e55272019-08-08 14:08:05 +0800254
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800255 try:
256 bt_a2dp_sink = host.chameleon.get_bluetooth_a2dp_sink()
257 if bt_a2dp_sink.CheckSerialConnection():
258 labels.append('bt_a2dp_sink')
259 except:
260 logging.error('Error with initializing bt_a2dp_sink')
howardchung83e55272019-08-08 14:08:05 +0800261
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800262 try:
Joseph Hwang94044ea2020-01-03 14:47:43 +0800263 bt_audio_device = host.chameleon.get_bluetooth_audio()
264 if bt_audio_device.IsDetected():
265 labels.append('bt_audio')
266 except:
267 logging.error('Error in detecting bt_audio')
268
269 try:
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800270 bt_base_device = host.chameleon.get_bluetooth_base()
271 if bt_base_device.IsDetected():
272 labels.append('bt_base')
273 except:
274 logging.error('Error in detecting bt_base')
howardchung83e55272019-08-08 14:08:05 +0800275
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800276 if labels != []:
277 labels.append('bt_peer')
Joseph Hwang89e779c2019-12-24 16:05:56 +0800278
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800279 logging.info('Chameleon Bluetooth labels are %s', labels)
280 return labels
Shijin Abrahamff61ac32019-05-20 12:35:44 -0700281
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800282 def update_for_task(self, task_name):
283 # This label is stored in the lab config, so only deploy tasks update it
284 # or when no task name is mentioned.
285 return task_name in (DEPLOY_TASK_NAME, '')
Joseph Hwangeac44312016-08-31 12:08:38 +0800286
287
Kevin Chenga2619dc2016-03-28 11:42:08 -0700288class AudioLoopbackDongleLabel(base_label.BaseLabel):
289 """Return the label if an audio loopback dongle is plugged in."""
290
291 _NAME = 'audio_loopback_dongle'
292
293 def exists(self, host):
Gregory Nisbete280ea22019-08-16 17:50:03 -0700294 # Based on crbug.com/991285, AudioLoopbackDongle sometimes flips.
295 # Ensure that AudioLoopbackDongle.exists returns True
296 # forever, after it returns True *once*.
297 if self._cached_exists(host):
298 # If the current state is True, return it, don't run the command on
299 # the DUT and potentially flip the state.
300 return True
301 # If the current state is not True, run the command on
302 # the DUT. The new state will be set to whatever the command
303 # produces.
304 return self._host_run_exists(host)
305
306 def _cached_exists(self, host):
307 """Get the state of AudioLoopbackDongle in the data store"""
308 info = host.host_info_store.get()
309 for label in info.labels:
310 if label.startswith(self._NAME):
311 return True
312 return False
313
314 def _host_run_exists(self, host):
315 """Detect presence of audio_loopback_dongle by physically
316 running a command on the DUT."""
Kevin Chenga2619dc2016-03-28 11:42:08 -0700317 nodes_info = host.run(command=cras_utils.get_cras_nodes_cmd(),
318 ignore_status=True).stdout
319 if (cras_utils.node_type_is_plugged('HEADPHONE', nodes_info) and
320 cras_utils.node_type_is_plugged('MIC', nodes_info)):
Otabek Kasimovcefc0d12020-02-07 17:13:52 -0800321 return True
Kevin Chenga2619dc2016-03-28 11:42:08 -0700322 return False
323
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800324 def update_for_task(self, task_name):
325 # This label is stored in the state config, so only repair tasks update
326 # it or when no task name is mentioned.
327 return task_name in (REPAIR_TASK_NAME, '')
328
Kevin Chenga2619dc2016-03-28 11:42:08 -0700329
Otabek Kasimov43185912020-03-11 16:01:52 -0700330class ServoTypeLabel(base_label.StringPrefixLabel):
Otabek Kasimove7565282020-04-14 13:26:12 -0700331 _NAME = servo_constants.SERVO_TYPE_LABEL_PREFIX
Otabek Kasimov43185912020-03-11 16:01:52 -0700332
333 def generate_labels(self, host):
334 info = host.host_info_store.get()
335
336 servo_type = self._get_from_labels(info)
337 if servo_type != '':
Otabek Kasimov1b67c002020-04-15 13:27:38 -0700338 logging.info("Using servo_type: %s from cache!", servo_type)
Otabek Kasimov43185912020-03-11 16:01:52 -0700339 return [servo_type]
340
341 if host.servo is not None:
342 try:
343 servo_type = host.servo.get_servo_version()
344 if servo_type != '':
345 return [servo_type]
Otabek Kasimov1b67c002020-04-15 13:27:38 -0700346 logging.warning('Cannot collect servo_type from servo'
347 ' by `dut-control servo_type`! Please file a bug'
348 ' and inform infra team as we are not expected '
349 ' to reach this point.')
Otabek Kasimov43185912020-03-11 16:01:52 -0700350 except Exception as e:
351 # We don't want fail the label and break DUTs here just
352 # because of servo issue.
353 logging.error("Failed to update servo_type, %s", str(e))
354 return []
355
356 def _get_from_labels(self, info):
357 prefix = self._NAME + ':'
358 for label in info.labels:
359 if label.startswith(prefix):
360 suffix_length = len(prefix)
361 return label[suffix_length:]
362 return ''
363
364 def update_for_task(self, task_name):
365 # This label is stored in the lab config,
366 # only deploy and repair tasks update it
367 # or when no task name is mentioned.
Otabek Kasimove7908f52020-05-05 18:13:33 -0700368 return task_name in (DEPLOY_TASK_NAME, '')
Otabek Kasimov43185912020-03-11 16:01:52 -0700369
370
Xixuan Wu78569d02019-09-15 16:08:25 -0700371def _parse_hwid_labels(hwid_info_list):
372 if len(hwid_info_list) == 0:
373 return hwid_info_list
374
375 res = []
376 # See crbug.com/997816#c7 for details of two potential formats of returns
377 # from HWID server.
378 if isinstance(hwid_info_list[0], dict):
379 # Format of hwid_info:
380 # [{u'name': u'sku', u'value': u'xxx'}, ..., ]
381 for hwid_info in hwid_info_list:
382 value = hwid_info.get('value', '')
383 name = hwid_info.get('name', '')
384 # There should always be a name but just in case there is not.
385 if name:
386 new_label = name if not value else '%s:%s' % (name, value)
387 res.append(new_label)
388 else:
389 # Format of hwid_info:
390 # [<DUTLabel name: 'sku' value: u'xxx'>, ..., ]
391 for hwid_info in hwid_info_list:
392 new_label = str(hwid_info)
393 logging.info('processing hwid label: %s', new_label)
394 res.append(new_label)
395
396 return res
397
398
Kevin Cheng80ad5732016-03-31 16:01:56 -0700399class HWIDLabel(base_label.StringLabel):
400 """Return all the labels generated from the hwid."""
401
402 # We leave out _NAME because hwid_lib will generate everything for us.
403
404 def __init__(self):
405 # Grab the key file needed to access the hwid service.
406 self.key_file = global_config.global_config.get_config_value(
407 'CROS', 'HWID_KEY', type=str)
408
409
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700410 @staticmethod
411 def _merge_hwid_label_lists(new, old):
412 """merge a list of old and new values for hwid_labels.
413 preferring new values if available
414
415 @returns: list of labels"""
416 # TODO(gregorynisbet): what is the appropriate way to merge
417 # old and new information?
418 retained = set(x for x in old)
419 for label in new:
420 key, sep, value = label.partition(':')
421 # If we have a key-value key such as variant:aaa,
422 # then we remove all the old labels with the same key.
423 if sep:
424 retained = set(x for x in retained if (not x.startswith(key + ':')))
425 return list(sorted(retained.union(new)))
426
427
428 def _hwid_label_names(self):
429 """get the labels that hwid_lib controls.
430
431 @returns: hwid_labels
432 """
433 all_hwid_labels, _ = self.get_all_labels()
434 # If and only if get_all_labels was unsuccessful,
435 # it will return a falsey value.
Gregory Nisbetbfd120f2019-09-04 14:49:46 -0700436 out = all_hwid_labels or HWID_LABELS_FALLBACK
437
438 # TODO(gregorynisbet): remove this
439 # TODO(crbug.com/999785)
440 if "sku" not in out:
441 logging.info("sku-less label names %s", out)
442
443 return out
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700444
445
446 def _old_label_values(self, host):
447 """get the hwid_lib labels on previous run
448
449 @returns: hwid_labels"""
450 out = []
451 info = host.host_info_store.get()
452 for hwid_label in self._hwid_label_names():
453 for label in info.labels:
454 # NOTE: we want *all* the labels starting
455 # with this prefix.
456 if label.startswith(hwid_label):
457 out.append(label)
458 return out
459
460
Kevin Cheng80ad5732016-03-31 16:01:56 -0700461 def generate_labels(self, host):
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700462 # use previous values as default
463 old_hwid_labels = self._old_label_values(host)
Xixuan Wue63f8352019-09-13 15:18:03 -0700464 logging.info("old_hwid_labels: %r", old_hwid_labels)
Kevin Cheng80ad5732016-03-31 16:01:56 -0700465 hwid = host.run_output('crossystem hwid').strip()
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700466 hwid_info_list = []
467 try:
468 hwid_info_response = hwid_lib.get_hwid_info(
469 hwid=hwid,
470 info_type=hwid_lib.HWID_INFO_LABEL,
471 key_file=self.key_file,
472 )
Xixuan Wue63f8352019-09-13 15:18:03 -0700473 logging.info("hwid_info_response: %r", hwid_info_response)
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700474 hwid_info_list = hwid_info_response.get('labels', [])
475 except hwid_lib.HwIdException as e:
476 logging.info("HwIdException: %s", e)
Kevin Cheng80ad5732016-03-31 16:01:56 -0700477
Xixuan Wu78569d02019-09-15 16:08:25 -0700478 new_hwid_labels = _parse_hwid_labels(hwid_info_list)
479 logging.info("new HWID labels: %r", new_hwid_labels)
Gregory Nisbetbfd120f2019-09-04 14:49:46 -0700480
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700481 return HWIDLabel._merge_hwid_label_lists(
482 old=old_hwid_labels,
Xixuan Wu78569d02019-09-15 16:08:25 -0700483 new=new_hwid_labels,
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700484 )
Kevin Cheng80ad5732016-03-31 16:01:56 -0700485
486
487 def get_all_labels(self):
488 """We need to try all labels as a prefix and as standalone.
489
490 We don't know for sure which labels are prefix labels and which are
491 standalone so we try all of them as both.
492 """
493 all_hwid_labels = []
494 try:
495 all_hwid_labels = hwid_lib.get_all_possible_dut_labels(
496 self.key_file)
497 except IOError:
498 logging.error('Can not open key file: %s', self.key_file)
499 except hwid_lib.HwIdException as e:
500 logging.error('hwid service: %s', e)
501 return all_hwid_labels, all_hwid_labels
502
503
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700504class DutStorageLabel(base_label.StringPrefixLabel):
505 """Return the DUT storage label."""
506
507 _NAME = audit_const.DUT_STORAGE_STATE_PREFIX
508
509 def exists(self, host):
510 return host.servo is not None
511
512 def generate_labels(self, host):
513 verifier = audit_verify.VerifyDutStorage(host)
514 verifier.verify(set_label=False)
515 state = verifier.get_state()
516 return [state]
517
518 def update_for_task(self, task_name):
519 # This label is part of audit task, so updating it during deploy tasks
520 # update it or when no task name is mentioned.
521 return task_name in (DEPLOY_TASK_NAME, '')
522
523
Kevin Chenga2619dc2016-03-28 11:42:08 -0700524CROS_LABELS = [
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800525 AudioLoopbackDongleLabel(), #STATECONFIG
Shijin Abraham76bc1db2020-03-06 10:52:10 -0800526 BluetoothPeerLabel(), #STATECONFIG
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800527 ChameleonConnectionLabel(), #LABCONFIG
528 ChameleonLabel(), #STATECONFIG
529 ChameleonPeripheralsLabel(), #LABCONFIG
Kevin Chenga2619dc2016-03-28 11:42:08 -0700530 common_label.OSLabel(),
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800531 DeviceSkuLabel(), #LABCONFIG
Kevin Cheng80ad5732016-03-31 16:01:56 -0700532 HWIDLabel(),
Otabek Kasimov43185912020-03-11 16:01:52 -0700533 ServoTypeLabel(), #LABCONFIG
Xixuan Wu457b4ac2020-03-02 14:39:08 -0800534 # Temporarily add back as there's no way to reference cr50 configs.
535 # See crbug.com/1057145 for the root cause.
536 # See crbug.com/1057719 for future tracking.
537 Cr50Label(),
538 Cr50ROKeyidLabel(),
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700539 DutStorageLabel(), #STATECONFIG
Kevin Chenga2619dc2016-03-28 11:42:08 -0700540]
Garry Wange4b6d6e2019-06-17 17:08:46 -0700541
542LABSTATION_LABELS = [
Garry Wange4b6d6e2019-06-17 17:08:46 -0700543 common_label.OSLabel(),
544]