diff --git a/ironic_python_agent/numa_inspector.py b/ironic_python_agent/numa_inspector.py index 0b8509a11..3f5ef9d84 100644 --- a/ironic_python_agent/numa_inspector.py +++ b/ironic_python_agent/numa_inspector.py @@ -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', diff --git a/ironic_python_agent/tests/unit/test_numa_inspector.py b/ironic_python_agent/tests/unit/test_numa_inspector.py index 1bd8df45c..21dd001c2 100644 --- a/ironic_python_agent/tests/unit/test_numa_inspector.py +++ b/ironic_python_agent/tests/unit/test_numa_inspector.py @@ -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): diff --git a/releasenotes/notes/fix-nic-without-numa-node-b401f97c46afa4a1.yaml b/releasenotes/notes/fix-nic-without-numa-node-b401f97c46afa4a1.yaml new file mode 100644 index 000000000..c9c7012c8 --- /dev/null +++ b/releasenotes/notes/fix-nic-without-numa-node-b401f97c46afa4a1.yaml @@ -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.