X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=RO-VIM-openstack%2Fosm_rovim_openstack%2Ftests%2Ftest_vimconn_openstack.py;h=1c6a40b0e058cbe0a0c34fdee6a043754a4f4e79;hb=0bb2d81cc74ef6f98500b7e89083b4f34dc5c41d;hp=68517fa0b4f2f438973b4489bc18fbd4daf30483;hpb=cb767b954aaae6504bd6e3bc4a4f68692e89a8a9;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 68517fa0..1c6a40b0 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 = ( { @@ -2672,6 +2671,7 @@ class TestNewVmInstance(unittest.TestCase): """Prepare disks for VM instance successfully.""" existing_vim_volumes = [] created_items = {} + block_device_mapping = {} vm_av_zone = ["nova"] mock_root_volumes.return_value = root_vol_id @@ -2680,7 +2680,12 @@ class TestNewVmInstance(unittest.TestCase): self.vimconn.cinder = CopyingMock() self.vimconn._prepare_disk_for_vminstance( - name, existing_vim_volumes, created_items, vm_av_zone, disk_list2 + name, + existing_vim_volumes, + created_items, + vm_av_zone, + block_device_mapping, + disk_list2, ) self.vimconn.cinder.volumes.set_bootable.assert_called_once_with( root_vol_id, True @@ -2723,6 +2728,7 @@ class TestNewVmInstance(unittest.TestCase): existing_vim_volumes = [] created_items = {} vm_av_zone = ["nova"] + block_device_mapping = {} mock_root_volumes.return_value = root_vol_id mock_created_vol_availability.return_value = 1700 @@ -2730,7 +2736,12 @@ class TestNewVmInstance(unittest.TestCase): with self.assertRaises(VimConnException) as err: self.vimconn._prepare_disk_for_vminstance( - name, existing_vim_volumes, created_items, vm_av_zone, disk_list2 + name, + existing_vim_volumes, + created_items, + vm_av_zone, + block_device_mapping, + disk_list2, ) self.assertEqual( str(err.exception), "Timeout creating volumes for instance basicvm" @@ -2775,12 +2786,18 @@ class TestNewVmInstance(unittest.TestCase): """Disk list is empty.""" existing_vim_volumes = [] created_items = {} + block_device_mapping = {} vm_av_zone = ["nova"] mock_created_vol_availability.return_value = 2 mock_existing_vol_availability.return_value = 3 self.vimconn._prepare_disk_for_vminstance( - name, existing_vim_volumes, created_items, vm_av_zone, disk_list + name, + existing_vim_volumes, + created_items, + vm_av_zone, + block_device_mapping, + disk_list, ) self.vimconn.cinder.volumes.set_bootable.assert_not_called() mock_created_vol_availability.assert_called_once_with(0, created_items) @@ -2803,6 +2820,7 @@ class TestNewVmInstance(unittest.TestCase): existing_vim_volumes = [] created_items = {} vm_av_zone = ["nova"] + block_device_mapping = {} mock_root_volumes.side_effect = Exception() mock_created_vol_availability.return_value = 10 @@ -2810,7 +2828,12 @@ class TestNewVmInstance(unittest.TestCase): with self.assertRaises(Exception): self.vimconn._prepare_disk_for_vminstance( - name, existing_vim_volumes, created_items, vm_av_zone, disk_list2 + name, + existing_vim_volumes, + created_items, + vm_av_zone, + block_device_mapping, + disk_list2, ) self.vimconn.cinder.volumes.set_bootable.assert_not_called() mock_created_vol_availability.assert_not_called() @@ -2841,13 +2864,19 @@ class TestNewVmInstance(unittest.TestCase): existing_vim_volumes = [] created_items = {} vm_av_zone = ["nova"] + block_device_mapping = {} mock_root_volumes.return_value = root_vol_id mock_non_root_volumes.side_effect = Exception with self.assertRaises(Exception): self.vimconn._prepare_disk_for_vminstance( - name, existing_vim_volumes, created_items, vm_av_zone, disk_list2 + name, + existing_vim_volumes, + created_items, + vm_av_zone, + block_device_mapping, + disk_list2, ) self.vimconn.cinder.volumes.set_bootable.assert_not_called() mock_created_vol_availability.assert_not_called() @@ -4022,6 +4051,7 @@ class TestNewVmInstance(unittest.TestCase): existing_vim_volumes=[], created_items={}, vm_av_zone="nova", + block_device_mapping={}, disk_list=disk_list2, ) self.vimconn.nova.servers.create.assert_called_once_with( @@ -4034,7 +4064,7 @@ class TestNewVmInstance(unittest.TestCase): key_name="my_keypair", userdata="userdata", config_drive=True, - block_device_mapping=None, + block_device_mapping={}, scheduler_hints={}, ) mock_time.assert_called_once() @@ -4188,6 +4218,7 @@ class TestNewVmInstance(unittest.TestCase): existing_vim_volumes=[], created_items={}, vm_av_zone="nova", + block_device_mapping={}, disk_list=disk_list2, ) self.vimconn.nova.servers.create.assert_called_once_with( @@ -4200,7 +4231,7 @@ class TestNewVmInstance(unittest.TestCase): key_name="my_keypair", userdata="userdata", config_drive=True, - block_device_mapping=None, + block_device_mapping={}, scheduler_hints={}, ) mock_time.assert_called_once() @@ -4282,6 +4313,7 @@ class TestNewVmInstance(unittest.TestCase): existing_vim_volumes=[], created_items={}, vm_av_zone="nova", + block_device_mapping={}, disk_list=disk_list2, ) self.vimconn.nova.servers.create.assert_called_once_with( @@ -4294,7 +4326,7 @@ class TestNewVmInstance(unittest.TestCase): key_name="my_keypair", userdata="userdata", config_drive=True, - block_device_mapping=None, + block_device_mapping={}, scheduler_hints={"group": "38b73-e9cc-5a6a-t270-82cc4811bd4a"}, ) mock_time.assert_called_once() @@ -4375,6 +4407,7 @@ class TestNewVmInstance(unittest.TestCase): existing_vim_volumes=[], created_items={}, vm_av_zone="nova", + block_device_mapping={}, disk_list=disk_list2, ) @@ -4388,7 +4421,7 @@ class TestNewVmInstance(unittest.TestCase): key_name="my_keypair", userdata="userdata", config_drive=True, - block_device_mapping=None, + block_device_mapping={}, scheduler_hints={}, ) mock_time.assert_not_called() @@ -5475,6 +5508,7 @@ class TestNewFlavor(unittest.TestCase): for mocking in mocks: mocking.assert_not_called() + @patch.object(vimconnector, "process_vio_numa_nodes", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_memory", new_callable=CopyingMock()) @patch.object(vimconnector, "process_numa_vcpu", new_callable=CopyingMock()) @patch.object( @@ -5491,6 +5525,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. @@ -5499,21 +5534,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, @@ -5522,8 +5553,6 @@ class TestNewFlavor(unittest.TestCase): 0, { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5535,8 +5564,6 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5548,8 +5575,6 @@ class TestNewFlavor(unittest.TestCase): 0, { "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5561,8 +5586,6 @@ class TestNewFlavor(unittest.TestCase): { "hw:cpu_sockets": "2", "hw:numa_nodes": "2", - "vmware:extra_config": '{"numa.nodeAffinity":"0"}', - "vmware:latency_sensitivity_level": "high", }, ), ) @@ -5575,6 +5598,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( @@ -5591,6 +5615,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. @@ -5599,17 +5624,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 @@ -5655,6 +5677,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( @@ -5671,6 +5694,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. @@ -5678,17 +5702,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] ) @@ -5714,6 +5736,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( @@ -5730,26 +5753,22 @@ 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) + 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] ) @@ -5759,34 +5778,34 @@ class TestNewFlavor(unittest.TestCase): _call_mock_process_numa_paired_threads = ( mock_process_numa_paired_threads.call_args_list ) + mock_process_vio_numa_nodes.assert_called_once_with( + 2, {"some-key": "some-value", "hw:numa_nodes": "2"} + ) self.assertEqual( _call_mock_process_numa_paired_threads[0].args, ( - {"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( @@ -5803,20 +5822,23 @@ 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.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,14 +5848,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( @@ -5850,6 +5873,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. @@ -5857,35 +5881,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.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) self.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( @@ -5902,6 +5935,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. @@ -5913,17 +5947,12 @@ 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) + 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, @@ -5932,17 +5961,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( @@ -5959,6 +5993,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. @@ -5971,20 +6006,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) + 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, 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) @@ -5993,11 +6027,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( @@ -6014,22 +6049,14 @@ 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.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) self.check_if_assert_not_called( [ mock_process_numa_memory, @@ -6039,8 +6066,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( @@ -6057,18 +6086,16 @@ 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.vimconn._process_numa_parameters_of_flavor(numas, extra_specs) + self.check_if_assert_not_called( [ mock_process_numa_memory, @@ -6076,6 +6103,7 @@ class TestNewFlavor(unittest.TestCase): mock_process_numa_cores, mock_process_numa_paired_threads, mock_process_numa_threads, + mock_process_vio_numa_nodes, ] ) self.assertDictEqual(extra_specs, expected_extra_specs) @@ -6103,14 +6131,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 +6436,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 +6448,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 +6468,6 @@ class TestNewFlavor(unittest.TestCase): {"memory": 1, "threads": 3}, {"memory": 2, "vcpu": [2]}, ] - vcpus = 3 extended = { "numas": numas, "disk-quota": {"limit": 50}, @@ -6462,13 +6477,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 +6492,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 +6503,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 +6531,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 +6559,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 +6587,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 +6620,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 +6651,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 +6679,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 +6711,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 +6732,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 +6792,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 +6806,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 +6834,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 +6869,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 +6906,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 +7025,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 +7035,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 +7071,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 +7288,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( @@ -7362,6 +7322,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()