@@ -3184,15 +3184,41 @@ def test_refresh_associations_disabled(self):
3184
3184
3185
3185
class TestAllocations (SchedulerReportClientTestCase ):
3186
3186
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
+
3187
3211
@mock .patch ('nova.scheduler.client.report.SchedulerReportClient.'
3188
3212
'get_providers_in_tree' )
3189
3213
@mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3190
3214
"delete" )
3215
+ @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3216
+ "_remove_allocations_for_evacuated_instances" )
3191
3217
@mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3192
3218
"delete_allocation_for_instance" )
3193
3219
@mock .patch ("nova.objects.InstanceList.get_uuids_by_host_and_node" )
3194
3220
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 ):
3196
3222
cn = objects .ComputeNode (uuid = uuids .cn , host = "fake_host" ,
3197
3223
hypervisor_hostname = "fake_hostname" , )
3198
3224
mock_by_host .return_value = [uuids .inst1 , uuids .inst2 ]
@@ -3208,6 +3234,7 @@ def test_delete_resource_provider_cascade(self, mock_by_host,
3208
3234
mock_by_host .assert_called_once_with (
3209
3235
self .context , cn .host , cn .hypervisor_hostname )
3210
3236
self .assertEqual (2 , mock_del_alloc .call_count )
3237
+ mock_evacuate .assert_called_once_with (self .context , cn )
3211
3238
exp_url = "/resource_providers/%s" % uuids .cn
3212
3239
mock_delete .assert_called_once_with (
3213
3240
exp_url , global_request_id = self .context .global_id )
@@ -3217,11 +3244,13 @@ def test_delete_resource_provider_cascade(self, mock_by_host,
3217
3244
'get_providers_in_tree' )
3218
3245
@mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3219
3246
"delete" )
3247
+ @mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3248
+ "_remove_allocations_for_evacuated_instances" )
3220
3249
@mock .patch ("nova.scheduler.client.report.SchedulerReportClient."
3221
3250
"delete_allocation_for_instance" )
3222
3251
@mock .patch ("nova.objects.InstanceList.get_uuids_by_host_and_node" )
3223
3252
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 ):
3225
3254
self .client ._association_refresh_time [uuids .cn ] = mock .Mock ()
3226
3255
cn = objects .ComputeNode (uuid = uuids .cn , host = "fake_host" ,
3227
3256
hypervisor_hostname = "fake_hostname" , )
@@ -3236,6 +3265,7 @@ def test_delete_resource_provider_no_cascade(self, mock_by_host,
3236
3265
mock_delete .return_value = resp_mock
3237
3266
self .client .delete_resource_provider (self .context , cn )
3238
3267
mock_del_alloc .assert_not_called ()
3268
+ mock_evacuate .assert_not_called ()
3239
3269
exp_url = "/resource_providers/%s" % uuids .cn
3240
3270
mock_delete .assert_called_once_with (
3241
3271
exp_url , global_request_id = self .context .global_id )
0 commit comments