[autotest] Loosens board list check when adding new board labels.
testbed may have a mix of different boards. This change loosens the board list
check to allow any board labels ending with -number to be added to a host.
BUG=chromium:660271
TEST=unittest
Change-Id: If5f8487472f1092b5ebc24e3df90c7965aa382d0
Reviewed-on: https://chromium-review.googlesource.com/407068
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/server/site_utils.py b/server/site_utils.py
index fab9ea2..de724ed 100644
--- a/server/site_utils.py
+++ b/server/site_utils.py
@@ -835,3 +835,24 @@
yield wait_for_idle_duts(locked_duts, afe, max_wait)
finally:
afe.unlock_hosts(locked_duts)
+
+
+def board_labels_allowed(boards):
+ """Check if the list of board labels can be set to a single host.
+
+ The only case multiple board labels can be set to a single host is for
+ testbed, which may have a list of board labels like
+ board:angler-1, board:angler-2, board:angler-3, board:marlin-1'
+
+ @param boards: A list of board labels (may include platform label).
+
+ @returns True if the the list of boards can be set to a single host.
+ """
+ # Filter out any non-board labels
+ boards = [b for b in boards if re.match('board:.*', b)]
+ if len(boards) <= 1:
+ return True
+ for board in boards:
+ if not re.match('board:[^-]+-\d+', board):
+ return False
+ return True
diff --git a/server/site_utils_unittest.py b/server/site_utils_unittest.py
index a44e90d..6d7edf8 100644
--- a/server/site_utils_unittest.py
+++ b/server/site_utils_unittest.py
@@ -52,5 +52,19 @@
'%s' % (test_job_name, expected_info))
+ def test_board_labels_allowed(self):
+ """Test method board_labels_allowed."""
+ boards = ['board:name']
+ self.assertEquals(True, site_utils.board_labels_allowed(boards))
+ boards = ['board:name', 'board:another']
+ self.assertEquals(False, site_utils.board_labels_allowed(boards))
+ boards = ['board:name-1', 'board:name-2']
+ self.assertEquals(True, site_utils.board_labels_allowed(boards))
+ boards = ['board:name-1', 'board:another-2']
+ self.assertEquals(True, site_utils.board_labels_allowed(boards))
+ boards = ['board:name', 'board:another-1']
+ self.assertEquals(False, site_utils.board_labels_allowed(boards))
+
+
if __name__ == '__main__':
unittest.main()