aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-01-23 11:02:24 +0000
committerGerrit Code Review <review@openstack.org>2017-01-23 11:02:24 +0000
commitb4ecaa5c344cc33691d91398bfa187e876e6e40d (patch)
treee9aff977101d81b1541156ed92056db49c2b4eae
parentf40b61ed6712f80a76a39cddfb11d02d20d06e2d (diff)
parent3a0c8dabfa7ded08fec8aeebf5f432db1dbdc4e7 (diff)
Merge "Exclude SR-IOV VFs in the nic numbering"
-rw-r--r--os_net_config/tests/test_utils.py24
-rw-r--r--os_net_config/utils.py11
2 files changed, 34 insertions, 1 deletions
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