SEBA-405 Update VOLT Service to use synchronizer library
Change-Id: I8292e0e7d1b7c76b1e53d9bd944abf95d9b38333
diff --git a/xos/synchronizer/pull_steps/pull_olts.py b/xos/synchronizer/pull_steps/pull_olts.py
index 574a527..c7a7c16 100644
--- a/xos/synchronizer/pull_steps/pull_olts.py
+++ b/xos/synchronizer/pull_steps/pull_olts.py
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from synchronizers.new_base.pullstep import PullStep
-from synchronizers.new_base.modelaccessor import model_accessor, OLTDevice, VOLTService, PONPort, NNIPort
+from xossynchronizer.pull_steps.pullstep import PullStep
+from xossynchronizer.modelaccessor import model_accessor, OLTDevice, VOLTService, PONPort, NNIPort
from xosconfig import Config
from multistructlog import create_logger
@@ -30,8 +30,8 @@
log = create_logger(Config().get('logging'))
class OLTDevicePullStep(PullStep):
- def __init__(self):
- super(OLTDevicePullStep, self).__init__(observed_model=OLTDevice)
+ def __init__(self, model_accessor):
+ super(OLTDevicePullStep, self).__init__(model_accessor=model_accessor, observed_model=OLTDevice)
@staticmethod
def get_ids_from_logical_device(o):
diff --git a/xos/synchronizer/pull_steps/pull_onus.py b/xos/synchronizer/pull_steps/pull_onus.py
index c94e956..c30f52c 100644
--- a/xos/synchronizer/pull_steps/pull_onus.py
+++ b/xos/synchronizer/pull_steps/pull_onus.py
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from synchronizers.new_base.pullstep import PullStep
-from synchronizers.new_base.modelaccessor import model_accessor, ONUDevice, VOLTService, OLTDevice, PONPort, PONONUPort, UNIPort
+from xossynchronizer.pull_steps.pullstep import PullStep
+from xossynchronizer.modelaccessor import model_accessor, ONUDevice, VOLTService, OLTDevice, PONPort, PONONUPort, UNIPort
from xosconfig import Config
from multistructlog import create_logger
@@ -30,8 +30,8 @@
log = create_logger(Config().get('logging'))
class ONUDevicePullStep(PullStep):
- def __init__(self):
- super(ONUDevicePullStep, self).__init__(observed_model=ONUDevice)
+ def __init__(self, model_accessor):
+ super(ONUDevicePullStep, self).__init__(model_accessor=model_accessor, observed_model=ONUDevice)
def pull_records(self):
log.debug("pulling ONU devices from VOLTHA")
diff --git a/xos/synchronizer/pull_steps/test_pull_olts.py b/xos/synchronizer/pull_steps/test_pull_olts.py
index 755f4fb..0859bdf 100644
--- a/xos/synchronizer/pull_steps/test_pull_olts.py
+++ b/xos/synchronizer/pull_steps/test_pull_olts.py
@@ -18,27 +18,7 @@
import os, sys
-# Hack to load synchronizer framework
test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
-xos_dir=os.path.join(test_path, "../../..")
-if not os.path.exists(os.path.join(test_path, "new_base")):
- xos_dir=os.path.join(test_path, "../../../../../../orchestration/xos/xos")
- services_dir = os.path.join(xos_dir, "../../xos_services")
-sys.path.append(xos_dir)
-sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
-# END Hack to load synchronizer framework
-
-# generate model from xproto
-def get_models_fn(service_name, xproto_name):
- name = os.path.join(service_name, "xos", xproto_name)
- if os.path.exists(os.path.join(services_dir, name)):
- return name
- else:
- name = os.path.join(service_name, "xos", "synchronizer", "models", xproto_name)
- if os.path.exists(os.path.join(services_dir, name)):
- return name
- raise Exception("Unable to find service=%s xproto=%s" % (service_name, xproto_name))
-# END generate model from xproto
class TestSyncOLTDevice(unittest.TestCase):
@@ -46,8 +26,6 @@
global DeferredException
self.sys_path_save = sys.path
- sys.path.append(xos_dir)
- sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
# Setting up the config module
from xosconfig import Config
@@ -56,16 +34,18 @@
Config.init(config, "synchronizer-config-schema.yaml")
# END Setting up the config module
- from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
- # build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.xproto")])
+ from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config
+ mock_modelaccessor_config(test_path, [("olt-service", "volt.xproto"),
+ ("vsg", "vsg.xproto"),
+ ("../profiles/rcord", "rcord.xproto"),])
- # FIXME this is to get jenkins to pass the tests, somehow it is running tests in a different order
- # and apparently it is not overriding the generated model accessor
- build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.xproto"),
- get_models_fn("vsg", "vsg.xproto"),
- get_models_fn("../profiles/rcord", "rcord.xproto")])
- import synchronizers.new_base.modelaccessor
- from pull_olts import OLTDevicePullStep, model_accessor
+ import xossynchronizer.modelaccessor
+ reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test
+
+ from xossynchronizer.modelaccessor import model_accessor
+ self.model_accessor = model_accessor
+
+ from pull_olts import OLTDevicePullStep
# import all class names to globals
for (k, v) in model_accessor.all_model_classes.items():
@@ -144,7 +124,7 @@
m.get("http://voltha_url:1234/api/v1/devices/test_id/ports", status_code=200, json=self.ports)
m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=self.logical_devices)
- self.sync_step().pull_records()
+ self.sync_step(model_accessor=self.model_accessor).pull_records()
# TODO how to asster this?
# self.assertEqual(existing_olt.admin_state, "ENABLED")
@@ -178,7 +158,7 @@
m.get("http://voltha_url:1234/api/v1/devices/test_id/ports", status_code=200, json=self.ports)
m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=self.logical_devices)
- self.sync_step().pull_records()
+ self.sync_step(model_accessor=self.model_accessor).pull_records()
self.assertEqual(existing_olt.admin_state, "ENABLED")
self.assertEqual(existing_olt.oper_status, "ACTIVE")
@@ -211,7 +191,7 @@
m.get("http://voltha_url:1234/api/v1/devices/test_id/ports", status_code=200, json=self.ports)
m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=self.logical_devices)
- self.sync_step().pull_records()
+ self.sync_step(model_accessor=self.model_accessor).pull_records()
mock_olt_save.assert_not_called()
mock_pon_save.assert_called()
@@ -233,7 +213,7 @@
olt_service_mock.return_value = [self.volt_service]
mock_get.return_value = [existing_olt]
- self.sync_step().pull_records()
+ self.sync_step(model_accessor=self.model_accessor).pull_records()
mock_olt_delete.assert_called()
diff --git a/xos/synchronizer/pull_steps/test_pull_onus.py b/xos/synchronizer/pull_steps/test_pull_onus.py
index 0898018..cafb435 100644
--- a/xos/synchronizer/pull_steps/test_pull_onus.py
+++ b/xos/synchronizer/pull_steps/test_pull_onus.py
@@ -19,27 +19,7 @@
import os, sys
-# Hack to load synchronizer framework
test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
-xos_dir=os.path.join(test_path, "../../..")
-if not os.path.exists(os.path.join(test_path, "new_base")):
- xos_dir=os.path.join(test_path, "../../../../../../orchestration/xos/xos")
- services_dir = os.path.join(xos_dir, "../../xos_services")
-sys.path.append(xos_dir)
-sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
-# END Hack to load synchronizer framework
-
-# generate model from xproto
-def get_models_fn(service_name, xproto_name):
- name = os.path.join(service_name, "xos", xproto_name)
- if os.path.exists(os.path.join(services_dir, name)):
- return name
- else:
- name = os.path.join(service_name, "xos", "synchronizer", "models", xproto_name)
- if os.path.exists(os.path.join(services_dir, name)):
- return name
- raise Exception("Unable to find service=%s xproto=%s" % (service_name, xproto_name))
-# END generate model from xproto
class TestPullONUDevice(unittest.TestCase):
@@ -47,8 +27,6 @@
global DeferredException
self.sys_path_save = sys.path
- sys.path.append(xos_dir)
- sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
# Setting up the config module
from xosconfig import Config
@@ -57,16 +35,18 @@
Config.init(config, "synchronizer-config-schema.yaml")
# END Setting up the config module
- from synchronizers.new_base.mock_modelaccessor_build import build_mock_modelaccessor
- # build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.xproto")])
+ from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config
+ mock_modelaccessor_config(test_path, [("olt-service", "volt.xproto"),
+ ("vsg", "vsg.xproto"),
+ ("../profiles/rcord", "rcord.xproto"),])
- # FIXME this is to get jenkins to pass the tests, somehow it is running tests in a different order
- # and apparently it is not overriding the generated model accessor
- build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.xproto"),
- get_models_fn("vsg", "vsg.xproto"),
- get_models_fn("../profiles/rcord", "rcord.xproto")])
- import synchronizers.new_base.modelaccessor
- from pull_onus import ONUDevicePullStep, model_accessor
+ import xossynchronizer.modelaccessor
+ reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test
+
+ from xossynchronizer.modelaccessor import model_accessor
+ self.model_accessor = model_accessor
+
+ from pull_onus import ONUDevicePullStep
# import all class names to globals
for (k, v) in model_accessor.all_model_classes.items():
@@ -180,7 +160,7 @@
m.get("http://voltha_url:1234/api/v1/devices", status_code=200, json=self.devices)
m.get("http://voltha_url:1234/api/v1/devices/0001130158f01b2d/ports", status_code=200, json=self.ports)
- self.sync_step().pull_records()
+ self.sync_step(model_accessor=self.model_accessor).pull_records()
saved_onu = mock_save.call_args[0][0]
@@ -222,7 +202,7 @@
m.get("http://voltha_url:1234/api/v1/devices/0001130158f01b2d/ports", status_code=200, json=self.ports)
m.get("http://voltha_url:1234/api/v1/devices/0001130158f01b2e/ports", status_code=200, json=self.ports)
- self.sync_step().pull_records()
+ self.sync_step(model_accessor=self.model_accessor).pull_records()
self.assertEqual(mock_save.call_count, 1)
saved_onu = mock_save.call_args[0][0]
@@ -261,7 +241,7 @@
m.get("http://voltha_url:1234/api/v1/devices/0001130158f01b2d/ports", status_code=200, json=self.ports)
m.get("http://voltha_url:1234/api/v1/devices/0001130158f01b2e/ports", status_code=200, json=self.ports)
- self.sync_step().pull_records()
+ self.sync_step(model_accessor=self.model_accessor).pull_records()
self.assertEqual(mock_save.call_count, 1)
saved_onu = mock_save.call_args[0][0]