blob: 6bc1f18bd5bcd304d950cee76a7ef860140c6ee6 [file] [log] [blame]
Derek Beckettf73baca2020-08-19 15:08:47 -07001# Lint as: python2, python3
Kevin Chenga2619dc2016-03-28 11:42:08 -07002# Copyright 2016 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""This class defines the CrosHost Label class."""
7
Derek Beckettf73baca2020-08-19 15:08:47 -07008from __future__ import absolute_import
9from __future__ import division
10from __future__ import print_function
11
C Shapiro05dd3222017-09-22 10:42:33 -060012import collections
Kevin Chenga2619dc2016-03-28 11:42:08 -070013import logging
Kevin Chenga2619dc2016-03-28 11:42:08 -070014import re
15
16import common
17
18from autotest_lib.client.bin import utils
Kevin Cheng80ad5732016-03-31 16:01:56 -070019from autotest_lib.client.common_lib import global_config
Kevin Chenga2619dc2016-03-28 11:42:08 -070020from autotest_lib.client.cros.audio import cras_utils
Kevin Chenga2619dc2016-03-28 11:42:08 -070021from autotest_lib.server.cros.dynamic_suite import constants as ds_constants
22from autotest_lib.server.hosts import base_label
23from autotest_lib.server.hosts import common_label
Garry Wang11b5e872020-03-11 15:14:08 -070024from autotest_lib.server.hosts import servo_constants
Kevin Cheng80ad5732016-03-31 16:01:56 -070025from autotest_lib.site_utils import hwid_lib
Otabek Kasimov40ccb972020-05-26 15:14:39 -070026from autotest_lib.site_utils.admin_audit import verifiers as audit_verify
27from autotest_lib.site_utils.admin_audit import constants as audit_const
Derek Beckettf73baca2020-08-19 15:08:47 -070028from six.moves import zip
Kevin Chenga2619dc2016-03-28 11:42:08 -070029
30# pylint: disable=missing-docstring
C Shapiro05dd3222017-09-22 10:42:33 -060031LsbOutput = collections.namedtuple('LsbOutput', ['unibuild', 'board'])
32
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -070033# fallback values if we can't contact the HWID server
34HWID_LABELS_FALLBACK = ['sku', 'phase', 'touchscreen', 'touchpad', 'variant', 'stylus']
35
Eshwar Narayan871a2c02020-02-06 11:15:24 -080036# Repair and Deploy taskName
37REPAIR_TASK_NAME = 'repair'
38DEPLOY_TASK_NAME = 'deploy'
39
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -070040
C Shapiro05dd3222017-09-22 10:42:33 -060041def _parse_lsb_output(host):
Allen Lia0c7afc2019-02-26 15:50:06 -080042 """Parses the LSB output and returns key data points for labeling.
C Shapiro05dd3222017-09-22 10:42:33 -060043
Allen Lia0c7afc2019-02-26 15:50:06 -080044 @param host: Host that the command will be executed against
45 @returns: LsbOutput with the result of parsing the /etc/lsb-release output
46 """
47 release_info = utils.parse_cmd_output('cat /etc/lsb-release',
48 run_method=host.run)
C Shapiro05dd3222017-09-22 10:42:33 -060049
Allen Lia0c7afc2019-02-26 15:50:06 -080050 unibuild = release_info.get('CHROMEOS_RELEASE_UNIBUILD') == '1'
51 return LsbOutput(unibuild, release_info['CHROMEOS_RELEASE_BOARD'])
C Shapiro05dd3222017-09-22 10:42:33 -060052
Kevin Chenga2619dc2016-03-28 11:42:08 -070053
C Shapirobe0ff8d2019-06-14 10:41:43 -060054class DeviceSkuLabel(base_label.StringPrefixLabel):
55 """Determine the correct device_sku label for the device."""
56
57 _NAME = ds_constants.DEVICE_SKU_LABEL
58
59 def generate_labels(self, host):
60 device_sku = host.host_info_store.get().device_sku
61 if device_sku:
62 return [device_sku]
63
64 mosys_cmd = 'mosys platform sku'
65 result = host.run(command=mosys_cmd, ignore_status=True)
66 if result.exit_status == 0:
67 return [result.stdout.strip()]
68
69 return []
70
Eshwar Narayan871a2c02020-02-06 11:15:24 -080071 def update_for_task(self, task_name):
72 # This label is stored in the lab config, so only deploy tasks update it
73 # or when no task name is mentioned.
74 return task_name in (DEPLOY_TASK_NAME, '')
75
C Shapirobe0ff8d2019-06-14 10:41:43 -060076
Ned Nguyene0a619d2019-07-01 15:50:23 -060077class BrandCodeLabel(base_label.StringPrefixLabel):
78 """Determine the correct brand_code (aka RLZ-code) for the device."""
79
80 _NAME = ds_constants.BRAND_CODE_LABEL
81
82 def generate_labels(self, host):
83 brand_code = host.host_info_store.get().brand_code
84 if brand_code:
85 return [brand_code]
86
Greg Edelston7cea0c42019-11-26 15:17:22 -070087 cros_config_cmd = 'cros_config / brand-code'
88 result = host.run(command=cros_config_cmd, ignore_status=True)
Ned Nguyene0a619d2019-07-01 15:50:23 -060089 if result.exit_status == 0:
90 return [result.stdout.strip()]
91
92 return []
93
94
Shijin Abrahamc09587d2020-02-14 20:46:55 -080095class BluetoothPeerLabel(base_label.StringPrefixLabel):
96 """Return the Bluetooth peer labels.
97
98 working_bluetooth_btpeer label is applied if a Raspberry Pi Bluetooth peer
99 is detected.There can be up to 4 Bluetooth peers. Labels
100 working_bluetooth_btpeer:[1-4] will be assigned depending on the number of
101 peers present.
102
103 """
104
105 _NAME = 'working_bluetooth_btpeer'
106
107 def exists(self, host):
108 return len(host._btpeer_host_list) > 0
109
110 def generate_labels(self, host):
111 labels_list = []
112 count = 1
113
114 for (btpeer, btpeer_host) in \
115 zip(host.btpeer_list, host._btpeer_host_list):
116 try:
117 # Initialize one device type to make sure the peer is working
118 bt_hid_device = btpeer.get_bluetooth_hid_mouse()
119 if bt_hid_device.CheckSerialConnection():
120 labels_list.append(str(count))
121 count += 1
122 except Exception as e:
123 logging.error('Error with initializing bt_hid_mouse on '
124 'btpeer %s %s', btpeer_host.hostname, e)
125
126 logging.info('Bluetooth Peer labels are %s', labels_list)
127 return labels_list
128
129 def update_for_task(self, task_name):
Shijin Abraham76bc1db2020-03-06 10:52:10 -0800130 # This label is stored in the state config, so only repair tasks update
131 # it or when no task name is mentioned.
132 return task_name in (REPAIR_TASK_NAME, '')
Shijin Abrahamc09587d2020-02-14 20:46:55 -0800133
Kevin Chenga2619dc2016-03-28 11:42:08 -0700134
Mary Ruthven935ebad2018-06-13 16:13:20 -0700135class Cr50Label(base_label.StringPrefixLabel):
Mary Ruthven6c462642019-09-17 19:13:36 -0700136 """Label indicating the cr50 image type."""
Mary Ruthven935ebad2018-06-13 16:13:20 -0700137
138 _NAME = 'cr50'
139
140 def __init__(self):
141 self.ver = None
142
Mary Ruthven935ebad2018-06-13 16:13:20 -0700143 def exists(self, host):
144 # Make sure the gsctool version command runs ok
145 self.ver = host.run('gsctool -a -f', ignore_status=True)
146 return self.ver.exit_status == 0
147
Mary Ruthven6c462642019-09-17 19:13:36 -0700148 def _get_version(self, region):
149 """Get the version number of the given region"""
150 return re.search(region + ' (\d+\.\d+\.\d+)', self.ver.stdout).group(1)
Mary Ruthven935ebad2018-06-13 16:13:20 -0700151
152 def generate_labels(self, host):
153 # Check the major version to determine prePVT vs PVT
Mary Ruthven6c462642019-09-17 19:13:36 -0700154 version = self._get_version('RW')
155 major_version = int(version.split('.')[1])
Mary Ruthven935ebad2018-06-13 16:13:20 -0700156 # PVT images have a odd major version prePVT have even
Mary Ruthven6c462642019-09-17 19:13:36 -0700157 return ['pvt' if (major_version % 2) else 'prepvt']
158
Xixuan Wu61b2b262020-03-06 10:09:55 -0800159 def update_for_task(self, task_name):
160 # This label is stored in the state config, so only repair tasks update
161 # it or when no task name is mentioned.
162 return task_name in (REPAIR_TASK_NAME, '')
163
Mary Ruthven6c462642019-09-17 19:13:36 -0700164
165class Cr50RWKeyidLabel(Cr50Label):
166 """Label indicating the cr50 RW version."""
167 _REGION = 'RW'
168 _NAME = 'cr50-rw-keyid'
169
170 def _get_keyid_info(self, region):
171 """Get the keyid of the given region."""
172 match = re.search('keyids:.*%s (\S+)' % region, self.ver.stdout)
173 keyid = match.group(1).rstrip(',')
174 is_prod = int(keyid, 16) & (1 << 2)
175 return [keyid, 'prod' if is_prod else 'dev']
176
177 def generate_labels(self, host):
178 """Get the key type."""
179 return self._get_keyid_info(self._REGION)
180
181
182class Cr50ROKeyidLabel(Cr50RWKeyidLabel):
183 """Label indicating the RO key type."""
184 _REGION = 'RO'
185 _NAME = 'cr50-ro-keyid'
186
187
Kevin Chenga2619dc2016-03-28 11:42:08 -0700188class ChameleonLabel(base_label.BaseLabel):
189 """Determine if a Chameleon is connected to this host."""
190
191 _NAME = 'chameleon'
192
193 def exists(self, host):
Xixuan Wu7afb54f2019-09-17 11:45:20 -0700194 # See crbug.com/1004500#2 for details.
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800195 has_chameleon = host._chameleon_host is not None
Gregory Nisbetb2f6d792019-09-11 14:30:47 -0700196 # TODO(crbug.com/995900) -- debug why chameleon label is flipping
197 try:
198 logging.info("has_chameleon %s", has_chameleon)
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800199 logging.info("_chameleon_host %s",
200 getattr(host, "_chameleon_host", "NO_ATTRIBUTE"))
201 logging.info("chameleon %s",
202 getattr(host, "chameleon", "NO_ATTRIBUTE"))
Gregory Nisbetb2f6d792019-09-11 14:30:47 -0700203 except:
204 pass
205 return has_chameleon
206
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800207 def update_for_task(self, task_name):
208 # This label is stored in the state config, so only repair tasks update
209 # it or when no task name is mentioned.
210 return task_name in (REPAIR_TASK_NAME, '')
Kevin Chenga2619dc2016-03-28 11:42:08 -0700211
212
213class ChameleonConnectionLabel(base_label.StringPrefixLabel):
214 """Return the Chameleon connection label."""
215
216 _NAME = 'chameleon'
217
218 def exists(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800219 return host._chameleon_host is not None
Joseph Hwangeac44312016-08-31 12:08:38 +0800220
Kevin Chenga2619dc2016-03-28 11:42:08 -0700221 def generate_labels(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800222 return [host.chameleon.get_label()]
Kevin Chenga2619dc2016-03-28 11:42:08 -0700223
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800224 def update_for_task(self, task_name):
225 # This label is stored in the lab config, so only deploy tasks update it
226 # or when no task name is mentioned.
227 return task_name in (DEPLOY_TASK_NAME, '')
228
Kevin Chenga2619dc2016-03-28 11:42:08 -0700229
Joseph Hwangeac44312016-08-31 12:08:38 +0800230class ChameleonPeripheralsLabel(base_label.StringPrefixLabel):
231 """Return the Chameleon peripherals labels.
232
233 The 'chameleon:bt_hid' label is applied if the bluetooth
234 classic hid device, i.e, RN-42 emulation kit, is detected.
235
236 Any peripherals plugged into the chameleon board would be
237 detected and applied proper labels in this class.
238 """
239
240 _NAME = 'chameleon'
241
242 def exists(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800243 return host._chameleon_host is not None
Joseph Hwangeac44312016-08-31 12:08:38 +0800244
245 def generate_labels(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800246 labels = []
247 try:
248 bt_hid_device = host.chameleon.get_bluetooth_hid_mouse()
249 if bt_hid_device.CheckSerialConnection():
250 labels.append('bt_hid')
251 except:
252 logging.error('Error with initializing bt_hid_mouse')
howardchung83e55272019-08-08 14:08:05 +0800253
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800254 try:
255 ble_hid_device = host.chameleon.get_ble_mouse()
256 if ble_hid_device.CheckSerialConnection():
257 labels.append('bt_ble_hid')
258 except:
259 logging.error('Error with initializing ble_hid_mouse')
howardchung83e55272019-08-08 14:08:05 +0800260
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800261 try:
262 bt_a2dp_sink = host.chameleon.get_bluetooth_a2dp_sink()
263 if bt_a2dp_sink.CheckSerialConnection():
264 labels.append('bt_a2dp_sink')
265 except:
266 logging.error('Error with initializing bt_a2dp_sink')
howardchung83e55272019-08-08 14:08:05 +0800267
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800268 try:
Joseph Hwang94044ea2020-01-03 14:47:43 +0800269 bt_audio_device = host.chameleon.get_bluetooth_audio()
270 if bt_audio_device.IsDetected():
271 labels.append('bt_audio')
272 except:
273 logging.error('Error in detecting bt_audio')
274
275 try:
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800276 bt_base_device = host.chameleon.get_bluetooth_base()
277 if bt_base_device.IsDetected():
278 labels.append('bt_base')
279 except:
280 logging.error('Error in detecting bt_base')
howardchung83e55272019-08-08 14:08:05 +0800281
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800282 if labels != []:
283 labels.append('bt_peer')
Joseph Hwang89e779c2019-12-24 16:05:56 +0800284
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800285 logging.info('Chameleon Bluetooth labels are %s', labels)
286 return labels
Shijin Abrahamff61ac32019-05-20 12:35:44 -0700287
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800288 def update_for_task(self, task_name):
289 # This label is stored in the lab config, so only deploy tasks update it
290 # or when no task name is mentioned.
291 return task_name in (DEPLOY_TASK_NAME, '')
Joseph Hwangeac44312016-08-31 12:08:38 +0800292
293
Kevin Chenga2619dc2016-03-28 11:42:08 -0700294class AudioLoopbackDongleLabel(base_label.BaseLabel):
295 """Return the label if an audio loopback dongle is plugged in."""
296
297 _NAME = 'audio_loopback_dongle'
298
299 def exists(self, host):
Gregory Nisbete280ea22019-08-16 17:50:03 -0700300 # Based on crbug.com/991285, AudioLoopbackDongle sometimes flips.
301 # Ensure that AudioLoopbackDongle.exists returns True
302 # forever, after it returns True *once*.
303 if self._cached_exists(host):
304 # If the current state is True, return it, don't run the command on
305 # the DUT and potentially flip the state.
306 return True
307 # If the current state is not True, run the command on
308 # the DUT. The new state will be set to whatever the command
309 # produces.
310 return self._host_run_exists(host)
311
312 def _cached_exists(self, host):
313 """Get the state of AudioLoopbackDongle in the data store"""
314 info = host.host_info_store.get()
315 for label in info.labels:
316 if label.startswith(self._NAME):
317 return True
318 return False
319
320 def _host_run_exists(self, host):
321 """Detect presence of audio_loopback_dongle by physically
322 running a command on the DUT."""
Kevin Chenga2619dc2016-03-28 11:42:08 -0700323 nodes_info = host.run(command=cras_utils.get_cras_nodes_cmd(),
324 ignore_status=True).stdout
325 if (cras_utils.node_type_is_plugged('HEADPHONE', nodes_info) and
326 cras_utils.node_type_is_plugged('MIC', nodes_info)):
Otabek Kasimovcefc0d12020-02-07 17:13:52 -0800327 return True
Kevin Chenga2619dc2016-03-28 11:42:08 -0700328 return False
329
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800330 def update_for_task(self, task_name):
331 # This label is stored in the state config, so only repair tasks update
332 # it or when no task name is mentioned.
333 return task_name in (REPAIR_TASK_NAME, '')
334
Kevin Chenga2619dc2016-03-28 11:42:08 -0700335
Otabek Kasimov43185912020-03-11 16:01:52 -0700336class ServoTypeLabel(base_label.StringPrefixLabel):
Otabek Kasimove7565282020-04-14 13:26:12 -0700337 _NAME = servo_constants.SERVO_TYPE_LABEL_PREFIX
Otabek Kasimov43185912020-03-11 16:01:52 -0700338
339 def generate_labels(self, host):
340 info = host.host_info_store.get()
341
342 servo_type = self._get_from_labels(info)
343 if servo_type != '':
Otabek Kasimov1b67c002020-04-15 13:27:38 -0700344 logging.info("Using servo_type: %s from cache!", servo_type)
Otabek Kasimov43185912020-03-11 16:01:52 -0700345 return [servo_type]
346
347 if host.servo is not None:
348 try:
349 servo_type = host.servo.get_servo_version()
350 if servo_type != '':
351 return [servo_type]
Otabek Kasimov1b67c002020-04-15 13:27:38 -0700352 logging.warning('Cannot collect servo_type from servo'
353 ' by `dut-control servo_type`! Please file a bug'
354 ' and inform infra team as we are not expected '
355 ' to reach this point.')
Otabek Kasimov43185912020-03-11 16:01:52 -0700356 except Exception as e:
357 # We don't want fail the label and break DUTs here just
358 # because of servo issue.
359 logging.error("Failed to update servo_type, %s", str(e))
360 return []
361
362 def _get_from_labels(self, info):
363 prefix = self._NAME + ':'
364 for label in info.labels:
365 if label.startswith(prefix):
366 suffix_length = len(prefix)
367 return label[suffix_length:]
368 return ''
369
370 def update_for_task(self, task_name):
371 # This label is stored in the lab config,
372 # only deploy and repair tasks update it
373 # or when no task name is mentioned.
Otabek Kasimove7908f52020-05-05 18:13:33 -0700374 return task_name in (DEPLOY_TASK_NAME, '')
Otabek Kasimov43185912020-03-11 16:01:52 -0700375
376
Xixuan Wu78569d02019-09-15 16:08:25 -0700377def _parse_hwid_labels(hwid_info_list):
378 if len(hwid_info_list) == 0:
379 return hwid_info_list
380
381 res = []
382 # See crbug.com/997816#c7 for details of two potential formats of returns
383 # from HWID server.
384 if isinstance(hwid_info_list[0], dict):
385 # Format of hwid_info:
386 # [{u'name': u'sku', u'value': u'xxx'}, ..., ]
387 for hwid_info in hwid_info_list:
388 value = hwid_info.get('value', '')
389 name = hwid_info.get('name', '')
390 # There should always be a name but just in case there is not.
391 if name:
392 new_label = name if not value else '%s:%s' % (name, value)
393 res.append(new_label)
394 else:
395 # Format of hwid_info:
396 # [<DUTLabel name: 'sku' value: u'xxx'>, ..., ]
397 for hwid_info in hwid_info_list:
398 new_label = str(hwid_info)
399 logging.info('processing hwid label: %s', new_label)
400 res.append(new_label)
401
402 return res
403
404
Kevin Cheng80ad5732016-03-31 16:01:56 -0700405class HWIDLabel(base_label.StringLabel):
406 """Return all the labels generated from the hwid."""
407
408 # We leave out _NAME because hwid_lib will generate everything for us.
409
410 def __init__(self):
411 # Grab the key file needed to access the hwid service.
412 self.key_file = global_config.global_config.get_config_value(
413 'CROS', 'HWID_KEY', type=str)
414
415
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700416 @staticmethod
417 def _merge_hwid_label_lists(new, old):
418 """merge a list of old and new values for hwid_labels.
419 preferring new values if available
420
421 @returns: list of labels"""
422 # TODO(gregorynisbet): what is the appropriate way to merge
423 # old and new information?
424 retained = set(x for x in old)
425 for label in new:
426 key, sep, value = label.partition(':')
427 # If we have a key-value key such as variant:aaa,
428 # then we remove all the old labels with the same key.
429 if sep:
430 retained = set(x for x in retained if (not x.startswith(key + ':')))
431 return list(sorted(retained.union(new)))
432
433
434 def _hwid_label_names(self):
435 """get the labels that hwid_lib controls.
436
437 @returns: hwid_labels
438 """
439 all_hwid_labels, _ = self.get_all_labels()
440 # If and only if get_all_labels was unsuccessful,
441 # it will return a falsey value.
Gregory Nisbetbfd120f2019-09-04 14:49:46 -0700442 out = all_hwid_labels or HWID_LABELS_FALLBACK
443
444 # TODO(gregorynisbet): remove this
445 # TODO(crbug.com/999785)
446 if "sku" not in out:
447 logging.info("sku-less label names %s", out)
448
449 return out
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700450
451
452 def _old_label_values(self, host):
453 """get the hwid_lib labels on previous run
454
455 @returns: hwid_labels"""
456 out = []
457 info = host.host_info_store.get()
458 for hwid_label in self._hwid_label_names():
459 for label in info.labels:
460 # NOTE: we want *all* the labels starting
461 # with this prefix.
462 if label.startswith(hwid_label):
463 out.append(label)
464 return out
465
466
Kevin Cheng80ad5732016-03-31 16:01:56 -0700467 def generate_labels(self, host):
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700468 # use previous values as default
469 old_hwid_labels = self._old_label_values(host)
Xixuan Wue63f8352019-09-13 15:18:03 -0700470 logging.info("old_hwid_labels: %r", old_hwid_labels)
Kevin Cheng80ad5732016-03-31 16:01:56 -0700471 hwid = host.run_output('crossystem hwid').strip()
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700472 hwid_info_list = []
473 try:
474 hwid_info_response = hwid_lib.get_hwid_info(
475 hwid=hwid,
476 info_type=hwid_lib.HWID_INFO_LABEL,
477 key_file=self.key_file,
478 )
Xixuan Wue63f8352019-09-13 15:18:03 -0700479 logging.info("hwid_info_response: %r", hwid_info_response)
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700480 hwid_info_list = hwid_info_response.get('labels', [])
481 except hwid_lib.HwIdException as e:
482 logging.info("HwIdException: %s", e)
Kevin Cheng80ad5732016-03-31 16:01:56 -0700483
Xixuan Wu78569d02019-09-15 16:08:25 -0700484 new_hwid_labels = _parse_hwid_labels(hwid_info_list)
485 logging.info("new HWID labels: %r", new_hwid_labels)
Gregory Nisbetbfd120f2019-09-04 14:49:46 -0700486
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700487 return HWIDLabel._merge_hwid_label_lists(
488 old=old_hwid_labels,
Xixuan Wu78569d02019-09-15 16:08:25 -0700489 new=new_hwid_labels,
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700490 )
Kevin Cheng80ad5732016-03-31 16:01:56 -0700491
492
493 def get_all_labels(self):
494 """We need to try all labels as a prefix and as standalone.
495
496 We don't know for sure which labels are prefix labels and which are
497 standalone so we try all of them as both.
498 """
499 all_hwid_labels = []
500 try:
501 all_hwid_labels = hwid_lib.get_all_possible_dut_labels(
502 self.key_file)
503 except IOError:
504 logging.error('Can not open key file: %s', self.key_file)
505 except hwid_lib.HwIdException as e:
506 logging.error('hwid service: %s', e)
507 return all_hwid_labels, all_hwid_labels
508
509
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700510class DutStorageLabel(base_label.StringPrefixLabel):
511 """Return the DUT storage label."""
512
513 _NAME = audit_const.DUT_STORAGE_STATE_PREFIX
514
515 def exists(self, host):
516 return host.servo is not None
517
518 def generate_labels(self, host):
519 verifier = audit_verify.VerifyDutStorage(host)
520 verifier.verify(set_label=False)
521 state = verifier.get_state()
522 return [state]
523
524 def update_for_task(self, task_name):
Otabek Kasimov1fe268f2020-09-01 09:41:13 -0700525 # This label is part of audit task, so updating it only during
526 # deploy tasks to update it for new deployments.
527 return task_name == DEPLOY_TASK_NAME
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700528
529
Kevin Chenga2619dc2016-03-28 11:42:08 -0700530CROS_LABELS = [
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800531 AudioLoopbackDongleLabel(), #STATECONFIG
Shijin Abraham76bc1db2020-03-06 10:52:10 -0800532 BluetoothPeerLabel(), #STATECONFIG
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800533 ChameleonConnectionLabel(), #LABCONFIG
534 ChameleonLabel(), #STATECONFIG
535 ChameleonPeripheralsLabel(), #LABCONFIG
Kevin Chenga2619dc2016-03-28 11:42:08 -0700536 common_label.OSLabel(),
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800537 DeviceSkuLabel(), #LABCONFIG
Kevin Cheng80ad5732016-03-31 16:01:56 -0700538 HWIDLabel(),
Otabek Kasimov43185912020-03-11 16:01:52 -0700539 ServoTypeLabel(), #LABCONFIG
Xixuan Wu457b4ac2020-03-02 14:39:08 -0800540 # Temporarily add back as there's no way to reference cr50 configs.
541 # See crbug.com/1057145 for the root cause.
542 # See crbug.com/1057719 for future tracking.
543 Cr50Label(),
544 Cr50ROKeyidLabel(),
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700545 DutStorageLabel(), #STATECONFIG
Kevin Chenga2619dc2016-03-28 11:42:08 -0700546]
Garry Wange4b6d6e2019-06-17 17:08:46 -0700547
548LABSTATION_LABELS = [
Garry Wange4b6d6e2019-06-17 17:08:46 -0700549 common_label.OSLabel(),
550]