blob: d4ae343022a03bbc22a5458dde59dbdff6b5e886 [file] [log] [blame]
Dan Shia1ecd5c2013-06-06 11:21:31 -07001# Copyright (c) 2013 The Chromium 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
5import logging
6
7from autotest_lib.server.cros.dynamic_suite import constants
8
9
10def get_label_from_afe(hostname, label_prefix, afe):
11 """Retrieve a host's specific label from the AFE.
12
13 Looks for a host label that has the form <label_prefix>:<value>
14 and returns the "<value>" part of the label. None is returned
15 if there is not a label matching the pattern
16
17 @param hostname: hostname of given DUT.
18 @param label_prefix: prefix of label to be matched, e.g., |board:|
19 @param afe: afe instance.
20 @returns the label that matches the prefix or 'None'
21
22 """
23 labels = afe.get_labels(name__startswith=label_prefix,
24 host__hostname__in=[hostname])
25 if labels and len(labels) == 1:
26 return labels[0].name.split(label_prefix, 1)[1]
27
28
29def get_board_from_afe(hostname, afe):
30 """Retrieve given host's board from its labels in the AFE.
31
32 Looks for a host label of the form "board:<board>", and
33 returns the "<board>" part of the label. `None` is returned
34 if there is not a single, unique label matching the pattern.
35
36 @param hostname: hostname of given DUT.
37 @param afe: afe instance.
38 @returns board from label, or `None`.
39
40 """
41 return get_label_from_afe(hostname, constants.BOARD_PREFIX, afe)
42
43
44def get_build_from_afe(hostname, afe):
45 """Retrieve the current build for given host from the AFE.
46
47 Looks through the host's labels in the AFE to determine its build.
48
49 @param hostname: hostname of given DUT.
50 @param afe: afe instance.
51 @returns The current build or None if it could not find it or if there
52 were multiple build labels assigned to this host.
53
54 """
55 return get_label_from_afe(hostname, constants.VERSION_PREFIX, afe)
56
57