SEBA-405 Update addressmanager service to use synchronizer library

Change-Id: I753ac0414caadff95de19aa32257f641512126bc
diff --git a/Dockerfile.synchronizer b/Dockerfile.synchronizer
index fc6ad45..a86816a 100644
--- a/Dockerfile.synchronizer
+++ b/Dockerfile.synchronizer
@@ -14,7 +14,7 @@
 
 # xosproject/addressmanager-synchronizer
 
-FROM xosproject/xos-synchronizer-base:2.1.32
+FROM xosproject/xos-synchronizer-base:2.1.38
 
 COPY xos/synchronizer /opt/xos/synchronizers/addressmanager
 COPY VERSION /opt/xos/synchronizers/addressmanager/
diff --git a/VERSION b/VERSION
index 2165f8f..e010258 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0.4
+2.0.5
diff --git a/xos/synchronizer/addressmanager-synchronizer.py b/xos/synchronizer/addressmanager-synchronizer.py
index b9b8d8c..583242a 100755
--- a/xos/synchronizer/addressmanager-synchronizer.py
+++ b/xos/synchronizer/addressmanager-synchronizer.py
@@ -18,15 +18,11 @@
 
 # This imports and runs ../../xos-observer.py
 
-import importlib
 import os
-import sys
+from xossynchronizer import Synchronizer
 from xosconfig import Config
 
 config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/addressmanager_config.yaml')
 Config.init(config_file, 'synchronizer-config-schema.yaml')
 
-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()
+Synchronizer().run()
diff --git a/xos/synchronizer/model_policies/model_policy_addressmanagerserviceinstance.py b/xos/synchronizer/model_policies/model_policy_addressmanagerserviceinstance.py
index cb3dac8..a5b2dbb 100644
--- a/xos/synchronizer/model_policies/model_policy_addressmanagerserviceinstance.py
+++ b/xos/synchronizer/model_policies/model_policy_addressmanagerserviceinstance.py
@@ -14,8 +14,8 @@
 # limitations under the License.
 
 
-from synchronizers.new_base.modelaccessor import *
-from synchronizers.new_base.policy import Policy
+from xossynchronizer.modelaccessor import *
+from xossynchronizer.model_policies.policy import Policy
 
 class AddressManagerServiceInstancePolicy(Policy):
     model_name = "AddressManagerServiceInstance"
diff --git a/xos/synchronizer/steps/sync_addressmanagerserviceinstance.py b/xos/synchronizer/steps/sync_addressmanagerserviceinstance.py
index 8c15676..20aa63c 100644
--- a/xos/synchronizer/steps/sync_addressmanagerserviceinstance.py
+++ b/xos/synchronizer/steps/sync_addressmanagerserviceinstance.py
@@ -14,8 +14,8 @@
 # limitations under the License.
 
 import requests
-from synchronizers.new_base.syncstep import SyncStep, DeferredException
-from synchronizers.new_base.modelaccessor import *
+from xossynchronizer.steps.syncstep import SyncStep, DeferredException
+from xossynchronizer.modelaccessor import *
 
 from xosconfig import Config
 from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/test_sync_addressmanagerserviceinstance.py b/xos/synchronizer/steps/test_sync_addressmanagerserviceinstance.py
index fa6a073..68c3b61 100644
--- a/xos/synchronizer/steps/test_sync_addressmanagerserviceinstance.py
+++ b/xos/synchronizer/steps/test_sync_addressmanagerserviceinstance.py
@@ -19,13 +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")
-# END Hack to load synchronizer framework
 
 def match_json(desired, req):
     if desired!=req.json():
@@ -33,26 +27,12 @@
         return False
     return True
 
-# 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 TestSyncAddressManagerServiceInstance(unittest.TestCase):
 
     def setUp(self):
         global MockObjectList, model_accessor, SyncStep
 
         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
@@ -61,17 +41,20 @@
         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("fabric", "fabric.xproto"),
-                                                         get_models_fn("addressmanager", "addressmanager.xproto"),
-                                                         get_models_fn("onos-service", "onos.xproto")])
-        import synchronizers.new_base.modelaccessor
-        from synchronizers.new_base.syncstep import SyncStep
-        from sync_addressmanagerserviceinstance import SyncAddressManagerServiceInstance, model_accessor
+        from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config
+        mock_modelaccessor_config(test_path, [("fabric", "fabric.xproto"),
+                                              ("addressmanager", "addressmanager.xproto"),
+                                              ("onos-service", "onos.xproto")])
 
+        import xossynchronizer.modelaccessor
+        import mock_modelaccessor
+        reload(mock_modelaccessor) # in case nose2 loaded it in a previous test
+        reload(xossynchronizer.modelaccessor)      # in case nose2 loaded it in a previous test
+
+        from sync_addressmanagerserviceinstance import SyncAddressManagerServiceInstance, model_accessor, SyncStep
         from mock_modelaccessor import MockObjectList
 
-        self.sync_step = SyncAddressManagerServiceInstance()
+        self.sync_step = SyncAddressManagerServiceInstance(model_accessor = model_accessor)
 
         # import all class names to globals
         for (k, v) in model_accessor.all_model_classes.items():