Merge "Fill the RequestGroup mapping during schedule"
This commit is contained in:
commit
8f38da3bf7
@ -1245,6 +1245,28 @@ class ComputeTaskManager(base.Base):
|
||||
with obj_target_cell(inst, cell0):
|
||||
inst.destroy()
|
||||
|
||||
def _fill_provider_mapping(self, context, instance_uuid, request_spec):
|
||||
"""Fills out the request group - resource provider mapping in the
|
||||
request spec.
|
||||
|
||||
This is a workaround as placement does not return which PR
|
||||
fulfills which granular request group in the allocation candidate
|
||||
request. There is a spec proposing a solution in placement:
|
||||
https://review.openstack.org/#/c/597601/
|
||||
When that spec is implemented then this function can be
|
||||
replaced with a simpler code that copies the group - RP
|
||||
mapping out from the Selection object returned by the scheduler's
|
||||
select_destinations call.
|
||||
"""
|
||||
allocs = self.report_client.get_allocations_for_consumer(
|
||||
context, instance_uuid)
|
||||
provider_traits = {
|
||||
rp_uuid: self.report_client._get_provider_traits(
|
||||
context, rp_uuid).traits
|
||||
for rp_uuid in allocs}
|
||||
request_spec.map_requested_resources_to_providers(
|
||||
allocs, provider_traits)
|
||||
|
||||
def schedule_and_build_instances(self, context, build_requests,
|
||||
request_specs, image,
|
||||
admin_password, injected_files,
|
||||
@ -1359,6 +1381,19 @@ class ComputeTaskManager(base.Base):
|
||||
scheduler_utils.populate_retry(filter_props, instance.uuid)
|
||||
scheduler_utils.populate_filter_properties(filter_props,
|
||||
host)
|
||||
|
||||
try:
|
||||
self._fill_provider_mapping(
|
||||
context, instance.uuid, request_spec)
|
||||
except Exception as exc:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self._cleanup_build_artifacts(context, exc, instances,
|
||||
build_requests,
|
||||
request_specs,
|
||||
block_device_mapping,
|
||||
tags,
|
||||
cell_mapping_cache)
|
||||
|
||||
# TODO(melwitt): Maybe we should set_target_cell on the contexts
|
||||
# once we map to a cell, and remove these separate with statements.
|
||||
with obj_target_cell(instance, cell) as cctxt:
|
||||
|
@ -2055,6 +2055,54 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
|
||||
self.assertTrue(mock_build.called)
|
||||
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'_get_provider_traits')
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'get_allocations_for_consumer')
|
||||
@mock.patch('nova.objects.request_spec.RequestSpec.'
|
||||
'map_requested_resources_to_providers')
|
||||
def test_schedule_and_build_instances_fill_request_spec(
|
||||
self, mock_map, mock_get_allocs, mock_traits):
|
||||
# makes sure there is some request group in the spec to be mapped
|
||||
self.params['request_specs'][0].requested_resources = [
|
||||
objects.RequestGroup()]
|
||||
|
||||
mock_get_allocs.return_value = {uuids.rp1: mock.sentinel.rp1_allocs}
|
||||
mock_traits.return_value.traits = ['TRAIT1']
|
||||
|
||||
instance_uuid = self._do_schedule_and_build_instances_test(
|
||||
self.params)
|
||||
|
||||
mock_map.assert_called_once_with({uuids.rp1: mock.sentinel.rp1_allocs},
|
||||
{uuids.rp1: ['TRAIT1']})
|
||||
mock_get_allocs.assert_called_once_with(mock.ANY, instance_uuid)
|
||||
mock_traits.assert_called_once_with(mock.ANY, uuids.rp1)
|
||||
|
||||
@mock.patch('nova.conductor.manager.ComputeTaskManager.'
|
||||
'_cleanup_build_artifacts')
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'_get_provider_traits')
|
||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||
'get_allocations_for_consumer')
|
||||
@mock.patch('nova.objects.request_spec.RequestSpec.'
|
||||
'map_requested_resources_to_providers')
|
||||
def test_schedule_and_build_instances_fill_request_spec_error(
|
||||
self, mock_map, mock_get_allocs, mock_traits, mock_cleanup):
|
||||
# makes sure there is some request group in the spec to be mapped
|
||||
self.params['request_specs'][0].requested_resources = [
|
||||
objects.RequestGroup()]
|
||||
|
||||
mock_get_allocs.side_effect = exc.ConsumerAllocationRetrievalFailed(
|
||||
consumer_uuid=uuids.inst, error='some error')
|
||||
|
||||
self.assertRaises(
|
||||
exc.ConsumerAllocationRetrievalFailed,
|
||||
self._do_schedule_and_build_instances_test, self.params)
|
||||
|
||||
self.assertFalse(mock_map.called)
|
||||
self.assertFalse(mock_traits.called)
|
||||
self.assertTrue(mock_cleanup.called)
|
||||
|
||||
@mock.patch('nova.objects.CellMapping.get_by_uuid')
|
||||
def test_bury_in_cell0_no_cell0(self, mock_cm_get):
|
||||
mock_cm_get.side_effect = exc.CellMappingNotFound(uuid='0')
|
||||
|
Loading…
Reference in New Issue
Block a user