@@ -3184,15 +3184,41 @@ def test_refresh_associations_disabled(self):
31843184
31853185class TestAllocations (SchedulerReportClientTestCase ):
31863186
3187+ @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3188+ "remove_provider_tree_from_instance_allocation" )
3189+ @mock .patch ('nova.objects.MigrationList.get_by_filters' )
3190+ def test_remove_allocations_for_evacuated_instances (self ,
3191+ mock_get_migrations , mock_rm_pr_tree ):
3192+ cn = objects .ComputeNode (uuid = uuids .cn , host = "fake_host" ,
3193+ hypervisor_hostname = "fake_hostname" , )
3194+ migrations = [mock .Mock (instance_uuid = uuids .inst1 , status = 'done' ),
3195+ mock .Mock (instance_uuid = uuids .inst2 , status = 'done' )]
3196+ mock_get_migrations .return_value = migrations
3197+ mock_rm_pr_tree .return_value = True
3198+ self .client ._remove_allocations_for_evacuated_instances (self .context ,
3199+ cn )
3200+ mock_get_migrations .assert_called_once_with (
3201+ self .context ,
3202+ {'source_compute' : cn .host , 'status' : ['done' ],
3203+ 'migration_type' : 'evacuation' })
3204+ mock_rm_pr_tree .assert_has_calls (
3205+ [mock .call (self .context , uuids .inst1 , cn .uuid ),
3206+ mock .call (self .context , uuids .inst2 , cn .uuid )])
3207+ # status of migrations should be kept
3208+ for migration in migrations :
3209+ self .assertEqual ('done' , migration .status )
3210+
31873211 @mock .patch ('nova.scheduler.client.report.SchedulerReportClient.'
31883212 'get_providers_in_tree' )
31893213 @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
31903214 "delete" )
3215+ @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3216+ "_remove_allocations_for_evacuated_instances" )
31913217 @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
31923218 "delete_allocation_for_instance" )
31933219 @mock .patch ("nova.objects.InstanceList.get_uuids_by_host_and_node" )
31943220 def test_delete_resource_provider_cascade (self , mock_by_host ,
3195- mock_del_alloc , mock_delete , mock_get_rpt ):
3221+ mock_del_alloc , mock_evacuate , mock_delete , mock_get_rpt ):
31963222 cn = objects .ComputeNode (uuid = uuids .cn , host = "fake_host" ,
31973223 hypervisor_hostname = "fake_hostname" , )
31983224 mock_by_host .return_value = [uuids .inst1 , uuids .inst2 ]
@@ -3208,6 +3234,7 @@ def test_delete_resource_provider_cascade(self, mock_by_host,
32083234 mock_by_host .assert_called_once_with (
32093235 self .context , cn .host , cn .hypervisor_hostname )
32103236 self .assertEqual (2 , mock_del_alloc .call_count )
3237+ mock_evacuate .assert_called_once_with (self .context , cn )
32113238 exp_url = "/resource_providers/%s" % uuids .cn
32123239 mock_delete .assert_called_once_with (
32133240 exp_url , global_request_id = self .context .global_id )
@@ -3217,11 +3244,13 @@ def test_delete_resource_provider_cascade(self, mock_by_host,
32173244 'get_providers_in_tree' )
32183245 @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
32193246 "delete" )
3247+ @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3248+ "_remove_allocations_for_evacuated_instances" )
32203249 @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
32213250 "delete_allocation_for_instance" )
32223251 @mock .patch ("nova.objects.InstanceList.get_uuids_by_host_and_node" )
32233252 def test_delete_resource_provider_no_cascade (self , mock_by_host ,
3224- mock_del_alloc , mock_delete , mock_get_rpt ):
3253+ mock_del_alloc , mock_evacuate , mock_delete , mock_get_rpt ):
32253254 self .client ._association_refresh_time [uuids .cn ] = mock .Mock ()
32263255 cn = objects .ComputeNode (uuid = uuids .cn , host = "fake_host" ,
32273256 hypervisor_hostname = "fake_hostname" , )
@@ -3236,6 +3265,7 @@ def test_delete_resource_provider_no_cascade(self, mock_by_host,
32363265 mock_delete .return_value = resp_mock
32373266 self .client .delete_resource_provider (self .context , cn )
32383267 mock_del_alloc .assert_not_called ()
3268+ mock_evacuate .assert_not_called ()
32393269 exp_url = "/resource_providers/%s" % uuids .cn
32403270 mock_delete .assert_called_once_with (
32413271 exp_url , global_request_id = self .context .global_id )
0 commit comments