From e829d8c551d35efff3756217c564711ec6a83f4b Mon Sep 17 00:00:00 2001 From: Gulsum Atici Date: Mon, 14 Nov 2022 13:06:06 +0300 Subject: [PATCH] Fix Bug 2180 Adding VIO Numa support with unit tests Change-Id: I7a7b18a00b22156c6b8116f07e3a04d8c2dd8a99 Signed-off-by: Gulsum Atici (cherry picked from commit d0571febfae2dea93305bd99d09ff52204c26662) --- .../tests/test_vimconn_openstack.py | 108 +++++++++++++----- .../osm_rovim_openstack/vimconn_openstack.py | 20 +++- ...ing_vio_numa_support-6717ff4c02776dda.yaml | 22 ++++ 3 files changed, 117 insertions(+), 33 deletions(-) create mode 100644 releasenotes/notes/adding_vio_numa_support-6717ff4c02776dda.yaml diff --git a/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py index be60c366..98ecdfb6 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py @@ -5474,6 +5474,7 @@ class TestNewFlavor(unittest.TestCase): for mocking in mocks: mocking.assert_not_called() + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5490,6 +5491,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, id, memory, vcpu exist, vim type is VIO, paired-threads, cores, threads do not exist in numa. @@ -5501,8 +5503,6 @@ class TestNewFlavor(unittest.TestCase): extra_specs = {} expected_extra_specs = { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", "hw:cpu_sockets": "2", } self.vimconn.vim_type = "VIO" @@ -5510,6 +5510,7 @@ class TestNewFlavor(unittest.TestCase): self.assertEqual(mock_process_numa_memory.call_count, 2) self.assertEqual(mock_process_numa_vcpu.call_count, 2) + mock_process_vio_numa_nodes.assert_called_once_with(2, {"hw:numa_nodes": "2"}) _call_mock_process_numa_memory = mock_process_numa_memory.call_args_list self.assertEqual( _call_mock_process_numa_memory[0].args, @@ -5518,8 +5519,6 @@ class TestNewFlavor(unittest.TestCase): 0, { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5531,8 +5530,6 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5544,8 +5541,6 @@ class TestNewFlavor(unittest.TestCase): 0, { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5557,8 +5552,6 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5571,6 +5564,7 @@ class TestNewFlavor(unittest.TestCase): ] ) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5587,6 +5581,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, id, memory, vcpu exist, vim type is openstack, paired-threads, cores, threads do not exist in numa. @@ -5648,6 +5643,7 @@ class TestNewFlavor(unittest.TestCase): ] ) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5664,6 +5660,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, id, paired-threads exist, vim type is openstack. vcpus calculation according to paired-threads in numa, there is extra_spec. @@ -5705,6 +5702,7 @@ class TestNewFlavor(unittest.TestCase): ) self.assertDictEqual(extra_specs, expected_extra_specs) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5721,6 +5719,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, id, paired-threads exist, vim type is VIO. vcpus calculation according to paired-threads in numa, there is extra_spec. @@ -5729,8 +5728,6 @@ class TestNewFlavor(unittest.TestCase): extra_specs = {"some-key": "some-value"} expected_extra_specs = { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", "hw:cpu_sockets": "2", "hw:cpu_threads": "8", "some-key": "some-value", @@ -5747,6 +5744,9 @@ class TestNewFlavor(unittest.TestCase): _call_mock_process_numa_paired_threads = ( mock_process_numa_paired_threads.call_args_list ) + mock_process_vio_numa_nodes.assert_called_once_with( + 2, {"some-key": "some-value", "hw:numa_nodes": "2"} + ) self.assertEqual( _call_mock_process_numa_paired_threads[0].args, ( @@ -5755,8 +5755,6 @@ class TestNewFlavor(unittest.TestCase): "hw:cpu_sockets": "2", "hw:numa_nodes": "2", "some-key": "some-value", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5768,13 +5766,12 @@ class TestNewFlavor(unittest.TestCase): "hw:cpu_sockets": "2", "hw:numa_nodes": "2", "some-key": "some-value", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) self.assertDictEqual(extra_specs, expected_extra_specs) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5791,6 +5788,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, id, cores exist, vim type is openstack. vcpus calculation according to cores in numa. @@ -5824,6 +5822,7 @@ class TestNewFlavor(unittest.TestCase): ) self.assertDictEqual(extra_specs, expected_extra_specs) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5840,6 +5839,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, id, cores exist, vim type is VIO. vcpus calculation according to cores in numa. @@ -5850,8 +5850,6 @@ class TestNewFlavor(unittest.TestCase): "hw:cpu_cores": "3", "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", } self.vimconn.vim_type = "VIO" mock_process_numa_cores.side_effect = [1, 2] @@ -5862,6 +5860,7 @@ class TestNewFlavor(unittest.TestCase): self.assertEqual(mock_process_numa_memory.call_count, 2) self.assertEqual(mock_process_numa_vcpu.call_count, 2) self.assertEqual(mock_process_numa_cores.call_count, 2) + mock_process_vio_numa_nodes.assert_called_once_with(2, {"hw:numa_nodes": "2"}) _call_mock_process_numa_cores = mock_process_numa_cores.call_args_list self.assertEqual( _call_mock_process_numa_cores[0].args, @@ -5870,8 +5869,6 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5882,13 +5879,12 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) self.assertDictEqual(extra_specs, expected_extra_specs) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5905,6 +5901,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, memory, vcpu, thread exist, vim type is VIO, vcpus calculation according threads in numa, there are not numa ids. @@ -5916,8 +5913,6 @@ class TestNewFlavor(unittest.TestCase): extra_specs = {} expected_extra_specs = { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", "hw:cpu_sockets": "2", "hw:cpu_threads": "3", } @@ -5932,6 +5927,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, ] ) + mock_process_vio_numa_nodes.assert_called_once_with(2, {"hw:numa_nodes": "2"}) self.assertEqual(mock_process_numa_threads.call_count, 1) _call_mock_process_numa_threads = mock_process_numa_threads.call_args_list self.assertEqual( @@ -5941,13 +5937,12 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) self.assertDictEqual(extra_specs, expected_extra_specs) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5964,6 +5959,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Process numa parameters, memory, vcpu, thread exist, vim type is openstack, vcpus calculation according threads in numa, there are not numa ids. @@ -5988,6 +5984,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_vcpu, mock_process_numa_cores, mock_process_numa_paired_threads, + mock_process_vio_numa_nodes, ] ) self.assertEqual(mock_process_numa_threads.call_count, 1) @@ -6001,6 +5998,7 @@ class TestNewFlavor(unittest.TestCase): ) self.assertDictEqual(extra_specs, expected_extra_specs) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -6017,15 +6015,12 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Numa list is empty, vim type is VIO.""" numas = [] extra_specs = {} - expected_extra_specs = { - "hw:numa_nodes": "0", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", - } + expected_extra_specs = {"hw:numa_nodes": "0"} self.vimconn.vim_type = "VIO" self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) self.check_if_assert_not_called( @@ -6037,8 +6032,10 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_threads, ] ) + mock_process_vio_numa_nodes.assert_called_once_with(0, {"hw:numa_nodes": "0"}) self.assertDictEqual(extra_specs, expected_extra_specs) + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -6055,6 +6052,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_paired_threads, mock_process_numa_vcpu, mock_process_numa_memory, + mock_process_vio_numa_nodes, ): """Numa list is empty, vim type is openstack.""" numas = [] @@ -6071,6 +6069,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_cores, mock_process_numa_paired_threads, mock_process_numa_threads, + mock_process_vio_numa_nodes, ] ) self.assertDictEqual(extra_specs, expected_extra_specs) @@ -7289,6 +7288,53 @@ class TestNewFlavor(unittest.TestCase): ) self.assertEqual(mock_format_exception.call_count, 1) + def test_process_process_vio_numa_nodes_without_numa_with_extra_spec(self): + numa_nodes = 0 + extra_specs = {"hw:numa_nodes": "0"} + expected_extra_spec = { + "vmware:extra_config": '{"numa.nodeAffinity":"0"}', + "vmware:latency_sensitivity_level": "high", + "hw:numa_nodes": "0", + } + self.vimconn.process_vio_numa_nodes(numa_nodes, extra_specs) + self.assertDictEqual(extra_specs, expected_extra_spec) + + def test_process_process_vio_numa_nodes_list_type_numa_nodes_empty_extra_spec(self): + numa_nodes = [7, 9, 4] + extra_specs = {} + expected_extra_spec = { + "vmware:latency_sensitivity_level": "high", + } + self.vimconn.process_vio_numa_nodes(numa_nodes, extra_specs) + self.assertDictEqual(extra_specs, expected_extra_spec) + + def test_process_process_vio_numa_nodes_with_numa_with_extra_spec(self): + numa_nodes = 5 + extra_specs = {"hw:numa_nodes": "5"} + expected_extra_spec = { + "vmware:latency_sensitivity_level": "high", + "hw:numa_nodes": "5", + } + self.vimconn.process_vio_numa_nodes(numa_nodes, extra_specs) + self.assertDictEqual(extra_specs, expected_extra_spec) + + def test_process_process_vio_numa_nodes_none_numa_nodes(self): + numa_nodes = None + extra_specs = {"hw:numa_nodes": "None"} + expected_extra_spec = { + "vmware:latency_sensitivity_level": "high", + "hw:numa_nodes": "None", + "vmware:extra_config": '{"numa.nodeAffinity":"0"}', + } + self.vimconn.process_vio_numa_nodes(numa_nodes, extra_specs) + self.assertDictEqual(extra_specs, expected_extra_spec) + + def test_process_process_vio_numa_nodes_invalid_type_extra_specs(self): + numa_nodes = 5 + extra_specs = [] + with self.assertRaises(TypeError): + self.vimconn.process_vio_numa_nodes(numa_nodes, extra_specs) + if __name__ == "__main__": unittest.main() diff --git a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py index 8e9d4395..1fa99548 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py @@ -1353,8 +1353,7 @@ class vimconnector(vimconn.VimConnector): cpu_cores, cpu_threads = 0, 0 if self.vim_type == "VIO": - extra_specs["vmware:extra_config"] = '{"numa.nodeAffinity":"0"}' - extra_specs["vmware:latency_sensitivity_level"] = "high" + self.process_vio_numa_nodes(numa_nodes, extra_specs) for numa in numas: if "id" in numa: @@ -1384,6 +1383,23 @@ class vimconnector(vimconn.VimConnector): if cpu_threads: extra_specs["hw:cpu_threads"] = str(cpu_threads) + @staticmethod + def process_vio_numa_nodes(numa_nodes: int, extra_specs: Dict) -> None: + """According to number of numa nodes, updates the extra_specs for VIO. + + Args: + + numa_nodes (int): List keeps the numa node numbers + extra_specs (dict): Extra specs dict to be updated + + """ + # If there is not any numa, numas_nodes equals to 0. + if not numa_nodes: + extra_specs["vmware:extra_config"] = '{"numa.nodeAffinity":"0"}' + + # If there are several numas, we do not define specific affinity. + extra_specs["vmware:latency_sensitivity_level"] = "high" + def _change_flavor_name( self, name: str, name_suffix: int, flavor_data: dict ) -> str: diff --git a/releasenotes/notes/adding_vio_numa_support-6717ff4c02776dda.yaml b/releasenotes/notes/adding_vio_numa_support-6717ff4c02776dda.yaml new file mode 100644 index 00000000..b8d6179c --- /dev/null +++ b/releasenotes/notes/adding_vio_numa_support-6717ff4c02776dda.yaml @@ -0,0 +1,22 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### +--- +fixes: + - | + Bug 2180 Adding VIO Numa support with unit tests. + + -- 2.25.1