Remove legacy RequestSpec compat from conductor rebuild_instance

Change I34ffaf285718059b55f90e812b57f1e11d566c6f made the
RequestSpec lookup required in the API, so we should not get
to conductor's rebuild_instance() method without a request spec
so this change removes the compat code from that method.

Related to blueprint request-spec-use-by-compute

Change-Id: I0a8c18df7ef060647e822e81064d4c663166db8f
This commit is contained in:
Matt Riedemann 2018-12-17 15:20:40 -05:00
parent c9b7f4d067
commit f00956352d
2 changed files with 9 additions and 39 deletions

View File

@ -904,6 +904,7 @@ class ComputeTaskManager(base.Base):
LOG.warning('Specified host %s for evacuate is '
'invalid.', host, instance=instance)
# TODO(mriedem): Make request_spec required in ComputeTaskAPI RPC v2.0.
@targets_cell
def rebuild_instance(self, context, instance, orig_image_ref, image_ref,
injected_files, new_pass, orig_sys_metadata,
@ -968,19 +969,7 @@ class ComputeTaskManager(base.Base):
# In either case, the API passes host=None but sets up the
# RequestSpec.requested_destination field for the specified
# host.
if not request_spec:
# NOTE(sbauza): We were unable to find an original
# RequestSpec object - probably because the instance is old
# We need to mock that the old way
filter_properties = {'ignore_hosts': [instance.host]}
# build_request_spec expects a primitive image dict
image_meta = nova_object.obj_to_primitive(
instance.image_meta)
request_spec = scheduler_utils.build_request_spec(
image_meta, [instance])
request_spec = objects.RequestSpec.from_primitives(
context, request_spec, filter_properties)
elif recreate:
if recreate:
# NOTE(sbauza): Augment the RequestSpec object by excluding
# the source host for avoiding the scheduler to pick it
request_spec.ignore_hosts = request_spec.ignore_hosts or []

View File

@ -1364,30 +1364,21 @@ class _BaseTaskTestCase(object):
nodename=expected_node, limits=None)
rebuild_args, compute_args = self._prepare_rebuild_args(
{'host': None, 'node': expected_node, 'limits': expected_limits})
request_spec = {}
filter_properties = {'ignore_hosts': [(inst_obj.host)]}
fake_spec = objects.RequestSpec()
rebuild_args['request_spec'] = fake_spec
inst_uuids = [inst_obj.uuid]
with test.nested(
mock.patch.object(self.conductor_manager.compute_rpcapi,
'rebuild_instance'),
mock.patch.object(scheduler_utils, 'setup_instance_group',
return_value=False),
mock.patch.object(objects.RequestSpec, 'from_primitives',
return_value=fake_spec),
mock.patch.object(self.conductor_manager.scheduler_client,
'select_destinations',
return_value=[[fake_selection]]),
mock.patch('nova.scheduler.utils.build_request_spec',
return_value=request_spec)
) as (rebuild_mock, sig_mock, fp_mock, select_dest_mock, bs_mock):
return_value=[[fake_selection]])
) as (rebuild_mock, sig_mock, select_dest_mock):
self.conductor_manager.rebuild_instance(context=self.context,
instance=inst_obj,
**rebuild_args)
bs_mock.assert_called_once_with(
obj_base.obj_to_primitive(inst_obj.image_meta), [inst_obj])
fp_mock.assert_called_once_with(self.context, request_spec,
filter_properties)
self.ensure_network_metadata_mock.assert_called_once_with(
inst_obj)
self.heal_reqspec_is_bfv_mock.assert_called_once_with(
@ -1410,31 +1401,24 @@ class _BaseTaskTestCase(object):
inst_obj = self._create_fake_instance_obj()
inst_obj.host = 'noselect'
rebuild_args, _ = self._prepare_rebuild_args({'host': None})
request_spec = {}
filter_properties = {'ignore_hosts': [(inst_obj.host)]}
fake_spec = objects.RequestSpec()
rebuild_args['request_spec'] = fake_spec
with test.nested(
mock.patch.object(self.conductor_manager.compute_rpcapi,
'rebuild_instance'),
mock.patch.object(scheduler_utils, 'setup_instance_group',
return_value=False),
mock.patch.object(objects.RequestSpec, 'from_primitives',
return_value=fake_spec),
mock.patch.object(self.conductor_manager.scheduler_client,
'select_destinations',
side_effect=exc.NoValidHost(reason='')),
mock.patch('nova.scheduler.utils.build_request_spec',
return_value=request_spec),
mock.patch.object(scheduler_utils, 'set_vm_state_and_notify')
) as (rebuild_mock, sig_mock, fp_mock,
select_dest_mock, bs_mock, set_vm_state_and_notify_mock):
) as (rebuild_mock, sig_mock,
select_dest_mock, set_vm_state_and_notify_mock):
self.assertRaises(exc.NoValidHost,
self.conductor_manager.rebuild_instance,
context=self.context, instance=inst_obj,
**rebuild_args)
fp_mock.assert_called_once_with(self.context, request_spec,
filter_properties)
select_dest_mock.assert_called_once_with(self.context, fake_spec,
[inst_obj.uuid], return_objects=True,
return_alternates=False)
@ -1448,19 +1432,16 @@ class _BaseTaskTestCase(object):
@mock.patch.object(scheduler_utils, 'setup_instance_group')
@mock.patch.object(conductor_manager.scheduler_client.SchedulerClient,
'select_destinations')
@mock.patch('nova.scheduler.utils.build_request_spec')
@mock.patch.object(conductor_manager.ComputeTaskManager,
'_set_vm_state_and_notify')
def test_rebuild_instance_with_scheduler_group_failure(self,
state_mock,
bs_mock,
select_dest_mock,
sig_mock,
rebuild_mock):
inst_obj = self._create_fake_instance_obj()
rebuild_args, _ = self._prepare_rebuild_args({'host': None})
request_spec = {}
bs_mock.return_value = request_spec
rebuild_args['request_spec'] = self.request_spec
exception = exc.UnsupportedPolicyException(reason='')
sig_mock.side_effect = exception