[CORD-3004] Refactor, improve XOS OLT service
Change-Id: I33aedccacde0737b741a113cf3455f90a5902394
diff --git a/xos/synchronizer/models/volt.xproto b/xos/synchronizer/models/volt.xproto
index b462f0f..d7e8b70 100644
--- a/xos/synchronizer/models/volt.xproto
+++ b/xos/synchronizer/models/volt.xproto
@@ -5,14 +5,15 @@
option verbose_name = "vOLT Service";
option kind = "vOLT";
- required string voltha_url = 2 [max_length = 254, null = False, db_index = False, blank = False];
- optional string voltha_user = 3 [max_length = 254, null = True, db_index = False, blank = True];
- optional string voltha_pass = 4 [max_length = 254, null = True, db_index = False, blank = True];
- required string p_onos_url = 5 [max_length = 254, null = False, db_index = False, blank = False];
- optional string p_onos_user = 6 [max_length = 254, null = True, db_index = False, blank = True];
- optional string p_onos_pass = 7 [max_length = 254, null = True, db_index = False, blank = True];
-
- required string onu_provisioning = 8 [default = "allow_all", choices = "(('allow_all', 'Allow All'), ('pre_provisioned', 'Pre-provisione'), ('oss', 'OSS'))", null = False, db_index = False, blank = False];
+ required string voltha_url = 1 [help_text = "The Voltha API address. By default voltha.voltha.svc.cluster.local", default = "voltha.voltha.svc.cluster.local", max_length = 254, null = False, db_index = False, blank = False];
+ required int32 voltha_port = 2 [help_text = "The Voltha API port. By default 8882", default=8882, null = False, db_index = False, blank = False];
+ required string voltha_user = 3 [help_text = "The Voltha username. By default voltha", default="voltha", max_length = 254, null = False, db_index = False, blank = False];
+ required string voltha_pass = 4 [help_text = "The Voltha password. By default admin", default="admin", max_length = 254, null = False, db_index = False, blank = False];
+ required string onos_voltha_url = 5 [help_text = "The ONOS Voltha address. By default onos-voltha-ui.voltha.svc.cluster.local", default="onos-voltha-ui.voltha.svc.cluster.local", max_length = 254, null = False, db_index = False, blank = False];
+ required int32 onos_voltha_port = 6 [help_text = "The Voltha API port. By default 8181", default=8181, null = False, db_index = False, blank = False];
+ required string onos_voltha_user = 7 [help_text = "The ONOS Voltha username. By default sdn", max_length = 254, default="onos", null = True, db_index = False, blank = False];
+ required string onos_voltha_pass = 8 [help_text = "The ONOS Voltha password. By default rocks", max_length = 254, default="rocks", null = True, db_index = False, blank = False];
+ required string onu_provisioning = 9 [help_text = "If to automatically discover and provision the ONU or not", default = "allow_all", choices = "(('allow_all', 'Allow All'), ('pre_provisioned', 'Pre-provisione'), ('oss', 'OSS'))", null = False, db_index = False, blank = False];
}
message VOLTServiceInstance (ServiceInstance){
diff --git a/xos/synchronizer/steps/helpers.py b/xos/synchronizer/steps/helpers.py
index 914279e..cb310af 100644
--- a/xos/synchronizer/steps/helpers.py
+++ b/xos/synchronizer/steps/helpers.py
@@ -24,16 +24,18 @@
def get_voltha_info(olt_service):
return {
'url': Helpers.format_url(olt_service.voltha_url),
+ 'port': olt_service.voltha_port,
'user': olt_service.voltha_user,
'pass': olt_service.voltha_pass
}
@staticmethod
- def get_p_onos_info(olt_service):
+ def get_onos_voltha_info(olt_service):
return {
- 'url': Helpers.format_url(olt_service.p_onos_url),
- 'user': olt_service.p_onos_user,
- 'pass': olt_service.p_onos_pass
+ 'url': Helpers.format_url(olt_service.onos_voltha_url),
+ 'port': olt_service.onos_voltha_port,
+ 'user': olt_service.onos_voltha_user,
+ 'pass': olt_service.onos_voltha_pass
}
@staticmethod
diff --git a/xos/synchronizer/steps/sync_olt_device.py b/xos/synchronizer/steps/sync_olt_device.py
index 2845721..4a42ec1 100644
--- a/xos/synchronizer/steps/sync_olt_device.py
+++ b/xos/synchronizer/steps/sync_olt_device.py
@@ -27,36 +27,38 @@
class SyncOLTDevice(SyncStep):
provides = [OLTDevice]
-
observes = OLTDevice
@staticmethod
def get_ids_from_logical_device(o):
- voltha_url = Helpers.get_voltha_info(o.volt_service)['url']
+ voltha = Helpers.get_voltha_info(o.volt_service)
- r = requests.get(voltha_url + "/api/v1/logical_devices")
+ request = requests.get("%s:%d/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)
+ if request.status_code != 200:
+ raise Exception("Failed to retrieve logical devices from VOLTHA: %s" % request.text)
- res = r.json()
+ response = request.json()
- for ld in res["items"]:
+ for ld in response["items"]:
if ld["root_device_id"] == o.device_id:
o.of_id = ld["id"]
- o.dp_id = "of:" + Helpers.datapath_id_to_hex(ld["datapath_id"]) # convert to hex
+ o.dp_id = "of:%s" % (Helpers.datapath_id_to_hex(ld["datapath_id"])) # Convert to hex
return o
raise Exception("Can't find a logical device for device id: %s" % o.device_id)
def sync_record(self, o):
- log.info("sync'ing device", object=str(o), **o.tologdict())
+ log.info("Synching device", object=str(o), **o.tologdict())
+
+ voltha = Helpers.get_voltha_info(o.volt_service)
+ onos_voltha = Helpers.get_onos_voltha_info(o.volt_service)
+ onos_voltha_basic_auth = HTTPBasicAuth(onos_voltha['user'], onos_voltha['pass'])
# If the device has feedback_state is already present in voltha
if not o.device_id and not o.admin_state and not o.oper_status and not o.of_id:
log.info("Pushing device to VOLTHA", object=str(o), **o.tologdict())
- voltha_url = Helpers.get_voltha_info(o.volt_service)['url']
data = {
"type": o.device_type,
@@ -64,57 +66,56 @@
}
if o.device_type == 'simulated_olt':
- # simulated devices won't accept host and port, for testing only
+ # Simulated devices will not accept host and port. This is for test only
data.pop('host_and_port')
data['mac_address'] = "00:0c:e2:31:40:00"
- log.info("pushing olt to voltha", data=data)
+ log.info("Pushing OLT to Voltha", data=data)
- r = requests.post(voltha_url + "/api/v1/devices", json=data)
+ request = requests.post("%s:%d/api/v1/devices" % (voltha['url'], voltha['port']), json=data)
- if r.status_code != 200:
- raise Exception("Failed to add device: %s" % r.text)
+ if request.status_code != 200:
+ raise Exception("Failed to add device: %s" % request.text)
- log.info("add device response", text=r.text)
+ log.info("Add device response", text=request.text)
- res = r.json()
+ res = request.json()
- log.info("add device json res", res=res)
+ log.info("Add device json res", res=res)
if not res['id']:
raise Exception('VOLTHA Device Id is empty, this probably means that the device is already provisioned in VOLTHA')
else:
o.device_id = res['id'];
- # enable device
+ # Enable device
+ request = requests.post("%s:%d/api/v1/devices/%s/enable" % (voltha['url'], voltha['port'], o.device_id))
- r = requests.post(voltha_url + "/api/v1/devices/" + o.device_id + "/enable")
+ if request.status_code != 200:
+ raise Exception("Failed to enable device: %s" % request.text)
- if r.status_code != 200:
- raise Exception("Failed to enable device: %s" % r.text)
-
- # read state
- r = requests.get(voltha_url + "/api/v1/devices/" + o.device_id).json()
- while r['oper_status'] == "ACTIVATING":
+ # Read state
+ request = requests.get("%s:%d/api/v1/devices/%s" % (voltha['url'], voltha['port'], o.device_id)).json()
+ while request['oper_status'] == "ACTIVATING":
log.info("Waiting for device %s (%s) to activate" % (o.name, o.device_id))
sleep(5)
- r = requests.get(voltha_url + "/api/v1/devices/" + o.device_id).json()
+ request = requests.get("%s:%d/api/v1/devices/%s" % (voltha['url'], voltha['port'], o.device_id)).json()
- o.admin_state = r['admin_state']
- o.oper_status = r['oper_status']
+ o.admin_state = request['admin_state']
+ o.oper_status = request['oper_status']
- # find of_id of device
+ # Find the of_id of the device
o = self.get_ids_from_logical_device(o)
o.save()
else:
log.info("Device already exists in VOLTHA", object=str(o), **o.tologdict())
- # NOTE do we need to move this synchronization in a PON_PORT specific step?
- # for now we assume that each OLT has only one Port
+ # Do we need to move this synchronization in a PON_PORT specific step?
+ # For now, we assume that each OLT has only one port
vlan = o.ports.all()[0].s_tag
- # add device info to P-ONOS
+ # Add device info to onos-voltha
data = {
"devices": {
o.dp_id: {
@@ -129,45 +130,44 @@
}
}
- onos= Helpers.get_p_onos_info(o.volt_service)
+ request = requests.post("%s:%d/onos/v1/network/configuration/" % (onos_voltha['url'], onos_voltha['port']), data=json.dumps(data), auth=onos_voltha_basic_auth)
- r = requests.post(onos['url'] + '/onos/v1/network/configuration/', data=json.dumps(data), auth=HTTPBasicAuth(onos['user'], onos['pass']))
-
- if r.status_code != 200:
- log.error(r.text)
+ if request.status_code != 200:
+ log.error(request.text)
raise Exception("Failed to add device %s into ONOS" % o.name)
else:
try:
- print r.json()
+ print request.json()
except Exception:
- print r.text
+ print request.text
def delete_record(self, o):
+ log.info("Deleting device", object=str(o), **o.tologdict())
- voltha_url = Helpers.get_voltha_info(o.volt_service)['url']
- onos = Helpers.get_p_onos_info(o.volt_service)
+ voltha = Helpers.get_voltha_info(o.volt_service)
+ onos_voltha = Helpers.get_onos_voltha_info(o.volt_service)
+ onos_voltha_basic_auth = HTTPBasicAuth(onos_voltha['user'], onos_voltha['pass'])
+
if not o.device_id:
log.error("Device %s has no device_id" % o.name)
-
else:
+ # Remove the device from ONOS
+ request = requests.delete("%s:%d/onos/v1/network/configuration/devices/%s" % (onos_voltha['url'], onos_voltha['port'], o.of_id), auth=onos_voltha_basic_auth)
- # remove the device from ONOS
- r = requests.delete(onos['url'] + '/onos/v1/network/configuration/devices/' + o.of_id, auth=HTTPBasicAuth(onos['user'], onos['pass']))
-
- if r.status_code != 200:
- log.error("Failed to remove device from ONOS: %s - %s" % (o.name, o.of_id), rest_responese=r.text, rest_status_code=r.status_code)
+ if request.status_code != 200:
+ log.error("Failed to remove device from ONOS: %s - %s" % (o.name, o.of_id), rest_responese=request.text, rest_status_code=request.status_code)
raise Exception("Failed to remove device in ONOS")
- # disable the device
- r = requests.post(voltha_url + "/api/v1/devices/" + o.device_id + "/disable")
+ # Disable the device
+ request = requests.post("%s:%d/api/v1/devices/%s/disable" % (voltha['url'], voltha['port'], o.device_id))
- if r.status_code != 200:
- log.error("Failed to disable device in VOLTHA: %s - %s" % (o.name, o.device_id), rest_responese=r.text, rest_status_code=r.status_code)
+ if request.status_code != 200:
+ log.error("Failed to disable device in VOLTHA: %s - %s" % (o.name, o.device_id), rest_responese=request.text, rest_status_code=request.status_code)
raise Exception("Failed to disable device in VOLTHA")
- # delete the device
- r = requests.delete(voltha_url + "/api/v1/devices/" + o.device_id + "/delete")
+ # Delete the device
+ request = requests.delete("%s:%d/api/v1/devices/%s/delete" % (voltha['url'], voltha['port'], o.device_id))
- if r.status_code != 200:
- log.error("Failed to delete device in VOLTHA: %s - %s" % (o.name, o.device_id), rest_responese=r.text, rest_status_code=r.status_code)
+ if request.status_code != 200:
+ log.error("Failed to delete device in VOLTHA: %s - %s" % (o.name, o.device_id), rest_responese=request.text, rest_status_code=request.status_code)
raise Exception("Failed to delete device in VOLTHA")
diff --git a/xos/synchronizer/steps/sync_volt_service.py b/xos/synchronizer/steps/sync_volt_service.py
index cae1ea3..80ff7b4 100644
--- a/xos/synchronizer/steps/sync_volt_service.py
+++ b/xos/synchronizer/steps/sync_volt_service.py
@@ -26,36 +26,19 @@
class SyncOLTService(SyncStep):
provides = [VOLTService]
-
observes = VOLTService
- @staticmethod
- def format_url(url):
- if 'http' in url:
- return url
- else:
- return 'http://%s' % url
-
- @staticmethod
- def get_p_onos_info(o):
- return {
- 'url': SyncOLTDevice.format_url(o.volt_service.p_onos_url),
- 'user': o.volt_service.p_onos_user,
- 'pass': o.volt_service.p_onos_pass
- }
-
def sync_record(self, o):
- log.info("sync'ing olt service", object=str(o), **o.tologdict())
+ log.info("synching OLT service", object=str(o), **o.tologdict())
if o.onu_provisioning == "allow_all":
- # tell ONOS to create the ONU device (POST xosapi/v1/volt/onudevices)
+ # TODO: Tell ONOS to create the ONU device (POST xosapi/v1/volt/onudevices)
pass
if o.onu_provisioning == "pre_provisioned" or o.onu_provisioning == "oss":
- # tell ONOS to update the ONU device (POST xosapi/v1/volt/onudevices/<id>)
- # NOTE ONOS will need to find the <id>
- # NOTE if onu_provisioning == oss then XOS will need to make a call to the oss server to validate the onu
+ # TODO: Tell ONOS to update the ONU device (POST xosapi/v1/volt/onudevices/<id>)
+ # ONOS will need to find the <id>
+ # if onu_provisioning == oss then XOS will need to make a call to the oss server to validate the ONU
pass
-
def delete_record(self, o):
pass
diff --git a/xos/synchronizer/steps/sync_volt_service_instance.py b/xos/synchronizer/steps/sync_volt_service_instance.py
index dccac6a..eef6f7e 100644
--- a/xos/synchronizer/steps/sync_volt_service_instance.py
+++ b/xos/synchronizer/steps/sync_volt_service_instance.py
@@ -35,7 +35,7 @@
si = ServiceInstance.objects.get(id=o.id)
- log.info("sync'ing OLTServiceInstance", object=str(o), **o.tologdict())
+ log.info("Synching OLTServiceInstance", object=str(o), **o.tologdict())
c_tag = si.get_westbound_service_instance_properties("c_tag")
uni_port_id = si.get_westbound_service_instance_properties("uni_port_id")
@@ -48,21 +48,21 @@
raise DeferredException("Waiting for OLTDevice %s to be synchronized" % olt_device.name)
log.debug("Adding subscriber with info",
- c_tag=c_tag,
- uni_port_id=uni_port_id,
- dp_id=olt_device.dp_id)
+ c_tag = c_tag,
+ uni_port_id = uni_port_id,
+ dp_id = olt_device.dp_id)
- # sending request to ONOS
+ # Send request to ONOS
+ onos_voltha = Helpers.get_onos_voltha_info(volt_service)
+ onos_voltha_basic_auth = HTTPBasicAuth(onos_voltha['user'], onos_voltha['pass'])
- onos = Helpers.get_p_onos_info(volt_service)
+ full_url = "%s:%d/onos/olt/oltapp/%s/%s/%s" % (onos_voltha['url'], onos_voltha['port'], olt_device.dp_id, uni_port_id, c_tag)
- url = onos['url'] + "/onos/olt/oltapp/%s/%s/%s" % (olt_device.dp_id, uni_port_id, c_tag)
+ log.info("Sending request to onos-voltha", url=full_url)
- log.info("sending request to P_ONOS", url=url)
+ request = requests.post(full_url, auth=onos_voltha_basic_auth)
- r = requests.post(url,auth=HTTPBasicAuth(onos['user'], onos['pass']))
+ if request.status_code != 200:
+ raise Exception("Failed to add subscriber in onos-voltha: %s" % request.text)
- if r.status_code != 200:
- raise Exception("Failed to add subscriber in P_ONOS: %s" % r.text)
-
- log.info("P_ONOS response", res=r.text)
\ No newline at end of file
+ log.info("onos voltha response", response=request.text)
\ No newline at end of file
diff --git a/xos/synchronizer/steps/test_helpers.py b/xos/synchronizer/steps/test_helpers.py
index 2820d9e..f97625e 100644
--- a/xos/synchronizer/steps/test_helpers.py
+++ b/xos/synchronizer/steps/test_helpers.py
@@ -19,14 +19,16 @@
class TestHelpers(unittest.TestCase):
def setUp(self):
- # create a mock service instance
+ # Create a mock service instance
o = Mock()
o.voltha_url = "voltha_url"
+ o.voltha_port = 1234
o.voltha_user = "voltha_user"
o.voltha_pass = "voltha_pass"
- o.p_onos_url = "p_onos_url"
- o.p_onos_user = "p_onos_user"
- o.p_onos_pass = "p_onos_pass"
+ o.onos_voltha_url = "onos_voltha_url"
+ o.onos_voltha_port = 4321
+ o.onos_voltha_user = "onos_voltha_user"
+ o.onos_voltha_pass = "onos_voltha_pass"
self.o = o
@@ -40,15 +42,17 @@
voltha_dict = Helpers.get_voltha_info(self.o)
self.assertEqual(voltha_dict["url"], "http://voltha_url")
+ self.assertEqual(voltha_dict["port"], 1234)
self.assertEqual(voltha_dict["user"], "voltha_user")
self.assertEqual(voltha_dict["pass"], "voltha_pass")
def test_get_onos_info(self):
- p_onos_dict = Helpers.get_p_onos_info(self.o)
+ onos_voltha_dict = Helpers.get_onos_voltha_info(self.o)
- self.assertEqual(p_onos_dict["url"], "http://p_onos_url")
- self.assertEqual(p_onos_dict["user"], "p_onos_user")
- self.assertEqual(p_onos_dict["pass"], "p_onos_pass")
+ self.assertEqual(onos_voltha_dict["url"], "http://onos_voltha_url")
+ self.assertEqual(onos_voltha_dict["port"], 4321)
+ self.assertEqual(onos_voltha_dict["user"], "onos_voltha_user")
+ self.assertEqual(onos_voltha_dict["pass"], "onos_voltha_pass")
def test_datapath_id_to_hex(self):
hex = Helpers.datapath_id_to_hex(55334486016)
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()
diff --git a/xos/synchronizer/steps/test_sync_volt_service_instance.py b/xos/synchronizer/steps/test_sync_volt_service_instance.py
index dfab503..85138d5 100644
--- a/xos/synchronizer/steps/test_sync_volt_service_instance.py
+++ b/xos/synchronizer/steps/test_sync_volt_service_instance.py
@@ -44,7 +44,6 @@
return prop
class TestSyncOLTDevice(unittest.TestCase):
-
def setUp(self):
global DeferredException
@@ -78,9 +77,10 @@
o.tologdict.return_value = {}
volt_service = Mock()
- volt_service.p_onos_url = "p_onos_url"
- volt_service.p_onos_user = "p_onos_user"
- volt_service.p_onos_pass = "p_onos_pass"
+ volt_service.onos_voltha_url = "onos_voltha_url"
+ volt_service.onos_voltha_port = 4321
+ volt_service.onos_voltha_user = "onos_voltha_user"
+ volt_service.onos_voltha_pass = "onos_voltha_pass"
si = Mock()
si.get_westbound_service_instance_properties = mock_get_westbound_service_instance_properties
@@ -97,11 +97,8 @@
self.o = None
sys.path = self.sys_path_save
-
-
@requests_mock.Mocker()
def test_do_not_sync(self, m):
-
self.olt_device.dp_id = None
with patch.object(ServiceInstance.objects, "get") as service_instance_mock, \
@@ -119,8 +116,7 @@
@requests_mock.Mocker()
def test_do_sync(self, m):
-
- m.post("http://p_onos_url/onos/olt/oltapp/of:dp_id/uni_port_id/c_tag", status_code=200, json={})
+ m.post("http://onos_voltha_url:4321/onos/olt/oltapp/of:dp_id/uni_port_id/c_tag", status_code=200, json={})
self.olt_device.dp_id = "of:dp_id"
@@ -136,7 +132,7 @@
@requests_mock.Mocker()
def test_do_sync_fail(self, m):
- m.post("http://p_onos_url/onos/olt/oltapp/of:dp_id/uni_port_id/c_tag", status_code=500, text="Mock Error")
+ m.post("http://onos_voltha_url:4321/onos/olt/oltapp/of:dp_id/uni_port_id/c_tag", status_code=500, text="Mock Error")
self.olt_device.dp_id = "of:dp_id"
@@ -149,10 +145,8 @@
with self.assertRaises(Exception) as e:
self.sync_step().sync_record(self.o)
-
- self.assertTrue(m.called)
- self.assertEqual(e.exception.message, "Failed to add subscriber in P_ONOS: Mock Error")
-
+ self.assertTrue(m.called)
+ self.assertEqual(e.exception.message, "Failed to add subscriber in onos voltha: Mock Error")
if __name__ == "__main__":
- unittest.main()
\ No newline at end of file
+ unittest.main()