SEBA-497 delayering, Makefile, and tox for fabric-synchronizer

Change-Id: I916f4b632019dddceae5a6f024a0b1c64d8188d8
diff --git a/xos/synchronizer/steps/__init__.py b/xos/synchronizer/steps/__init__.py
new file mode 100644
index 0000000..19d1424
--- /dev/null
+++ b/xos/synchronizer/steps/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/xos/synchronizer/steps/helpers.py b/xos/synchronizer/steps/helpers.py
index 2203db1..3ac04fe 100644
--- a/xos/synchronizer/steps/helpers.py
+++ b/xos/synchronizer/steps/helpers.py
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import absolute_import
+
 class Helpers():
     @staticmethod
     def format_url(url):
@@ -19,6 +21,7 @@
             return url
         else:
             return 'http://%s' % url
+
     @staticmethod
     def get_onos_fabric_service(model_accessor):
         # FIXME do not select by name but follow ServiceDependency
diff --git a/xos/synchronizer/steps/sync_fabric_port.py b/xos/synchronizer/steps/sync_fabric_port.py
index 1ab0f52..4f0c914 100644
--- a/xos/synchronizer/steps/sync_fabric_port.py
+++ b/xos/synchronizer/steps/sync_fabric_port.py
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+#from __future__ import absolute_import
+
 import requests
 import urllib
 from requests.auth import HTTPBasicAuth
@@ -117,15 +119,21 @@
     def delete_record(self, model):
         if model.leaf_model_name == "PortInterface":
             log.info("Received update for PortInterface", port=model.port.portId, interface=model.name)
-            log.info("Removing port interface %s from port %s/%s in onos-fabric" % (model.name, model.port.switch.ofId, model.port.portId))
+            log.info("Removing port interface %s from port %s/%s in onos-fabric" %
+                     (model.name, model.port.switch.ofId, model.port.portId))
 
             # resync the existing interfaces
             return self.sync_record(model.port)
 
         if model.leaf_model_name == "FabricIpAddress":
             # TODO add unit tests
-            log.info("Received update for FabricIpAddress", port=model.interface.port.portId, interface=model.interface.name, ip=model.ip)
-            log.info("Removing IP %s from interface %s, on port %s/%s in onos-fabric" % (model.ip, model.interface.name, model.interface.port.switch.ofId, model.interface.port.portId))
+            log.info(
+                "Received update for FabricIpAddress",
+                port=model.interface.port.portId,
+                interface=model.interface.name,
+                ip=model.ip)
+            log.info("Removing IP %s from interface %s, on port %s/%s in onos-fabric" %
+                     (model.ip, model.interface.name, model.interface.port.switch.ofId, model.interface.port.portId))
 
             # resync the existing interfaces
             return self.sync_record(model.interface.port)
diff --git a/xos/synchronizer/steps/sync_fabric_switch.py b/xos/synchronizer/steps/sync_fabric_switch.py
index 31c5575..cac7ac5 100644
--- a/xos/synchronizer/steps/sync_fabric_switch.py
+++ b/xos/synchronizer/steps/sync_fabric_switch.py
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+#from __future__ import absolute_import
+
 import requests
 from requests.auth import HTTPBasicAuth
 from xossynchronizer.steps.syncstep import SyncStep
@@ -25,6 +27,7 @@
 
 log = create_logger(Config().get('logging'))
 
+
 class SyncFabricSwitch(SyncStep):
     provides = [Switch]
     observes = Switch
@@ -33,22 +36,22 @@
         log.info("Adding switch %s to onos-fabric" % model.name)
         # Send device info to onos-fabric netcfg
         data = {
-          "devices": {
-            model.ofId: {
-              "basic": {
-                "name": model.name,
-                "driver": model.driver
-              },
-              "segmentrouting" : {
-                "name" : model.name,
-                "ipv4NodeSid" : model.ipv4NodeSid,
-                "ipv4Loopback" : model.ipv4Loopback,
-                "routerMac" : model.routerMac,
-                "isEdgeRouter" : model.isEdgeRouter,
-                "adjacencySids" : []
-              }
+            "devices": {
+                model.ofId: {
+                    "basic": {
+                        "name": model.name,
+                        "driver": model.driver
+                    },
+                    "segmentrouting": {
+                        "name": model.name,
+                        "ipv4NodeSid": model.ipv4NodeSid,
+                        "ipv4Loopback": model.ipv4Loopback,
+                        "routerMac": model.routerMac,
+                        "isEdgeRouter": model.isEdgeRouter,
+                        "adjacencySids": []
+                    }
+                }
             }
-          }
         }
 
         onos = Helpers.get_onos_fabric_service(model_accessor=self.model_accessor)
@@ -61,15 +64,15 @@
             raise Exception("Failed to add device %s into ONOS" % model.name)
         else:
             try:
-                print r.json()
+                log.info("result", json=r.json())
             except Exception:
-                print r.text
+                log.info("result", text=r.text)
 
     def delete_record(self, model):
         log.info("Removing switch %s from onos-fabric" % model.name)
         onos = Helpers.get_onos_fabric_service(model_accessor=self.model_accessor)
         url = 'http://%s:%s/onos/v1/network/configuration/devices/%s' % (
-        onos.rest_hostname, onos.rest_port, model.ofId)
+            onos.rest_hostname, onos.rest_port, model.ofId)
 
         r = requests.delete(url, auth=HTTPBasicAuth(onos.rest_username, onos.rest_password))
 
diff --git a/xos/synchronizer/steps/test_sync_fabric_port.py b/xos/synchronizer/steps/test_sync_fabric_port.py
index 234a048..af370cb 100644
--- a/xos/synchronizer/steps/test_sync_fabric_port.py
+++ b/xos/synchronizer/steps/test_sync_fabric_port.py
@@ -12,6 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+#from __future__ import absolute_import
+
+import imp
 import unittest
 import urllib
 import functools
@@ -30,6 +33,7 @@
         return False
     return True
 
+
 class TestSyncFabricPort(unittest.TestCase):
 
     def setUp(self):
@@ -49,8 +53,8 @@
 
         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
+        imp.reload(mock_modelaccessor)  # in case nose2 loaded it in a previous test
+        imp.reload(xossynchronizer.modelaccessor)  # in case nose2 loaded it in a previous test
 
         from xossynchronizer.modelaccessor import model_accessor
         self.model_accessor = model_accessor
diff --git a/xos/synchronizer/steps/test_sync_fabric_switch.py b/xos/synchronizer/steps/test_sync_fabric_switch.py
index 2184a6d..b749b94 100644
--- a/xos/synchronizer/steps/test_sync_fabric_switch.py
+++ b/xos/synchronizer/steps/test_sync_fabric_switch.py
@@ -12,24 +12,27 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+#from __future__ import absolute_import
+
+import imp
 import unittest
-
 import functools
-from mock import patch, call, Mock, PropertyMock
+from mock import patch, Mock
 import requests_mock
-import multistructlog
-from multistructlog import create_logger
 
-import os, sys
+import os
+import sys
 
-test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+test_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+
 
 def match_json(desired, req):
-    if desired!=req.json():
+    if desired != req.json():
         raise Exception("Got request %s, but body is not matching" % req.url)
         return False
     return True
 
+
 class TestSyncFabricSwitch(unittest.TestCase):
 
     def setUp(self):
@@ -49,8 +52,8 @@
 
         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
+        imp.reload(mock_modelaccessor)  # in case nose2 loaded it in a previous test
+        imp.reload(xossynchronizer.modelaccessor)      # in case nose2 loaded it in a previous test
 
         from xossynchronizer.modelaccessor import model_accessor
         self.model_accessor = model_accessor
@@ -61,11 +64,9 @@
         for (k, v) in model_accessor.all_model_classes.items():
             globals()[k] = v
 
-
         self.sync_step = SyncFabricSwitch
         self.sync_step.log = Mock()
 
-
         # mock onos-fabric
         onos_fabric = Mock()
         onos_fabric.name = "onos-fabric"
@@ -105,17 +106,17 @@
             "devices": {
                 self.o.ofId: {
                     "basic": {
-                    "name": self.o.name,
-                    "driver": self.o.driver
-                },
-                "segmentrouting" : {
-                    "name" : self.o.name,
-                    "ipv4NodeSid" : self.o.ipv4NodeSid,
-                    "ipv4Loopback" : self.o.ipv4Loopback,
-                    "routerMac" : self.o.routerMac,
-                    "isEdgeRouter" : self.o.isEdgeRouter,
-                    "adjacencySids" : []
-              }
+                        "name": self.o.name,
+                        "driver": self.o.driver
+                    },
+                    "segmentrouting": {
+                        "name": self.o.name,
+                        "ipv4NodeSid": self.o.ipv4NodeSid,
+                        "ipv4Loopback": self.o.ipv4Loopback,
+                        "routerMac": self.o.routerMac,
+                        "isEdgeRouter": self.o.isEdgeRouter,
+                        "adjacencySids": []
+                    }
                 }
             }
         }
@@ -134,7 +135,7 @@
     @requests_mock.Mocker()
     def test_delete_switch(self, m):
         m.delete("http://onos-fabric:8181/onos/v1/network/configuration/devices/of:1234",
-            status_code=204)
+                 status_code=204)
 
         self.o.ofId = "of:1234"
 
@@ -145,5 +146,6 @@
 
             self.assertTrue(m.called)
 
+
 if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
+    unittest.main()