[CORD-3004] Refactor, improve XOS OLT service

Change-Id: I33aedccacde0737b741a113cf3455f90a5902394
diff --git a/xos/synchronizer/steps/test_sync_olt_device.py b/xos/synchronizer/steps/test_sync_olt_device.py
index 8143ef8..a1ef7b8 100644
--- a/xos/synchronizer/steps/test_sync_olt_device.py
+++ b/xos/synchronizer/steps/test_sync_olt_device.py
@@ -26,9 +26,9 @@
     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
+# END of hack to load synchronizer framework
 
-# generate model from xproto
+# 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)):
@@ -41,20 +41,18 @@
 # END generate model from xproto
 
 def match_onos_req(req):
-    r = req.json()['devices']
-    if not r['of:0000000ce2314000']:
+    request = req.json()['devices']
+    if not request['of:0000000ce2314000']:
         return False
     else:
-        if not r['of:0000000ce2314000']['basic']['driver'] == 'pmc-olt':
+        if not request['of:0000000ce2314000']['basic']['driver'] == 'pmc-olt':
             return False
-        if not r['of:0000000ce2314000']['accessDevice']['vlan'] == "s_tag" or not r['of:0000000ce2314000']['accessDevice']['uplink'] == "129":
+        if not request['of:0000000ce2314000']['accessDevice']['vlan'] == "s_tag" or not request['of:0000000ce2314000']['accessDevice']['uplink'] == "129":
             return False
     return True
 
 class TestSyncOLTDevice(unittest.TestCase):
-
     def setUp(self):
-
         self.sys_path_save = sys.path
         sys.path.append(xos_dir)
         sys.path.append(os.path.join(xos_dir, 'synchronizers', 'new_base'))
@@ -64,7 +62,7 @@
         config = os.path.join(test_path, "../model_policies/test_config.yaml")
         Config.clear()
         Config.init(config, "synchronizer-config-schema.yaml")
-        # END Setting up the config module
+        # 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")])
@@ -76,14 +74,16 @@
         pon_port.port_id = "00ff00"
         pon_port.s_tag = "s_tag"
 
-        # create a mock service instance
+        # Create a mock service instance
         o = Mock()
         o.volt_service.voltha_url = "voltha_url"
+        o.volt_service.voltha_port = 1234
         o.volt_service.voltha_user = "voltha_user"
         o.volt_service.voltha_pass = "voltha_pass"
-        o.volt_service.p_onos_url = "p_onos_url"
-        o.volt_service.p_onos_user = "p_onos_user"
-        o.volt_service.p_onos_pass = "p_onos_pass"
+        o.volt_service.onos_voltha_url = "onos_voltha_url"
+        o.volt_service.onos_voltha_port = 4321
+        o.volt_service.onos_voltha_user = "onos_voltha_user"
+        o.volt_service.onos_voltha_pass = "onos_voltha_pass"
 
         o.device_type = "ponsim_olt"
         o.host = "172.17.0.1"
@@ -109,8 +109,6 @@
         self.o = None
         sys.path = self.sys_path_save
 
-
-
     @requests_mock.Mocker()
     def test_get_of_id_from_device(self, m):
         logical_devices = {
@@ -119,7 +117,7 @@
                 {"root_device_id": "0001cc4974a62b87", "id": "0001000000000001"}
             ]
         }
-        m.get("http://voltha_url/api/v1/logical_devices", status_code=200, json=logical_devices)
+        m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=logical_devices)
         self.o.device_id = "123"
         self.o = self.sync_step.get_ids_from_logical_device(self.o)
         self.assertEqual(self.o.of_id, "0001000ce2314000")
@@ -135,7 +133,7 @@
         """
         Should print an error if we can't add the device in VOLTHA
         """
-        m.post("http://voltha_url/api/v1/devices", status_code=500, text="MockError")
+        m.post("http://voltha_url:1234/api/v1/devices", status_code=500, text="MockError")
 
         with self.assertRaises(Exception) as e:
             self.sync_step().sync_record(self.o)
@@ -146,7 +144,7 @@
         """
         Should print an error if VOLTHA does not return the device id
         """
-        m.post("http://voltha_url/api/v1/devices", status_code=200, json={"id": ""})
+        m.post("http://voltha_url:1234/api/v1/devices", status_code=200, json={"id": ""})
 
         with self.assertRaises(Exception) as e:
             self.sync_step().sync_record(self.o)
@@ -157,8 +155,8 @@
         """
         Should print an error if device.enable fails
         """
-        m.post("http://voltha_url/api/v1/devices", status_code=200, json={"id": "123"})
-        m.post("http://voltha_url/api/v1/devices/123/enable", status_code=500, text="EnableError")
+        m.post("http://voltha_url:1234/api/v1/devices", status_code=200, json={"id": "123"})
+        m.post("http://voltha_url:1234/api/v1/devices/123/enable", status_code=500, text="EnableError")
 
         with self.assertRaises(Exception) as e:
             self.sync_step().sync_record(self.o)
@@ -169,53 +167,50 @@
         """
         If device.enable succed should fetch the state, retrieve the of_id and push it to ONOS
         """
-        m.post("http://voltha_url/api/v1/devices", status_code=200, json={"id": "123"})
-        m.post("http://voltha_url/api/v1/devices/123/enable", status_code=200)
-        m.get("http://voltha_url/api/v1/devices/123", json={"oper_status": "ENABLED", "admin_state": "ACTIVE"})
+        m.post("http://voltha_url:1234/api/v1/devices", status_code=200, json={"id": "123"})
+        m.post("http://voltha_url:1234/api/v1/devices/123/enable", status_code=200)
+        m.get("http://voltha_url:1234/api/v1/devices/123", json={"oper_status": "ENABLED", "admin_state": "ACTIVE"})
         logical_devices = {
             "items": [
                 {"root_device_id": "123", "id": "0001000ce2314000", "datapath_id": "55334486016"},
                 {"root_device_id": "0001cc4974a62b87", "id": "0001000000000001"}
             ]
         }
-        m.get("http://voltha_url/api/v1/logical_devices", status_code=200, json=logical_devices)
+        m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=logical_devices)
 
-        m.post("http://p_onos_url/onos/v1/network/configuration/", status_code=200, additional_matcher=match_onos_req, json={})
+        m.post("http://onos_voltha_url:4321/onos/v1/network/configuration/", status_code = 200, additional_matcher=match_onos_req, json={})
 
         self.sync_step().sync_record(self.o)
         self.assertEqual(self.o.admin_state, "ACTIVE")
         self.assertEqual(self.o.oper_status, "ENABLED")
         self.assertEqual(self.o.of_id, "0001000ce2314000")
-        # self.assertEqual(self.o.dp_id, "of:0000000ce2314000")
         self.o.save.assert_called_once()
 
     @requests_mock.Mocker()
     def test_sync_record_already_existing_in_voltha(self, m):
-
         # mock device feedback state
         self.o.device_id = "123"
         self.o.admin_state = "ACTIVE"
         self.o.oper_status = "ENABLED"
         self.o.dp_id = "of:0000000ce2314000"
 
-        m.post("http://p_onos_url/onos/v1/network/configuration/", status_code=200, additional_matcher=match_onos_req, json={})
+        m.post("http://onos_voltha_url:4321/onos/v1/network/configuration/", status_code = 200, additional_matcher=match_onos_req, json={})
 
         self.sync_step().sync_record(self.o)
         self.o.save.assert_not_called()
 
-
     @requests_mock.Mocker()
     def test_delete_record(self, m):
         self.o.of_id = "0001000ce2314000"
         self.o.device_id = "123"
 
-        m.delete("http://p_onos_url/onos/v1/network/configuration/devices/0001000ce2314000", status_code=200)
-        m.post("http://voltha_url/api/v1/devices/123/disable", status_code=200)
-        m.delete("http://voltha_url/api/v1/devices/123/delete", status_code=200)
+        m.delete("http://onos_voltha_url:4321/onos/v1/network/configuration/devices/0001000ce2314000", status_code=200)
+        m.post("http://voltha_url:1234/api/v1/devices/123/disable", status_code=200)
+        m.delete("http://voltha_url:1234/api/v1/devices/123/delete", status_code=200)
 
         self.sync_step().delete_record(self.o)
 
-        # we don't need to assert here, if there are no exceptions it succeded
+        # We don't need to assert here if there are no exceptions happening
 
 if __name__ == "__main__":
-    unittest.main()
\ No newline at end of file
+    unittest.main()