コード例 #1
0
ファイル: test_cli.py プロジェクト: gkelle/os-net-config
    def test_sriov_vf_with_dpdk_noop_output(self):
        def test_get_vf_devname(device, vfid):
            return device + '_' + str(vfid)

        self.stub_out('os_net_config.utils.get_vf_devname',
                      test_get_vf_devname)
        ivs_yaml = os.path.join(SAMPLE_BASE, 'sriov_pf_ovs_dpdk.yaml')
        ivs_json = os.path.join(SAMPLE_BASE, 'sriov_pf_ovs_dpdk.json')
        stdout_yaml, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_yaml)
        self.assertEqual('', stderr)
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
        sriov_config_yaml = yaml.load(contents)
        os.remove(sriov_config._SRIOV_CONFIG_FILE)
        stdout_json, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_json)
        self.assertEqual('', stderr)
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
        sriov_config_json = yaml.load(contents)
        sanity_devices = [
            'DEVICE=p2p1', 'DEVICE=p2p1_5', 'DEVICE=br-vfs',
            'TYPE=OVSUserBridge', 'DEVICE=dpdk0', 'TYPE=OVSDPDKPort'
        ]
        for dev in sanity_devices:
            self.assertIn(dev, stdout_yaml)
        self.assertEqual(stdout_yaml, stdout_json)
        self.assertItemsEqual(sriov_config_yaml, sriov_config_json)
コード例 #2
0
    def test_dhcp_ovs_bridge_network_apply(self):
        interface = objects.Interface("em1")
        bridge = objects.OvsBridge("br-ctlplane", use_dhcp=True, members=[interface])
        self.provider.add_interface(interface)
        self.provider.add_bridge(bridge)
        self.provider.apply()

        ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name)
        self.assertEqual(_OVS_INTERFACE, ifcfg_data)
        bridge_data = utils.get_file_data(self.temp_bridge_file.name)
        self.assertEqual(_OVS_BRIDGE_DHCP, bridge_data)
        route_data = utils.get_file_data(self.temp_route_file.name)
        self.assertEqual("", route_data)
コード例 #3
0
    def test_network_apply(self):
        route1 = objects.Route("192.168.1.1", default=True)
        route2 = objects.Route("192.168.1.1", "172.19.0.0/24")
        v4_addr = objects.Address("192.168.1.2/24")
        interface = objects.Interface("em1", addresses=[v4_addr], routes=[route1, route2])
        self.provider.add_interface(interface)

        self.provider.apply()

        ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name)
        self.assertEqual(_V4_IFCFG, ifcfg_data)
        route_data = utils.get_file_data(self.temp_route_file.name)
        self.assertEqual(_ROUTES, route_data)
コード例 #4
0
    def test_network_apply(self):
        route1 = objects.Route('192.168.1.1', default=True)
        route2 = objects.Route('192.168.1.1', '172.19.0.0/24')
        v4_addr = objects.Address('192.168.1.2/24')
        interface = objects.Interface('em1',
                                      addresses=[v4_addr],
                                      routes=[route1, route2])
        self.provider.add_interface(interface)

        self.provider.apply()

        ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name)
        self.assertEqual(_V4_IFCFG, ifcfg_data)
        route_data = utils.get_file_data(self.temp_route_file.name)
        self.assertEqual(_ROUTES, route_data)
コード例 #5
0
    def test_dhcp_ovs_bridge_network_apply(self):
        interface = objects.Interface('em1')
        bridge = objects.OvsBridge('br-ctlplane',
                                   use_dhcp=True,
                                   members=[interface])
        self.provider.add_interface(interface)
        self.provider.add_bridge(bridge)
        self.provider.apply()

        ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name)
        self.assertEqual(_OVS_INTERFACE, ifcfg_data)
        bridge_data = utils.get_file_data(self.temp_bridge_file.name)
        self.assertEqual(_OVS_BRIDGE_DHCP, bridge_data)
        route_data = utils.get_file_data(self.temp_route_file.name)
        self.assertEqual("", route_data)
コード例 #6
0
    def test_vlan_apply(self):
        vlan = objects.Vlan('em1', 5)
        self.provider.addVlan(vlan)
        self.provider.apply()

        ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name)
        self.assertEqual(_VLAN_NO_IP, ifcfg_data)
コード例 #7
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
    def test_update_sriov_vf_map_exist_complete(self):
        vf_initial = [{'device_type': 'vf', 'name': 'eth1_2',
                       'device': {'name': 'eth1', 'vfid': 2},
                       'vlan_id': 10, 'qos': 5,
                       'spoofcheck': 'on', 'trust': 'on',
                       'state': 'enable',
                       'macaddr': 'AA:BB:CC:DD:EE:FF',
                       'promisc': 'off',
                       'pci_address': "0000:80:00.1"}]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, vf_initial)

        utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=100, qos=15,
                                  spoofcheck="off", trust="off", state="auto",
                                  macaddr="BB:BB:CC:DD:EE:FF", promisc="on",
                                  pci_address="0000:80:00.1")
        vf_final = [{'device_type': 'vf', 'name': 'eth1_2',
                     'device': {'name': 'eth1', 'vfid': 2},
                     'vlan_id': 100, 'qos': 15,
                     'spoofcheck': 'off', 'trust': 'off',
                     'state': 'auto',
                     'macaddr': 'BB:BB:CC:DD:EE:FF',
                     'promisc': 'on',
                     'pci_address': '0000:80:00.1'}]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        vf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(vf_map))
        self.assertListEqual(vf_final, vf_map)
コード例 #8
0
    def test_update_sriov_pf_map_exist_with_promisc(self):
        def get_numvfs_stub(pf_name):
            return 10

        self.stub_out('os_net_config.sriov_config.get_numvfs', get_numvfs_stub)
        pf_initial = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 10,
            'promisc': 'on'
        }]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
        pf_final = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 10,
            'promisc': 'off'
        }]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        pf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
コード例 #9
0
 def test_update_sriov_vf_map_complete_new(self):
     utils.update_sriov_vf_map('eth1',
                               2,
                               'eth1_2',
                               vlan_id=10,
                               qos=5,
                               spoofcheck="on",
                               trust="on",
                               state="enable",
                               macaddr="AA:BB:CC:DD:EE:FF",
                               promisc="off",
                               pci_address="0000:80:00.1")
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_vf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_vf_map))
     test_sriov_vf_map = [{
         'device_type': 'vf',
         'name': 'eth1_2',
         'device': {
             'name': 'eth1',
             'vfid': 2
         },
         'vlan_id': 10,
         'qos': 5,
         'spoofcheck': 'on',
         'trust': 'on',
         'state': 'enable',
         'macaddr': 'AA:BB:CC:DD:EE:FF',
         'promisc': 'off',
         'pci_address': "0000:80:00.1"
     }]
     self.assertListEqual(test_sriov_vf_map, sriov_vf_map)
コード例 #10
0
    def test_vlan_apply(self):
        vlan = objects.Vlan('em1', 5)
        self.provider.add_vlan(vlan)
        self.provider.apply()

        ifcfg_data = utils.get_file_data(self.temp_ifcfg_file.name)
        self.assertEqual(_VLAN_NO_IP, ifcfg_data)
コード例 #11
0
 def test_update_sriov_pf_map_new(self):
     utils.update_sriov_pf_map('eth1', 10, False)
     contents = utils.get_file_data(utils._SRIOV_PF_CONFIG_FILE)
     sriov_pf_map = yaml.load(contents) if contents else []
     self.assertEqual(1, len(sriov_pf_map))
     test_sriov_pf_map = [{'name': 'eth1', 'numvfs': 10}]
     self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
コード例 #12
0
ファイル: test_utils.py プロジェクト: zeus-iiit/os-net-config
    def test_update_sriov_vf_map_exist_complete(self):
        vf_initial = [{'device_type': 'vf', 'name': 'eth1_2',
                       'device': {'name': 'eth1', 'vfid': 2},
                       'vlan_id': 10, 'qos': 5,
                       'spoofcheck': 'on', 'trust': 'on',
                       'state': 'enable',
                       'macaddr': 'AA:BB:CC:DD:EE:FF',
                       'promisc': 'off',
                       'pci_address': "0000:80:00.1"}]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, vf_initial)

        utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=100, qos=15,
                                  spoofcheck="off", trust="off", state="auto",
                                  macaddr="BB:BB:CC:DD:EE:FF", promisc="on",
                                  pci_address="0000:80:00.1")
        vf_final = [{'device_type': 'vf', 'name': 'eth1_2',
                     'device': {'name': 'eth1', 'vfid': 2},
                     'vlan_id': 100, 'qos': 15,
                     'spoofcheck': 'off', 'trust': 'off',
                     'state': 'auto',
                     'macaddr': 'BB:BB:CC:DD:EE:FF',
                     'promisc': 'on',
                     'pci_address': '0000:80:00.1'}]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        vf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(vf_map))
        self.assertListEqual(vf_final, vf_map)
コード例 #13
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
 def test_update_sriov_pf_map_new_with_promisc(self):
     utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_pf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_pf_map))
     test_sriov_pf_map = [{'device_type': 'pf', 'link_mode': 'legacy',
                           'name': 'eth1', 'numvfs': 10, 'promisc': 'off'}]
     self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
コード例 #14
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
 def test_update_sriov_vf_map_minimal_new(self):
     utils.update_sriov_vf_map('eth1', 2, 'eth1_2')
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_vf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_vf_map))
     test_sriov_vf_map = [{'device_type': 'vf', 'name': 'eth1_2',
                           'device': {"name": "eth1", "vfid": 2}}]
     self.assertListEqual(test_sriov_vf_map, sriov_vf_map)
コード例 #15
0
 def test_dhcp_ovs_bridge_network_apply(self):
     interface = objects.Interface('eth0')
     bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface])
     self.provider.addInterface(interface)
     self.provider.addBridge(bridge)
     self.provider.apply()
     iface_data = utils.get_file_data(self.temp_config_file.name)
     self.assertEqual((_OVS_BRIDGE_DHCP + _OVS_PORT_IFACE), iface_data)
コード例 #16
0
ファイル: test_utils.py プロジェクト: zeus-iiit/os-net-config
 def test_update_sriov_vf_map_minimal_new(self):
     utils.update_sriov_vf_map('eth1', 2, 'eth1_2')
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_vf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_vf_map))
     test_sriov_vf_map = [{'device_type': 'vf', 'name': 'eth1_2',
                           'device': {"name": "eth1", "vfid": 2}}]
     self.assertListEqual(test_sriov_vf_map, sriov_vf_map)
コード例 #17
0
 def test_dhcp_ovs_bridge_network_apply(self):
     interface = objects.Interface('eth0')
     bridge = objects.OvsBridge('br0', use_dhcp=True,
                                members=[interface])
     self.provider.addInterface(interface)
     self.provider.addBridge(bridge)
     self.provider.apply()
     iface_data = utils.get_file_data(self.temp_config_file.name)
     self.assertEqual((_OVS_BRIDGE_DHCP + _OVS_PORT_IFACE), iface_data)
コード例 #18
0
    def test_network_apply(self):
        route = objects.Route('192.168.1.1', '172.19.0.0/24')
        v4_addr = objects.Address('192.168.1.2/24')
        interface = objects.Interface('eth0', addresses=[v4_addr],
                                      routes=[route])
        self.provider.addInterface(interface)

        self.provider.apply()
        iface_data = utils.get_file_data(self.temp_config_file.name)
        self.assertEqual((_V4_IFACE_STATIC_IP + _RTS), iface_data)
コード例 #19
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
    def test__update_dpdk_map_new(self):
        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)

        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        self.assertListEqual(dpdk_test, dpdk_map)
コード例 #20
0
    def test_network_apply(self):
        route = objects.Route('192.168.1.1', '172.19.0.0/24')
        v4_addr = objects.Address('192.168.1.2/24')
        interface = objects.Interface('eth0',
                                      addresses=[v4_addr],
                                      routes=[route])
        self.provider.addInterface(interface)

        self.provider.apply()
        iface_data = utils.get_file_data(self.temp_config_file.name)
        self.assertEqual((_V4_IFACE_STATIC_IP + _RTS), iface_data)
コード例 #21
0
ファイル: test_utils.py プロジェクト: gfidente/os-net-config
    def test__update_dpdk_map_new(self):
        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)

        dpdk_map = yaml.load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        self.assertListEqual(dpdk_test, dpdk_map)
コード例 #22
0
    def test_update_sriov_pf_map_exist(self):
        pf_initial = [{'name': 'eth1', 'numvfs': 10}]
        utils.write_yaml_config(utils._SRIOV_PF_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 20, False)
        pf_final = [{'name': 'eth1', 'numvfs': 20}]
        contents = utils.get_file_data(utils._SRIOV_PF_CONFIG_FILE)

        pf_map = yaml.load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
コード例 #23
0
ファイル: test_cli.py プロジェクト: openstack/os-net-config
    def test_sriov_noop_output(self):
        def test_get_vf_devname(device, vfid):
            return device + '_' + str(vfid)

        def test_get_pci_address(ifname, noop):
            return '0000:79:10.2'

        def test_interface_mac(name):
            return 'AA:BB:CC:DD:EE:FF'

        self.stub_out('os_net_config.utils.get_vf_devname',
                      test_get_vf_devname)
        self.stub_out('os_net_config.utils.get_pci_address',
                      test_get_pci_address)
        self.stub_out('os_net_config.utils.interface_mac',
                      test_interface_mac)
        ivs_yaml = os.path.join(SAMPLE_BASE, 'sriov_pf.yaml')
        ivs_json = os.path.join(SAMPLE_BASE, 'sriov_pf.json')
        stdout_yaml, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_yaml)
        self.assertEqual('', stderr)
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
        sriov_config_yaml = yaml.safe_load(contents)
        os.remove(sriov_config._SRIOV_CONFIG_FILE)
        stdout_json, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_json)
        self.assertEqual('', stderr)
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
        sriov_config_json = yaml.safe_load(contents)
        sanity_devices = ['DEVICE=p2p1',
                          'DEVICE=p2p1_5',
                          'DEVICE=p2p1_1',
                          'DEVICE=br-vfs',
                          'DEVICE=br-bond',
                          'TYPE=OVSBridge']
        for dev in sanity_devices:
            self.assertIn(dev, stdout_yaml)
        self.assertEqual(stdout_yaml, stdout_json)
        self.assertItemsEqual(sriov_config_yaml, sriov_config_json)
コード例 #24
0
 def test_update_sriov_pf_map_new(self):
     utils.update_sriov_pf_map('eth1', 10, False)
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_pf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_pf_map))
     test_sriov_pf_map = [{
         'device_type': 'pf',
         'link_mode': 'legacy',
         'name': 'eth1',
         'numvfs': 10
     }]
     self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
コード例 #25
0
ファイル: test_utils.py プロジェクト: mk1234567/os-net-config
 def test_update_sriov_pf_map_new_with_promisc(self):
     utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_pf_map = yaml.load(contents) if contents else []
     self.assertEqual(1, len(sriov_pf_map))
     test_sriov_pf_map = [{
         'device_type': 'pf',
         'name': 'eth1',
         'numvfs': 10,
         'promisc': 'off'
     }]
     self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
コード例 #26
0
ファイル: test_utils.py プロジェクト: zeus-iiit/os-net-config
 def test_update_sriov_pf_map_new_with_promisc(self):
     def get_numvfs_stub(pf_name):
         return 0
     self.stub_out('os_net_config.sriov_config.get_numvfs',
                   get_numvfs_stub)
     utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_pf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_pf_map))
     test_sriov_pf_map = [{'device_type': 'pf', 'link_mode': 'legacy',
                           'name': 'eth1', 'numvfs': 10, 'promisc': 'off'}]
     self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
コード例 #27
0
    def test_update_vpp_mapping(self):
        tmpdir = tempfile.mkdtemp()
        vpp_exec_path = os.path.join(tmpdir, 'vpp-exec')
        utils._VPP_EXEC_FILE = vpp_exec_path

        def test_get_dpdk_map():
            return [{
                'name': 'eth1',
                'pci_address': '0000:00:09.0',
                'mac_address': '01:02:03:04:05:06',
                'driver': 'vfio-pci'
            }]

        self.stub_out('os_net_config.utils._get_dpdk_map', test_get_dpdk_map)

        def test_execute(name, *args, **kwargs):
            return None, None

        self.stub_out('oslo_concurrency.processutils.execute', test_execute)

        def test_get_vpp_interface(pci_dev, tries, timeout):
            return {'name': 'GigabitEthernet0/9/0', 'index': '1'}

        self.stub_out('os_net_config.utils._get_vpp_interface',
                      test_get_vpp_interface)

        int1 = objects.VppInterface('eth1', options="vlan-strip-offload off")
        int1.pci_dev = '0000:00:09.0'
        int1.hwaddr = '01:02:03:04:05:06'
        int2 = objects.VppInterface('eth2')
        int2.pci_dev = '0000:00:09.1'
        int2.hwaddr = '01:02:03:04:05:07'
        interfaces = [int1, int2]

        utils.update_vpp_mapping(interfaces, [])

        contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)

        dpdk_test = [{
            'name': 'eth1',
            'pci_address': '0000:00:09.0',
            'mac_address': '01:02:03:04:05:06',
            'driver': 'vfio-pci'
        }, {
            'name': 'eth2',
            'pci_address': '0000:00:09.1',
            'mac_address': '01:02:03:04:05:07',
            'driver': 'vfio-pci'
        }]
        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(2, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
コード例 #28
0
    def test_apply_noactivate(self):
        route1 = objects.Route('192.168.1.1', '172.19.0.0/24')
        route2 = objects.Route('192.168.1.5', '172.20.0.0/24',
                               route_options="metric 100")
        v4_addr = objects.Address('192.168.1.2/24')
        interface = objects.Interface('eth0', addresses=[v4_addr],
                                      routes=[route1, route2])
        self.provider.add_interface(interface)

        self.provider.apply(activate=False)
        iface_data = utils.get_file_data(self.temp_config_file.name)
        self.assertEqual((_V4_IFACE_STATIC_IP + _RTS), iface_data)
        self.assertEqual([], self.ifup_interface_names)
コード例 #29
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
    def test_update_sriov_pf_map_exist_with_promisc(self):
        pf_initial = [{'device_type': 'pf', 'link_mode': 'legacy',
                       'name': 'eth1', 'numvfs': 10, 'promisc': 'on'}]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 20, False)
        pf_final = [{'device_type': 'pf', 'link_mode': 'legacy',
                     'name': 'eth1', 'numvfs': 20, 'promisc': 'on'}]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        pf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
コード例 #30
0
ファイル: test_cli.py プロジェクト: zeus-iiit/os-net-config
    def test_sriov_noop_output(self):
        def test_get_vf_devname(device, vfid):
            return device + '_' + str(vfid)

        def test_get_pci_address(ifname, noop):
            return '0000:79:10.2'

        def test_interface_mac(name):
            return 'AA:BB:CC:DD:EE:FF'

        self.stub_out('os_net_config.utils.get_vf_devname',
                      test_get_vf_devname)
        self.stub_out('os_net_config.utils.get_pci_address',
                      test_get_pci_address)
        self.stub_out('os_net_config.utils.interface_mac', test_interface_mac)
        ivs_yaml = os.path.join(SAMPLE_BASE, 'sriov_pf.yaml')
        ivs_json = os.path.join(SAMPLE_BASE, 'sriov_pf.json')
        stdout_yaml, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_yaml)
        self.assertEqual('', stderr)
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
        sriov_config_yaml = yaml.safe_load(contents)
        os.remove(sriov_config._SRIOV_CONFIG_FILE)
        stdout_json, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_json)
        self.assertEqual('', stderr)
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
        sriov_config_json = yaml.safe_load(contents)
        sanity_devices = [
            'DEVICE=p2p1', 'DEVICE=p2p1_5', 'DEVICE=p2p1_1', 'DEVICE=br-vfs',
            'DEVICE=br-bond', 'TYPE=OVSBridge'
        ]
        for dev in sanity_devices:
            self.assertIn(dev, stdout_yaml)
        self.assertEqual(stdout_yaml, stdout_json)
        self.assertItemsEqual(sriov_config_yaml, sriov_config_json)
コード例 #31
0
    def test_update_vpp_mapping(self):
        def test_get_dpdk_map():
            return [{
                'name': 'eth1',
                'pci_address': '0000:00:09.0',
                'mac_address': '01:02:03:04:05:06',
                'driver': 'vfio-pci'
            }]

        self.stubs.Set(utils, '_get_dpdk_map', test_get_dpdk_map)

        def test_execute(name, dummy1, dummy2=None, dummy3=None):
            return None, None

        self.stubs.Set(processutils, 'execute', test_execute)

        def test_get_vpp_interface_name(pci_dev, tries, timeout):
            return 'GigabitEthernet0/9/0'

        self.stubs.Set(utils, '_get_vpp_interface_name',
                       test_get_vpp_interface_name)

        int1 = objects.VppInterface('eth1', options="vlan-strip-offload off")
        int1.pci_dev = '0000:00:09.0'
        int1.hwaddr = '01:02:03:04:05:06'
        int2 = objects.VppInterface('eth2')
        int2.pci_dev = '0000:00:09.1'
        int2.hwaddr = '01:02:03:04:05:07'
        interfaces = [int1, int2]

        utils.update_vpp_mapping(interfaces)

        contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)

        dpdk_test = [{
            'name': 'eth1',
            'pci_address': '0000:00:09.0',
            'mac_address': '01:02:03:04:05:06',
            'driver': 'vfio-pci'
        }, {
            'name': 'eth2',
            'pci_address': '0000:00:09.1',
            'mac_address': '01:02:03:04:05:07',
            'driver': 'vfio-pci'
        }]
        dpdk_map = yaml.load(contents) if contents else []
        self.assertEqual(2, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
コード例 #32
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
 def test_update_sriov_vf_map_complete_new(self):
     utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=10, qos=5,
                               spoofcheck="on", trust="on", state="enable",
                               macaddr="AA:BB:CC:DD:EE:FF", promisc="off",
                               pci_address="0000:80:00.1")
     contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
     sriov_vf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_vf_map))
     test_sriov_vf_map = [{'device_type': 'vf', 'name': 'eth1_2',
                           'device': {'name': 'eth1', 'vfid': 2},
                           'vlan_id': 10, 'qos': 5,
                           'spoofcheck': 'on', 'trust': 'on',
                           'state': 'enable',
                           'macaddr': 'AA:BB:CC:DD:EE:FF',
                           'promisc': 'off',
                           'pci_address': "0000:80:00.1"}]
     self.assertListEqual(test_sriov_vf_map, sriov_vf_map)
コード例 #33
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
    def test_update_dpdk_map_value_change(self):
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'driver': 'vfio-pci'}]
        utils.write_yaml_config(utils._DPDK_MAPPING_FILE, dpdk_test)

        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        try:
            contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)
        except IOError:
            pass

        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
コード例 #34
0
ファイル: test_utils.py プロジェクト: gfidente/os-net-config
    def test_update_dpdk_map_value_change(self):
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'driver': 'vfio-pci'}]
        utils.write_yaml_config(utils._DPDK_MAPPING_FILE, dpdk_test)

        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        try:
            contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)
        except IOError:
            pass

        dpdk_map = yaml.load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
コード例 #35
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
    def test_update_vpp_mapping(self):
        tmpdir = tempfile.mkdtemp()
        vpp_exec_path = os.path.join(tmpdir, 'vpp-exec')
        utils._VPP_EXEC_FILE = vpp_exec_path

        def test_get_dpdk_map():
            return [{'name': 'eth1', 'pci_address': '0000:00:09.0',
                     'mac_address': '01:02:03:04:05:06',
                     'driver': 'vfio-pci'}]

        self.stub_out('os_net_config.utils._get_dpdk_map', test_get_dpdk_map)

        def test_execute(name, *args, **kwargs):
            return None, None
        self.stub_out('oslo_concurrency.processutils.execute', test_execute)

        def test_get_vpp_interface(pci_dev, tries, timeout):
            return {'name': 'GigabitEthernet0/9/0', 'index': '1'}

        self.stub_out('os_net_config.utils._get_vpp_interface',
                      test_get_vpp_interface)

        int1 = objects.VppInterface('eth1', options="vlan-strip-offload off")
        int1.pci_dev = '0000:00:09.0'
        int1.hwaddr = '01:02:03:04:05:06'
        int2 = objects.VppInterface('eth2')
        int2.pci_dev = '0000:00:09.1'
        int2.hwaddr = '01:02:03:04:05:07'
        interfaces = [int1, int2]

        utils.update_vpp_mapping(interfaces, [])

        contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)

        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:00:09.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'},
                     {'name': 'eth2', 'pci_address': '0000:00:09.1',
                      'mac_address': '01:02:03:04:05:07',
                      'driver': 'vfio-pci'}]
        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(2, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
コード例 #36
0
ファイル: test_utils.py プロジェクト: mk1234567/os-net-config
    def test_update_sriov_vf_map_exist(self):
        vf_initial = [{
            'device_type': 'vf',
            'name': 'eth1_2',
            'device': {
                "name": "eth1",
                "vfid": 2
            }
        }]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, vf_initial)

        utils.update_sriov_vf_map('eth1',
                                  2,
                                  'eth1_2',
                                  vlan_id=10,
                                  qos=5,
                                  spoofcheck="on",
                                  trust="on",
                                  state="enable",
                                  macaddr="AA:BB:CC:DD:EE:FF",
                                  promisc="off")
        vf_final = [{
            'device_type': 'vf',
            'name': 'eth1_2',
            'device': {
                'name': 'eth1',
                'vfid': 2
            },
            'vlan_id': 10,
            'qos': 5,
            'spoofcheck': 'on',
            'trust': 'on',
            'state': 'enable',
            'macaddr': 'AA:BB:CC:DD:EE:FF',
            'promisc': 'off'
        }]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        vf_map = yaml.load(contents) if contents else []
        self.assertEqual(1, len(vf_map))
        self.assertListEqual(vf_final, vf_map)
コード例 #37
0
    def test_update_sriov_pf_map_exist(self):
        pf_initial = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 10
        }]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 20, False)
        pf_final = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 20
        }]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        pf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)