• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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 TestBed Label detection classes."""
6
7import common
8
9from autotest_lib.server.cros.dynamic_suite import constants
10from autotest_lib.server.hosts import adb_label
11from autotest_lib.server.hosts import base_label
12
13
14class ADBDeviceLabels(base_label.StringLabel):
15    """Return a list of the labels gathered from the devices connected."""
16
17    # _NAME is omitted because the labels generated are full labels.
18    # The generated labels are from an adb device, so we just want to grab the
19    # possible labels from ADBLabels.
20    _LABEL_LIST = adb_label.ADB_LABELS
21
22    # pylint: disable=missing-docstring
23    def generate_labels(self, testbed):
24        labels = []
25        for adb_device in testbed.get_adb_devices().values():
26            labels.extend(adb_device.get_labels())
27        # Currently the board label will need to be modified for each adb
28        # device.  We'll get something like 'board:android-shamu' and
29        # we'll need to update it to 'board:android-shamu-1'.  Let's store all
30        # the labels in a dict and keep track of how many times we encounter
31        # it, that way we know what number to append.
32        board_label_dict = {}
33        updated_labels = set()
34        for label in labels:
35            # Update the board labels
36            if label.startswith(constants.BOARD_PREFIX):
37                # Now let's grab the board num and append it to the board_label.
38                board_num = board_label_dict.setdefault(label, 0) + 1
39                board_label_dict[label] = board_num
40                updated_labels.add('%s-%d' % (label, board_num))
41            else:
42                # We don't need to mess with this.
43                updated_labels.add(label)
44        return list(updated_labels)
45
46
47TESTBED_LABELS = [
48        ADBDeviceLabels(),
49]
50