Do not provision the OLT until the Tech-profile has been pushed into ETCD
Change-Id: I78671e63acfaab1ac8d865b22f12a4ca35c11fc1
diff --git a/xos/synchronizer/steps/sync_olt_device.py b/xos/synchronizer/steps/sync_olt_device.py
index 686afcf..469e879 100644
--- a/xos/synchronizer/steps/sync_olt_device.py
+++ b/xos/synchronizer/steps/sync_olt_device.py
@@ -18,7 +18,7 @@
from multistructlog import create_logger
from requests.auth import HTTPBasicAuth
from xossynchronizer.steps.syncstep import SyncStep, DeferredException
-from xossynchronizer.modelaccessor import OLTDevice, model_accessor
+from xossynchronizer.modelaccessor import OLTDevice, TechnologyProfile, model_accessor
from xosconfig import Config
import os, sys
@@ -166,9 +166,25 @@
except Exception:
print request.text
+ def wait_for_tp(self, technology):
+ """
+ Check if a technology profile for this technology has been already pushed to ETCD,
+ if not defer the OLT Provisioning.
+ :param technology: string - the technology to check for a tech profile
+ :return: True (or raises DeferredException)
+ """
+ try:
+ tps = TechnologyProfile.objects.get(technology=technology, backend_code=1)
+ except IndexError:
+ raise DeferredException("Waiting for a TechnologyProfile (technology=%s) to be synchronized" % technology)
+
+ return True
+
def sync_record(self, model):
log.info("Synching device", object=str(model), **model.tologdict())
+ self.wait_for_tp(model.technology)
+
if model.admin_state not in ["ENABLED", "DISABLED"]:
raise Exception("OLT Device %s admin_state has invalid value %s" % (model.id, model.admin_state))