[CORD-2760] Cleanup R-CORD chain
Change-Id: I7d2246c61416ea97f657cb5b018e0efd7f8241d3
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)