[autotest] Create a shard with multiple board labels
'atest shard create' allows only one label for a shard.
Since our sharding architecture allows multiple board labels for
a shard, update atest tool accordingly.
Old code only lists all shards with 'atest shard list' even
in the case a user passes 'shards' parameter.
'shards' parameter didn't work. This CL corrects the feature.
In addition, old code doesn't have '--label' option for
'atest shard list', but there is a code to parse the option.
Removed the parsing code.
BUG=chromium:489914
TEST=Test 'atest' tool on local machine.
DEPLOY=apache
Change-Id: Ia18374d9b8b9d44ead63c98cc13fb47a84ddf70f
Reviewed-on: https://chromium-review.googlesource.com/286194
Trybot-Ready: Mungyung Ryu <mkryu@google.com>
Tested-by: Mungyung Ryu <mkryu@google.com>
Reviewed-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Fang Deng <fdeng@chromium.org>
Commit-Queue: Mungyung Ryu <mkryu@google.com>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index 3163b8a..a79146d 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -442,26 +442,30 @@
return serialized_shards
-def add_shard(hostname, label):
+def add_shard(hostname, labels):
"""Add a shard and start running jobs on it.
@param hostname: The hostname of the shard to be added; needs to be unique.
- @param label: A platform label. Jobs of this label will be assigned to the
- shard.
+ @param labels: Board labels separated by a comma. Jobs of one of the labels
+ will be assigned to the shard.
@raises error.RPCException: If label provided doesn't start with `board:`
@raises model_logic.ValidationError: If a shard with the given hostname
already exists.
@raises models.Label.DoesNotExist: If the label specified doesn't exist.
"""
- if not label.startswith('board:'):
- raise error.RPCException('Sharding only supported for `board:.*` '
- 'labels.')
+ labels = labels.split(',')
+ label_models = []
+ for label in labels:
+ if not label.startswith('board:'):
+ raise error.RPCException('Sharding only supports for `board:.*` '
+ 'labels.')
+ # Fetch label first, so shard isn't created when label doesn't exist.
+ label_models.append(models.Label.smart_get(label))
- # Fetch label first, so shard isn't created when label doesn't exist.
- label = models.Label.smart_get(label)
shard = models.Shard.add_object(hostname=hostname)
- shard.labels.add(label)
+ for label in label_models:
+ shard.labels.add(label)
return shard.id