Example #1
0
    def test_get_devices_info_vlan(self):
        interfaces_tested = []
        vlan_interfaces = []
        vlan_id = 1000
        for interface in self.interfaces:
            priv_ip_lib.create_interface(interface, self.namespace, 'dummy')
            vlan_interface = interface + '_' + str(vlan_id)
            vlan_interfaces.append(vlan_interface)
            priv_ip_lib.create_interface(vlan_interface,
                                         self.namespace,
                                         'vlan',
                                         physical_interface=interface,
                                         vlan_id=vlan_id)
            vlan_id += 1

        devices = priv_ip_lib.get_link_devices(self.namespace)
        self.assertGreater(len(devices), 0)
        for device in devices:
            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
            if name in self.interfaces_to_exclude:
                continue
            self.assertIn(name, self.interfaces + vlan_interfaces)
            ifla_linkinfo = ip_lib.get_attr(device, 'IFLA_LINKINFO')
            if name in vlan_interfaces:
                self.assertEqual(
                    ip_lib.get_attr(ifla_linkinfo, 'IFLA_INFO_KIND'), 'vlan')
                ifla_infodata = ip_lib.get_attr(ifla_linkinfo,
                                                'IFLA_INFO_DATA')
                vlan_id = int(name.split('_')[-1])
                self.assertEqual(
                    ip_lib.get_attr(ifla_infodata, 'IFLA_VLAN_ID'), vlan_id)
            interfaces_tested.append(name)
        self.assertEqual(sorted(interfaces_tested),
                         sorted(self.interfaces + vlan_interfaces))
 def test_get_devices_info_lo(self):
     devices = priv_ip_lib.get_link_devices(self.namespace)
     self.assertGreater(len(devices), 0)
     for device in devices:
         if ip_lib.get_attr(device, 'IFLA_IFNAME') != 'lo':
             continue
         self.assertIsNone(ip_lib.get_attr(device, 'IFLA_LINKINFO'))
         break
     else:
         self.fail('Device "lo" not found')
 def setUp(self):
     super(GetLinkAttributesTestCase, self).setUp()
     self.namespace = self.useFixture(net_helpers.NamespaceFixture()).name
     self.device_name = 'test_device'
     ip_lib.IPWrapper(self.namespace).add_dummy(self.device_name)
     self.device = ip_lib.IPDevice(self.device_name, self.namespace)
     self.pyroute_dev = priv_ip_lib.get_link_devices(
         self.namespace, ifname=self.device_name)
     self.assertEqual(1, len(self.pyroute_dev))
     self.pyroute_dev = self.pyroute_dev[0]
    def test_get_devices_info_vxlan(self):
        interfaces_tested = []
        vxlan_interfaces = []
        vxlan_id = 1000
        for interface in self.interfaces:
            priv_ip_lib.create_interface(interface, self.namespace, 'dummy')
            vxlan_interface = interface + '_' + str(vxlan_id)
            vxlan_interfaces.append(vxlan_interface)
            priv_ip_lib.create_interface(vxlan_interface,
                                         self.namespace,
                                         'vxlan',
                                         physical_interface=interface,
                                         vxlan_id=vxlan_id,
                                         vxlan_group='239.1.1.1')
            vxlan_id += 1

        devices = priv_ip_lib.get_link_devices(self.namespace)
        self.assertGreater(len(devices), 0)
        device_name_index = {}
        for device in devices:
            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
            device_name_index[name] = device['index']

        for device in devices:
            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
            if name in self.interfaces_to_exclude:
                continue
            self.assertIn(name, self.interfaces + vxlan_interfaces)
            ifla_linkinfo = ip_lib.get_attr(device, 'IFLA_LINKINFO')
            if name in vxlan_interfaces:
                self.assertEqual(
                    ip_lib.get_attr(ifla_linkinfo, 'IFLA_INFO_KIND'), 'vxlan')
                ifla_infodata = ip_lib.get_attr(ifla_linkinfo,
                                                'IFLA_INFO_DATA')
                vxlan_id = int(name.split('_')[-1])
                self.assertEqual(
                    ip_lib.get_attr(ifla_infodata, 'IFLA_VXLAN_ID'), vxlan_id)
                self.assertEqual(
                    ip_lib.get_attr(ifla_infodata, 'IFLA_VXLAN_GROUP'),
                    '239.1.1.1')
                vxlan_link_name = self.interfaces[vxlan_interfaces.index(name)]
                vxlan_link_index = device_name_index[vxlan_link_name]
                self.assertEqual(
                    vxlan_link_index,
                    ip_lib.get_attr(ifla_infodata, 'IFLA_VXLAN_LINK'))
            interfaces_tested.append(name)
        self.assertEqual(sorted(interfaces_tested),
                         sorted(self.interfaces + vxlan_interfaces))
    def test_get_devices_info_dummy(self):
        interfaces_tested = []
        for interface in self.interfaces:
            priv_ip_lib.create_interface(interface, self.namespace, 'dummy')

        devices = priv_ip_lib.get_link_devices(self.namespace)
        self.assertGreater(len(devices), 0)
        for device in devices:
            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
            if name in self.interfaces_to_exclude:
                continue
            self.assertIn(name, self.interfaces)
            ifla_linkinfo = ip_lib.get_attr(device, 'IFLA_LINKINFO')
            self.assertEqual(ip_lib.get_attr(ifla_linkinfo, 'IFLA_INFO_KIND'),
                             'dummy')
            interfaces_tested.append(name)
        self.assertEqual(sorted(interfaces_tested), sorted(self.interfaces))
Example #6
0
    def test_get_devices_info_veth_same_namespaces(self):
        ip_wrapper = ip_lib.IPWrapper(self.namespace)
        ip_wrapper.add_veth('veth1_1', 'veth1_2')

        devices = priv_ip_lib.get_link_devices(self.namespace)
        veth1_1 = veth1_2 = None
        for device in devices:
            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
            if name == 'veth1_1':
                veth1_1 = device
            elif name == 'veth1_2':
                veth1_2 = device

        self.assertIsNotNone(veth1_1)
        self.assertIsNotNone(veth1_2)
        veth1_1_link = ip_lib.get_attr(veth1_1, 'IFLA_LINK')
        veth1_2_link = ip_lib.get_attr(veth1_2, 'IFLA_LINK')
        self.assertEqual(veth1_1['index'], veth1_2_link)
        self.assertEqual(veth1_2['index'], veth1_1_link)
Example #7
0
    def test_get_devices_info_veth_different_namespaces(self):
        namespace2 = 'ns_test-' + uuidutils.generate_uuid()
        priv_ip_lib.create_netns(namespace2)
        self.addCleanup(self._remove_ns, namespace2)
        ip_wrapper = ip_lib.IPWrapper(self.namespace)
        ip_wrapper.add_veth('veth1_1', 'veth1_2', namespace2)

        devices = priv_ip_lib.get_link_devices(self.namespace)
        for device in devices:
            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
            if name == 'veth1_1':
                veth1_1 = device
                break
        else:
            self.fail('Interface "veth1_1" not found')

        ifla_linkinfo = ip_lib.get_attr(veth1_1, 'IFLA_LINKINFO')
        self.assertEqual(ip_lib.get_attr(ifla_linkinfo, 'IFLA_INFO_KIND'),
                         'veth')
        self.assertIsNone(ip_lib.get_attr(veth1_1, 'IFLA_LINK'))
 def _retrieve_interface(self, interface_name, namespace):
     for device in priv_ip_lib.get_link_devices(namespace):
         if interface_name == ip_lib.get_attr(device, 'IFLA_IFNAME'):
             return device
     else:
         self.fail('Interface "%s" not found' % interface_name)