Skip nic numa_node discovery if it's not assigned to a numa_node

In some rare case, such as a VM with virtual numa node, nics might
not be in a numa node and this breaks numa-topology discovery.

Change-Id: I52f52119a5f3175b1723fde291eb26d4f86c8223
Story: 2007105
Task: 38151
This commit is contained in:
David Hill 2020-01-16 16:35:58 -05:00 committed by Dmitry Tantsur
parent 1b20dd9b96
commit a1a121fbf8
3 changed files with 14 additions and 7 deletions

View File

@ -193,7 +193,8 @@ def get_nodes_nics_info(nic_device_path):
{'nic_device_path': nic_device_path})
raise errors.IncompatibleNumaFormatError(msg)
for nic_dir in os.listdir(nic_device_path):
if not os.path.isdir(os.path.join(nic_device_path, nic_dir, 'device')):
if not os.path.isfile(os.path.join(nic_device_path,
nic_dir, 'device', 'numa_node')):
continue
try:
with open(os.path.join(nic_device_path, nic_dir, 'device',

View File

@ -303,12 +303,12 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
numa_insp.get_nodes_cores_info,
numa_node_dirs)
@mock.patch.object(os.path, 'isdir', autospec=True)
@mock.patch.object(os.path, 'isfile', autospec=True)
@mock.patch.object(os, 'listdir', autospec=True)
def test_get_nodes_nics_info(self, mock_listdir, mock_isdir):
def test_get_nodes_nics_info(self, mock_listdir, mock_isfile):
nic_dirs = ['enp0s01', 'enp0s02']
mock_listdir.return_value = nic_dirs
mock_isdir.return_value = True
mock_isfile.return_value = True
reads = ['0', '1']
expected_nicsinfo = [{'name': 'enp0s01', 'numa_node': 0},
{'name': 'enp0s02', 'numa_node': 1}]
@ -319,12 +319,12 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
nics = numa_insp.get_nodes_nics_info('/sys/class/net/')
self.assertListEqual(expected_nicsinfo, nics)
@mock.patch.object(os.path, 'isdir', autospec=True)
@mock.patch.object(os.path, 'isfile', autospec=True)
@mock.patch.object(os, 'listdir', autospec=True)
def test_bad_nodes_nics_info(self, mock_listdir, mock_isdir):
def test_bad_nodes_nics_info(self, mock_listdir, mock_isfile):
nic_dirs = ['enp0s01', 'enp0s02']
mock_listdir.return_value = nic_dirs
mock_isdir.return_value = True
mock_isfile.return_value = True
reads = ['0', IOError]
mock_open = mock.mock_open()
with mock.patch('builtins.open', mock_open):

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Skips NIC numa_node discovery if it's not assigned to a numa_node as
in some rare case, such as a VM with virtual NUMA node, NICs might
not be in a NUMA node and this breaks numa-topology discovery.