Fixing OLTDevice pull step

Change-Id: I2b7d0b68f0db61d3b1da93fdf7c582c3240b8a77
diff --git a/xos/synchronizer/models/volt.xproto b/xos/synchronizer/models/volt.xproto
index 16c3955..874e523 100644
--- a/xos/synchronizer/models/volt.xproto
+++ b/xos/synchronizer/models/volt.xproto
@@ -41,7 +41,7 @@
     optional string dp_id = 14 [help_text = "datapath id", null = True, db_index = False, blank = False, feedback_state = True];
 
     required string uplink = 15 [default="129", help_text = "uplink port", null = False, db_index = False, blank = False];
-    required string driver = 16 [default="pmc-olt", help_text = "Olt driver", null = True, db_index = False, blank = False];
+    required string driver = 16 [default="voltha", help_text = "Olt driver", null = True, db_index = False, blank = False];
 
     optional string switch_datapath_id = 17 [help_text = "Fabric switch to which the OLT is connected", null = False, db_index = False, blank = False];
     optional string switch_port = 18 [help_text = "Fabric port to which the OLT is connected", null = False, db_index = False, blank = False];
diff --git a/xos/synchronizer/pull_steps/pull_olts.py b/xos/synchronizer/pull_steps/pull_olts.py
index e377f1b..0fc5e2d 100644
--- a/xos/synchronizer/pull_steps/pull_olts.py
+++ b/xos/synchronizer/pull_steps/pull_olts.py
@@ -40,6 +40,7 @@
     def get_voltha_info(olt_service):
         return {
             'url': OLTDevicePullStep.format_url(olt_service.voltha_url),
+            'port': olt_service.voltha_port,
             'user': olt_service.voltha_user,
             'pass': olt_service.voltha_pass
         }
@@ -53,8 +54,9 @@
     @staticmethod
     def get_ids_from_logical_device(o):
         voltha_url = OLTDevicePullStep.get_voltha_info(o.volt_service)['url']
+        voltha_port = OLTDevicePullStep.get_voltha_info(o.volt_service)['port']
 
-        r = requests.get(voltha_url + "/api/v1/logical_devices")
+        r = requests.get("%s:%s/api/v1/logical_devices" % (voltha_url, voltha_port))
 
         if r.status_code != 200:
             raise Exception("Failed to retrieve logical devices from VOLTHA: %s" % r.text)
@@ -80,10 +82,10 @@
             return
 
         voltha_url = OLTDevicePullStep.get_voltha_info(self.volt_service)['url']
+        voltha_port = OLTDevicePullStep.get_voltha_info(self.volt_service)['port']
 
         try:
-            devices = []
-            r = requests.get(voltha_url + "/api/v1/devices")
+            r = requests.get("%s:%s/api/v1/devices" % (voltha_url, voltha_port))
 
             if r.status_code != 200:
                 log.info("It was not possible to fetch devices from VOLTHA")
@@ -94,11 +96,7 @@
             log.debug("received devices", olts=devices)
 
             # TODO
-            # [X] for each device
-            # [X] check if exists, if not save it
-            # [X] if exists and enacted > updated it has already been sync'ed
-            # [X] keep track of the updated OLTs
-            # delete OLTS as OLTDevice.objects.all() - updated OLTs
+            # [ ] delete OLTS as OLTDevice.objects.all() - updated OLTs
 
             if r.status_code != 200:
                 log.info("It was not possible to fetch devices from VOLTHA")
diff --git a/xos/synchronizer/pull_steps/test_pull_olts.py b/xos/synchronizer/pull_steps/test_pull_olts.py
index f377f8c..a0ef017 100644
--- a/xos/synchronizer/pull_steps/test_pull_olts.py
+++ b/xos/synchronizer/pull_steps/test_pull_olts.py
@@ -57,7 +57,13 @@
         # 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")])
+        # build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.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
 
@@ -73,6 +79,7 @@
         self.volt_service.voltha_url = "voltha_url"
         self.volt_service.voltha_user = "voltha_user"
         self.volt_service.voltha_pass = "voltha_pass"
+        self.volt_service.voltha_port = 1234
 
         # mock voltha responses
         self.devices = {
@@ -111,8 +118,8 @@
                 patch.object(OLTDevice, "save") as mock_save:
             olt_service_mock.return_value = [self.volt_service]
 
-            m.get("http://voltha_url/api/v1/devices", status_code=200, json=self.devices)
-            m.get("http://voltha_url/api/v1/logical_devices", status_code=200, json=self.logical_devices)
+            m.get("http://voltha_url:1234/api/v1/devices", status_code=200, json=self.devices)
+            m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=self.logical_devices)
 
             self.sync_step().pull_records()
 
@@ -139,8 +146,8 @@
             olt_service_mock.return_value = [self.volt_service]
             mock_get.return_value = [existing_olt]
 
-            m.get("http://voltha_url/api/v1/devices", status_code=200, json=self.devices)
-            m.get("http://voltha_url/api/v1/logical_devices", status_code=200, json=self.logical_devices)
+            m.get("http://voltha_url:1234/api/v1/devices", status_code=200, json=self.devices)
+            m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=self.logical_devices)
 
             self.sync_step().pull_records()
 
@@ -165,8 +172,8 @@
             olt_service_mock.return_value = [self.volt_service]
             mock_get.return_value = existing_olt
 
-            m.get("http://voltha_url/api/v1/devices", status_code=200, json=self.devices)
-            m.get("http://voltha_url/api/v1/logical_devices", status_code=200, json=self.logical_devices)
+            m.get("http://voltha_url:1234/api/v1/devices", status_code=200, json=self.devices)
+            m.get("http://voltha_url:1234/api/v1/logical_devices", status_code=200, json=self.logical_devices)
 
             self.sync_step().pull_records()
 
diff --git a/xos/synchronizer/steps/sync_olt_device.py b/xos/synchronizer/steps/sync_olt_device.py
index cb2d4c6..4aaebdf 100644
--- a/xos/synchronizer/steps/sync_olt_device.py
+++ b/xos/synchronizer/steps/sync_olt_device.py
@@ -146,20 +146,6 @@
                 print request.text
         return model
 
-    def hack_to_get_onos_to_load_the_proper_driver(self, model):
-        # Remove the device from ONOS
-        log.info("Updating ONOS driver")
-        onos_voltha = Helpers.get_onos_voltha_info(model.volt_service)
-        onos_voltha_basic_auth = HTTPBasicAuth(onos_voltha['user'], onos_voltha['pass'])
-        request = requests.delete("%s:%d/onos/v1/network/configuration/devices/%s" % (
-            onos_voltha['url'], onos_voltha['port'], model.of_id), auth=onos_voltha_basic_auth)
-
-        if request.status_code != 204:
-            log.error("Failed to remove OLT device from ONOS: %s - %s" % (model.name, model.of_id),
-                      rest_response=request.text,
-                      rest_status_code=request.status_code)
-            raise Exception("Failed to remove OLT device from ONOS")
-
     def sync_record(self, model):
         log.info("Synching device", object=str(model), **model.tologdict())
 
@@ -173,10 +159,6 @@
 
         self.configure_onos(model)
 
-        # FIXME this is need to solve a bug in ONOS
-        self.hack_to_get_onos_to_load_the_proper_driver(model)
-        # FIXME END
-
     def delete_record(self, o):
         log.info("Deleting OLT device", object=str(o), **o.tologdict())
 
diff --git a/xos/synchronizer/steps/test_sync_olt_device.py b/xos/synchronizer/steps/test_sync_olt_device.py
index e73b249..55d477e 100644
--- a/xos/synchronizer/steps/test_sync_olt_device.py
+++ b/xos/synchronizer/steps/test_sync_olt_device.py
@@ -65,7 +65,14 @@
         # 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")])
+        # build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.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 sync_olt_device import SyncOLTDevice
         self.sync_step = SyncOLTDevice
@@ -181,9 +188,6 @@
 
         m.post("http://onos_voltha_url:4321/onos/v1/network/configuration/", status_code = 200, additional_matcher=match_onos_req, json={})
 
-        # FIXME this is part of the block in the syncstep
-        m.delete("http://onos_voltha_url:4321/onos/v1/network/configuration/devices/0001000ce2314000", status_code=200)
-
         self.sync_step().sync_record(self.o)
         self.assertEqual(self.o.admin_state, "ACTIVE")
         self.assertEqual(self.o.oper_status, "ENABLED")
@@ -201,9 +205,6 @@
 
         m.post("http://onos_voltha_url:4321/onos/v1/network/configuration/", status_code = 200, additional_matcher=match_onos_req, json={})
 
-        # FIXME this is part of the block in the syncstep
-        m.delete("http://onos_voltha_url:4321/onos/v1/network/configuration/devices/0001000ce2314000", status_code=200)
-
         self.sync_step().sync_record(self.o)
         self.o.save.assert_not_called()
 
@@ -212,7 +213,7 @@
         self.o.of_id = "0001000ce2314000"
         self.o.device_id = "123"
 
-        m.delete("http://onos_voltha_url:4321/onos/v1/network/configuration/devices/0001000ce2314000", status_code=200)
+        m.delete("http://onos_voltha_url:4321/onos/v1/network/configuration/devices/0001000ce2314000", status_code=204)
         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)
 
diff --git a/xos/synchronizer/steps/test_sync_volt_service_instance.py b/xos/synchronizer/steps/test_sync_volt_service_instance.py
index 85138d5..60d2d7d 100644
--- a/xos/synchronizer/steps/test_sync_volt_service_instance.py
+++ b/xos/synchronizer/steps/test_sync_volt_service_instance.py
@@ -60,7 +60,13 @@
 
         from synchronizers.new_base.syncstep import DeferredException
         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")])
+        # build_mock_modelaccessor(xos_dir, services_dir, [get_models_fn("olt-service", "volt.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 sync_volt_service_instance import SyncVOLTServiceInstance, model_accessor