SEBA-450 Update Fabric-Crossconnect to use synchronizer library

Change-Id: I9d524e22562798d85807b7706d09e8a6bcaad01b
diff --git a/xos/synchronizer/steps/sync_fabric_crossconnect_service_instance.py b/xos/synchronizer/steps/sync_fabric_crossconnect_service_instance.py
index 5299fc1..0880988 100644
--- a/xos/synchronizer/steps/sync_fabric_crossconnect_service_instance.py
+++ b/xos/synchronizer/steps/sync_fabric_crossconnect_service_instance.py
@@ -12,8 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from synchronizers.new_base.syncstep import SyncStep, DeferredException
-from synchronizers.new_base.modelaccessor import model_accessor, FabricCrossconnectServiceInstance, ServiceInstance, BNGPortMapping
+from xossynchronizer.steps.syncstep import SyncStep, DeferredException
+from xossynchronizer.modelaccessor import model_accessor, FabricCrossconnectServiceInstance, ServiceInstance, BNGPortMapping
 
 from xosconfig import Config
 from multistructlog import create_logger
diff --git a/xos/synchronizer/steps/test_sync_fabric_crossconnect_service_instance.py b/xos/synchronizer/steps/test_sync_fabric_crossconnect_service_instance.py
index 9f07687..62c8d5b 100644
--- a/xos/synchronizer/steps/test_sync_fabric_crossconnect_service_instance.py
+++ b/xos/synchronizer/steps/test_sync_fabric_crossconnect_service_instance.py
@@ -22,27 +22,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
 
 def mock_get_westbound_service_instance_properties(props, prop):
     return props[prop]
@@ -59,8 +39,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
@@ -69,11 +47,19 @@
         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-crossconnect", "fabric-crossconnect.xproto")])
-        import synchronizers.new_base.modelaccessor
+        from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config
+        mock_modelaccessor_config(test_path, [("fabric-crossconnect", "fabric-crossconnect.xproto"),])
 
-        from sync_fabric_crossconnect_service_instance import SyncFabricCrossconnectServiceInstance, model_accessor, DeferredException
+        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 xossynchronizer.modelaccessor import model_accessor
+        self.model_accessor = model_accessor
+
+        from sync_fabric_crossconnect_service_instance import SyncFabricCrossconnectServiceInstance, model_accessor, \
+            DeferredException
 
         # import all class names to globals
         for (k, v) in model_accessor.all_model_classes.items():
@@ -103,15 +89,15 @@
         return si
 
     def test_format_url(self):
-        url = self.sync_step().format_url("foo.com/bar")
+        url = self.sync_step(model_accessor=self.model_accessor).format_url("foo.com/bar")
         self.assertEqual(url, "http://foo.com/bar")
 
-        url = self.sync_step().format_url("http://foo.com/bar")
+        url = self.sync_step(model_accessor=self.model_accessor).format_url("http://foo.com/bar")
         self.assertEqual(url, "http://foo.com/bar")
 
     def test_make_handle_extract_handle(self):
-        h = self.sync_step().make_handle(222, "of:0000000000000201")
-        (s_tag, switch_datapath_id) = self.sync_step().extract_handle(h)
+        h = self.sync_step(model_accessor=self.model_accessor).make_handle(222, "of:0000000000000201")
+        (s_tag, switch_datapath_id) = self.sync_step(model_accessor=self.model_accessor).extract_handle(h)
 
         self.assertEqual(s_tag, 222)
         self.assertEqual(switch_datapath_id, "of:0000000000000201")
@@ -119,27 +105,27 @@
     def test_get_fabric_onos_init(self):
         fsi = FabricCrossconnectServiceInstance(id=7777, owner=self.service)
 
-        d = self.sync_step().get_fabric_onos_info(fsi)
+        d = self.sync_step(model_accessor=self.model_accessor).get_fabric_onos_info(fsi)
 
         self.assertEqual(d["url"], "http://onos-fabric:8181")
         self.assertEqual(d["user"], "onos")
         self.assertEqual(d["pass"], "rocks")
 
     def test_range_matches_single(self):
-        self.assertTrue(self.sync_step().range_matches(123, "123"))
+        self.assertTrue(self.sync_step(model_accessor=self.model_accessor).range_matches(123, "123"))
 
     def test_range_matches_single_incorrect(self):
-        self.assertFalse(self.sync_step().range_matches(123, "456"))
+        self.assertFalse(self.sync_step(model_accessor=self.model_accessor).range_matches(123, "456"))
 
     def test_range_matches_range(self):
-        self.assertTrue(self.sync_step().range_matches(123, "122-124"))
+        self.assertTrue(self.sync_step(model_accessor=self.model_accessor).range_matches(123, "122-124"))
 
     def test_range_matches_range_incorrect(self):
-        self.assertFalse(self.sync_step().range_matches(123, "110-113"))
+        self.assertFalse(self.sync_step(model_accessor=self.model_accessor).range_matches(123, "110-113"))
 
     def test_range_matches_any(self):
-        self.assertTrue(self.sync_step().range_matches(123, "ANY"))
-        self.assertTrue(self.sync_step().range_matches(123, "any"))
+        self.assertTrue(self.sync_step(model_accessor=self.model_accessor).range_matches(123, "ANY"))
+        self.assertTrue(self.sync_step(model_accessor=self.model_accessor).range_matches(123, "any"))
 
     def test_find_bng_single(self):
         with patch.object(BNGPortMapping.objects, "get_items") as bng_objects, \
@@ -150,7 +136,7 @@
             # this should not be called
             range_matches.return_value = False
 
-            found_bng = self.sync_step().find_bng(111)
+            found_bng = self.sync_step(model_accessor=self.model_accessor).find_bng(111)
             self.assertTrue(found_bng)
             self.assertEqual(found_bng.switch_port, 4)
 
@@ -161,7 +147,7 @@
             bngmapping = BNGPortMapping(s_tag="ANY", switch_port=4)
             bng_objects.return_value = [bngmapping]
 
-            found_bng = self.sync_step().find_bng(111)
+            found_bng = self.sync_step(model_accessor=self.model_accessor).find_bng(111)
             self.assertTrue(found_bng)
             self.assertEqual(found_bng.switch_port, 4)
 
@@ -170,7 +156,7 @@
             bngmapping = BNGPortMapping(s_tag="100-200", switch_port=4)
             bng_objects.return_value = [bngmapping]
 
-            found_bng = self.sync_step().find_bng(111)
+            found_bng = self.sync_step(model_accessor=self.model_accessor).find_bng(111)
             self.assertTrue(found_bng)
             self.assertEqual(found_bng.switch_port, 4)
 
@@ -196,7 +182,7 @@
                    status_code=200,
                    additional_matcher=functools.partial(match_json, desired_data))
 
-            self.sync_step().sync_record(fsi)
+            self.sync_step(model_accessor=self.model_accessor).sync_record(fsi)
             self.assertTrue(m.called)
 
             self.assertEqual(fsi.backend_handle, "111/of:0000000000000201")
@@ -212,7 +198,7 @@
             serviceinstance_objects.return_value = [fsi]
 
             with self.assertRaises(Exception) as e:
-                self.sync_step().sync_record(fsi)
+                self.sync_step(model_accessor=self.model_accessor).sync_record(fsi)
 
             self.assertEqual(e.exception.message, "Unable to determine BNG port for s_tag 111")
 
@@ -226,7 +212,7 @@
             serviceinstance_objects.return_value = [fsi]
 
             with self.assertRaises(Exception) as e:
-                self.sync_step().sync_record(fsi)
+                self.sync_step(model_accessor=self.model_accessor).sync_record(fsi)
 
             self.assertEqual(e.exception.message, "Waiting for model_policy to run on fcsi 7777")
 
@@ -240,7 +226,7 @@
             serviceinstance_objects.return_value = [fsi]
 
             with self.assertRaises(Exception) as e:
-                self.sync_step().sync_record(fsi)
+                self.sync_step(model_accessor=self.model_accessor).sync_record(fsi)
 
             self.assertEqual(e.exception.message, "Cannot sync FabricCrossconnectServiceInstance if s_tag is None on fcsi 7777")
 
@@ -254,7 +240,7 @@
             serviceinstance_objects.return_value = [fsi]
 
             with self.assertRaises(Exception) as e:
-                self.sync_step().sync_record(fsi)
+                self.sync_step(model_accessor=self.model_accessor).sync_record(fsi)
 
             self.assertEqual(e.exception.message, "Cannot sync FabricCrossconnectServiceInstance if switch_datapath_id is unset on fcsi 7777")
 
@@ -268,7 +254,7 @@
             serviceinstance_objects.return_value = [fsi]
 
             with self.assertRaises(Exception) as e:
-                self.sync_step().sync_record(fsi)
+                self.sync_step(model_accessor=self.model_accessor).sync_record(fsi)
 
             self.assertEqual(e.exception.message, "Cannot sync FabricCrossconnectServiceInstance if source_port is None on fcsi 7777")
 
@@ -289,7 +275,7 @@
                    status_code=204,
                    additional_matcher=functools.partial(match_json, desired_data))
 
-            self.sync_step().delete_record(fsi)
+            self.sync_step(model_accessor=self.model_accessor).delete_record(fsi)
             self.assertTrue(m.called)
 
     def tearDown(self):