blob: c4eb2fd1f9b1ce1ce4d52fda81ae7e36aacd53d3 [file] [log] [blame]
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
from autotest_lib.server import frontend
from constants import Labels
class EnumeratorException(Exception):
"""Base class for exceptions from this module."""
class EnumerateException(EnumeratorException):
"""Raised when an error is returned from the AFE during enumeration."""
class NoBoardException(EnumeratorException):
"""Raised when an error is returned from the AFE during enumeration."""
def __init__(self):
super(NoBoardException, self).__init__('No supported boards.')
class BoardEnumerator(object):
"""Talks to the AFE and enumerates the boards it knows about.
@var _afe: a frontend.AFE instance used to talk to autotest.
def __init__(self, afe=None):
@param afe: an instance of AFE as defined in server/
self._afe = afe
def Enumerate(self):
"""Enumerate currently supported boards.
Lists all labels known to the AFE that start with self._LABEL_PREFIX,
as this is the way that we define 'boards' in the AFE today.
@return list of board names, e.g. 'x86-mario'
labels = self._afe.get_labels(name__startswith=Labels.BOARD_PREFIX)
except Exception as e:
raise EnumerateException(e)
if not labels:
raise NoBoardException()
return map(lambda l:':', 1)[1], labels)