Move dependencies on non-core models into try/except blocks
Change-Id: I5a613bd763c5538a93934e18061681d03726f91c
diff --git a/xos/synchronizer/steps/sync_onos_netcfg.py b/xos/synchronizer/steps/sync_onos_netcfg.py
index b41a5f0..e12e242 100644
--- a/xos/synchronizer/steps/sync_onos_netcfg.py
+++ b/xos/synchronizer/steps/sync_onos_netcfg.py
@@ -7,7 +7,6 @@
from synchronizers.base.syncstep import SyncStep
from core.models import Service, Slice, Controller, ControllerSlice, ControllerUser, Node, TenantAttribute, Tag
from services.vtn.models import VTNService
-from services.vrouter.models import VRouterService
from xos.logger import Logger, logging
logger = Logger(level=logging.INFO)
@@ -124,16 +123,21 @@
# Generate apps->org.onosproject.cordvtn->cordvtn->publicGateways
# Pull the gateway information from vRouter
- vrouters = VRouterService.get_service_objects().all()
- if vrouters:
- for gateway in vrouters[0].get_gateways():
- gatewayIp = gateway['gateway_ip'].split('/',1)[0]
- gatewayMac = gateway['gateway_mac']
- gateway_dict = {
- "gatewayIp": gatewayIp,
- "gatewayMac": gatewayMac
- }
- data["apps"]["org.opencord.vtn"]["cordvtn"]["publicGateways"].append(gateway_dict)
+ try:
+ from services.vrouter.models import VRouterService
+
+ vrouters = VRouterService.get_service_objects().all()
+ if vrouters:
+ for gateway in vrouters[0].get_gateways():
+ gatewayIp = gateway['gateway_ip'].split('/',1)[0]
+ gatewayMac = gateway['gateway_mac']
+ gateway_dict = {
+ "gatewayIp": gatewayIp,
+ "gatewayMac": gatewayMac
+ }
+ data["apps"]["org.opencord.vtn"]["cordvtn"]["publicGateways"].append(gateway_dict)
+ except:
+ logger.info("No VRouter service present, not adding publicGateways to config")
return json.dumps(data, indent=4, sort_keys=True)
diff --git a/xos/synchronizer/steps/sync_port_addresses.py b/xos/synchronizer/steps/sync_port_addresses.py
index 0ff7d67..37d8dc6 100644
--- a/xos/synchronizer/steps/sync_port_addresses.py
+++ b/xos/synchronizer/steps/sync_port_addresses.py
@@ -8,7 +8,6 @@
from synchronizers.base.syncstep import SyncStep
from core.models import Service, Port, Controller, Tag, Tenant
from core.models.service import COARSE_KIND
-from services.vsg.models import VSGTenant
from xos.logger import Logger, logging
from requests.auth import HTTPBasicAuth
from services.vtn.models import VTNService
@@ -41,49 +40,54 @@
logger.info("skipping SyncPortAddresses due to VTN API Version")
return
- logger.info("sync'ing vsg tenant to port addresses")
-
# build up a dictionary of port-->[wan_addrs] mappings
port_addrs = {}
- for vsg in VSGTenant.get_tenant_objects().all():
- if not vsg.instance:
- logger.info("skipping vsg %s because it has no instance" % vsg)
+ try:
+ from services.vsg.models import VSGTenant
- wan_ip = vsg.wan_container_ip
- if not wan_ip:
- logger.info("skipping vsg %s because it has no wan_container_ip" % vsg)
+ logger.info("sync'ing vsg tenant to port addresses")
- wan_mac = vsg.wan_container_mac
- if not wan_mac:
- logger.info("skipping vsg %s because it has no wan_container_mac" % vsg)
+ for vsg in VSGTenant.get_tenant_objects().all():
+ if not vsg.instance:
+ logger.info("skipping vsg %s because it has no instance" % vsg)
- lan_network = vsg.get_lan_network(vsg.instance)
- if not lan_network:
- logger.info("skipping vsg %s because it has no lan_network" % vsg)
+ wan_ip = vsg.wan_container_ip
+ if not wan_ip:
+ logger.info("skipping vsg %s because it has no wan_container_ip" % vsg)
- lan_port = Port.objects.filter(instance = vsg.instance, network=lan_network)
- if not lan_port:
- logger.info("skipping vsg %s because it has no lan_port" % vsg)
- lan_port = lan_port[0]
+ wan_mac = vsg.wan_container_mac
+ if not wan_mac:
+ logger.info("skipping vsg %s because it has no wan_container_mac" % vsg)
- if not lan_port.port_id:
- logger.info("skipping vsg %s because its lan_port has no port_id" % vsg)
+ lan_network = vsg.get_lan_network(vsg.instance)
+ if not lan_network:
+ logger.info("skipping vsg %s because it has no lan_network" % vsg)
- if not (lan_port.pk in port_addrs):
- port_addrs[lan_port.pk] = []
- entry = {"mac_address": wan_mac, "ip_address": wan_ip}
- addr_pairs = port_addrs[lan_port.pk]
- if not entry in addr_pairs:
- addr_pairs.append(entry)
+ lan_port = Port.objects.filter(instance = vsg.instance, network=lan_network)
+ if not lan_port:
+ logger.info("skipping vsg %s because it has no lan_port" % vsg)
+ lan_port = lan_port[0]
- # now do the VM_WAN_IP from the instance
- if vsg.instance:
- wan_vm_ip = vsg.wan_vm_ip
- wan_vm_mac = vsg.wan_vm_mac
- entry = {"mac_address": wan_vm_mac, "ip_address": wan_vm_ip}
+ if not lan_port.port_id:
+ logger.info("skipping vsg %s because its lan_port has no port_id" % vsg)
+
+ if not (lan_port.pk in port_addrs):
+ port_addrs[lan_port.pk] = []
+ entry = {"mac_address": wan_mac, "ip_address": wan_ip}
+ addr_pairs = port_addrs[lan_port.pk]
if not entry in addr_pairs:
addr_pairs.append(entry)
+ # now do the VM_WAN_IP from the instance
+ if vsg.instance:
+ wan_vm_ip = vsg.wan_vm_ip
+ wan_vm_mac = vsg.wan_vm_mac
+ entry = {"mac_address": wan_vm_mac, "ip_address": wan_vm_ip}
+ if not entry in addr_pairs:
+ addr_pairs.append(entry)
+ except:
+ logger.info("No VSG service present")
+
# Get all ports in all controllers
ports_by_id = {}
for controller in Controller.objects.all():