blob: 87daa732e8e86a94bc0998138f3eb7d154d262a4 [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
9import os
10import re
11
12import common
13
14from autotest_lib.client.bin import utils
Kevin Cheng80ad5732016-03-31 16:01:56 -070015from autotest_lib.client.common_lib import global_config
Kevin Chenga2619dc2016-03-28 11:42:08 -070016from autotest_lib.client.cros.audio import cras_utils
Kevin Chenga2619dc2016-03-28 11:42:08 -070017from autotest_lib.client.cros.video import constants as video_test_constants
18from autotest_lib.server.cros.dynamic_suite import constants as ds_constants
19from autotest_lib.server.hosts import base_label
20from autotest_lib.server.hosts import common_label
Kevin Chengd9dfa582016-05-04 09:37:34 -070021from autotest_lib.server.hosts import servo_host
Kevin Cheng80ad5732016-03-31 16:01:56 -070022from autotest_lib.site_utils import hwid_lib
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
27def _parse_lsb_output(host):
28 """Parses the LSB output and returns key data points for labeling.
29
30 @param host: Host that the command will be executed against
31 @returns: LsbOutput with the result of parsing the /etc/lsb-release output
32 """
33 release_info = utils.parse_cmd_output('cat /etc/lsb-release',
34 run_method=host.run)
35
36 unibuild = release_info.get('CHROMEOS_RELEASE_UNIBUILD') == '1'
37 return LsbOutput(unibuild, release_info['CHROMEOS_RELEASE_BOARD'])
38
Kevin Chenga2619dc2016-03-28 11:42:08 -070039
Kevin Chenga8455302016-08-31 20:54:41 +000040class BoardLabel(base_label.StringPrefixLabel):
41 """Determine the correct board label for the device."""
42
43 _NAME = ds_constants.BOARD_PREFIX.rstrip(':')
44
45 def generate_labels(self, host):
46 # We only want to apply the board labels once, which is when they get
47 # added to the AFE. That way we don't have to worry about the board
48 # label switching on us if the wrong builds get put on the devices.
49 # crbug.com/624207 records one event of the board label switching
50 # unexpectedly on us.
51 for label in host._afe_host.labels:
52 if label.startswith(self._NAME + ':'):
53 return [label.split(':')[-1]]
54
C Shapiro10970222017-10-24 08:55:55 -060055 return [_parse_lsb_output(host).board]
Kevin Chenga8455302016-08-31 20:54:41 +000056
57
C Shapirob05c00b2017-07-18 15:06:49 -060058class ModelLabel(base_label.StringPrefixLabel):
59 """Determine the correct model label for the device."""
60
61 _NAME = ds_constants.MODEL_LABEL
62
63 def generate_labels(self, host):
C Shapirod7ba4a72018-01-16 17:04:35 -070064 # Based on the issue explained in BoardLabel, return the existing
65 # label if it has already been set once.
66 for label in host._afe_host.labels:
67 if label.startswith(self._NAME + ':'):
68 return [label.split(':')[-1]]
C Shapirob05c00b2017-07-18 15:06:49 -060069
C Shapiro32700032017-11-03 12:46:55 -060070 lsb_output = _parse_lsb_output(host)
71 model = None
72
73 if lsb_output.unibuild:
C Shapiro26fb1012017-12-14 16:38:03 -070074 test_label_cmd = 'cros_config / test-label'
75 result = host.run(command=test_label_cmd, ignore_status=True)
C Shapiro32700032017-11-03 12:46:55 -060076 if result.exit_status == 0:
77 model = result.stdout.strip()
C Shapiro26fb1012017-12-14 16:38:03 -070078 if not model:
79 mosys_cmd = 'mosys platform model'
80 result = host.run(command=mosys_cmd, ignore_status=True)
81 if result.exit_status == 0:
82 model = result.stdout.strip()
C Shapiro32700032017-11-03 12:46:55 -060083
84 # We need some sort of backwards compatibility for boards that
85 # are not yet supported with mosys and unified builds.
86 # This is necessary so that we can begin changing cbuildbot to take
87 # advantage of the model/board label differentiations for
88 # scheduling, while still retaining backwards compatibility.
89 return [model or lsb_output.board]
C Shapirob05c00b2017-07-18 15:06:49 -060090
91
Kevin Chenga2619dc2016-03-28 11:42:08 -070092class LightSensorLabel(base_label.BaseLabel):
93 """Label indicating if a light sensor is detected."""
94
95 _NAME = 'lightsensor'
96 _LIGHTSENSOR_SEARCH_DIR = '/sys/bus/iio/devices'
97 _LIGHTSENSOR_FILES = [
98 "in_illuminance0_input",
99 "in_illuminance_input",
100 "in_illuminance0_raw",
101 "in_illuminance_raw",
102 "illuminance0_input",
103 ]
104
105 def exists(self, host):
106 search_cmd = "find -L %s -maxdepth 4 | egrep '%s'" % (
107 self._LIGHTSENSOR_SEARCH_DIR, '|'.join(self._LIGHTSENSOR_FILES))
108 # Run the search cmd following the symlinks. Stderr_tee is set to
109 # None as there can be a symlink loop, but the command will still
110 # execute correctly with a few messages printed to stderr.
111 result = host.run(search_cmd, stdout_tee=None, stderr_tee=None,
112 ignore_status=True)
113
114 return result.exit_status == 0
115
116
117class BluetoothLabel(base_label.BaseLabel):
118 """Label indicating if bluetooth is detected."""
119
120 _NAME = 'bluetooth'
121
122 def exists(self, host):
123 result = host.run('test -d /sys/class/bluetooth/hci0',
124 ignore_status=True)
125
126 return result.exit_status == 0
127
128
129class ECLabel(base_label.BaseLabel):
130 """Label to determine the type of EC on this host."""
131
132 _NAME = 'ec:cros'
133
134 def exists(self, host):
135 cmd = 'mosys ec info'
136 # The output should look like these, so that the last field should
137 # match our EC version scheme:
138 #
139 # stm | stm32f100 | snow_v1.3.139-375eb9f
140 # ti | Unknown-10de | peppy_v1.5.114-5d52788
141 #
142 # Non-Chrome OS ECs will look like these:
143 #
144 # ENE | KB932 | 00BE107A00
145 # ite | it8518 | 3.08
146 #
147 # And some systems don't have ECs at all (Lumpy, for example).
148 regexp = r'^.*\|\s*(\S+_v\d+\.\d+\.\d+-[0-9a-f]+)\s*$'
149
150 ecinfo = host.run(command=cmd, ignore_status=True)
151 if ecinfo.exit_status == 0:
152 res = re.search(regexp, ecinfo.stdout)
153 if res:
154 logging.info("EC version is %s", res.groups()[0])
155 return True
156 logging.info("%s got: %s", cmd, ecinfo.stdout)
157 # Has an EC, but it's not a Chrome OS EC
158 logging.info("%s exited with status %d", cmd, ecinfo.exit_status)
159 return False
160
161
Mary Ruthven935ebad2018-06-13 16:13:20 -0700162class Cr50Label(base_label.StringPrefixLabel):
163 """Label indicating the cr50 version."""
164
165 _NAME = 'cr50'
166
167 def __init__(self):
168 self.ver = None
169
170
171 def exists(self, host):
172 # Make sure the gsctool version command runs ok
173 self.ver = host.run('gsctool -a -f', ignore_status=True)
174 return self.ver.exit_status == 0
175
176
177 def generate_labels(self, host):
178 # Check the major version to determine prePVT vs PVT
179 major_ver = int(re.search('RW \d+\.(\d+)\.\d+[\r\n]',
180 self.ver.stdout).group(1))
181 # PVT images have a odd major version prePVT have even
182 return ['pvt' if (major_ver % 2) else 'prepvt']
183
184
Kevin Chenga2619dc2016-03-28 11:42:08 -0700185class AccelsLabel(base_label.BaseLabel):
186 """Determine the type of accelerometers on this host."""
187
188 _NAME = 'accel:cros-ec'
189
190 def exists(self, host):
191 # Check to make sure we have ectool
192 rv = host.run('which ectool', ignore_status=True)
193 if rv.exit_status:
194 logging.info("No ectool cmd found; assuming no EC accelerometers")
195 return False
196
197 # Check that the EC supports the motionsense command
Kevin Cheng856f8a32016-03-31 16:08:08 -0700198 rv = host.run('ectool motionsense', ignore_status=True)
Kevin Chenga2619dc2016-03-28 11:42:08 -0700199 if rv.exit_status:
200 logging.info("EC does not support motionsense command; "
201 "assuming no EC accelerometers")
202 return False
203
204 # Check that EC motion sensors are active
Kevin Cheng17e2f002016-05-04 08:48:03 -0700205 active = host.run('ectool motionsense active').stdout.split('\n')
Kevin Chenga2619dc2016-03-28 11:42:08 -0700206 if active[0] == "0":
207 logging.info("Motion sense inactive; assuming no EC accelerometers")
208 return False
209
210 logging.info("EC accelerometers found")
211 return True
212
213
214class ChameleonLabel(base_label.BaseLabel):
215 """Determine if a Chameleon is connected to this host."""
216
217 _NAME = 'chameleon'
218
219 def exists(self, host):
220 return host._chameleon_host is not None
221
222
223class ChameleonConnectionLabel(base_label.StringPrefixLabel):
224 """Return the Chameleon connection label."""
225
226 _NAME = 'chameleon'
227
228 def exists(self, host):
229 return host._chameleon_host is not None
230
Joseph Hwangeac44312016-08-31 12:08:38 +0800231
Kevin Chenga2619dc2016-03-28 11:42:08 -0700232 def generate_labels(self, host):
233 return [host.chameleon.get_label()]
234
235
Joseph Hwangeac44312016-08-31 12:08:38 +0800236class ChameleonPeripheralsLabel(base_label.StringPrefixLabel):
237 """Return the Chameleon peripherals labels.
238
239 The 'chameleon:bt_hid' label is applied if the bluetooth
240 classic hid device, i.e, RN-42 emulation kit, is detected.
241
242 Any peripherals plugged into the chameleon board would be
243 detected and applied proper labels in this class.
244 """
245
246 _NAME = 'chameleon'
247
248 def exists(self, host):
249 return host._chameleon_host is not None
250
251
252 def generate_labels(self, host):
253 bt_hid_device = host.chameleon.get_bluetooh_hid_mouse()
254 return ['bt_hid'] if bt_hid_device.CheckSerialConnection() else []
255
256
Kevin Chenga2619dc2016-03-28 11:42:08 -0700257class AudioLoopbackDongleLabel(base_label.BaseLabel):
258 """Return the label if an audio loopback dongle is plugged in."""
259
260 _NAME = 'audio_loopback_dongle'
261
262 def exists(self, host):
263 nodes_info = host.run(command=cras_utils.get_cras_nodes_cmd(),
264 ignore_status=True).stdout
265 if (cras_utils.node_type_is_plugged('HEADPHONE', nodes_info) and
266 cras_utils.node_type_is_plugged('MIC', nodes_info)):
267 return True
268 return False
269
270
271class PowerSupplyLabel(base_label.StringPrefixLabel):
272 """
273 Return the label describing the power supply type.
274
275 Labels representing this host's power supply.
276 * `power:battery` when the device has a battery intended for
277 extended use
278 * `power:AC_primary` when the device has a battery not intended
279 for extended use (for moving the machine, etc)
280 * `power:AC_only` when the device has no battery at all.
281 """
282
283 _NAME = 'power'
284
285 def __init__(self):
286 self.psu_cmd_result = None
287
288
289 def exists(self, host):
290 self.psu_cmd_result = host.run(command='mosys psu type',
291 ignore_status=True)
292 return self.psu_cmd_result.stdout.strip() != 'unknown'
293
294
295 def generate_labels(self, host):
296 if self.psu_cmd_result.exit_status:
297 # The psu command for mosys is not included for all platforms. The
298 # assumption is that the device will have a battery if the command
299 # is not found.
300 return ['battery']
301 return [self.psu_cmd_result.stdout.strip()]
302
303
304class StorageLabel(base_label.StringPrefixLabel):
305 """
306 Return the label describing the storage type.
307
308 Determine if the internal device is SCSI or dw_mmc device.
309 Then check that it is SSD or HDD or eMMC or something else.
310
311 Labels representing this host's internal device type:
312 * `storage:ssd` when internal device is solid state drive
313 * `storage:hdd` when internal device is hard disk drive
314 * `storage:mmc` when internal device is mmc drive
Gwendal Grignou327fec62017-07-26 15:25:43 -0700315 * `storage:nvme` when internal device is NVMe drive
Kevin Chenga2619dc2016-03-28 11:42:08 -0700316 * None When internal device is something else or
317 when we are unable to determine the type
318 """
319
320 _NAME = 'storage'
321
322 def __init__(self):
323 self.type_str = ''
324
325
326 def exists(self, host):
327 # The output should be /dev/mmcblk* for SD/eMMC or /dev/sd* for scsi
328 rootdev_cmd = ' '.join(['. /usr/sbin/write_gpt.sh;',
329 '. /usr/share/misc/chromeos-common.sh;',
330 'load_base_vars;',
331 'get_fixed_dst_drive'])
332 rootdev = host.run(command=rootdev_cmd, ignore_status=True)
333 if rootdev.exit_status:
334 logging.info("Fail to run %s", rootdev_cmd)
335 return False
336 rootdev_str = rootdev.stdout.strip()
337
338 if not rootdev_str:
339 return False
340
341 rootdev_base = os.path.basename(rootdev_str)
342
343 mmc_pattern = '/dev/mmcblk[0-9]'
344 if re.match(mmc_pattern, rootdev_str):
345 # Use type to determine if the internal device is eMMC or somthing
346 # else. We can assume that MMC is always an internal device.
347 type_cmd = 'cat /sys/block/%s/device/type' % rootdev_base
348 type = host.run(command=type_cmd, ignore_status=True)
349 if type.exit_status:
350 logging.info("Fail to run %s", type_cmd)
351 return False
352 type_str = type.stdout.strip()
353
354 if type_str == 'MMC':
355 self.type_str = 'mmc'
356 return True
357
358 scsi_pattern = '/dev/sd[a-z]+'
359 if re.match(scsi_pattern, rootdev.stdout):
360 # Read symlink for /sys/block/sd* to determine if the internal
361 # device is connected via ata or usb.
362 link_cmd = 'readlink /sys/block/%s' % rootdev_base
363 link = host.run(command=link_cmd, ignore_status=True)
364 if link.exit_status:
365 logging.info("Fail to run %s", link_cmd)
366 return False
367 link_str = link.stdout.strip()
368 if 'usb' in link_str:
369 return False
370
371 # Read rotation to determine if the internal device is ssd or hdd.
372 rotate_cmd = str('cat /sys/block/%s/queue/rotational'
373 % rootdev_base)
374 rotate = host.run(command=rotate_cmd, ignore_status=True)
375 if rotate.exit_status:
376 logging.info("Fail to run %s", rotate_cmd)
377 return False
378 rotate_str = rotate.stdout.strip()
379
380 rotate_dict = {'0':'ssd', '1':'hdd'}
381 self.type_str = rotate_dict.get(rotate_str)
382 return True
383
Gwendal Grignou327fec62017-07-26 15:25:43 -0700384 nvme_pattern = '/dev/nvme[0-9]+n[0-9]+'
385 if re.match(nvme_pattern, rootdev_str):
Gwendal Grignou3660c192017-12-06 10:11:23 -0800386 self.type_str = 'nvme'
Gwendal Grignou327fec62017-07-26 15:25:43 -0700387 return True
388
Kevin Chenga2619dc2016-03-28 11:42:08 -0700389 # All other internal device / error case will always fall here
390 return False
391
392
393 def generate_labels(self, host):
394 return [self.type_str]
395
396
397class ServoLabel(base_label.BaseLabel):
398 """Label to apply if a servo is present."""
399
400 _NAME = 'servo'
401
402 def exists(self, host):
Kevin Chengbbe5cf12016-06-08 21:50:01 -0700403 """
404 Check if the servo label should apply to the host or not.
405
406 @returns True if a servo host is detected, False otherwise.
407 """
Kevin Cheng745b8162017-05-26 09:48:36 -0700408 servo_host_hostname = None
Kevin Chengbbe5cf12016-06-08 21:50:01 -0700409 servo_args, _ = servo_host._get_standard_servo_args(host)
Kevin Cheng745b8162017-05-26 09:48:36 -0700410 if servo_args:
411 servo_host_hostname = servo_args.get(servo_host.SERVO_HOST_ATTR)
Kevin Chengbbe5cf12016-06-08 21:50:01 -0700412 return (servo_host_hostname is not None
413 and servo_host.servo_host_is_up(servo_host_hostname))
Kevin Chenga2619dc2016-03-28 11:42:08 -0700414
415
416class VideoLabel(base_label.StringLabel):
417 """Labels detailing video capabilities."""
418
419 # List gathered from
420 # https://chromium.googlesource.com/chromiumos/
421 # platform2/+/master/avtest_label_detect/main.c#19
Hirokazu Hondad6cfe922017-10-03 13:07:37 +0900422 # TODO(hiroh): '4k_video' won't be used. It will be removed in the future.
Kevin Chenga2619dc2016-03-28 11:42:08 -0700423 _NAME = [
424 'hw_jpeg_acc_dec',
425 'hw_video_acc_h264',
426 'hw_video_acc_vp8',
427 'hw_video_acc_vp9',
428 'hw_video_acc_enc_h264',
429 'hw_video_acc_enc_vp8',
430 'webcam',
Hirokazu Honda57dbf002017-09-21 16:05:06 +0900431 '4k_video',
Hirokazu Hondad6cfe922017-10-03 13:07:37 +0900432 '4k_video_h264',
433 '4k_video_vp8',
434 '4k_video_vp9',
Kevin Chenga2619dc2016-03-28 11:42:08 -0700435 ]
436
437 def generate_labels(self, host):
438 result = host.run('/usr/local/bin/avtest_label_detect',
439 ignore_status=True).stdout
440 return re.findall('^Detected label: (\w+)$', result, re.M)
441
442
Ilja H. Friedel50290642017-12-01 19:39:53 -0800443class ArcLabel(base_label.BaseLabel):
444 """Label indicates if host has ARC support."""
445
446 _NAME = 'arc'
447
448 @base_label.forever_exists_decorate
449 def exists(self, host):
450 return 0 == host.run(
451 'grep CHROMEOS_ARC_VERSION /etc/lsb-release',
452 ignore_status=True).exit_status
453
454
455class CtsArchLabel(base_label.StringLabel):
456 """Labels to determine the abi of the CTS bundle (arm or x86 only)."""
457 # TODO(ihf): create labels for ABIs supported by container like x86_64.
Rohit Makasana5a153502016-06-13 15:50:09 -0700458
459 _NAME = ['cts_abi_arm', 'cts_abi_x86']
460
461 def _get_cts_abis(self, host):
462 """Return supported CTS ABIs.
463
464 @return List of supported CTS bundle ABIs.
465 """
466 cts_abis = {'x86_64': ['arm', 'x86'], 'arm': ['arm']}
467 return cts_abis.get(host.get_cpu_arch(), [])
468
Rohit Makasana5a153502016-06-13 15:50:09 -0700469 def generate_labels(self, host):
470 return ['cts_abi_' + abi for abi in self._get_cts_abis(host)]
471
472
Ilja H. Friedel50290642017-12-01 19:39:53 -0800473class SparseCoverageLabel(base_label.StringLabel):
474 """Label indicates if it is desirable to cover a test for this build."""
Rohit Makasanac6e5d622016-06-16 17:13:39 -0700475
Ilja H. Friedel50290642017-12-01 19:39:53 -0800476 # Prime numbers. We can easily construct 6, 10, 15 and 30 from these.
477 _NAME = ['sparse_coverage_2', 'sparse_coverage_3', 'sparse_coverage_5']
Rohit Makasanac6e5d622016-06-16 17:13:39 -0700478
Ilja H. Friedel50290642017-12-01 19:39:53 -0800479 def _should_cover(self, host, nth_build):
480 release_info = utils.parse_cmd_output(
481 'cat /etc/lsb-release', run_method=host.run)
482 build = release_info.get('CHROMEOS_RELEASE_BUILD_NUMBER')
483 branch = release_info.get('CHROMEOS_RELEASE_BRANCH_NUMBER')
484 patch = release_info.get('CHROMEOS_RELEASE_PATCH_NUMBER')
485 builder = release_info.get('CHROMEOS_RELEASE_BUILDER_PATH')
486 if not 'release' in builder:
487 # Sparse coverage only makes sense on release/canary builds.
488 return True
489 if patch != '0':
490 # We are on a paladin or pfq build. These are never sparse.
491 # Redundant with release check above but just in case.
492 return True
493 if branch != '0':
494 # We are on a branch. For now these are not sparse.
495 # TODO(ihf): Consider sparse coverage on beta.
496 return True
497 # Now we can be sure we are on master.
498 if int(build) % nth_build == 0:
499 # We only want to cover one in n builds on master. This is the
500 # lucky one.
501 return True
502 # We skip all other builds on master.
503 return False
504
505 def generate_labels(self, host):
506 labels = []
507 for n in [2, 3, 5]:
508 if self._should_cover(host, n):
509 labels.append('sparse_coverage_%d' % n)
510 return labels
Rohit Makasanac6e5d622016-06-16 17:13:39 -0700511
512
Kevin Chenga2619dc2016-03-28 11:42:08 -0700513class VideoGlitchLabel(base_label.BaseLabel):
514 """Label indicates if host supports video glitch detection tests."""
515
516 _NAME = 'video_glitch_detection'
517
518 def exists(self, host):
519 board = host.get_board().replace(ds_constants.BOARD_PREFIX, '')
520
521 return board in video_test_constants.SUPPORTED_BOARDS
522
523
Kevin Chenga2619dc2016-03-28 11:42:08 -0700524class InternalDisplayLabel(base_label.StringLabel):
525 """Label that determines if the device has an internal display."""
526
527 _NAME = 'internal_display'
528
529 def generate_labels(self, host):
530 from autotest_lib.client.cros.graphics import graphics_utils
531 from autotest_lib.client.common_lib import utils as common_utils
532
533 def __system_output(cmd):
534 return host.run(cmd).stdout
535
536 def __read_file(remote_path):
537 return host.run('cat %s' % remote_path).stdout
538
539 # Hijack the necessary client functions so that we can take advantage
540 # of the client lib here.
541 # FIXME: find a less hacky way than this
542 original_system_output = utils.system_output
543 original_read_file = common_utils.read_file
544 utils.system_output = __system_output
545 common_utils.read_file = __read_file
546 try:
547 return ([self._NAME]
548 if graphics_utils.has_internal_display()
549 else [])
550 finally:
551 utils.system_output = original_system_output
552 common_utils.read_file = original_read_file
553
554
555class LucidSleepLabel(base_label.BaseLabel):
556 """Label that determines if device has support for lucid sleep."""
557
558 # TODO(kevcheng): See if we can determine if this label is applicable a
559 # better way (crbug.com/592146).
560 _NAME = 'lucidsleep'
561 LUCID_SLEEP_BOARDS = ['samus', 'lulu']
562
563 def exists(self, host):
564 board = host.get_board().replace(ds_constants.BOARD_PREFIX, '')
565 return board in self.LUCID_SLEEP_BOARDS
566
567
Kevin Cheng80ad5732016-03-31 16:01:56 -0700568class HWIDLabel(base_label.StringLabel):
569 """Return all the labels generated from the hwid."""
570
571 # We leave out _NAME because hwid_lib will generate everything for us.
572
573 def __init__(self):
574 # Grab the key file needed to access the hwid service.
575 self.key_file = global_config.global_config.get_config_value(
576 'CROS', 'HWID_KEY', type=str)
577
578
579 def generate_labels(self, host):
580 hwid_labels = []
581 hwid = host.run_output('crossystem hwid').strip()
582 hwid_info_list = hwid_lib.get_hwid_info(hwid, hwid_lib.HWID_INFO_LABEL,
583 self.key_file).get('labels', [])
584
585 for hwid_info in hwid_info_list:
586 # If it's a prefix, we'll have:
587 # {'name': prefix_label, 'value': postfix_label} and create
588 # 'prefix_label:postfix_label'; otherwise it'll just be
589 # {'name': label} which should just be 'label'.
590 value = hwid_info.get('value', '')
591 name = hwid_info.get('name', '')
592 # There should always be a name but just in case there is not.
593 if name:
594 hwid_labels.append(name if not value else
595 '%s:%s' % (name, value))
596 return hwid_labels
597
598
599 def get_all_labels(self):
600 """We need to try all labels as a prefix and as standalone.
601
602 We don't know for sure which labels are prefix labels and which are
603 standalone so we try all of them as both.
604 """
605 all_hwid_labels = []
606 try:
607 all_hwid_labels = hwid_lib.get_all_possible_dut_labels(
608 self.key_file)
609 except IOError:
610 logging.error('Can not open key file: %s', self.key_file)
611 except hwid_lib.HwIdException as e:
612 logging.error('hwid service: %s', e)
613 return all_hwid_labels, all_hwid_labels
614
615
Chih-Yu Huangcaca4882018-01-30 11:21:48 +0800616class DetachableBaseLabel(base_label.BaseLabel):
617 """Label indicating if device has detachable keyboard."""
618
619 _NAME = 'detachablebase'
620
621 def exists(self, host):
622 return host.run('which hammerd', ignore_status=True).exit_status == 0
623
624
Kevin Chenga2619dc2016-03-28 11:42:08 -0700625CROS_LABELS = [
626 AccelsLabel(),
Rohit Makasanac6e5d622016-06-16 17:13:39 -0700627 ArcLabel(),
Kevin Chenga2619dc2016-03-28 11:42:08 -0700628 AudioLoopbackDongleLabel(),
629 BluetoothLabel(),
Kevin Chenga8455302016-08-31 20:54:41 +0000630 BoardLabel(),
C Shapiro05dd3222017-09-22 10:42:33 -0600631 ModelLabel(),
Kevin Chenga2619dc2016-03-28 11:42:08 -0700632 ChameleonConnectionLabel(),
633 ChameleonLabel(),
Joseph Hwangeac44312016-08-31 12:08:38 +0800634 ChameleonPeripheralsLabel(),
Kevin Chenga2619dc2016-03-28 11:42:08 -0700635 common_label.OSLabel(),
Mary Ruthven935ebad2018-06-13 16:13:20 -0700636 Cr50Label(),
Ilja H. Friedel50290642017-12-01 19:39:53 -0800637 CtsArchLabel(),
Chih-Yu Huangcaca4882018-01-30 11:21:48 +0800638 DetachableBaseLabel(),
Kevin Chenga2619dc2016-03-28 11:42:08 -0700639 ECLabel(),
Kevin Cheng80ad5732016-03-31 16:01:56 -0700640 HWIDLabel(),
Kevin Chenga2619dc2016-03-28 11:42:08 -0700641 InternalDisplayLabel(),
642 LightSensorLabel(),
643 LucidSleepLabel(),
644 PowerSupplyLabel(),
645 ServoLabel(),
Ilja H. Friedel50290642017-12-01 19:39:53 -0800646 SparseCoverageLabel(),
Kevin Chenga2619dc2016-03-28 11:42:08 -0700647 StorageLabel(),
Kevin Chenga2619dc2016-03-28 11:42:08 -0700648 VideoGlitchLabel(),
649 VideoLabel(),
650]