Preventing the chain to be created if the subscriber is in pre-provisioned state
Change-Id: Ibc1bf02f68cce2360d407cb7b44509cf79d681a8
diff --git a/xos/synchronizer/model_policies/model_policy_rcordsubscriber.py b/xos/synchronizer/model_policies/model_policy_rcordsubscriber.py
index 14e79b5..f50c7d7 100644
--- a/xos/synchronizer/model_policies/model_policy_rcordsubscriber.py
+++ b/xos/synchronizer/model_policies/model_policy_rcordsubscriber.py
@@ -24,6 +24,10 @@
def handle_update(self, si):
+ if si.status == "pre-provisioned":
+ self.logger.debug("MODEL_POLICY: Skipping chain creation as RCORDSubscriber %s is in 'pre-provisioned' state" % si.id)
+ return
+
chain = si.subscribed_links.all()
# Already has a chain
diff --git a/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py b/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py
index 85d89c9..895a254 100644
--- a/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py
+++ b/xos/synchronizer/model_policies/test_model_policy_rcordsubscriber.py
@@ -75,12 +75,29 @@
def tearDown(self):
sys.path = self.sys_path_save
+ def test_update_pre_provisione(self):
+ si = self.si
+ si.status = "pre-provisioned"
+ self.policy.handle_create(si)
+
+ with patch.object(VOLTServiceInstance, "save", autospec=True) as save_volt, \
+ patch.object(ServiceInstanceLink, "save", autospec=True) as save_link:
+
+ self.policy.handle_create(si)
+ self.assertEqual(save_link.call_count, 0)
+ self.assertEqual(save_volt.call_count, 0)
+
def test_update_and_do_nothing(self):
si = self.si
si.is_new = False
si.subscribed_links.all.return_value = ["already", "have", "a", "chain"]
- self.policy.handle_create(si)
- # NOTE assert that no models are created
+
+ with patch.object(VOLTServiceInstance, "save", autospec=True) as save_volt, \
+ patch.object(ServiceInstanceLink, "save", autospec=True) as save_link:
+
+ self.policy.handle_create(si)
+ self.assertEqual(save_link.call_count, 0)
+ self.assertEqual(save_volt.call_count, 0)
def test_create(self):
volt = Mock()