From d66107f9c92b90e3b90ff2eccbb3bd7bd068cabb Mon Sep 17 00:00:00 2001 From: Gulsum Atici Date: Mon, 23 Jan 2023 16:22:59 +0300 Subject: [PATCH] Correcting invalid vcpu calculation and vcpu pinning policy evaluation. Correcting invalid vcpu calculation according to numa nodes core and thread settings, correcting vcpu pinning policy evaluation. Change-Id: I8126a1e5a47e879a42809ded8ca07b8d1c78ac8f Signed-off-by: Gulsum Atici (cherry picked from commit 6a6e3344cc0d68064a592941e33cdc6629eb3405) --- NG-RO/osm_ng_ro/ns.py | 5 +- NG-RO/osm_ng_ro/tests/test_ns.py | 42 ++- .../tests/test_vimconn_openstack.py | 245 ++++++------------ .../osm_rovim_openstack/vimconn_openstack.py | 62 +++-- ...ing_vcpu_calculation-83aa1e4c3ee72a24.yaml | 21 ++ 5 files changed, 180 insertions(+), 195 deletions(-) create mode 100644 releasenotes/notes/Correcting_vcpu_calculation-83aa1e4c3ee72a24.yaml diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index 3ae392ea..4e88cc4b 100644 --- a/NG-RO/osm_ng_ro/ns.py +++ b/NG-RO/osm_ng_ro/ns.py @@ -722,9 +722,12 @@ class Ns(object): guest_epa_quota.get("cpu-pinning-policy") == "DEDICATED" and not epa_vcpu_set ): + # Pinning policy "REQUIRE" uses threads as host should support SMT architecture + # Pinning policy "ISOLATE" uses cores as host should not support SMT architecture + # Pinning policy "PREFER" uses threads in case host supports SMT architecture numa[ "cores" - if guest_epa_quota.get("cpu-thread-pinning-policy") != "PREFER" + if guest_epa_quota.get("cpu-thread-pinning-policy") == "ISOLATE" else "threads" ] = max(vcpu_count, 1) local_epa_vcpu_set = True diff --git a/NG-RO/osm_ng_ro/tests/test_ns.py b/NG-RO/osm_ng_ro/tests/test_ns.py index 7ae29856..d2fdc4dc 100644 --- a/NG-RO/osm_ng_ro/tests/test_ns.py +++ b/NG-RO/osm_ng_ro/tests/test_ns.py @@ -1494,7 +1494,7 @@ class TestNs(unittest.TestCase): self.assertDictEqual(expected_numa_result, numa_result) self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result) - def test__process_guest_epa_cpu_pinning_params_with_threads(self): + def test__process_guest_epa_cpu_pinning_params_with_policy_prefer(self): expected_numa_result = {"threads": 3} expected_epa_vcpu_set_result = True guest_epa_quota = { @@ -1513,9 +1513,47 @@ class TestNs(unittest.TestCase): self.assertDictEqual(expected_numa_result, numa_result) self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result) - def test__process_guest_epa_cpu_pinning_params(self): + def test__process_guest_epa_cpu_pinning_params_with_policy_isolate(self): expected_numa_result = {"cores": 3} expected_epa_vcpu_set_result = True + guest_epa_quota = { + "cpu-pinning-policy": "DEDICATED", + "cpu-thread-pinning-policy": "ISOLATE", + } + vcpu_count = 3 + epa_vcpu_set = False + + numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params( + guest_epa_quota=guest_epa_quota, + vcpu_count=vcpu_count, + epa_vcpu_set=epa_vcpu_set, + ) + + self.assertDictEqual(expected_numa_result, numa_result) + self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result) + + def test__process_guest_epa_cpu_pinning_params_with_policy_require(self): + expected_numa_result = {"threads": 3} + expected_epa_vcpu_set_result = True + guest_epa_quota = { + "cpu-pinning-policy": "DEDICATED", + "cpu-thread-pinning-policy": "REQUIRE", + } + vcpu_count = 3 + epa_vcpu_set = False + + numa_result, epa_vcpu_set_result = Ns._process_guest_epa_cpu_pinning_params( + guest_epa_quota=guest_epa_quota, + vcpu_count=vcpu_count, + epa_vcpu_set=epa_vcpu_set, + ) + + self.assertDictEqual(expected_numa_result, numa_result) + self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result) + + def test__process_guest_epa_cpu_pinning_params(self): + expected_numa_result = {"threads": 3} + expected_epa_vcpu_set_result = True guest_epa_quota = { "cpu-pinning-policy": "DEDICATED", } 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 acf6be48..a351d532 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 @@ -81,7 +81,6 @@ created_items_all_true = { # Variables used in TestNewFlavor Class -flavor_id = "075d2482-5edb-43e3-91b3-234e65b6268a" name1 = "sample-flavor" extended = ( { @@ -5970,7 +5969,6 @@ class TestNewFlavor(unittest.TestCase): {"id": 0, "memory": 1, "vcpu": [1, 3]}, {"id": 1, "memory": 2, "vcpu": [2]}, ] - vcpus = 3 extra_specs = {} expected_extra_specs = { "hw:numa_nodes": "2", @@ -5979,10 +5977,8 @@ class TestNewFlavor(unittest.TestCase): "hw:cpu_sockets": "2", } self.vimconn.vim_type = "VIO" - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + self.assertEqual(mock_process_numa_memory.call_count, 2) self.assertEqual(mock_process_numa_vcpu.call_count, 2) _call_mock_process_numa_memory = mock_process_numa_memory.call_args_list @@ -6070,17 +6066,14 @@ class TestNewFlavor(unittest.TestCase): {"id": 0, "memory": 1, "vcpu": [1, 3]}, {"id": 1, "memory": 2, "vcpu": [2]}, ] - vcpus = 3 extra_specs = {} expected_extra_specs = { "hw:numa_nodes": "2", "hw:cpu_sockets": "2", } self.vimconn.vim_type = "openstack" - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + self.assertEqual(mock_process_numa_memory.call_count, 2) self.assertEqual(mock_process_numa_vcpu.call_count, 2) _call_mock_process_numa_memory = mock_process_numa_memory.call_args_list @@ -6149,17 +6142,15 @@ class TestNewFlavor(unittest.TestCase): numas = [{"id": 0, "paired-threads": 3}, {"id": 1, "paired-threads": 3}] extra_specs = {"some-key": "some-value"} expected_extra_specs = { - "hw:numa_nodes": "2", "hw:cpu_sockets": "2", + "hw:cpu_threads": "12", + "hw:numa_nodes": "2", "some-key": "some-value", } self.vimconn.vim_type = "openstack" - vcpus = 6 mock_process_numa_paired_threads.side_effect = [6, 6] - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + self.check_if_assert_not_called( [mock_process_numa_threads, mock_process_numa_cores] ) @@ -6205,22 +6196,19 @@ class TestNewFlavor(unittest.TestCase): """Process numa parameters, id, paired-threads exist, vim type is VIO. vcpus calculation according to paired-threads in numa, there is extra_spec. """ - numas = [{"id": 0, "paired-threads": 3}, {"id": 1, "paired-threads": 3}] + numas = [{"id": 0, "paired-threads": 2}, {"id": 1, "paired-threads": 2}] 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", } self.vimconn.vim_type = "VIO" - vcpus = 6 - mock_process_numa_paired_threads.side_effect = [6, 6] - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + mock_process_numa_paired_threads.side_effect = [4, 4] + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) self.check_if_assert_not_called( [mock_process_numa_threads, mock_process_numa_cores] ) @@ -6233,7 +6221,7 @@ class TestNewFlavor(unittest.TestCase): self.assertEqual( _call_mock_process_numa_paired_threads[0].args, ( - {"id": 0, "paired-threads": 3}, + {"id": 0, "paired-threads": 2}, { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", @@ -6246,7 +6234,7 @@ class TestNewFlavor(unittest.TestCase): self.assertEqual( _call_mock_process_numa_paired_threads[1].args, ( - {"id": 1, "paired-threads": 3}, + {"id": 1, "paired-threads": 2}, { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", @@ -6280,14 +6268,16 @@ class TestNewFlavor(unittest.TestCase): """ numas = [{"id": 0, "cores": 1}, {"id": 1, "cores": 2}] extra_specs = {} - expected_extra_specs = {"hw:numa_nodes": "2", "hw:cpu_sockets": "2"} + updated_extra_specs = {"hw:numa_nodes": "2", "hw:cpu_sockets": "2"} + expected_extra_specs = { + "hw:numa_nodes": "2", + "hw:cpu_sockets": "2", + "hw:cpu_cores": "3", + } self.vimconn.vim_type = "openstack" - vcpus = 2 mock_process_numa_cores.side_effect = [1, 2] - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + self.check_if_assert_not_called( [mock_process_numa_threads, mock_process_numa_paired_threads] ) @@ -6297,11 +6287,11 @@ class TestNewFlavor(unittest.TestCase): _call_mock_process_numa_cores = mock_process_numa_cores.call_args_list self.assertEqual( _call_mock_process_numa_cores[0].args, - ({"id": 0, "cores": 1}, {"hw:cpu_sockets": "2", "hw:numa_nodes": "2"}), + ({"id": 0, "cores": 1}, updated_extra_specs), ) self.assertEqual( _call_mock_process_numa_cores[1].args, - ({"id": 1, "cores": 2}, {"hw:cpu_sockets": "2", "hw:numa_nodes": "2"}), + ({"id": 1, "cores": 2}, updated_extra_specs), ) self.assertDictEqual(extra_specs, expected_extra_specs) @@ -6328,18 +6318,15 @@ class TestNewFlavor(unittest.TestCase): numas = [{"id": 0, "cores": 1}, {"id": 1, "cores": 2}] extra_specs = {} expected_extra_specs = { - "hw:numa_nodes": "2", + "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" - vcpus = 2 mock_process_numa_cores.side_effect = [1, 2] - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) self.check_if_assert_not_called( [mock_process_numa_threads, mock_process_numa_paired_threads] ) @@ -6349,11 +6336,27 @@ class TestNewFlavor(unittest.TestCase): _call_mock_process_numa_cores = mock_process_numa_cores.call_args_list self.assertEqual( _call_mock_process_numa_cores[0].args, - ({"id": 0, "cores": 1}, expected_extra_specs), + ( + {"id": 0, "cores": 1}, + { + "hw:cpu_sockets": "2", + "hw:numa_nodes": "2", + "vmware:extra_config": '{"numa.nodeAffinity":"0"}', + "vmware:latency_sensitivity_level": "high", + }, + ), ) self.assertEqual( _call_mock_process_numa_cores[1].args, - ({"id": 1, "cores": 2}, expected_extra_specs), + ( + {"id": 1, "cores": 2}, + { + "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) @@ -6387,14 +6390,11 @@ class TestNewFlavor(unittest.TestCase): "vmware:extra_config": '{"numa.nodeAffinity":"0"}', "vmware:latency_sensitivity_level": "high", "hw:cpu_sockets": "2", + "hw:cpu_threads": "3", } self.vimconn.vim_type = "VIO" - vcpus = 3 - mock_process_numa_threads.return_value = vcpus - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + mock_process_numa_threads.return_value = 3 + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) self.check_if_assert_not_called( [ mock_process_numa_memory, @@ -6409,7 +6409,12 @@ class TestNewFlavor(unittest.TestCase): _call_mock_process_numa_threads[0].args, ( {"memory": 1, "vcpu": [1, 3], "threads": 3}, - expected_extra_specs, + { + "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) @@ -6442,14 +6447,12 @@ class TestNewFlavor(unittest.TestCase): expected_extra_specs = { "hw:numa_nodes": "2", "hw:cpu_sockets": "2", + "hw:cpu_threads": "3", } self.vimconn.vim_type = "openstack" - vcpus = 3 - mock_process_numa_threads.return_value = vcpus - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + mock_process_numa_threads.return_value = 3 + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + self.check_if_assert_not_called( [ mock_process_numa_memory, @@ -6464,7 +6467,7 @@ class TestNewFlavor(unittest.TestCase): _call_mock_process_numa_threads[0].args, ( {"memory": 1, "vcpu": [1, 3], "threads": 3}, - expected_extra_specs, + {"hw:cpu_sockets": "2", "hw:numa_nodes": "2"}, ), ) self.assertDictEqual(extra_specs, expected_extra_specs) @@ -6495,12 +6498,7 @@ class TestNewFlavor(unittest.TestCase): "vmware:latency_sensitivity_level": "high", } self.vimconn.vim_type = "VIO" - vcpus = 4 - mock_process_numa_threads.return_value = None - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) self.check_if_assert_not_called( [ mock_process_numa_memory, @@ -6534,12 +6532,9 @@ class TestNewFlavor(unittest.TestCase): extra_specs = {} expected_extra_specs = {"hw:numa_nodes": "0"} self.vimconn.vim_type = "openstack" - vcpus = 5 mock_process_numa_threads.return_value = None - result = self.vimconn._process_numa_parameters_of_flavor( - numas, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + self.check_if_assert_not_called( [ mock_process_numa_memory, @@ -6574,14 +6569,6 @@ class TestNewFlavor(unittest.TestCase): self.vimconn.process_numa_memory(numa, node_id, extra_specs) self.assertDictEqual(extra_specs, expected_extra_spec) - def test_process_numa_memory_node_id_is_int(self): - numa = {"memory": 2, "vcpu": [2]} - node_id = 0 - extra_specs = {} - expected_extra_spec = {"hw:numa_mem.0": 2048} - self.vimconn.process_numa_memory(numa, node_id, extra_specs) - self.assertDictEqual(extra_specs, expected_extra_spec) - def test_process_numa_vcpu_empty_extra_spec(self): numa = {"vcpu": [2]} node_id = 0 @@ -6887,7 +6874,6 @@ class TestNewFlavor(unittest.TestCase): {"memory": 1, "vcpu": [1, 3], "threads": 3}, {"memory": 2, "vcpu": [2]}, ] - vcpus = 3 extended = { "numas": numas, "cpu-quota": {"limit": 3}, @@ -6900,13 +6886,10 @@ class TestNewFlavor(unittest.TestCase): expected_extra_specs = { "hw:mem_page_size": "large", } - mock_process_numa_parameters_of_flavor.return_value = vcpus - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) + self.assertEqual(mock_process_resource_quota.call_count, 4) - mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}, vcpus) + mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}) self.assertEqual(extra_specs, expected_extra_specs) @patch.object( @@ -6923,7 +6906,6 @@ class TestNewFlavor(unittest.TestCase): {"memory": 1, "threads": 3}, {"memory": 2, "vcpu": [2]}, ] - vcpus = 3 extended = { "numas": numas, "disk-quota": {"limit": 50}, @@ -6933,13 +6915,9 @@ class TestNewFlavor(unittest.TestCase): expected_extra_specs = { "hw:mem_page_size": "any", } - mock_process_numa_parameters_of_flavor.return_value = vcpus - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) mock_process_resource_quota.assert_not_called() - mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}, vcpus) + mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}) self.assertEqual(extra_specs, expected_extra_specs) @patch.object( @@ -6952,7 +6930,6 @@ class TestNewFlavor(unittest.TestCase): self, mock_process_resource_quota, mock_process_numa_parameters_of_flavor ): """Process extended config, extended has cpu, mem, vif and disk-io quota but not numas.""" - vcpus = 3 extended = { "cpu-quota": {"limit": 3}, "mem-quota": {"limit": 1}, @@ -6964,11 +6941,7 @@ class TestNewFlavor(unittest.TestCase): expected_extra_specs = { "hw:mem_page_size": "small", } - mock_process_numa_parameters_of_flavor.return_value = vcpus - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, vcpus) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 4) mock_process_numa_parameters_of_flavor.assert_not_called() self.assertEqual(extra_specs, expected_extra_specs) @@ -6996,19 +6969,14 @@ class TestNewFlavor(unittest.TestCase): "mem-policy": "STRICT", } extra_specs = {} - vcpus = 3 expected_extra_specs = { "hw:mem_page_size": "large", "hw:cpu_policy": "dedicated", "hw:numa_mempolicy": "strict", } - mock_process_numa_parameters_of_flavor.return_value = 4 - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, 4) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 2) - mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}, vcpus) + mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}) self.assertEqual(extra_specs, expected_extra_specs) @patch.object( @@ -7029,16 +6997,12 @@ class TestNewFlavor(unittest.TestCase): "mem-policy": "STRICT", } extra_specs = {} - vcpus = 3 expected_extra_specs = { "hw:mem_page_size": "large", "hw:cpu_policy": "dedicated", "hw:numa_mempolicy": "strict", } - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, 3) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 2) mock_process_numa_parameters_of_flavor.assert_not_called() self.assertEqual(extra_specs, expected_extra_specs) @@ -7061,15 +7025,12 @@ class TestNewFlavor(unittest.TestCase): "mem-policy": "STRICT", } extra_specs = {} - vcpus = 6 + expected_extra_specs = { "hw:cpu_policy": "dedicated", "hw:numa_mempolicy": "strict", } - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, 6) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 2) mock_process_numa_parameters_of_flavor.assert_not_called() self.assertEqual(extra_specs, expected_extra_specs) @@ -7097,18 +7058,13 @@ class TestNewFlavor(unittest.TestCase): "mem-policy": "STRICT", } extra_specs = {} - mock_process_numa_parameters_of_flavor.return_value = 4 - vcpus = 1 expected_extra_specs = { "hw:cpu_policy": "dedicated", "hw:numa_mempolicy": "strict", } - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, 4) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 2) - mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}, vcpus) + mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}) self.assertEqual(extra_specs, expected_extra_specs) @patch.object( @@ -7133,19 +7089,14 @@ class TestNewFlavor(unittest.TestCase): "cpu-pinning-policy": "DEDICATED", "mem-policy": "STRICT", } - mock_process_numa_parameters_of_flavor.return_value = 1 extra_specs = {} - vcpus = None expected_extra_specs = { "hw:cpu_policy": "dedicated", "hw:numa_mempolicy": "strict", } - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, 1) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 2) - mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}, vcpus) + mock_process_numa_parameters_of_flavor.assert_called_once_with(numas, {}) self.assertEqual(extra_specs, expected_extra_specs) @patch.object( @@ -7166,16 +7117,12 @@ class TestNewFlavor(unittest.TestCase): "mem-policy": "STRICT", } extra_specs = {"some-key": "some-val"} - vcpus = None expected_extra_specs = { "hw:cpu_policy": "dedicated", "hw:numa_mempolicy": "strict", "some-key": "some-val", } - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, None) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 2) mock_process_numa_parameters_of_flavor.assert_not_called() self.assertEqual(extra_specs, expected_extra_specs) @@ -7202,17 +7149,12 @@ class TestNewFlavor(unittest.TestCase): "cpu-pinning-pol": "DEDICATED", "mem-pol": "STRICT", } - mock_process_numa_parameters_of_flavor.return_value = 1 extra_specs = {} - vcpus = "" expected_extra_specs = {} - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, 1) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.assertEqual(mock_process_resource_quota.call_count, 2) mock_process_numa_parameters_of_flavor.assert_called_once_with( - numas, extra_specs, vcpus + numas, extra_specs ) self.assertEqual(extra_specs, expected_extra_specs) @@ -7228,11 +7170,7 @@ class TestNewFlavor(unittest.TestCase): """Process extended config, extended is empty.""" extended = {} extra_specs = {} - vcpus = 2 - result = self.vimconn._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) - self.assertEqual(result, 2) + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) self.check_if_assert_not_called( [mock_process_resource_quota, mock_process_numa_parameters_of_flavor] ) @@ -7292,7 +7230,6 @@ class TestNewFlavor(unittest.TestCase): name_suffix = 0 vcpus = 8 mock_change_flavor_name.return_value = name1 - mock_extended_config_of_flavor.return_value = vcpus mock_get_flavor_details.return_value = ( 3, vcpus, @@ -7307,7 +7244,7 @@ class TestNewFlavor(unittest.TestCase): mock_get_flavor_details.assert_called_once_with(flavor_data) mock_change_flavor_name.assert_called_once_with(name1, name_suffix, flavor_data) mock_extended_config_of_flavor.assert_called_once_with( - extended, {"some-key": "some-value"}, vcpus + extended, {"some-key": "some-value"} ) self.vimconn.nova.flavors.create.assert_called_once_with( name=name1, ram=3, vcpus=8, disk=50, ephemeral=0, swap=0, is_public=True @@ -7335,16 +7272,14 @@ class TestNewFlavor(unittest.TestCase): name_suffix = 0 vcpus = 8 mock_change_flavor_name.return_value = name1 - mock_extended_config_of_flavor.return_value = vcpus mock_get_flavor_details.return_value = (3, vcpus, {}, extended) expected_result = self.new_flavor.id result = self.vimconn.new_flavor(flavor_data) self.assertEqual(result, expected_result) mock_reload_connection.assert_called_once() - mock_get_flavor_details.assert_called_once_with(flavor_data) mock_change_flavor_name.assert_called_once_with(name1, name_suffix, flavor_data) - mock_extended_config_of_flavor.assert_called_once_with(extended, {}, vcpus) + mock_extended_config_of_flavor.assert_called_once_with(extended, {}) self.vimconn.nova.flavors.create.assert_called_once_with( name=name1, ram=3, vcpus=vcpus, disk=50, ephemeral=0, swap=0, is_public=True ) @@ -7372,15 +7307,14 @@ class TestNewFlavor(unittest.TestCase): """Create new flavor, change_name_if_used_false, there is extended.""" vcpus = 8 mock_get_flavor_details.return_value = (3, vcpus, {}, extended) - mock_extended_config_of_flavor.return_value = 16 expected_result = self.new_flavor.id result = self.vimconn.new_flavor(flavor_data, False) self.assertEqual(result, expected_result) mock_reload_connection.assert_called_once() self.assertEqual(mock_get_flavor_details.call_count, 1) - mock_extended_config_of_flavor.assert_called_once_with(extended, {}, vcpus) + mock_extended_config_of_flavor.assert_called_once_with(extended, {}) self.vimconn.nova.flavors.create.assert_called_once_with( - name=name1, ram=3, vcpus=16, disk=50, ephemeral=0, swap=0, is_public=True + name=name1, ram=3, vcpus=8, disk=50, ephemeral=0, swap=0, is_public=True ) self.check_if_assert_not_called( [mock_change_flavor_name, mock_format_exception, self.new_flavor.set_keys] @@ -7410,13 +7344,11 @@ class TestNewFlavor(unittest.TestCase): mock_get_flavor_details.return_value = (3, 8, {}, None) result = self.vimconn.new_flavor(flavor_data2) self.assertEqual(result, expected_result) - mock_reload_connection.assert_called_once() mock_change_flavor_name.assert_called_once_with( name1, name_suffix, flavor_data2 ) self.assertEqual(mock_get_flavor_details.call_count, 1) - self.vimconn.nova.flavors.create.assert_called_once_with( name=name1, ram=3, vcpus=8, disk=50, ephemeral=0, swap=0, is_public=True ) @@ -7531,11 +7463,9 @@ class TestNewFlavor(unittest.TestCase): mock_change_flavor_name.side_effect = [error2, "sample-flavor-3"] expected_result = self.new_flavor.id mock_get_flavor_details.return_value = (3, 8, {}, extended) - mock_extended_config_of_flavor.return_value = 10 result = self.vimconn.new_flavor(flavor_data2) self.assertEqual(result, expected_result) self.assertEqual(mock_reload_connection.call_count, 2) - mock_change_flavor_name.assert_called_with(name1, name_suffix, flavor_data2) self.assertEqual(mock_change_flavor_name.call_count, 2) self.assertEqual(mock_get_flavor_details.call_count, 1) @@ -7543,7 +7473,7 @@ class TestNewFlavor(unittest.TestCase): self.vimconn.nova.flavors.create.assert_called_once_with( name="sample-flavor-3", ram=3, - vcpus=10, + vcpus=8, disk=50, ephemeral=0, swap=0, @@ -7579,13 +7509,11 @@ class TestNewFlavor(unittest.TestCase): expected_result = self.new_flavor.id mock_get_flavor_details.return_value = (3, 8, {}, None) result = self.vimconn.new_flavor(flavor_data2) - self.assertEqual(result, expected_result) self.assertEqual(mock_reload_connection.call_count, 2) mock_change_flavor_name.assert_called_with(name1, name_suffix, flavor_data2) self.assertEqual(mock_change_flavor_name.call_count, 2) self.assertEqual(mock_get_flavor_details.call_count, 1) - self.vimconn.nova.flavors.create.assert_called_once_with( name="sample-flavor-3", ram=3, @@ -7798,7 +7726,6 @@ class TestNewFlavor(unittest.TestCase): } ), ) - self.assertEqual(mock_reload_connection.call_count, 3) _call_mock_change_flavor = mock_change_flavor_name.call_args_list self.assertEqual( diff --git a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py index d70e2ec2..e404f22e 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py @@ -1287,16 +1287,17 @@ class vimconnector(vimconn.VimConnector): extra_specs (dict): To be filled. Returns: - vcpus (int) Number of virtual cpus + threads (int) Number of virtual cpus """ if not numa.get("paired-threads"): return + # cpu_thread_policy "require" implies that compute node must have an STM architecture - vcpus = numa["paired-threads"] * 2 + threads = numa["paired-threads"] * 2 extra_specs["hw:cpu_thread_policy"] = "require" extra_specs["hw:cpu_policy"] = "dedicated" - return vcpus + return threads @staticmethod def process_numa_cores(numa: dict, extra_specs: dict) -> Optional[int]: @@ -1306,17 +1307,17 @@ class vimconnector(vimconn.VimConnector): extra_specs (dict): To be filled. Returns: - vcpus (int) Number of virtual cpus + cores (int) Number of virtual cpus """ # cpu_thread_policy "isolate" implies that the host must not have an SMT # architecture, or a non-SMT architecture will be emulated if not numa.get("cores"): return - vcpus = numa["cores"] + cores = numa["cores"] extra_specs["hw:cpu_thread_policy"] = "isolate" extra_specs["hw:cpu_policy"] = "dedicated" - return vcpus + return cores @staticmethod def process_numa_threads(numa: dict, extra_specs: dict) -> Optional[int]: @@ -1326,33 +1327,30 @@ class vimconnector(vimconn.VimConnector): extra_specs (dict): To be filled. Returns: - vcpus (int) Number of virtual cpus + threads (int) Number of virtual cpus """ # cpu_thread_policy "prefer" implies that the host may or may not have an SMT architecture if not numa.get("threads"): return - vcpus = numa["threads"] + threads = numa["threads"] extra_specs["hw:cpu_thread_policy"] = "prefer" extra_specs["hw:cpu_policy"] = "dedicated" - return vcpus + return threads def _process_numa_parameters_of_flavor( - self, numas: List, extra_specs: Dict, vcpus: Optional[int] - ) -> int: + self, numas: List, extra_specs: Dict + ) -> None: """Process numa parameters and fill up extra_specs. Args: numas (list): List of dictionary which includes numa information extra_specs (dict): To be filled. - vcpus (int) Number of virtual cpus - - Returns: - vcpus (int) Number of virtual cpus """ numa_nodes = len(numas) extra_specs["hw:numa_nodes"] = str(numa_nodes) + cpu_cores, cpu_threads = 0, 0 if self.vim_type == "VIO": extra_specs["vmware:extra_config"] = '{"numa.nodeAffinity":"0"}' @@ -1370,15 +1368,21 @@ class vimconnector(vimconn.VimConnector): extra_specs["hw:cpu_sockets"] = str(numa_nodes) if "paired-threads" in numa: - vcpus = self.process_numa_paired_threads(numa, extra_specs) + threads = self.process_numa_paired_threads(numa, extra_specs) + cpu_threads += threads elif "cores" in numa: - vcpus = self.process_numa_cores(numa, extra_specs) + cores = self.process_numa_cores(numa, extra_specs) + cpu_cores += cores elif "threads" in numa: - vcpus = self.process_numa_threads(numa, extra_specs) + threads = self.process_numa_threads(numa, extra_specs) + cpu_threads += threads - return vcpus + if cpu_cores: + extra_specs["hw:cpu_cores"] = str(cpu_cores) + if cpu_threads: + extra_specs["hw:cpu_threads"] = str(cpu_threads) def _change_flavor_name( self, name: str, name_suffix: int, flavor_data: dict @@ -1405,17 +1409,13 @@ class vimconnector(vimconn.VimConnector): return name def _process_extended_config_of_flavor( - self, extended: dict, extra_specs: dict, vcpus: Optional[int] - ) -> int: + self, extended: dict, extra_specs: dict + ) -> None: """Process the extended dict to fill up extra_specs. Args: - extended (dict): Keeping the extra specification of flavor - extra_specs (dict) Dict to be filled to be used during flavor creation - vcpus (int) Number of virtual cpus - - Returns: - vcpus (int) Number of virtual cpus + extended (dict): Keeping the extra specification of flavor + extra_specs (dict) Dict to be filled to be used during flavor creation """ quotas = { @@ -1441,7 +1441,7 @@ class vimconnector(vimconn.VimConnector): numas = extended.get("numas") if numas: - vcpus = self._process_numa_parameters_of_flavor(numas, extra_specs, vcpus) + self._process_numa_parameters_of_flavor(numas, extra_specs) for quota, item in quotas.items(): if quota in extended.keys(): @@ -1462,8 +1462,6 @@ class vimconnector(vimconn.VimConnector): if extended.get(policy): extra_specs[hw_policy] = extended[policy].lower() - return vcpus - @staticmethod def _get_flavor_details(flavor_data: dict) -> Tuple: """Returns the details of flavor @@ -1513,9 +1511,7 @@ class vimconnector(vimconn.VimConnector): flavor_data ) if extended: - vcpus = self._process_extended_config_of_flavor( - extended, extra_specs, vcpus - ) + self._process_extended_config_of_flavor(extended, extra_specs) # Create flavor diff --git a/releasenotes/notes/Correcting_vcpu_calculation-83aa1e4c3ee72a24.yaml b/releasenotes/notes/Correcting_vcpu_calculation-83aa1e4c3ee72a24.yaml new file mode 100644 index 00000000..d7f5f18a --- /dev/null +++ b/releasenotes/notes/Correcting_vcpu_calculation-83aa1e4c3ee72a24.yaml @@ -0,0 +1,21 @@ +####################################################################################### +# 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. +####################################################################################### +--- +other: + - | + Correcting invalid vcpu calculation according to numa nodes core and thread settings, + correcting vcpu pinning policy evaluation according to https://osm.etsi.org/gerrit/#/c/osm/IM/+/12851/. -- 2.25.1