|
11 | 11 | # under the License.
|
12 | 12 |
|
13 | 13 | import mock
|
| 14 | +from oslo_serialization import jsonutils |
14 | 15 | from oslo_utils.fixture import uuidsentinel as uuids
|
15 | 16 |
|
16 | 17 | from nova.compute import rpcapi as compute_rpcapi
|
@@ -220,6 +221,77 @@ def set_migration_uuid(*a, **k):
|
220 | 221 | mock_get_resources.assert_called_once_with(
|
221 | 222 | self.context, self.instance.uuid)
|
222 | 223 |
|
| 224 | + @mock.patch.object(scheduler_utils, 'fill_provider_mapping') |
| 225 | + @mock.patch.object(scheduler_utils, 'claim_resources') |
| 226 | + @mock.patch.object(context.RequestContext, 'elevated') |
| 227 | + def test_execute_reschedule( |
| 228 | + self, mock_elevated, mock_claim, mock_fill_provider_mapping): |
| 229 | + report_client = report.SchedulerReportClient() |
| 230 | + # setup task for re-schedule |
| 231 | + alloc_req = { |
| 232 | + "allocations": { |
| 233 | + uuids.host1: { |
| 234 | + "resources": { |
| 235 | + "VCPU": 1, |
| 236 | + "MEMORY_MB": 1024, |
| 237 | + "DISK_GB": 100}}}} |
| 238 | + alternate_selection = objects.Selection( |
| 239 | + service_host="host1", |
| 240 | + nodename="node1", |
| 241 | + cell_uuid=uuids.cell1, |
| 242 | + allocation_request=jsonutils.dumps(alloc_req), |
| 243 | + allocation_request_version='1.19') |
| 244 | + task = migrate.MigrationTask( |
| 245 | + self.context, self.instance, self.flavor, self.request_spec, |
| 246 | + self.clean_shutdown, compute_rpcapi.ComputeAPI(), |
| 247 | + query.SchedulerQueryClient(), report_client, |
| 248 | + host_list=[alternate_selection], network_api=self.mock_network_api) |
| 249 | + mock_claim.return_value = True |
| 250 | + |
| 251 | + actual_selection = task._reschedule() |
| 252 | + |
| 253 | + self.assertIs(alternate_selection, actual_selection) |
| 254 | + mock_claim.assert_called_once_with( |
| 255 | + mock_elevated.return_value, report_client, self.request_spec, |
| 256 | + self.instance.uuid, alloc_req, '1.19') |
| 257 | + mock_fill_provider_mapping.assert_called_once_with( |
| 258 | + self.context, report_client, self.request_spec, |
| 259 | + alternate_selection) |
| 260 | + |
| 261 | + @mock.patch.object(scheduler_utils, 'fill_provider_mapping') |
| 262 | + @mock.patch.object(scheduler_utils, 'claim_resources') |
| 263 | + @mock.patch.object(context.RequestContext, 'elevated') |
| 264 | + def test_execute_reschedule_claim_fails_no_more_alternate( |
| 265 | + self, mock_elevated, mock_claim, mock_fill_provider_mapping): |
| 266 | + report_client = report.SchedulerReportClient() |
| 267 | + # set up the task for re-schedule |
| 268 | + alloc_req = { |
| 269 | + "allocations": { |
| 270 | + uuids.host1: { |
| 271 | + "resources": { |
| 272 | + "VCPU": 1, |
| 273 | + "MEMORY_MB": 1024, |
| 274 | + "DISK_GB": 100}}}} |
| 275 | + alternate_selection = objects.Selection( |
| 276 | + service_host="host1", |
| 277 | + nodename="node1", |
| 278 | + cell_uuid=uuids.cell1, |
| 279 | + allocation_request=jsonutils.dumps(alloc_req), |
| 280 | + allocation_request_version='1.19') |
| 281 | + task = migrate.MigrationTask( |
| 282 | + self.context, self.instance, self.flavor, self.request_spec, |
| 283 | + self.clean_shutdown, compute_rpcapi.ComputeAPI(), |
| 284 | + query.SchedulerQueryClient(), report_client, |
| 285 | + host_list=[alternate_selection], network_api=self.mock_network_api) |
| 286 | + mock_claim.return_value = False |
| 287 | + |
| 288 | + self.assertRaises(exception.MaxRetriesExceeded, task._reschedule) |
| 289 | + |
| 290 | + mock_claim.assert_called_once_with( |
| 291 | + mock_elevated.return_value, report_client, self.request_spec, |
| 292 | + self.instance.uuid, alloc_req, '1.19') |
| 293 | + mock_fill_provider_mapping.assert_not_called() |
| 294 | + |
223 | 295 |
|
224 | 296 | class MigrationTaskAllocationUtils(test.NoDBTestCase):
|
225 | 297 | @mock.patch('nova.objects.ComputeNode.get_by_host_and_nodename')
|
|
0 commit comments