autotest: Let moblab_interface respect static labels.
BUG=chromium:792309
TEST=Ran unittest.
Change-Id: I7ae072a44bf31ae6bfe4be1d429bfcc1d99e9ab2
Reviewed-on: https://chromium-review.googlesource.com/869141
Commit-Ready: Xixuan Wu <[email protected]>
Tested-by: Xixuan Wu <[email protected]>
Reviewed-by: Shuqian Zhao <[email protected]>
diff --git a/frontend/afe/moblab_rpc_interface.py b/frontend/afe/moblab_rpc_interface.py
index 76fc227..398b7ef 100644
--- a/frontend/afe/moblab_rpc_interface.py
+++ b/frontend/afe/moblab_rpc_interface.py
@@ -619,6 +619,12 @@
label = models.Label.add_object(name=label_name)
except:
label = models.Label.smart_get(label_name)
+ if label.is_replaced_by_static():
+ raise error.UnmodifiableLabelException(
+ 'Failed to add label "%s" because it is a static label. '
+ 'Use go/chromeos-skylab-inventory-tools to add this '
+ 'label.' % label.name)
+
host_obj = models.Host.smart_get(ipaddress)
if label:
label.host_set.add(host_obj)
@@ -637,7 +643,14 @@
@return: A string giving information about the status.
"""
host_obj = models.Host.smart_get(ipaddress)
- models.Label.smart_get(label_name).host_set.remove(host_obj)
+ label = models.Label.smart_get(label_name)
+ if label.is_replaced_by_static():
+ raise error.UnmodifiableLabelException(
+ 'Failed to remove label "%s" because it is a static label. '
+ 'Use go/chromeos-skylab-inventory-tools to remove this '
+ 'label.' % label.name)
+
+ label.host_set.remove(host_obj)
return (True, 'Removed label %s from DUT %s' % (label_name, ipaddress))