Exemplo n.º 1
0
    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 subscribe(args):
    func = args[0]
    device = args[1]
    mode = args[2]

    gnmi = gNMIService()
    repository = Repository(get_local_repo_dir())
    provider = gNMIServiceProvider(repo=repository,
                                   address=device.hostname,
                                   port=device.port,
                                   username=device.username,
                                   password=device.password)

    build_int_config(provider)

    inf = openconfig_interfaces.Interfaces()
    i = openconfig_interfaces.Interfaces.Interface()
    inf.interface.append(i)

    int_subscription = gNMISubscription()
    int_subscription.entity = inf
    int_subscription.subscription_mode = "SAMPLE"
    int_subscription.sample_interval = 20 * 1000000000
    int_subscription.suppress_redundant = False
    int_subscription.heartbeat_interval = 100 * 1000000000

    gnmi.subscribe(provider, int_subscription, 10, mode, 'JSON_IETF', func)
Exemplo n.º 3
0
    def test_iana_if_type_decode(self):
        # Build some configuration
        ifcs_config = openconfig_interfaces.Interfaces()
        ifc_config = openconfig_interfaces.Interfaces.Interface()
        ifc_config.name = "GigabitEthernet0/0/0/2"
        ifc_config.config.name = "GigabitEthernet0/0/0/2"
        ifc_config.config.description = "Test interface"
        ifc_config.config.type = iana_if_type.EthernetCsmacd()
        ifcs_config.interface.append(ifc_config)
        self.assertTrue(self.crud.create(self.ncc, ifc_config))

        # Read interface type only
        ifcs = openconfig_interfaces.Interfaces()
        ifc = openconfig_interfaces.Interfaces.Interface()
        ifc.name = 'GigabitEthernet0/0/0/2'
        ifc.config.type = YFilter.read
        ifcs.interface.append(ifc)
        ifc_read = self.crud.read(self.ncc, ifc)
        self.assertIsNotNone(ifc_read)
        self.assertEqual(ifc_read.config.type, iana_if_type.EthernetCsmacd())
def build_int_config(provider):
    ifc = openconfig_interfaces.Interfaces()
    lo10 = ifc.Interface()
    lo10.name = 'Loopback10'
    lo10.config.name = 'Loopback10'
    lo10.config.description = 'Test'
    ifc.interface.append(lo10)
    ifc.yfilter = YFilter.replace

    gs = gNMIService()
    gs.set(provider, ifc)
Exemplo n.º 5
0
    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])
Exemplo n.º 6
0
    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])
Exemplo n.º 7
0
    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])