@@ -1644,10 +1644,13 @@ def test(mock_inst_get, mock_map_get):
16441644
16451645 test ()
16461646
1647+ @mock .patch ('nova.compute.api.API._get_source_compute_service' )
1648+ @mock .patch ('nova.servicegroup.api.API.service_is_up' , return_value = True )
16471649 @mock .patch .object (objects .Migration , 'save' )
16481650 @mock .patch .object (objects .Migration , 'get_by_instance_and_status' )
16491651 @mock .patch .object (context .RequestContext , 'elevated' )
16501652 def _test_confirm_resize (self , mock_elevated , mock_get , mock_save ,
1653+ mock_service_is_up , mock_get_service ,
16511654 mig_ref_passed = False ):
16521655 params = dict (vm_state = vm_states .RESIZED )
16531656 fake_inst = self ._create_instance_obj (params = params )
@@ -1678,6 +1681,8 @@ def _check_mig(expected_task_state=None):
16781681 self .compute_api .confirm_resize (self .context , fake_inst )
16791682
16801683 mock_elevated .assert_called_once_with ()
1684+ mock_service_is_up .assert_called_once_with (
1685+ mock_get_service .return_value )
16811686 mock_save .assert_called_once_with ()
16821687 mock_record .assert_called_once_with (self .context , fake_inst ,
16831688 'confirmResize' )
@@ -1694,6 +1699,34 @@ def test_confirm_resize(self):
16941699 def test_confirm_resize_with_migration_ref (self ):
16951700 self ._test_confirm_resize (mig_ref_passed = True )
16961701
1702+ @mock .patch ('nova.objects.HostMapping.get_by_host' ,
1703+ return_value = objects .HostMapping (
1704+ cell_mapping = objects .CellMapping (
1705+ database_connection = 'fake://' , transport_url = 'none://' ,
1706+ uuid = uuids .cell_uuid )))
1707+ @mock .patch ('nova.objects.Service.get_by_compute_host' )
1708+ def test_get_source_compute_service (self , mock_service_get , mock_hm_get ):
1709+ # First start with a same-cell migration.
1710+ migration = objects .Migration (source_compute = 'source.host' ,
1711+ cross_cell_move = False )
1712+ self .compute_api ._get_source_compute_service (self .context , migration )
1713+ mock_hm_get .assert_not_called ()
1714+ mock_service_get .assert_called_once_with (self .context , 'source.host' )
1715+ # Make sure the context was not targeted.
1716+ ctxt = mock_service_get .call_args [0 ][0 ]
1717+ self .assertIsNone (ctxt .cell_uuid )
1718+
1719+ # Now test with a cross-cell migration.
1720+ mock_service_get .reset_mock ()
1721+ migration .cross_cell_move = True
1722+ self .compute_api ._get_source_compute_service (self .context , migration )
1723+ mock_hm_get .assert_called_once_with (self .context , 'source.host' )
1724+ mock_service_get .assert_called_once_with (
1725+ test .MatchType (context .RequestContext ), 'source.host' )
1726+ # Make sure the context was targeted.
1727+ ctxt = mock_service_get .call_args [0 ][0 ]
1728+ self .assertEqual (uuids .cell_uuid , ctxt .cell_uuid )
1729+
16971730 @mock .patch ('nova.virt.hardware.numa_get_constraints' )
16981731 @mock .patch ('nova.network.neutron.API.get_requested_resource_for_instance' ,
16991732 return_value = [])
@@ -7460,8 +7493,10 @@ def test_get_migrations_sorted_filter_duplicates_using_created_at(self):
74607493 self ._test_get_migrations_sorted_filter_duplicates (
74617494 [older , newer ], newer )
74627495
7496+ @mock .patch ('nova.servicegroup.api.API.service_is_up' , return_value = True )
74637497 @mock .patch ('nova.objects.Migration.get_by_instance_and_status' )
7464- def test_confirm_resize_cross_cell_move_true (self , mock_migration_get ):
7498+ def test_confirm_resize_cross_cell_move_true (self , mock_migration_get ,
7499+ mock_service_is_up ):
74657500 """Tests confirm_resize where Migration.cross_cell_move is True"""
74667501 instance = fake_instance .fake_instance_obj (
74677502 self .context , vm_state = vm_states .RESIZED , task_state = None ,
@@ -7475,12 +7510,15 @@ def test_confirm_resize_cross_cell_move_true(self, mock_migration_get):
74757510 mock .patch .object (self .compute_api , '_record_action_start' ),
74767511 mock .patch .object (self .compute_api .compute_task_api ,
74777512 'confirm_snapshot_based_resize' ),
7513+ mock .patch .object (self .compute_api , '_get_source_compute_service' ),
74787514 ) as (
74797515 mock_elevated , mock_migration_save , mock_record_action ,
7480- mock_conductor_confirm
7516+ mock_conductor_confirm , mock_get_service
74817517 ):
74827518 self .compute_api .confirm_resize (self .context , instance )
74837519 mock_elevated .assert_called_once_with ()
7520+ mock_service_is_up .assert_called_once_with (
7521+ mock_get_service .return_value )
74847522 mock_migration_save .assert_called_once_with ()
74857523 self .assertEqual ('confirming' , migration .status )
74867524 mock_record_action .assert_called_once_with (
0 commit comments