Exemplo n.º 1
0
class SanityTest(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        # Need to keep a local reference for repo to keep it alive,
        # as the first argument for OpenDaylightServiceProvider in libydk
        # is a reference.
        repo_path = os.path.dirname(__file__)
        repo_path = os.path.join(repo_path, '..', '..', '..', 'cpp', 'core',
                                 'tests', 'models')
        self.repo = Repository(repo_path)
        self.odl = OpenDaylightServiceProvider(self.repo, 'localhost', 'admin',
                                               'admin', 12306,
                                               EncodingFormat.JSON)
        self.crud = CRUDService()

    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_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)
Exemplo n.º 2
0
class SanityTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        # Need to keep a local reference for repo to keep it alive,
        # as the first argument for OpenDaylightServiceProvider in libydk
        # is a reference.
        repo_path = os.path.dirname(__file__)
        repo_path = os.path.join(repo_path, '..', '..', '..', 'cpp', 'core', 'tests', 'models')
        self.repo = Repository(repo_path)
        self.odl = OpenDaylightServiceProvider(self.repo, 'localhost', 'admin', 'admin', 12306, EncodingFormat.JSON)
        self.crud = CRUDService()

    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_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)
Exemplo n.º 3
0
 def test_crud_get_all_config(self):
     self.logger.setLevel(logging.ERROR)
     crud = CRUDService()
     config = crud.read_config(self.ncc)
     self.assertNotEqual(len(config), 0)
     print("\n==== Retrieved entities:")
     for entity in config:
         print(entity.path())
Exemplo n.º 4
0
class SanityGnmiCrud(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.codec_provider = CodecServiceProvider()
        self.codec = CodecService()
        self.repo = Repository(get_local_repo_dir())
        self.provider = gNMIServiceProvider( self.repo, "127.0.0.1", "admin", "admin", port=50051)
        self.schema = self.provider.get_session().get_root_schema()
        self.crud = CRUDService()

    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])
Exemplo n.º 5
0
                        help="print debugging messages",
                        action="store_true")
    parser.add_argument("device",
                        help="gNMI device (ssh://user:password@host:port)")
    args = parser.parse_args()
    device = urlparse(args.device)

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.DEBUG)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                       "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    repo = Repository("/usr/local/share/ydk/0.0.0.0:50051/")
    # create gNMI provider
    provider = gNMIServiceProvider(repo, address="pavarotti:57400")
    # create CRUD service
    crud = CRUDService()

    bgp = openconfig_bgp.Bgp()  # create object

    # read data from gNMI device
    bgp = crud.read_config(provider, bgp)
    process_bgp(bgp)  # process object data

    exit()
# End of script
Exemplo n.º 6
0
    parser.add_argument("-v", "--verbose", help="print debugging messages",
                        action="store_true")
    parser.add_argument("device",
                        help="gNMI device (ssh://user:password@host:port)")
    args = parser.parse_args()
    device = urlparse(args.device)

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.DEBUG)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                      "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    repo = Repository("/usr/local/share/ydk/0.0.0.0:50051/")
    # create gNMI provider
    provider = gNMIServiceProvider(repo, address="pavarotti:57400")
    # create CRUD service
    crud = CRUDService()

    bgp = openconfig_bgp.Bgp()  # create object

    # read data from gNMI device
    bgp = crud.read_config(provider, bgp)
    process_bgp(bgp)  # process object data

    exit()
# End of script
Exemplo n.º 7
0
class SanityGnmiCrud(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.codec_provider = CodecServiceProvider()
        self.codec = CodecService()
        self.repo = Repository(get_local_repo_dir())
        self.provider = gNMIServiceProvider( self.repo, "127.0.0.1", 50051, "admin", "admin")
        self.schema = self.provider.get_session().get_root_schema()
        self.crud = CRUDService()

    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.º 8
0
    json_provider = CodecServiceProvider(type='json')
    xml_provider = CodecServiceProvider(type='xml')

    # create CRUD service
    crud = CRUDService()

    # create codec service
    codec = CodecService()

    # create object
    interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()
    oc_ifaces = openconfig_interfaces.Interfaces()

    # create NETCONF operation
    try:
        _result = crud.read_config(provider, interface_configurations)
        if _result is not None:
            result_json = codec.encode(json_provider, _result)
            with open("rd_ifmgr_cfg.json", "w") as f:
                f.write(result_json)
            result_xml = codec.encode(xml_provider, _result)
            with open("rd_ifmgr_cfg.xml", "w") as f:
                f.write(result_xml)
    except YServiceProviderError as err:
        print("NETCONF FAILED with Error:")
        print(err.message.split('</error-message>')[0].split('"en">')[1])
    except YModelError as err:
        print("YDK VALIDATION FAILED with YModelError:")
        print(err.message)

    end_time = time.time()