diff options
-rw-r--r-- | os_net_config/cli.py | 2 | ||||
-rw-r--r-- | os_net_config/impl_eni.py | 4 | ||||
-rw-r--r-- | os_net_config/impl_ifcfg.py | 33 | ||||
-rw-r--r-- | os_net_config/tests/test_objects.py | 4 | ||||
-rw-r--r-- | os_net_config/tests/test_utils.py | 24 | ||||
-rw-r--r-- | os_net_config/utils.py | 11 |
6 files changed, 57 insertions, 21 deletions
diff --git a/os_net_config/cli.py b/os_net_config/cli.py index c0ac5c4..479b3a3 100644 --- a/os_net_config/cli.py +++ b/os_net_config/cli.py @@ -186,7 +186,7 @@ def main(argv=sys.argv): files_changed = provider.apply(cleanup=opts.cleanup, activate=not opts.no_activate) if opts.noop: - for location, data in files_changed.iteritems(): + for location, data in files_changed.items(): print("File: %s\n" % location) print(data) print("----") diff --git a/os_net_config/impl_eni.py b/os_net_config/impl_eni.py index c6252ce..360d8c8 100644 --- a/os_net_config/impl_eni.py +++ b/os_net_config/impl_eni.py @@ -215,12 +215,12 @@ class ENINetConfig(os_net_config.NetConfig): # write out bridges first. This ensures that an ifup -a # on reboot brings them up first - for bridge_name, bridge_data in self.bridges.iteritems(): + for bridge_name, bridge_data in self.bridges.items(): route_data = self.routes.get(bridge_name) bridge_data += (route_data or '') new_config += bridge_data - for interface_name, iface_data in self.interfaces.iteritems(): + for interface_name, iface_data in self.interfaces.items(): route_data = self.routes.get(interface_name) iface_data += (route_data or '') new_config += iface_data diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index bcfc4dc..6d3c681 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -286,15 +286,18 @@ class IfcfgNetConfig(os_net_config.NetConfig): data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name elif isinstance(base_opt, objects.OvsDpdkBond): ovs_extra.extend(base_opt.ovs_extra) - if base_opt.primary_interface_name: - primary_name = base_opt.primary_interface_name - self.bond_primary_ifaces[base_opt.name] = primary_name + # Referring to bug:1643026, the below commenting of the interfaces, + # is to workaround the error, but is not the long term solution. + # The long term solution is to run DPDK options before + # os-net-config, which is being tracked at BUG:1654975 + # if base_opt.primary_interface_name: + # primary_name = base_opt.primary_interface_name + # self.bond_primary_ifaces[base_opt.name] = primary_name data += "DEVICETYPE=ovs\n" data += "TYPE=OVSDPDKBond\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name if base_opt.members: members = [member.name for member in base_opt.members] - self.member_names[base_opt.name] = members data += ("BOND_IFACES=\"%s\"\n" % " ".join(members)) if base_opt.ovs_options: data += "OVS_OPTIONS=\"%s\"\n" % base_opt.ovs_options @@ -681,7 +684,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): nfvswitch_internal_ifaces = [] # nfvswitch internal/management ports stop_dhclient_interfaces = [] - for interface_name, iface_data in self.interface_data.iteritems(): + for interface_name, iface_data in self.interface_data.items(): route_data = self.route_data.get(interface_name, '') route6_data = self.route6_data.get(interface_name, '') interface_path = self.root_dir + ifcfg_config_path(interface_name) @@ -709,7 +712,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): logger.info('No changes required for interface: %s' % interface_name) - for interface_name, iface_data in self.ivsinterface_data.iteritems(): + for interface_name, iface_data in self.ivsinterface_data.items(): route_data = self.route_data.get(interface_name, '') route6_data = self.route6_data.get(interface_name, '') interface_path = self.root_dir + ifcfg_config_path(interface_name) @@ -730,7 +733,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): logger.info('No changes required for ivs interface: %s' % interface_name) - for iface_name, iface_data in self.nfvswitch_intiface_data.iteritems(): + for iface_name, iface_data in self.nfvswitch_intiface_data.items(): route_data = self.route_data.get(iface_name, '') route6_data = self.route6_data.get(iface_name, '') iface_path = self.root_dir + ifcfg_config_path(iface_name) @@ -751,7 +754,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): logger.info('No changes required for nfvswitch interface: %s' % iface_name) - for vlan_name, vlan_data in self.vlan_data.iteritems(): + for vlan_name, vlan_data in self.vlan_data.items(): route_data = self.route_data.get(vlan_name, '') route6_data = self.route6_data.get(vlan_name, '') vlan_path = self.root_dir + ifcfg_config_path(vlan_name) @@ -771,7 +774,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): logger.info('No changes required for vlan interface: %s' % vlan_name) - for bridge_name, bridge_data in self.bridge_data.iteritems(): + for bridge_name, bridge_data in self.bridge_data.items(): route_data = self.route_data.get(bridge_name, '') route6_data = self.route6_data.get(bridge_name, '') bridge_path = self.root_dir + bridge_config_path(bridge_name) @@ -795,7 +798,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): else: logger.info('No changes required for bridge: %s' % bridge_name) - for bridge_name, bridge_data in self.linuxbridge_data.iteritems(): + for bridge_name, bridge_data in self.linuxbridge_data.items(): route_data = self.route_data.get(bridge_name, '') route6_data = self.route6_data.get(bridge_name, '') bridge_path = self.root_dir + bridge_config_path(bridge_name) @@ -815,7 +818,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): else: logger.info('No changes required for bridge: %s' % bridge_name) - for team_name, team_data in self.linuxteam_data.iteritems(): + for team_name, team_data in self.linuxteam_data.items(): route_data = self.route_data.get(team_name, '') route6_data = self.route6_data.get(team_name, '') team_path = self.root_dir + bridge_config_path(team_name) @@ -836,7 +839,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): logger.info('No changes required for linux team: %s' % team_name) - for bond_name, bond_data in self.linuxbond_data.iteritems(): + for bond_name, bond_data in self.linuxbond_data.items(): route_data = self.route_data.get(bond_name, '') route6_data = self.route6_data.get(bond_name, '') bond_path = self.root_dir + bridge_config_path(bond_name) @@ -858,7 +861,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): bond_name) # Infiniband interfaces are handled similarly to Ethernet interfaces - for interface_name, iface_data in self.ib_interface_data.iteritems(): + for interface_name, iface_data in self.ib_interface_data.items(): route_data = self.route_data.get(interface_name, '') route6_data = self.route6_data.get(interface_name, '') interface_path = self.root_dir + ifcfg_config_path(interface_name) @@ -909,10 +912,10 @@ class IfcfgNetConfig(os_net_config.NetConfig): for bridge in restart_bridges: self.ifdown(bridge, iftype='bridge') - for oldname, newname in self.renamed_interfaces.iteritems(): + for oldname, newname in self.renamed_interfaces.items(): self.ifrename(oldname, newname) - for location, data in update_files.iteritems(): + for location, data in update_files.items(): self.write_config(location, data) if ivs_uplinks or ivs_interfaces: diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py index 200d7b7..0ff653c 100644 --- a/os_net_config/tests/test_objects.py +++ b/os_net_config/tests/test_objects.py @@ -456,7 +456,7 @@ class TestIvsInterface(base.TestCase): objects.IvsBridge.from_json, json.loads(data)) expected = 'IVS does not support bond interfaces.' - self.assertIn(expected, err) + self.assertIn(expected, six.text_type(err)) class TestNfvswitchBridge(base.TestCase): @@ -521,7 +521,7 @@ class TestNfvswitchInterface(base.TestCase): objects.NfvswitchBridge.from_json, json.loads(data)) expected = 'NFVSwitch does not support bond interfaces.' - self.assertIn(expected, err) + self.assertIn(expected, six.text_type(err)) class TestBond(base.TestCase): diff --git a/os_net_config/tests/test_utils.py b/os_net_config/tests/test_utils.py index b766384..1885cbb 100644 --- a/os_net_config/tests/test_utils.py +++ b/os_net_config/tests/test_utils.py @@ -217,3 +217,27 @@ class TestUtils(base.TestCase): def test_interface_mac_raises(self): self.assertRaises(IOError, utils.interface_mac, 'ens20f2p3') + + def test_is_active_nic_for_sriov_vf(self): + + tmpdir = tempfile.mkdtemp() + self.stubs.Set(utils, '_SYS_CLASS_NET', tmpdir) + + # SR-IOV PF = ens802f0 + # SR-IOV VF = enp129s2 + for nic in ['ens802f0', 'enp129s2']: + nic_path = os.path.join(tmpdir, nic) + os.makedirs(nic_path) + os.makedirs(os.path.join(nic_path, 'device')) + with open(os.path.join(nic_path, 'operstate'), 'w') as f: + f.write('up') + with open(os.path.join(nic_path, 'address'), 'w') as f: + f.write('1.2.3.4') + + nic_path = os.path.join(tmpdir, 'enp129s2', 'device', 'physfn') + os.makedirs(nic_path) + + self.assertEqual(utils._is_active_nic('ens802f0'), True) + self.assertEqual(utils._is_active_nic('enp129s2'), False) + + shutil.rmtree(tmpdir) diff --git a/os_net_config/utils.py b/os_net_config/utils.py index af359d5..98bfe99 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -107,7 +107,16 @@ def _is_active_nic(interface_name): with open(_SYS_CLASS_NET + '/%s/address' % interface_name, 'r') as f: address = f.read().rstrip() - if has_device_dir and operstate == 'up' and address: + # If SR-IOV Virtual Functions (VF) are enabled in an interface, there + # will be additional nics created for each VF. It has to be ignored in + # the nic numbering. All the VFs will have a reference to the PF with + # directory name as 'physfn', if this directory is present it should be + # ignored. + vf_path_check = _SYS_CLASS_NET + '/%s/device/physfn' % interface_name + is_sriov_vf = os.path.isdir(vf_path_check) + + if (has_device_dir and operstate == 'up' and address and + not is_sriov_vf): return True else: return False |