Check for multiple platforms on a machine when modifying labels.
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3179 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index 3895190..6f9e5cc 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -30,8 +30,10 @@
__author__ = 'showard@google.com (Steve Howard)'
import datetime
-from frontend import thread_local
-from frontend.afe import models, model_logic, control_file, rpc_utils
+import common
+from autotest_lib.frontend import thread_local
+from autotest_lib.frontend.afe import models, model_logic, control_file
+from autotest_lib.frontend.afe import rpc_utils
from autotest_lib.client.common_lib import global_config
@@ -53,7 +55,10 @@
def label_add_hosts(id, hosts):
host_objs = models.Host.smart_get_bulk(hosts)
- models.Label.smart_get(id).host_set.add(*host_objs)
+ label = models.Label.smart_get(id)
+ if label.platform:
+ models.Host.check_no_platform(host_objs)
+ label.host_set.add(*host_objs)
def label_remove_hosts(id, hosts):
@@ -124,7 +129,16 @@
def host_add_labels(id, labels):
labels = models.Label.smart_get_bulk(labels)
- models.Host.smart_get(id).labels.add(*labels)
+ host = models.Host.smart_get(id)
+
+ platforms = [label.name for label in labels if label.platform]
+ if len(platforms) > 1:
+ raise model_logic.ValidationError(
+ {'labels': 'Adding more than one platform label: %s' %
+ ', '.join(platforms)})
+ if len(platforms) == 1:
+ models.Host.check_no_platform([host])
+ host.labels.add(*labels)
def host_remove_labels(id, labels):