From: Gulsum Atici Date: Mon, 23 Jan 2023 13:22:59 +0000 (+0300) Subject: Correcting invalid vcpu calculation and vcpu pinning policy evaluation. X-Git-Tag: v12.0.6~7 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=3c08761aeb45da522705d728689f940dfff79206;p=osm%2FRO.git 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) (cherry picked from commit d66107f9c92b90e3b90ff2eccbb3bd7bd068cabb) --- diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index 829fa5ed..bd43c019 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 dc814dd0..2c6a773e 100644 --- a/NG-RO/osm_ng_ro/tests/test_ns.py +++ b/NG-RO/osm_ng_ro/tests/test_ns.py @@ -1488,7 +1488,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 = { @@ -1507,9 +1507,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 68517fa0..be60c366 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 = ( { @@ -5499,7 +5498,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", @@ -5508,10 +5506,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 @@ -5599,17 +5595,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 @@ -5678,17 +5671,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] ) @@ -5734,22 +5725,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] ) @@ -5762,7 +5750,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", @@ -5775,7 +5763,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", @@ -5809,14 +5797,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] ) @@ -5826,11 +5816,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) @@ -5857,18 +5847,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] ) @@ -5878,11 +5865,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) @@ -5916,14 +5919,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, @@ -5938,7 +5938,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) @@ -5971,14 +5976,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, @@ -5993,7 +5996,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) @@ -6024,12 +6027,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, @@ -6063,12 +6061,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, @@ -6103,14 +6098,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 @@ -6416,7 +6403,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}, @@ -6429,13 +6415,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( @@ -6452,7 +6435,6 @@ class TestNewFlavor(unittest.TestCase): {"memory": 1, "threads": 3}, {"memory": 2, "vcpu": [2]}, ] - vcpus = 3 extended = { "numas": numas, "disk-quota": {"limit": 50}, @@ -6462,13 +6444,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( @@ -6481,7 +6459,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}, @@ -6493,11 +6470,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) @@ -6525,19 +6498,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( @@ -6558,16 +6526,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) @@ -6590,15 +6554,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) @@ -6626,18 +6587,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( @@ -6662,19 +6618,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( @@ -6695,16 +6646,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) @@ -6731,17 +6678,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) @@ -6757,11 +6699,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] ) @@ -6821,7 +6759,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, @@ -6836,7 +6773,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 @@ -6864,16 +6801,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 ) @@ -6901,15 +6836,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] @@ -6939,13 +6873,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 ) @@ -7060,11 +6992,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) @@ -7072,7 +7002,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, @@ -7108,13 +7038,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, @@ -7327,7 +7255,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 fe7c847d..8e9d4395 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/.