CORD-1008 make fabric synchronizer use new_base
Change-Id: I523f61a33e83afcd7f99df23ac5cbaefb3f52b27
diff --git a/xos/synchronizer/fabric-synchronizer.py b/xos/synchronizer/fabric-synchronizer.py
index 84bec4f..26b44df 100755
--- a/xos/synchronizer/fabric-synchronizer.py
+++ b/xos/synchronizer/fabric-synchronizer.py
@@ -5,7 +5,7 @@
import importlib
import os
import sys
-observer_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../../synchronizers/base")
+observer_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../../synchronizers/new_base")
sys.path.append(observer_path)
mod = importlib.import_module("xos-synchronizer")
mod.main()
diff --git a/xos/synchronizer/steps/sync_vroutertenant.py b/xos/synchronizer/steps/sync_vroutertenant.py
index 3fa95a4..c20795a 100644
--- a/xos/synchronizer/steps/sync_vroutertenant.py
+++ b/xos/synchronizer/steps/sync_vroutertenant.py
@@ -1,16 +1,10 @@
import os
import base64
from collections import defaultdict
-from django.db.models import F, Q
from xos.config import Config
-from synchronizers.base.syncstep import *
-from core.models import Controller
-from core.models import Image, ControllerImages
+from synchronizers.new_base.syncstep import SyncStep, DeferredException
+from synchronizers.new_base.modelaccessor import *
from xos.logger import observer_logger as logger
-from synchronizers.base.ansible_helper import *
-from services.vrouter.models import VRouterTenant
-from services.onos.models import ONOSService
-from services.fabric.models import FabricService
import json
class SyncVRouterTenant(SyncStep):
@@ -21,27 +15,32 @@
def get_fabric_onos_service(self):
fos = None
- fs = FabricService.get_service_objects().all()[0]
+ fs = FabricService.objects.first()
if fs.subscribed_tenants.exists():
- app = fs.subscribed_tenants.all()[0]
+ app = fs.subscribed_tenants.first()
if app.provider_service:
ps = app.provider_service
- fos = ONOSService.get_service_objects().filter(id=ps.id)[0]
+ fos = ONOSService.objects.filter(id=ps.id)[0]
return fos
def get_node_tag(self, node, tagname):
tags = Tag.select_by_content_object(node).filter(name=tagname)
- return tags[0].value
-
- def fetch_pending(self, deleted):
- fs = FabricService.get_service_objects().all()[0]
- if not fs.autoconfig:
+ if tags:
+ return tags[0].value
+ else:
return None
+ def fetch_pending(self, deleted):
+ fs = FabricService.objects.first()
+ if (not fs) or (not fs.autoconfig):
+ return None
+
+ # TODO: Why is this a nonstandard synchronizer query?
+
if (not deleted):
- objs = VRouterTenant.get_tenant_objects().filter(Q(lazy_blocked=False))
+ objs = VRouterTenant.objects.all()
else:
- objs = VRouterTenant.get_deleted_tenant_objects()
+ objs = VRouterTenant.deleted_objects.all()
objs = list(objs)
@@ -50,10 +49,16 @@
# Do we have a vCPE subscriber_tenant?
if vroutertenant.subscriber_tenant:
sub = vroutertenant.subscriber_tenant
- if sub.kind != 'vCPE' or not sub.get_attribute("instance_id"):
+ if sub.kind != 'vCPE':
objs.remove(vroutertenant)
+ else:
+ # coerce the subscriber tenant over to the VSGTenant
+ vsg = VSGTenant.objects.filter(id=sub.id).first()
+ if not vsg.instance:
+ objs.remove(vroutertenant)
else:
# Maybe the VRouterTenant is for an instance
+ # TODO: tenant_for_instance_id needs to be a real database field
instance_id = vroutertenant.get_attribute("tenant_for_instance_id")
if not instance_id:
objs.remove(vroutertenant)
@@ -77,8 +82,9 @@
# * Get the "location" tag, push to the fabric
if vroutertenant.subscriber_tenant:
sub = vroutertenant.subscriber_tenant
- instance_id = sub.get_attribute("instance_id")
- instance = Instance.objects.filter(id=instance_id)[0]
+ assert(sub.kind == 'vCPE')
+ vsg = VSGTenant.objects.filter(id=sub.id).first()
+ instance = vsg.instance
name = str(sub)
else:
instance_id = vroutertenant.get_attribute("tenant_for_instance_id")
@@ -88,6 +94,9 @@
node = instance.node
location = self.get_node_tag(node, "location")
+ if not location:
+ raise DeferredException("No location tag for node %s tenant %s -- skipping" % (str(node), str(vroutertenant)))
+
# Create JSON
data = {
"%s/-1" % vroutertenant.public_mac : {