def test_crud_read_list(self): crud = CRUDService() # Build configuration of multiple objects native = ysanity.Native() native.hostname = 'NativeHost' native.version = '0.1.0' bgp = openconfig.Bgp() bgp.global_.config.as_ = 65001 bgp.global_.config.router_id = "1.2.3.4" create_list = [native, bgp] # Configure device result = crud.create(self.ncc, create_list) self.assertEqual(result, True) # Read configuration native_filter = ysanity.Native() bgp_filter = openconfig.Bgp() filter_list = [native_filter, bgp_filter] read_list = crud.read(self.ncc, filter_list) self.assertEqual(isinstance(read_list, list), True) self.assertEqual(len(read_list), 2) # Delete configuration result = crud.delete(self.ncc, create_list) self.assertEqual(result, True)
def test_create_ODL(self): bgp = oc_bgp.Bgp() bgp.global_.config.as_ = 65172 bgp.global_.config.router_id = '1.2.3.4' neighbor = oc_bgp.Bgp.Neighbors.Neighbor() neighbor.neighbor_address = '6.7.8.9' neighbor.config.neighbor_address = '6.7.8.9' neighbor.config.peer_as = 65001 neighbor.config.local_as = 65001 neighbor.config.peer_group = 'IBGP' bgp.neighbors.neighbor.append(neighbor) peer_group = oc_bgp.Bgp.PeerGroups.PeerGroup() peer_group.peer_group_name = 'IBGP' peer_group.config.peer_group_name = 'IBGP' peer_group.config.description = 'test description' peer_group.config.peer_as = 65001 peer_group.config.local_as = 65001 bgp.peer_groups.peer_group.append(peer_group) node_provider = self.odl.get_node_provider('xr') self.crud.create(node_provider, bgp) bgp_read = self.crud.read_config(node_provider, oc_bgp.Bgp()) self.assertEqual(bgp_read, bgp)
def test_read_ODL(self): bgp_filter = oc_bgp.Bgp() node_provider = self.odl.get_node_provider('xr') bgp_read = self.crud.read_config(node_provider, bgp_filter) self.assertEqual(bgp_read.global_.config.as_, '65172') self.assertEqual(bgp_read.global_.config.router_id, '1.2.3.4')
def test_gnmi_service_subscribe_multiple(self): # Create interface and BGP configurations bgp = build_bgp_config() bgp.yfilter = YFilter.replace ifc = build_int_config() ifc.yfilter = YFilter.replace reply = self.gs.set(self.provider, [bgp, ifc]) self.assertTrue(reply) bgp_filter = openconfig_bgp.Bgp() bgp_subscription = gNMISubscription() bgp_subscription.entity = bgp_filter int_filter = openconfig_interfaces.Interfaces() int_subscription = gNMISubscription() int_subscription.entity = int_filter self.gs.subscribe(self.provider, [int_subscription, bgp_subscription], 10, "ONCE", "JSON_IETF", gnmi_subscribe_multiples_callback) # Delete BGP configuration bgp.yfilter = YFilter.delete ifc.yfilter = YFilter.delete reply = self.gs.set(self.provider, [bgp, ifc]) self.assertTrue(reply)
def build_bgp_config(): # Build BGP configuration on server bgp = openconfig_bgp.Bgp() bgp.global_.config.as_ = 65172 neighbor = bgp.Neighbors.Neighbor() neighbor.neighbor_address = '172.16.255.2' neighbor.config.neighbor_address = '172.16.255.2' neighbor.config.peer_as = 65172 bgp.neighbors.neighbor.append(neighbor) return bgp
def test_crud_read_collection(self): crud = CRUDService() # Build configuration of multiple objects create_list = Config() native = ysanity.Native() native.hostname = 'NativeHost' native.version = '0.1.0' create_list.append(native) bgp = openconfig.Bgp() bgp.global_.config.as_ = 65001 bgp.global_.config.router_id = "1.2.3.4" create_list.append(bgp) create_list = Config([native, bgp]) # Configure device result = crud.create(self.ncc, create_list) self.assertEqual(result, True) # Read configuration read_filter = Filter([ysanity.Native(), openconfig.Bgp()]) read_config = crud.read(self.ncc, read_filter) self.assertEqual(isinstance(read_config, Config), True) self.assertEqual(len(read_config), 2) # Print configuration codec_service = CodecService() codec_provider = CodecServiceProvider() codec_provider.encoding = EncodingFormat.XML for entity in read_config: xml = codec_service.encode(codec_provider, entity) print('\n===== Printing entity: {}'.format(entity)) print(xml) # Delete configuration result = crud.delete(self.ncc, create_list) self.assertEqual(result, True)
def test_bgp_read_container(self): # Delete BGP config bgp_set = openconfig_bgp.Bgp() reply = self.crud.delete(self.ncc, bgp_set) self.assertIsNotNone(reply) # Create BGP config bgp_set.global_.config.as_ = 65001 bgp_set.global_.config.router_id = "1.2.3.4" d = openconfig_bgp.Bgp.Neighbors.Neighbor() d.neighbor_address = "1.2.3.4" d.config.neighbor_address = "1.2.3.4" q = openconfig_bgp.Bgp.Neighbors.Neighbor() q.neighbor_address = "1.2.3.5" q.config.neighbor_address = "1.2.3.5" bgp_set.neighbors.neighbor.extend([d, q]) reply = self.crud.create(self.ncc, bgp_set) self.assertIsNotNone(reply) # Read only 'global' container bgp_filter = openconfig_bgp.Bgp() bgp_filter.global_.yfilter = YFilter.read bgp_read = self.crud.read_config(self.ncc, bgp_filter) self.assertIsNotNone(bgp_read) self.assertTrue(len(bgp_read.neighbors.neighbor) == 0) self.assertTrue(bgp_read.global_.config.as_ == 65001) # Read only 'neighbors' container bgp_filter = openconfig_bgp.Bgp() bgp_filter.neighbors.yfilter = YFilter.read bgp_read = self.crud.read_config(self.ncc, bgp_filter) self.assertIsNotNone(bgp_read) self.assertTrue(len(bgp_read.neighbors.neighbor) == 2) self.assertFalse(bgp_read.global_.has_data()) # Delete BGP config bgp_set = openconfig_bgp.Bgp() reply = self.crud.delete(self.ncc, bgp_set) self.assertIsNotNone(reply)
def test_gnmi_service_subscribe_poll(self): # Create BGP configuration bgp = build_bgp_config() bgp.yfilter = YFilter.replace reply = self.gs.set(self.provider, bgp) subscription = gNMISubscription() bgp_filter = openconfig_bgp.Bgp() subscription.entity = bgp_filter self.gs.subscribe(self.provider, subscription, 10, "POLL", "JSON_IETF", gnmi_subscribe_callback) # Delete BGP configuration bgp.yfilter = YFilter.delete reply = self.gs.set(self.provider, bgp)
def test_gnmi_service_subscribe_stream(self): # Create BGP configuration bgp = build_bgp_config() bgp.yfilter = YFilter.replace reply = self.gs.set(self.provider, bgp) subscription = gNMISubscription() bgp_filter = openconfig_bgp.Bgp() subscription.subscription_mode = "SAMPLE" subscription.sample_interval = 2 * 1000000000 subscription.suppress_redundant = False subscription.heartbeat_interval = 8 * 1000000000 subscription.entity = bgp_filter self.gs.subscribe(self.provider, subscription, 10, "STREAM", "JSON_IETF", gnmi_subscribe_callback) # Delete BGP configuration bgp.yfilter = YFilter.delete reply = self.gs.set(self.provider, bgp)
def test_gnmi_service_subscribe_once(self): # Create BGP configuration bgp = build_bgp_config() bgp.yfilter = YFilter.replace reply = self.gs.set(self.provider, bgp) subscription = gNMISubscription() bgp_filter = openconfig_bgp.Bgp() subscription.subscription_mode = "ON_CHANGE" subscription.sample_interval = 10 * 1000000000 subscription.suppress_redundant = True subscription.heartbeat_interval = 100 * 1000000000 subscription.entity = bgp_filter self.gs.subscribe(self.provider, subscription, 10, "ONCE", "JSON_IETF", gnmi_subscribe_callback); # Delete BGP configuration bgp.yfilter = YFilter.delete reply = self.gs.set(self.provider, bgp)
def test_gnmi_service_set_get_multiple(self): # Create interface and BGP configuration ifc = build_int_config() ifc.yfilter = YFilter.replace bgp = build_bgp_config() bgp.yfilter = YFilter.replace reply = self.gs.set(self.provider, Config(ifc, bgp)) # Get and print interface and BGP configuration ifc_filter = openconfig_interfaces.Interfaces() bgp_filter = openconfig_bgp.Bgp() response = self.gs.get(self.provider, Filter(ifc_filter, bgp_filter), "CONFIG") self.assertIsNotNone(response) self.assertEqual(response.__len__(), 2) #for entity in response: # print_entity(entity, self.schema) # Delete interface and BGP configuration ifc.yfilter = YFilter.delete bgp.yfilter = YFilter.delete reply = self.gs.set(self.provider, [ifc, bgp])
def test_execute_get_schema(self): get_rpc = ietf_netconf.Get() get_rpc.input.filter = '<bgp xmlns="http://openconfig.net/yang/bgp"/>' self.es.execute_rpc(self.ncc, get_rpc, openconfig_bgp.Bgp())
def test_gnmi_crud_all_operations(self): # Configure interface lo10 = openconfig_interfaces.Interfaces.Interface() lo10.name = 'Loopback10' lo10.config.name = 'Loopback10' # Configure BGP bgp_global_config = openconfig_bgp.Bgp.Global.Config() bgp_global_config.as_ = 65172 neighbor = openconfig_bgp.Bgp.Neighbors.Neighbor() neighbor.neighbor_address = '172.16.255.2' neighbor.config.neighbor_address = '172.16.255.2' neighbor.config.peer_as = 65172 res = self.crud.create(self.provider, [lo10, bgp_global_config, neighbor]) # Update configuration lo10.config.description = 'Test' res = self.crud.update(self.provider, lo10) self.assertTrue(res) # Read all read_list = self.crud.read(self.provider, [openconfig_interfaces.Interfaces(), openconfig_bgp.Bgp()]) # Read config ifc_filter = openconfig_interfaces.Interfaces.Interface() ifc_filter.name = 'Loopback10' bgp_neighbor_filter = openconfig_bgp.Bgp.Neighbors.Neighbor() bgp_neighbor_filter.neighbor_address = '172.16.255.2' read_list = self.crud.read_config(self.provider, [ifc_filter, bgp_neighbor_filter]) self.assertIsNotNone(read_list) self.assertEqual(isinstance(read_list, list), True) self.assertEqual(len(read_list), 2) #for entity in read_list: # print_entity(entity, self.schema) # Read single container lo10 = openconfig_interfaces.Interfaces.Interface() lo10.name = 'Loopback10' lo10.config = YFilter.read ifc_config = self.crud.read(self.provider, lo10) #print_entity(ifc_config, self.schema) expected = '''<interface> <name>Loopback10</name> <config> <name>Loopback10</name> <description>Test</description> </config> </interface> ''' self.assertEqual( entity_to_string(ifc_config, self.schema), expected) # Read single leaf ifcs = openconfig_interfaces.Interfaces() lo10 = openconfig_interfaces.Interfaces.Interface() lo10.name = 'Loopback10' lo10.config.description = YFilter.read ifcs.interface.append(lo10) read_descr = self.crud.read(self.provider, lo10) #print_entity(read_descr, self.schema) expected = '''<interface> <name>Loopback10</name> <config> <description>Test</description> </config> </interface> ''' self.assertEqual( entity_to_string(read_descr, self.schema), expected) # Delete configuration ifc = openconfig_interfaces.Interfaces.Interface() ifc.name = 'Loopback10' bgp = openconfig_bgp.Bgp() res = self.crud.delete(self.provider, [ifc, bgp])
def test_gnmi_crud_with_no_validation(self): # Configure interface ifc_config = openconfig_interfaces.Interfaces() lo10 = openconfig_interfaces.Interfaces.Interface() lo10.name = 'Loopback10' lo10.config.name = 'Loopback10' lo10.ignore_validation = True ifc_config.interface.append(lo10) # Configure BGP bgp_config = openconfig_bgp.Bgp() bgp_config.global_.config.as_ = 65172 bgp_config.ignore_validation = True neighbor = openconfig_bgp.Bgp.Neighbors.Neighbor() neighbor.neighbor_address = '172.16.255.2' neighbor.config.neighbor_address = '172.16.255.2' neighbor.config.peer_as = 65172 bgp_config.neighbors.neighbor.append(neighbor) res = self.crud.create(self.provider, [lo10, bgp_config]) # Update configuration lo10.config.description = 'Test' res = self.crud.update(self.provider, lo10) self.assertTrue(res) # Read config ifc_filter = openconfig_interfaces.Interfaces() ifc = openconfig_interfaces.Interfaces.Interface() ifc.name = 'Loopback10' ifc.ignore_validation = True ifc_filter.interface.append(ifc) bgp_filter = openconfig_bgp.Bgp() bgp_neighbor_filter = openconfig_bgp.Bgp.Neighbors.Neighbor() bgp_neighbor_filter.neighbor_address = '172.16.255.2' bgp_neighbor_filter.ignore_validation = True bgp_filter.neighbors.neighbor.append(bgp_neighbor_filter) read_list = self.crud.read_config(self.provider, [ifc, bgp_neighbor_filter]) self.assertIsNotNone(read_list) self.assertEqual(isinstance(read_list, list), True) self.assertEqual(len(read_list), 2) # Read single container ifc_filter = openconfig_interfaces.Interfaces() lo10 = openconfig_interfaces.Interfaces.Interface() lo10.name = 'Loopback10' lo10.config = YFilter.read lo10.ignore_validation = True ifc_filter.interface.append(lo10) ifc_read = self.crud.read(self.provider, lo10) expected = '''<interface> <name>Loopback10</name> <config> <name>Loopback10</name> <description>Test</description> </config> </interface> ''' self.assertEqual( entity_to_string(ifc_read, self.schema), expected) # Read single leaf ifcs = openconfig_interfaces.Interfaces() lo10 = openconfig_interfaces.Interfaces.Interface() lo10.name = 'Loopback10' lo10.config.description = YFilter.read ifcs.interface.append(lo10) ifcs.ignore_validation = True read_descr = self.crud.read(self.provider, lo10) expected = '''<interface> <name>Loopback10</name> <config> <description>Test</description> </config> </interface> ''' self.assertEqual( entity_to_string(read_descr, self.schema), expected) # Delete configuration ifc = openconfig_interfaces.Interfaces.Interface() ifc.name = 'Loopback10' bgp = openconfig_bgp.Bgp() res = self.crud.delete(self.provider, [ifc, bgp])