X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=RO-VIM-openstack%2Fosm_rovim_openstack%2Ftests%2Ftest_vimconn_openstack.py;h=c102ed4b9d1ebf449f22e28f4cfe08e58a63d344;hb=8453602c784e1f2458612d70ff40e19c2ff73d6f;hp=acf6be483efa10526c2d2306cbaf16f749b74c32;hpb=760d5b9d0d2276649417e2529485c9137beee6c7;p=osm%2FRO.git 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..c102ed4b 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 = ( { @@ -108,6 +107,9 @@ flavor_data2 = { } +@unittest.skip( + "Test is incomplete as it did not mock reload_connection and SFC methods are not in use." +) class TestSfcOperations(unittest.TestCase): @mock.patch("logging.getLogger", autospec=True) def setUp(self, mock_logger): @@ -1128,6 +1130,11 @@ class TestSfcOperations(unittest.TestCase): self.assertEqual(result, "638f957c-82df-11e7-b7c8-132706021464") +def check_if_assert_not_called(mocks: list): + for mocking in mocks: + mocking.assert_not_called() + + class Status: def __init__(self, s): self.status = s @@ -5802,7 +5809,6 @@ class TestNewVmInstance(unittest.TestCase): self.assertDictEqual(result, created_items) def test_update_block_device_mapping_empty_volume(self): - """""" volume = "" block_device_mapping = {} base_disk_index = 100 @@ -5817,7 +5823,6 @@ class TestNewVmInstance(unittest.TestCase): self.assertEqual(created_items, {}) def test_update_block_device_mapping_invalid_volume(self): - """""" volume = "Volume-A" block_device_mapping = {} base_disk_index = 100 @@ -5834,7 +5839,6 @@ class TestNewVmInstance(unittest.TestCase): self.assertEqual(created_items, {}) def test_update_block_device_mapping(self): - """""" volume = MagicMock(autospec=True) volume.id = volume_id block_device_mapping = {} @@ -5852,7 +5856,6 @@ class TestNewVmInstance(unittest.TestCase): ) def test_update_block_device_mapping_with_keep_flag(self): - """""" volume = MagicMock(autospec=True) volume.id = volume_id block_device_mapping = {} @@ -5917,6 +5920,67 @@ class TestNewVmInstance(unittest.TestCase): with self.assertRaises(AttributeError): self.vimconn._extract_items_wth_keep_flag_from_created_items(created_items) + @patch.object(vimconnector, "_reload_connection", new_callable=CopyingMock()) + def test_get_monitoring_data(self, mock_reload_conection): + servers = ["server1", "server2"] + ports = {"ports": ["port1", "port2"]} + self.vimconn.nova.servers.list.return_value = servers + self.vimconn.neutron.list_ports.return_value = ports + result = self.vimconn.get_monitoring_data() + self.assertTupleEqual(result, (servers, ports)) + mock_reload_conection.assert_called_once() + self.vimconn.nova.servers.list.assert_called_once_with(detailed=True) + self.vimconn.neutron.list_ports.assert_called_once() + + @patch.object(vimconnector, "_reload_connection", new_callable=CopyingMock()) + def test_get_monitoring_data_reload_connection_raises(self, mock_reload_conection): + mock_reload_conection.side_effect = VimConnNotFoundException( + "Connection object not found." + ) + with self.assertRaises(VimConnException) as err: + result = self.vimconn.get_monitoring_data() + self.assertTupleEqual(result, None) + self.assertEqual( + str(err.exception.args[0]), + "Exception in monitoring while getting VMs and ports status: Connection object not found.", + ) + mock_reload_conection.assert_called_once() + check_if_assert_not_called( + [self.vimconn.nova.servers.list, self.vimconn.neutron.list_ports] + ) + + @patch.object(vimconnector, "_reload_connection", new_callable=CopyingMock()) + def test_get_monitoring_data_server_list_raises(self, mock_reload_conection): + self.vimconn.nova.servers.list.side_effect = VimConnConnectionException( + "Can not connect to Cloud API." + ) + with self.assertRaises(VimConnException) as err: + result = self.vimconn.get_monitoring_data() + self.assertTupleEqual(result, None) + self.assertEqual( + str(err.exception.args[0]), + "Exception in monitoring while getting VMs and ports status: Can not connect to Cloud API.", + ) + mock_reload_conection.assert_called_once() + self.vimconn.nova.servers.list.assert_called_once_with(detailed=True) + self.vimconn.neutron.list_ports.assert_not_called() + + @patch.object(vimconnector, "_reload_connection", new_callable=CopyingMock()) + def test_get_monitoring_data_list_ports_raises(self, mock_reload_conection): + self.vimconn.neutron.list_ports.side_effect = VimConnConnectionException( + "Can not connect to Cloud API." + ) + with self.assertRaises(VimConnException) as err: + result = self.vimconn.get_monitoring_data() + self.assertTupleEqual(result, None) + self.assertEqual( + str(err.exception.args[0]), + "Exception in monitoring while getting VMs and ports status: Can not connect to Cloud API.", + ) + mock_reload_conection.assert_called_once() + self.vimconn.nova.servers.list.assert_called_once_with(detailed=True) + self.vimconn.neutron.list_ports.assert_called_once() + class TestNewFlavor(unittest.TestCase): @patch("logging.getLogger", autospec=True) @@ -5941,11 +6005,7 @@ class TestNewFlavor(unittest.TestCase): self.new_flavor.id = "075d2482-5edb-43e3-91b3-234e65b6268a" self.vimconn.nova.flavors.create.return_value = self.new_flavor - @staticmethod - def check_if_assert_not_called(mocks: list): - 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( @@ -5962,6 +6022,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. @@ -5970,21 +6031,17 @@ 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", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", "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) + 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, @@ -5993,8 +6050,6 @@ class TestNewFlavor(unittest.TestCase): 0, { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -6006,8 +6061,6 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -6019,8 +6072,6 @@ class TestNewFlavor(unittest.TestCase): 0, { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -6032,13 +6083,11 @@ 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) - self.check_if_assert_not_called( + check_if_assert_not_called( [ mock_process_numa_threads, mock_process_numa_cores, @@ -6046,6 +6095,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( @@ -6062,6 +6112,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. @@ -6070,17 +6121,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 @@ -6118,7 +6166,7 @@ class TestNewFlavor(unittest.TestCase): ), ) self.assertDictEqual(extra_specs, expected_extra_specs) - self.check_if_assert_not_called( + check_if_assert_not_called( [ mock_process_numa_threads, mock_process_numa_cores, @@ -6126,6 +6174,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( @@ -6142,6 +6191,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. @@ -6149,20 +6199,16 @@ 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.check_if_assert_not_called( - [mock_process_numa_threads, mock_process_numa_cores] - ) + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + + check_if_assert_not_called([mock_process_numa_threads, mock_process_numa_cores]) self.assertEqual(mock_process_numa_memory.call_count, 2) self.assertEqual(mock_process_numa_vcpu.call_count, 2) self.assertEqual(mock_process_numa_paired_threads.call_count, 2) @@ -6185,6 +6231,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( @@ -6201,63 +6248,57 @@ 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. """ - 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) - self.check_if_assert_not_called( - [mock_process_numa_threads, mock_process_numa_cores] - ) + mock_process_numa_paired_threads.side_effect = [4, 4] + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + check_if_assert_not_called([mock_process_numa_threads, mock_process_numa_cores]) self.assertEqual(mock_process_numa_paired_threads.call_count, 2) self.assertEqual(mock_process_numa_memory.call_count, 2) self.assertEqual(mock_process_numa_vcpu.call_count, 2) _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, ( - {"id": 0, "paired-threads": 3}, + {"id": 0, "paired-threads": 2}, { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", "some-key": "some-value", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) 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", "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( @@ -6274,21 +6315,24 @@ 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. """ 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.check_if_assert_not_called( + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + + check_if_assert_not_called( [mock_process_numa_threads, mock_process_numa_paired_threads] ) self.assertEqual(mock_process_numa_cores.call_count, 2) @@ -6297,14 +6341,15 @@ 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) + @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( @@ -6321,6 +6366,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. @@ -6328,35 +6374,44 @@ 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", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", + "hw:numa_nodes": "2", } 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.check_if_assert_not_called( + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + check_if_assert_not_called( [mock_process_numa_threads, mock_process_numa_paired_threads] ) 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, - ({"id": 0, "cores": 1}, expected_extra_specs), + ( + {"id": 0, "cores": 1}, + { + "hw:cpu_sockets": "2", + "hw:numa_nodes": "2", + }, + ), ) 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", + }, + ), ) 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( @@ -6373,6 +6428,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. @@ -6384,18 +6440,13 @@ 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", } 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) - self.check_if_assert_not_called( + mock_process_numa_threads.return_value = 3 + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + check_if_assert_not_called( [ mock_process_numa_memory, mock_process_numa_vcpu, @@ -6403,17 +6454,22 @@ 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( _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) + @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( @@ -6430,6 +6486,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. @@ -6442,20 +6499,19 @@ 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) - self.check_if_assert_not_called( + mock_process_numa_threads.return_value = 3 + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + + check_if_assert_not_called( [ mock_process_numa_memory, 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) @@ -6464,11 +6520,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"}, ), ) 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( @@ -6485,23 +6542,15 @@ 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" - 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.check_if_assert_not_called( + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + check_if_assert_not_called( [ mock_process_numa_memory, mock_process_numa_vcpu, @@ -6510,8 +6559,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( @@ -6528,25 +6579,24 @@ 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 = [] 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.check_if_assert_not_called( + self.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + + check_if_assert_not_called( [ mock_process_numa_memory, mock_process_numa_vcpu, 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) @@ -6574,14 +6624,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 +6929,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 +6941,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 +6961,6 @@ class TestNewFlavor(unittest.TestCase): {"memory": 1, "threads": 3}, {"memory": 2, "vcpu": [2]}, ] - vcpus = 3 extended = { "numas": numas, "disk-quota": {"limit": 50}, @@ -6933,13 +6970,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 +6985,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 +6996,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 +7024,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 +7052,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 +7080,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 +7113,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 +7144,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 +7172,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 +7204,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,12 +7225,8 @@ 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.check_if_assert_not_called( + self.vimconn._process_extended_config_of_flavor(extended, extra_specs) + check_if_assert_not_called( [mock_process_resource_quota, mock_process_numa_parameters_of_flavor] ) self.assertEqual(extra_specs, {}) @@ -7292,7 +7285,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 +7299,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,22 +7327,18 @@ 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 ) - self.check_if_assert_not_called( - [self.new_flavor.set_keys, mock_format_exception] - ) + check_if_assert_not_called([self.new_flavor.set_keys, mock_format_exception]) @patch.object(vimconnector, "_get_flavor_details", new_callable=CopyingMock()) @patch.object( @@ -7372,17 +7360,16 @@ 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( + check_if_assert_not_called( [mock_change_flavor_name, mock_format_exception, self.new_flavor.set_keys] ) @@ -7410,17 +7397,15 @@ 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 ) - self.check_if_assert_not_called( + check_if_assert_not_called( [ self.new_flavor.set_keys, mock_extended_config_of_flavor, @@ -7458,7 +7443,7 @@ class TestNewFlavor(unittest.TestCase): self.assertEqual( str(call_mock_format_exception[0][0]), str(ClientException(error_msg)) ) - self.check_if_assert_not_called( + check_if_assert_not_called( [ mock_change_flavor_name, mock_get_flavor_details, @@ -7497,7 +7482,7 @@ class TestNewFlavor(unittest.TestCase): self.assertEqual( str(call_mock_format_exception[0][0]), str(KeyError(error_msg)) ) - self.check_if_assert_not_called( + check_if_assert_not_called( [ mock_reload_connection, mock_change_flavor_name, @@ -7531,11 +7516,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,15 +7526,13 @@ 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, is_public=True, ) - self.check_if_assert_not_called( - [self.new_flavor.set_keys, mock_format_exception] - ) + check_if_assert_not_called([self.new_flavor.set_keys, mock_format_exception]) @patch.object(vimconnector, "_get_flavor_details", new_callable=CopyingMock()) @patch.object( @@ -7579,13 +7560,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, @@ -7595,7 +7574,7 @@ class TestNewFlavor(unittest.TestCase): swap=0, is_public=True, ) - self.check_if_assert_not_called( + check_if_assert_not_called( [ self.new_flavor.set_keys, mock_extended_config_of_flavor, @@ -7643,7 +7622,7 @@ class TestNewFlavor(unittest.TestCase): self.assertEqual(mock_get_flavor_details.call_count, 3) self.assertEqual(self.vimconn.nova.flavors.create.call_count, 3) self.assertEqual(mock_reload_connection.call_count, 3) - self.check_if_assert_not_called( + check_if_assert_not_called( [mock_change_flavor_name, mock_extended_config_of_flavor] ) _call_mock_format_exception = mock_format_exception.call_args @@ -7798,7 +7777,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( @@ -7833,6 +7811,51 @@ 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: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", + } + 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()