def test_nsd_elements(self): """ Test that a particular element in a list is corerctly retrieved. In this case, we are trying to retrieve an NSD from the NSD catalog. """ # Create the initial NSD catalog nsd_catalog = NsdYang.YangData_Nsd_NsdCatalog() # Create an NSD, set its 'id', and add it to the catalog nsd_id = str(uuid.uuid4()) nsd_catalog.nsd.append(NsdYang.YangData_Nsd_NsdCatalog_Nsd( id=nsd_id, )) # Retrieve the NSD using and xpath expression xpath = '/nsd:nsd-catalog/nsd:nsd[nsd:id={}]'.format(nsd_id) nsd = rwxpath.getxattr(nsd_catalog, xpath) self.assertEqual(nsd_id, nsd.id) # Modified the name of the NSD using an xpath expression rwxpath.setxattr(nsd_catalog, xpath + "/nsd:name", "test-name") name = rwxpath.getxattr(nsd_catalog, xpath + "/nsd:name") self.assertEqual("test-name", name)
def test_bad_descriptor_type(self): nsd_msg = NsdYang.YangData_Nsd_NsdCatalog() with self.assertRaises(TypeError): yield from self._loop.run_in_executor(None, self._onboarder.update, nsd_msg) with self.assertRaises(TypeError): yield from self._loop.run_in_executor(None, self._onboarder.onboard, nsd_msg)
def nsd(): catalog = NsdYang.YangData_Nsd_NsdCatalog() nsd = catalog.nsd.add() nsd.id = str(uuid.uuid1()) return nsd
def test_nsd_merge(nsd, convertor): nsd.config_primitive.add().from_dict( { "parameter_group": [ { "parameter": [ { "data_type": "INTEGER", "default_value": "3000", "name": "Vlan ID", "mandatory": True } ], "name": "PE1", "mandatory": False }, { "parameter": [ { "data_type": "INTEGER", "default_value": "3000", "name": "Vlan ID", "mandatory": True } ], "name": "PE2", "mandatory": False } ], "parameter": [ { "data_type": "INTEGER", "default_value": "10", "name": "Tunnel Key", "mandatory": True, } ], "name": "Add SP Test Corporation", "user_defined_script": "add_corporation.py" }) ip_yaml = """Add SP Test Corporation: parameter: Tunnel Key: '10' parameter_group: PE1: Vlan ID: '3000' PE2: Vlan ID: '3000' """ catalog = NsdYang.YangData_Nsd_NsdCatalog() expected_nsd = catalog.nsd.add() expected_nsd.id = nsd.id expected_nsd.config_primitive.add().from_dict( { "parameter_group": [ { "parameter": [ { "data_type": "INTEGER", "default_value": "3000", "name": "Vlan ID", "mandatory": True } ], "name": "PE1", "mandatory": False }, { "parameter": [ { "data_type": "INTEGER", "default_value": "3000", "name": "Vlan ID", "mandatory": True } ], "name": "PE2", "mandatory": False } ], "parameter": [ { "data_type": "INTEGER", "default_value": "10", "name": "Tunnel Key", "mandatory": True, } ], "name": "Add SP Test Corporation", "user_defined_script": "add_corporation.py" }) convertor.merge_nsd_config(nsd, yaml.load(ip_yaml)) assert nsd.as_dict() == expected_nsd.as_dict()