[CORD-2760] Cleanup R-CORD chain
Change-Id: I7d2246c61416ea97f657cb5b018e0efd7f8241d3
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ee40bb3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.idea/
+*.pyc
\ No newline at end of file
diff --git a/xos/synchronizer/model_policies/model_policy_volttenant.py b/xos/synchronizer/model_policies/model_policy_volttenant.py
index 32bc036..a7da0bd 100644
--- a/xos/synchronizer/model_policies/model_policy_volttenant.py
+++ b/xos/synchronizer/model_policies/model_policy_volttenant.py
@@ -24,8 +24,15 @@
return self.handle_update(tenant)
def handle_update(self, tenant):
+
+ if (tenant.link_deleted_count > 0) and (not tenant.provided_links.exists()):
+ # If this instance has no links pointing to it, delete
+ self.handle_delete(tenant)
+ if VOLTTenant.objects.filter(id=tenant.id).exists():
+ tenant.delete()
+ return
+
self.manage_vsg(tenant)
- self.manage_subscriber(tenant)
self.cleanup_orphans(tenant)
def handle_delete(self, tenant):
@@ -76,27 +83,6 @@
if cur_vsg is None:
self.create_vsg(tenant)
- def manage_subscriber(self, tenant):
- # check for existing link to a root
- links = tenant.provided_links.all()
- for link in links:
- roots = CordSubscriberRoot.objects.filter(id = link.subscriber_service_instance.id)
- if roots:
- return
-
- subs = CordSubscriberRoot.objects.filter(service_specific_id = tenant.service_specific_id)
- if subs:
- self.logger.info("MODEL_POLICY: volttenant %s using existing subscriber root" % tenant)
- sub = subs[0]
- else:
- self.logger.info("MODEL_POLICY: volttenant %s creating new subscriber root" % tenant)
- sub = CordSubscriberRoot(service_specific_id = tenant.service_specific_id,
- name = "autogenerated-for-vOLT-%s" % tenant.id)
- sub.save()
-
- link = ServiceInstanceLink(provider_service_instance = tenant, subscriber_service_instance = sub)
- link.save()
-
def cleanup_orphans(self, tenant):
# ensure vOLT only has one vCPE
cur_vsg = self.get_current_vsg(tenant)
diff --git a/xos/synchronizer/model_policies/test_model_policy_volttenant.py b/xos/synchronizer/model_policies/test_model_policy_volttenant.py
index b3edf3f..3e27dee 100644
--- a/xos/synchronizer/model_policies/test_model_policy_volttenant.py
+++ b/xos/synchronizer/model_policies/test_model_policy_volttenant.py
@@ -81,10 +81,8 @@
def test_handle_create(self):
with patch.object(VOLTTenantPolicy, "manage_vsg") as manage_vsg, \
- patch.object(VOLTTenantPolicy, "manage_subscriber") as manage_subscriber, \
patch.object(VOLTTenantPolicy, "cleanup_orphans") as cleanup_orphans:
self.policy.handle_create(self.tenant)
- manage_subscriber.assert_called_with(self.tenant)
manage_vsg.assert_called_with(self.tenant)
cleanup_orphans.assert_called_with(self.tenant)
@@ -136,63 +134,6 @@
self.assertEqual(link.provider_service_instance, vsg)
self.assertEqual(link.subscriber_service_instance, self.tenant)
- def test_manage_subscriber(self):
- with patch.object(ServiceInstanceLink, "save", autospec=True) as save_link, \
- patch.object(CordSubscriberRoot, "save", autospec=True) as save_csr:
-
- self.tenant.provided_links = MockObjectList()
-
- self.policy.manage_subscriber(self.tenant)
-
- self.assertEqual(save_csr.call_count, 1)
- csr = save_csr.call_args[0][0]
-
- self.assertEqual(save_link.call_count, 1)
- link = save_link.call_args[0][0]
- self.assertEqual(link.provider_service_instance, self.tenant)
- self.assertEqual(link.subscriber_service_instance, csr)
-
- def test_manage_subscriber_exists(self):
- with patch.object(ServiceInstanceLink, "save", autospec=True) as save_link, \
- patch.object(CordSubscriberRoot, "save", autospec=True) as save_csr, \
- patch.object(CordSubscriberRoot.objects, "get_items") as csr_items, \
- patch.object(ServiceInstanceLink.objects, "get_items") as link_items:
- self.tenant.provided_links = MockObjectList()
-
- subscriber = CordSubscriberRoot(service_specific_id=1234)
- csr_items.return_value = [subscriber]
-
- link = ServiceInstanceLink(provider_service_instance= self.tenant, subscriber_service_instance = subscriber)
- link_items.return_value = [link]
-
- self.tenant.provided_links = MockObjectList(initial=[link])
-
- self.policy.manage_subscriber(self.tenant)
-
- self.assertEqual(save_csr.call_count, 0)
- self.assertEqual(save_link.call_count, 0)
-
- def test_manage_subscriber_exists_nolink(self):
- with patch.object(ServiceInstanceLink, "save", autospec=True) as save_link, \
- patch.object(CordSubscriberRoot, "save", autospec=True) as save_csr, \
- patch.object(CordSubscriberRoot.objects, "get_items") as csr_items, \
- patch.object(ServiceInstanceLink.objects, "get_items") as link_items:
- self.tenant.provided_links = MockObjectList()
-
- subscriber = CordSubscriberRoot(service_specific_id=1234)
- csr_items.return_value = [subscriber]
-
- self.tenant.provided_links = MockObjectList()
-
- self.policy.manage_subscriber(self.tenant)
-
- self.assertEqual(save_csr.call_count, 0)
-
- self.assertEqual(save_link.call_count, 1)
- link = save_link.call_args[0][0]
- self.assertEqual(link.provider_service_instance, self.tenant)
- self.assertEqual(link.subscriber_service_instance, subscriber)
-
def test_handle_delete(self):
self.policy.handle_delete(self.tenant)
# handle delete does nothing, and should trivially succeed