From 3a0c8dabfa7ded08fec8aeebf5f432db1dbdc4e7 Mon Sep 17 00:00:00 2001 From: Saravanan KR Date: Thu, 29 Dec 2016 17:27:42 +0530 Subject: Exclude SR-IOV VFs in the nic numbering SR-IOV Virtual Functions will be present as an interface in the directory '/sys/class/net'. As these are virtual interface created during the deployment process, it has to be ignored in the nic numbering logic. Closes-Bug: #1653097 Change-Id: I118a7314d496b531c52be45521d393123cdfe915 --- os_net_config/tests/test_utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'os_net_config/tests/test_utils.py') 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) -- cgit 1.2.3-korg