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:
parent
c9b7f4d067
commit
f00956352d
@ -904,6 +904,7 @@ class ComputeTaskManager(base.Base):
|
|||||||
LOG.warning('Specified host %s for evacuate is '
|
LOG.warning('Specified host %s for evacuate is '
|
||||||
'invalid.', host, instance=instance)
|
'invalid.', host, instance=instance)
|
||||||
|
|
||||||
|
# TODO(mriedem): Make request_spec required in ComputeTaskAPI RPC v2.0.
|
||||||
@targets_cell
|
@targets_cell
|
||||||
def rebuild_instance(self, context, instance, orig_image_ref, image_ref,
|
def rebuild_instance(self, context, instance, orig_image_ref, image_ref,
|
||||||
injected_files, new_pass, orig_sys_metadata,
|
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
|
# In either case, the API passes host=None but sets up the
|
||||||
# RequestSpec.requested_destination field for the specified
|
# RequestSpec.requested_destination field for the specified
|
||||||
# host.
|
# host.
|
||||||
if not request_spec:
|
if recreate:
|
||||||
# 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:
|
|
||||||
# NOTE(sbauza): Augment the RequestSpec object by excluding
|
# NOTE(sbauza): Augment the RequestSpec object by excluding
|
||||||
# the source host for avoiding the scheduler to pick it
|
# the source host for avoiding the scheduler to pick it
|
||||||
request_spec.ignore_hosts = request_spec.ignore_hosts or []
|
request_spec.ignore_hosts = request_spec.ignore_hosts or []
|
||||||
|
@ -1364,30 +1364,21 @@ class _BaseTaskTestCase(object):
|
|||||||
nodename=expected_node, limits=None)
|
nodename=expected_node, limits=None)
|
||||||
rebuild_args, compute_args = self._prepare_rebuild_args(
|
rebuild_args, compute_args = self._prepare_rebuild_args(
|
||||||
{'host': None, 'node': expected_node, 'limits': expected_limits})
|
{'host': None, 'node': expected_node, 'limits': expected_limits})
|
||||||
request_spec = {}
|
|
||||||
filter_properties = {'ignore_hosts': [(inst_obj.host)]}
|
|
||||||
fake_spec = objects.RequestSpec()
|
fake_spec = objects.RequestSpec()
|
||||||
|
rebuild_args['request_spec'] = fake_spec
|
||||||
inst_uuids = [inst_obj.uuid]
|
inst_uuids = [inst_obj.uuid]
|
||||||
with test.nested(
|
with test.nested(
|
||||||
mock.patch.object(self.conductor_manager.compute_rpcapi,
|
mock.patch.object(self.conductor_manager.compute_rpcapi,
|
||||||
'rebuild_instance'),
|
'rebuild_instance'),
|
||||||
mock.patch.object(scheduler_utils, 'setup_instance_group',
|
mock.patch.object(scheduler_utils, 'setup_instance_group',
|
||||||
return_value=False),
|
return_value=False),
|
||||||
mock.patch.object(objects.RequestSpec, 'from_primitives',
|
|
||||||
return_value=fake_spec),
|
|
||||||
mock.patch.object(self.conductor_manager.scheduler_client,
|
mock.patch.object(self.conductor_manager.scheduler_client,
|
||||||
'select_destinations',
|
'select_destinations',
|
||||||
return_value=[[fake_selection]]),
|
return_value=[[fake_selection]])
|
||||||
mock.patch('nova.scheduler.utils.build_request_spec',
|
) as (rebuild_mock, sig_mock, select_dest_mock):
|
||||||
return_value=request_spec)
|
|
||||||
) as (rebuild_mock, sig_mock, fp_mock, select_dest_mock, bs_mock):
|
|
||||||
self.conductor_manager.rebuild_instance(context=self.context,
|
self.conductor_manager.rebuild_instance(context=self.context,
|
||||||
instance=inst_obj,
|
instance=inst_obj,
|
||||||
**rebuild_args)
|
**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(
|
self.ensure_network_metadata_mock.assert_called_once_with(
|
||||||
inst_obj)
|
inst_obj)
|
||||||
self.heal_reqspec_is_bfv_mock.assert_called_once_with(
|
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 = self._create_fake_instance_obj()
|
||||||
inst_obj.host = 'noselect'
|
inst_obj.host = 'noselect'
|
||||||
rebuild_args, _ = self._prepare_rebuild_args({'host': None})
|
rebuild_args, _ = self._prepare_rebuild_args({'host': None})
|
||||||
request_spec = {}
|
|
||||||
filter_properties = {'ignore_hosts': [(inst_obj.host)]}
|
|
||||||
fake_spec = objects.RequestSpec()
|
fake_spec = objects.RequestSpec()
|
||||||
|
rebuild_args['request_spec'] = fake_spec
|
||||||
|
|
||||||
with test.nested(
|
with test.nested(
|
||||||
mock.patch.object(self.conductor_manager.compute_rpcapi,
|
mock.patch.object(self.conductor_manager.compute_rpcapi,
|
||||||
'rebuild_instance'),
|
'rebuild_instance'),
|
||||||
mock.patch.object(scheduler_utils, 'setup_instance_group',
|
mock.patch.object(scheduler_utils, 'setup_instance_group',
|
||||||
return_value=False),
|
return_value=False),
|
||||||
mock.patch.object(objects.RequestSpec, 'from_primitives',
|
|
||||||
return_value=fake_spec),
|
|
||||||
mock.patch.object(self.conductor_manager.scheduler_client,
|
mock.patch.object(self.conductor_manager.scheduler_client,
|
||||||
'select_destinations',
|
'select_destinations',
|
||||||
side_effect=exc.NoValidHost(reason='')),
|
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')
|
mock.patch.object(scheduler_utils, 'set_vm_state_and_notify')
|
||||||
) as (rebuild_mock, sig_mock, fp_mock,
|
) as (rebuild_mock, sig_mock,
|
||||||
select_dest_mock, bs_mock, set_vm_state_and_notify_mock):
|
select_dest_mock, set_vm_state_and_notify_mock):
|
||||||
self.assertRaises(exc.NoValidHost,
|
self.assertRaises(exc.NoValidHost,
|
||||||
self.conductor_manager.rebuild_instance,
|
self.conductor_manager.rebuild_instance,
|
||||||
context=self.context, instance=inst_obj,
|
context=self.context, instance=inst_obj,
|
||||||
**rebuild_args)
|
**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,
|
select_dest_mock.assert_called_once_with(self.context, fake_spec,
|
||||||
[inst_obj.uuid], return_objects=True,
|
[inst_obj.uuid], return_objects=True,
|
||||||
return_alternates=False)
|
return_alternates=False)
|
||||||
@ -1448,19 +1432,16 @@ class _BaseTaskTestCase(object):
|
|||||||
@mock.patch.object(scheduler_utils, 'setup_instance_group')
|
@mock.patch.object(scheduler_utils, 'setup_instance_group')
|
||||||
@mock.patch.object(conductor_manager.scheduler_client.SchedulerClient,
|
@mock.patch.object(conductor_manager.scheduler_client.SchedulerClient,
|
||||||
'select_destinations')
|
'select_destinations')
|
||||||
@mock.patch('nova.scheduler.utils.build_request_spec')
|
|
||||||
@mock.patch.object(conductor_manager.ComputeTaskManager,
|
@mock.patch.object(conductor_manager.ComputeTaskManager,
|
||||||
'_set_vm_state_and_notify')
|
'_set_vm_state_and_notify')
|
||||||
def test_rebuild_instance_with_scheduler_group_failure(self,
|
def test_rebuild_instance_with_scheduler_group_failure(self,
|
||||||
state_mock,
|
state_mock,
|
||||||
bs_mock,
|
|
||||||
select_dest_mock,
|
select_dest_mock,
|
||||||
sig_mock,
|
sig_mock,
|
||||||
rebuild_mock):
|
rebuild_mock):
|
||||||
inst_obj = self._create_fake_instance_obj()
|
inst_obj = self._create_fake_instance_obj()
|
||||||
rebuild_args, _ = self._prepare_rebuild_args({'host': None})
|
rebuild_args, _ = self._prepare_rebuild_args({'host': None})
|
||||||
request_spec = {}
|
rebuild_args['request_spec'] = self.request_spec
|
||||||
bs_mock.return_value = request_spec
|
|
||||||
|
|
||||||
exception = exc.UnsupportedPolicyException(reason='')
|
exception = exc.UnsupportedPolicyException(reason='')
|
||||||
sig_mock.side_effect = exception
|
sig_mock.side_effect = exception
|
||||||
|
Loading…
Reference in New Issue
Block a user