@@ -1644,10 +1644,13 @@ def test(mock_inst_get, mock_map_get):
1644
1644
1645
1645
test ()
1646
1646
1647
+ @mock .patch ('nova.compute.api.API._get_source_compute_service' )
1648
+ @mock .patch ('nova.servicegroup.api.API.service_is_up' , return_value = True )
1647
1649
@mock .patch .object (objects .Migration , 'save' )
1648
1650
@mock .patch .object (objects .Migration , 'get_by_instance_and_status' )
1649
1651
@mock .patch .object (context .RequestContext , 'elevated' )
1650
1652
def _test_confirm_resize (self , mock_elevated , mock_get , mock_save ,
1653
+ mock_service_is_up , mock_get_service ,
1651
1654
mig_ref_passed = False ):
1652
1655
params = dict (vm_state = vm_states .RESIZED )
1653
1656
fake_inst = self ._create_instance_obj (params = params )
@@ -1678,6 +1681,8 @@ def _check_mig(expected_task_state=None):
1678
1681
self .compute_api .confirm_resize (self .context , fake_inst )
1679
1682
1680
1683
mock_elevated .assert_called_once_with ()
1684
+ mock_service_is_up .assert_called_once_with (
1685
+ mock_get_service .return_value )
1681
1686
mock_save .assert_called_once_with ()
1682
1687
mock_record .assert_called_once_with (self .context , fake_inst ,
1683
1688
'confirmResize' )
@@ -1694,6 +1699,34 @@ def test_confirm_resize(self):
1694
1699
def test_confirm_resize_with_migration_ref (self ):
1695
1700
self ._test_confirm_resize (mig_ref_passed = True )
1696
1701
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
+
1697
1730
@mock .patch ('nova.virt.hardware.numa_get_constraints' )
1698
1731
@mock .patch ('nova.network.neutron.API.get_requested_resource_for_instance' ,
1699
1732
return_value = [])
@@ -7460,8 +7493,10 @@ def test_get_migrations_sorted_filter_duplicates_using_created_at(self):
7460
7493
self ._test_get_migrations_sorted_filter_duplicates (
7461
7494
[older , newer ], newer )
7462
7495
7496
+ @mock .patch ('nova.servicegroup.api.API.service_is_up' , return_value = True )
7463
7497
@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 ):
7465
7500
"""Tests confirm_resize where Migration.cross_cell_move is True"""
7466
7501
instance = fake_instance .fake_instance_obj (
7467
7502
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):
7475
7510
mock .patch .object (self .compute_api , '_record_action_start' ),
7476
7511
mock .patch .object (self .compute_api .compute_task_api ,
7477
7512
'confirm_snapshot_based_resize' ),
7513
+ mock .patch .object (self .compute_api , '_get_source_compute_service' ),
7478
7514
) as (
7479
7515
mock_elevated , mock_migration_save , mock_record_action ,
7480
- mock_conductor_confirm
7516
+ mock_conductor_confirm , mock_get_service
7481
7517
):
7482
7518
self .compute_api .confirm_resize (self .context , instance )
7483
7519
mock_elevated .assert_called_once_with ()
7520
+ mock_service_is_up .assert_called_once_with (
7521
+ mock_get_service .return_value )
7484
7522
mock_migration_save .assert_called_once_with ()
7485
7523
self .assertEqual ('confirming' , migration .status )
7486
7524
mock_record_action .assert_called_once_with (
0 commit comments