From a1a121fbf8f982d87efdb2417524603063e38968 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 16 Jan 2020 16:35:58 -0500 Subject: [PATCH] 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 --- ironic_python_agent/numa_inspector.py | 3 ++- .../tests/unit/test_numa_inspector.py | 12 ++++++------ .../fix-nic-without-numa-node-b401f97c46afa4a1.yaml | 6 ++++++ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/fix-nic-without-numa-node-b401f97c46afa4a1.yaml 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.