[autotest] Manage shards with atest

This adds functionality to list, create and delete shards to atest.

BUG=None
TEST=Ran suites, manual test of create/list/delete.

Change-Id: I0771d0c1b46c7c6890819822204f42ac2211b104
Reviewed-on: https://chromium-review.googlesource.com/218295
Tested-by: Jakob Jülich <jakobjuelich@chromium.org>
Reviewed-by: Prashanth B <beeps@chromium.org>
Commit-Queue: Jakob Jülich <jakobjuelich@chromium.org>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index 9e175d5..547e022 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -349,11 +349,19 @@
     @param label: A platform label. Jobs of this label will be assigned to the
                   shard.
 
-    @raises model_logic.ValidationError if a shard with the given hostname
+    @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.')
+
+    # 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(models.Label.smart_get(label))
+    shard.labels.add(label)
     return shard.id