blob: 1015b258a6fce1926022d8c540cea60ae8a25f58 [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):
Otabek Kasimovb80faf72020-09-15 21:22:00 -070072 # This label is stored in the lab config.
73 return task_name in (DEPLOY_TASK_NAME, REPAIR_TASK_NAME, '')
Eshwar Narayan871a2c02020-02-06 11:15:24 -080074
C Shapirobe0ff8d2019-06-14 10:41:43 -060075
Ned Nguyene0a619d2019-07-01 15:50:23 -060076class BrandCodeLabel(base_label.StringPrefixLabel):
77 """Determine the correct brand_code (aka RLZ-code) for the device."""
78
79 _NAME = ds_constants.BRAND_CODE_LABEL
80
81 def generate_labels(self, host):
82 brand_code = host.host_info_store.get().brand_code
83 if brand_code:
84 return [brand_code]
85
Greg Edelston7cea0c42019-11-26 15:17:22 -070086 cros_config_cmd = 'cros_config / brand-code'
87 result = host.run(command=cros_config_cmd, ignore_status=True)
Ned Nguyene0a619d2019-07-01 15:50:23 -060088 if result.exit_status == 0:
89 return [result.stdout.strip()]
90
91 return []
92
93
Shijin Abrahamc09587d2020-02-14 20:46:55 -080094class BluetoothPeerLabel(base_label.StringPrefixLabel):
95 """Return the Bluetooth peer labels.
96
97 working_bluetooth_btpeer label is applied if a Raspberry Pi Bluetooth peer
98 is detected.There can be up to 4 Bluetooth peers. Labels
99 working_bluetooth_btpeer:[1-4] will be assigned depending on the number of
100 peers present.
101
102 """
103
104 _NAME = 'working_bluetooth_btpeer'
105
106 def exists(self, host):
107 return len(host._btpeer_host_list) > 0
108
109 def generate_labels(self, host):
110 labels_list = []
111 count = 1
112
113 for (btpeer, btpeer_host) in \
114 zip(host.btpeer_list, host._btpeer_host_list):
115 try:
116 # Initialize one device type to make sure the peer is working
117 bt_hid_device = btpeer.get_bluetooth_hid_mouse()
118 if bt_hid_device.CheckSerialConnection():
119 labels_list.append(str(count))
120 count += 1
121 except Exception as e:
122 logging.error('Error with initializing bt_hid_mouse on '
123 'btpeer %s %s', btpeer_host.hostname, e)
124
125 logging.info('Bluetooth Peer labels are %s', labels_list)
126 return labels_list
127
128 def update_for_task(self, task_name):
Shijin Abraham76bc1db2020-03-06 10:52:10 -0800129 # This label is stored in the state config, so only repair tasks update
130 # it or when no task name is mentioned.
131 return task_name in (REPAIR_TASK_NAME, '')
Shijin Abrahamc09587d2020-02-14 20:46:55 -0800132
Kevin Chenga2619dc2016-03-28 11:42:08 -0700133
Mary Ruthven935ebad2018-06-13 16:13:20 -0700134class Cr50Label(base_label.StringPrefixLabel):
Mary Ruthven6c462642019-09-17 19:13:36 -0700135 """Label indicating the cr50 image type."""
Mary Ruthven935ebad2018-06-13 16:13:20 -0700136
137 _NAME = 'cr50'
138
139 def __init__(self):
140 self.ver = None
141
Mary Ruthven935ebad2018-06-13 16:13:20 -0700142 def exists(self, host):
143 # Make sure the gsctool version command runs ok
144 self.ver = host.run('gsctool -a -f', ignore_status=True)
145 return self.ver.exit_status == 0
146
Mary Ruthven6c462642019-09-17 19:13:36 -0700147 def _get_version(self, region):
148 """Get the version number of the given region"""
149 return re.search(region + ' (\d+\.\d+\.\d+)', self.ver.stdout).group(1)
Mary Ruthven935ebad2018-06-13 16:13:20 -0700150
151 def generate_labels(self, host):
152 # Check the major version to determine prePVT vs PVT
Mary Ruthven6c462642019-09-17 19:13:36 -0700153 version = self._get_version('RW')
154 major_version = int(version.split('.')[1])
Mary Ruthven935ebad2018-06-13 16:13:20 -0700155 # PVT images have a odd major version prePVT have even
Mary Ruthven6c462642019-09-17 19:13:36 -0700156 return ['pvt' if (major_version % 2) else 'prepvt']
157
Xixuan Wu61b2b262020-03-06 10:09:55 -0800158 def update_for_task(self, task_name):
159 # This label is stored in the state config, so only repair tasks update
160 # it or when no task name is mentioned.
161 return task_name in (REPAIR_TASK_NAME, '')
162
Mary Ruthven6c462642019-09-17 19:13:36 -0700163
164class Cr50RWKeyidLabel(Cr50Label):
165 """Label indicating the cr50 RW version."""
166 _REGION = 'RW'
167 _NAME = 'cr50-rw-keyid'
168
169 def _get_keyid_info(self, region):
170 """Get the keyid of the given region."""
171 match = re.search('keyids:.*%s (\S+)' % region, self.ver.stdout)
172 keyid = match.group(1).rstrip(',')
173 is_prod = int(keyid, 16) & (1 << 2)
174 return [keyid, 'prod' if is_prod else 'dev']
175
176 def generate_labels(self, host):
177 """Get the key type."""
178 return self._get_keyid_info(self._REGION)
179
180
181class Cr50ROKeyidLabel(Cr50RWKeyidLabel):
182 """Label indicating the RO key type."""
183 _REGION = 'RO'
184 _NAME = 'cr50-ro-keyid'
185
186
Kevin Chenga2619dc2016-03-28 11:42:08 -0700187class ChameleonLabel(base_label.BaseLabel):
188 """Determine if a Chameleon is connected to this host."""
189
190 _NAME = 'chameleon'
191
192 def exists(self, host):
Xixuan Wu7afb54f2019-09-17 11:45:20 -0700193 # See crbug.com/1004500#2 for details.
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800194 has_chameleon = host._chameleon_host is not None
Gregory Nisbetb2f6d792019-09-11 14:30:47 -0700195 # TODO(crbug.com/995900) -- debug why chameleon label is flipping
196 try:
197 logging.info("has_chameleon %s", has_chameleon)
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800198 logging.info("_chameleon_host %s",
199 getattr(host, "_chameleon_host", "NO_ATTRIBUTE"))
200 logging.info("chameleon %s",
201 getattr(host, "chameleon", "NO_ATTRIBUTE"))
Gregory Nisbetb2f6d792019-09-11 14:30:47 -0700202 except:
203 pass
204 return has_chameleon
205
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800206 def update_for_task(self, task_name):
207 # This label is stored in the state config, so only repair tasks update
208 # it or when no task name is mentioned.
209 return task_name in (REPAIR_TASK_NAME, '')
Kevin Chenga2619dc2016-03-28 11:42:08 -0700210
211
212class ChameleonConnectionLabel(base_label.StringPrefixLabel):
213 """Return the Chameleon connection label."""
214
215 _NAME = 'chameleon'
216
217 def exists(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800218 return host._chameleon_host is not None
Joseph Hwangeac44312016-08-31 12:08:38 +0800219
Kevin Chenga2619dc2016-03-28 11:42:08 -0700220 def generate_labels(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800221 return [host.chameleon.get_label()]
Kevin Chenga2619dc2016-03-28 11:42:08 -0700222
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800223 def update_for_task(self, task_name):
224 # This label is stored in the lab config, so only deploy tasks update it
225 # or when no task name is mentioned.
226 return task_name in (DEPLOY_TASK_NAME, '')
227
Kevin Chenga2619dc2016-03-28 11:42:08 -0700228
Joseph Hwangeac44312016-08-31 12:08:38 +0800229class ChameleonPeripheralsLabel(base_label.StringPrefixLabel):
230 """Return the Chameleon peripherals labels.
231
232 The 'chameleon:bt_hid' label is applied if the bluetooth
233 classic hid device, i.e, RN-42 emulation kit, is detected.
234
235 Any peripherals plugged into the chameleon board would be
236 detected and applied proper labels in this class.
237 """
238
239 _NAME = 'chameleon'
240
241 def exists(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800242 return host._chameleon_host is not None
Joseph Hwangeac44312016-08-31 12:08:38 +0800243
244 def generate_labels(self, host):
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800245 labels = []
246 try:
247 bt_hid_device = host.chameleon.get_bluetooth_hid_mouse()
248 if bt_hid_device.CheckSerialConnection():
249 labels.append('bt_hid')
250 except:
251 logging.error('Error with initializing bt_hid_mouse')
howardchung83e55272019-08-08 14:08:05 +0800252
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800253 try:
254 ble_hid_device = host.chameleon.get_ble_mouse()
255 if ble_hid_device.CheckSerialConnection():
256 labels.append('bt_ble_hid')
257 except:
258 logging.error('Error with initializing ble_hid_mouse')
howardchung83e55272019-08-08 14:08:05 +0800259
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800260 try:
261 bt_a2dp_sink = host.chameleon.get_bluetooth_a2dp_sink()
262 if bt_a2dp_sink.CheckSerialConnection():
263 labels.append('bt_a2dp_sink')
264 except:
265 logging.error('Error with initializing bt_a2dp_sink')
howardchung83e55272019-08-08 14:08:05 +0800266
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800267 try:
Joseph Hwang94044ea2020-01-03 14:47:43 +0800268 bt_audio_device = host.chameleon.get_bluetooth_audio()
269 if bt_audio_device.IsDetected():
270 labels.append('bt_audio')
271 except:
272 logging.error('Error in detecting bt_audio')
273
274 try:
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800275 bt_base_device = host.chameleon.get_bluetooth_base()
276 if bt_base_device.IsDetected():
277 labels.append('bt_base')
278 except:
279 logging.error('Error in detecting bt_base')
howardchung83e55272019-08-08 14:08:05 +0800280
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800281 if labels != []:
282 labels.append('bt_peer')
Joseph Hwang89e779c2019-12-24 16:05:56 +0800283
Shijin Abraham783a7dd2020-02-14 15:36:11 -0800284 logging.info('Chameleon Bluetooth labels are %s', labels)
285 return labels
Shijin Abrahamff61ac32019-05-20 12:35:44 -0700286
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800287 def update_for_task(self, task_name):
288 # This label is stored in the lab config, so only deploy tasks update it
289 # or when no task name is mentioned.
290 return task_name in (DEPLOY_TASK_NAME, '')
Joseph Hwangeac44312016-08-31 12:08:38 +0800291
292
Kevin Chenga2619dc2016-03-28 11:42:08 -0700293class AudioLoopbackDongleLabel(base_label.BaseLabel):
294 """Return the label if an audio loopback dongle is plugged in."""
295
296 _NAME = 'audio_loopback_dongle'
297
298 def exists(self, host):
Gregory Nisbete280ea22019-08-16 17:50:03 -0700299 # Based on crbug.com/991285, AudioLoopbackDongle sometimes flips.
300 # Ensure that AudioLoopbackDongle.exists returns True
301 # forever, after it returns True *once*.
302 if self._cached_exists(host):
303 # If the current state is True, return it, don't run the command on
304 # the DUT and potentially flip the state.
305 return True
306 # If the current state is not True, run the command on
307 # the DUT. The new state will be set to whatever the command
308 # produces.
309 return self._host_run_exists(host)
310
311 def _cached_exists(self, host):
312 """Get the state of AudioLoopbackDongle in the data store"""
313 info = host.host_info_store.get()
314 for label in info.labels:
315 if label.startswith(self._NAME):
316 return True
317 return False
318
319 def _host_run_exists(self, host):
320 """Detect presence of audio_loopback_dongle by physically
321 running a command on the DUT."""
Kevin Chenga2619dc2016-03-28 11:42:08 -0700322 nodes_info = host.run(command=cras_utils.get_cras_nodes_cmd(),
323 ignore_status=True).stdout
324 if (cras_utils.node_type_is_plugged('HEADPHONE', nodes_info) and
325 cras_utils.node_type_is_plugged('MIC', nodes_info)):
Otabek Kasimovcefc0d12020-02-07 17:13:52 -0800326 return True
Kevin Chenga2619dc2016-03-28 11:42:08 -0700327 return False
328
Eshwar Narayan871a2c02020-02-06 11:15:24 -0800329 def update_for_task(self, task_name):
330 # This label is stored in the state config, so only repair tasks update
331 # it or when no task name is mentioned.
332 return task_name in (REPAIR_TASK_NAME, '')
333
Kevin Chenga2619dc2016-03-28 11:42:08 -0700334
Otabek Kasimov43185912020-03-11 16:01:52 -0700335class ServoTypeLabel(base_label.StringPrefixLabel):
Otabek Kasimove7565282020-04-14 13:26:12 -0700336 _NAME = servo_constants.SERVO_TYPE_LABEL_PREFIX
Otabek Kasimov43185912020-03-11 16:01:52 -0700337
338 def generate_labels(self, host):
339 info = host.host_info_store.get()
340
341 servo_type = self._get_from_labels(info)
342 if servo_type != '':
Otabek Kasimov1b67c002020-04-15 13:27:38 -0700343 logging.info("Using servo_type: %s from cache!", servo_type)
Otabek Kasimov43185912020-03-11 16:01:52 -0700344 return [servo_type]
345
346 if host.servo is not None:
347 try:
348 servo_type = host.servo.get_servo_version()
349 if servo_type != '':
350 return [servo_type]
Otabek Kasimov1b67c002020-04-15 13:27:38 -0700351 logging.warning('Cannot collect servo_type from servo'
352 ' by `dut-control servo_type`! Please file a bug'
353 ' and inform infra team as we are not expected '
354 ' to reach this point.')
Otabek Kasimov43185912020-03-11 16:01:52 -0700355 except Exception as e:
356 # We don't want fail the label and break DUTs here just
357 # because of servo issue.
358 logging.error("Failed to update servo_type, %s", str(e))
359 return []
360
361 def _get_from_labels(self, info):
362 prefix = self._NAME + ':'
363 for label in info.labels:
364 if label.startswith(prefix):
365 suffix_length = len(prefix)
366 return label[suffix_length:]
367 return ''
368
369 def update_for_task(self, task_name):
370 # This label is stored in the lab config,
371 # only deploy and repair tasks update it
372 # or when no task name is mentioned.
Otabek Kasimove7908f52020-05-05 18:13:33 -0700373 return task_name in (DEPLOY_TASK_NAME, '')
Otabek Kasimov43185912020-03-11 16:01:52 -0700374
375
Xixuan Wu78569d02019-09-15 16:08:25 -0700376def _parse_hwid_labels(hwid_info_list):
377 if len(hwid_info_list) == 0:
378 return hwid_info_list
379
380 res = []
381 # See crbug.com/997816#c7 for details of two potential formats of returns
382 # from HWID server.
383 if isinstance(hwid_info_list[0], dict):
384 # Format of hwid_info:
385 # [{u'name': u'sku', u'value': u'xxx'}, ..., ]
386 for hwid_info in hwid_info_list:
387 value = hwid_info.get('value', '')
388 name = hwid_info.get('name', '')
389 # There should always be a name but just in case there is not.
390 if name:
391 new_label = name if not value else '%s:%s' % (name, value)
392 res.append(new_label)
393 else:
394 # Format of hwid_info:
395 # [<DUTLabel name: 'sku' value: u'xxx'>, ..., ]
396 for hwid_info in hwid_info_list:
397 new_label = str(hwid_info)
398 logging.info('processing hwid label: %s', new_label)
399 res.append(new_label)
400
401 return res
402
403
Kevin Cheng80ad5732016-03-31 16:01:56 -0700404class HWIDLabel(base_label.StringLabel):
405 """Return all the labels generated from the hwid."""
406
407 # We leave out _NAME because hwid_lib will generate everything for us.
408
409 def __init__(self):
410 # Grab the key file needed to access the hwid service.
411 self.key_file = global_config.global_config.get_config_value(
412 'CROS', 'HWID_KEY', type=str)
413
414
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700415 @staticmethod
416 def _merge_hwid_label_lists(new, old):
417 """merge a list of old and new values for hwid_labels.
418 preferring new values if available
419
420 @returns: list of labels"""
421 # TODO(gregorynisbet): what is the appropriate way to merge
422 # old and new information?
423 retained = set(x for x in old)
424 for label in new:
425 key, sep, value = label.partition(':')
426 # If we have a key-value key such as variant:aaa,
427 # then we remove all the old labels with the same key.
428 if sep:
429 retained = set(x for x in retained if (not x.startswith(key + ':')))
430 return list(sorted(retained.union(new)))
431
432
433 def _hwid_label_names(self):
434 """get the labels that hwid_lib controls.
435
436 @returns: hwid_labels
437 """
438 all_hwid_labels, _ = self.get_all_labels()
439 # If and only if get_all_labels was unsuccessful,
440 # it will return a falsey value.
Gregory Nisbetbfd120f2019-09-04 14:49:46 -0700441 out = all_hwid_labels or HWID_LABELS_FALLBACK
442
443 # TODO(gregorynisbet): remove this
444 # TODO(crbug.com/999785)
445 if "sku" not in out:
446 logging.info("sku-less label names %s", out)
447
448 return out
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700449
450
451 def _old_label_values(self, host):
452 """get the hwid_lib labels on previous run
453
454 @returns: hwid_labels"""
455 out = []
456 info = host.host_info_store.get()
457 for hwid_label in self._hwid_label_names():
458 for label in info.labels:
459 # NOTE: we want *all* the labels starting
460 # with this prefix.
461 if label.startswith(hwid_label):
462 out.append(label)
463 return out
464
465
Kevin Cheng80ad5732016-03-31 16:01:56 -0700466 def generate_labels(self, host):
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700467 # use previous values as default
468 old_hwid_labels = self._old_label_values(host)
Xixuan Wue63f8352019-09-13 15:18:03 -0700469 logging.info("old_hwid_labels: %r", old_hwid_labels)
Kevin Cheng80ad5732016-03-31 16:01:56 -0700470 hwid = host.run_output('crossystem hwid').strip()
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700471 hwid_info_list = []
472 try:
473 hwid_info_response = hwid_lib.get_hwid_info(
474 hwid=hwid,
475 info_type=hwid_lib.HWID_INFO_LABEL,
476 key_file=self.key_file,
477 )
Xixuan Wue63f8352019-09-13 15:18:03 -0700478 logging.info("hwid_info_response: %r", hwid_info_response)
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700479 hwid_info_list = hwid_info_response.get('labels', [])
480 except hwid_lib.HwIdException as e:
481 logging.info("HwIdException: %s", e)
Kevin Cheng80ad5732016-03-31 16:01:56 -0700482
Xixuan Wu78569d02019-09-15 16:08:25 -0700483 new_hwid_labels = _parse_hwid_labels(hwid_info_list)
484 logging.info("new HWID labels: %r", new_hwid_labels)
Gregory Nisbetbfd120f2019-09-04 14:49:46 -0700485
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700486 return HWIDLabel._merge_hwid_label_lists(
487 old=old_hwid_labels,
Xixuan Wu78569d02019-09-15 16:08:25 -0700488 new=new_hwid_labels,
Gregory Nisbetfb68a1f2019-08-22 10:27:33 -0700489 )
Kevin Cheng80ad5732016-03-31 16:01:56 -0700490
491
492 def get_all_labels(self):
493 """We need to try all labels as a prefix and as standalone.
494
495 We don't know for sure which labels are prefix labels and which are
496 standalone so we try all of them as both.
497 """
498 all_hwid_labels = []
499 try:
500 all_hwid_labels = hwid_lib.get_all_possible_dut_labels(
501 self.key_file)
502 except IOError:
503 logging.error('Can not open key file: %s', self.key_file)
504 except hwid_lib.HwIdException as e:
505 logging.error('hwid service: %s', e)
506 return all_hwid_labels, all_hwid_labels
507
508
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700509class DutStorageLabel(base_label.StringPrefixLabel):
510 """Return the DUT storage label."""
511
512 _NAME = audit_const.DUT_STORAGE_STATE_PREFIX
513
514 def exists(self, host):
515 return host.servo is not None
516
517 def generate_labels(self, host):
518 verifier = audit_verify.VerifyDutStorage(host)
519 verifier.verify(set_label=False)
520 state = verifier.get_state()
521 return [state]
522
523 def update_for_task(self, task_name):
Otabek Kasimov1fe268f2020-09-01 09:41:13 -0700524 # This label is part of audit task, so updating it only during
525 # deploy tasks to update it for new deployments.
526 return task_name == DEPLOY_TASK_NAME
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700527
528
Kevin Chenga2619dc2016-03-28 11:42:08 -0700529CROS_LABELS = [
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800530 AudioLoopbackDongleLabel(), #STATECONFIG
Shijin Abraham76bc1db2020-03-06 10:52:10 -0800531 BluetoothPeerLabel(), #STATECONFIG
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800532 ChameleonConnectionLabel(), #LABCONFIG
533 ChameleonLabel(), #STATECONFIG
534 ChameleonPeripheralsLabel(), #LABCONFIG
Kevin Chenga2619dc2016-03-28 11:42:08 -0700535 common_label.OSLabel(),
Eshwar Narayanf46904c2020-02-11 17:57:31 -0800536 DeviceSkuLabel(), #LABCONFIG
Kevin Cheng80ad5732016-03-31 16:01:56 -0700537 HWIDLabel(),
Otabek Kasimov43185912020-03-11 16:01:52 -0700538 ServoTypeLabel(), #LABCONFIG
Xixuan Wu457b4ac2020-03-02 14:39:08 -0800539 # Temporarily add back as there's no way to reference cr50 configs.
540 # See crbug.com/1057145 for the root cause.
541 # See crbug.com/1057719 for future tracking.
542 Cr50Label(),
543 Cr50ROKeyidLabel(),
Otabek Kasimov40ccb972020-05-26 15:14:39 -0700544 DutStorageLabel(), #STATECONFIG
Kevin Chenga2619dc2016-03-28 11:42:08 -0700545]
Garry Wange4b6d6e2019-06-17 17:08:46 -0700546
547LABSTATION_LABELS = [
Garry Wange4b6d6e2019-06-17 17:08:46 -0700548 common_label.OSLabel(),
549]