1# Copyright (c) 2012 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 5from autotest_lib.server.cros.dynamic_suite import frontend_wrappers 6from autotest_lib.server import frontend 7 8from constants import Labels 9 10 11class EnumeratorException(Exception): 12 """Base class for exceptions from this module.""" 13 pass 14 15 16class EnumerateException(EnumeratorException): 17 """Raised when an error is returned from the AFE during enumeration.""" 18 pass 19 20 21class NoBoardException(EnumeratorException): 22 """Raised when an error is returned from the AFE during enumeration.""" 23 24 25 def __init__(self): 26 super(NoBoardException, self).__init__('No supported boards.') 27 28 29class BoardEnumerator(object): 30 """Talks to the AFE and enumerates the boards it knows about. 31 32 @var _afe: a frontend.AFE instance used to talk to autotest. 33 """ 34 35 36 def __init__(self, afe=None): 37 """Constructor 38 39 @param afe: an instance of AFE as defined in server/frontend.py. 40 """ 41 self._afe = afe 42 43 44 def Enumerate(self): 45 """Enumerate currently supported boards. 46 47 Lists all labels known to the AFE that start with self._LABEL_PREFIX, 48 as this is the way that we define 'boards' in the AFE today. 49 50 @return list of board names, e.g. 'x86-mario' 51 """ 52 try: 53 labels = self._afe.get_labels(name__startswith=Labels.BOARD_PREFIX) 54 except Exception as e: 55 raise EnumerateException(e) 56 57 if not labels: 58 raise NoBoardException() 59 60 return map(lambda l: l.name.split(':', 1)[1], labels) 61