Cleanup build_request_spec
The RequestContext parameter was unused so it's removed. Change-Id: I2391aa8e61c5e450d123cf3df1294bc119d361dc
This commit is contained in:
parent
6979a62aef
commit
749b220ef6
|
@ -198,8 +198,7 @@ class CellsScheduler(base.Base):
|
|||
instance_uuids = [inst['uuid'] for inst in
|
||||
build_inst_kwargs['instances']]
|
||||
instances = build_inst_kwargs['instances']
|
||||
request_spec = scheduler_utils.build_request_spec(message.ctxt,
|
||||
image, instances)
|
||||
request_spec = scheduler_utils.build_request_spec(image, instances)
|
||||
filter_properties = copy.copy(build_inst_kwargs['filter_properties'])
|
||||
filter_properties.update({'context': message.ctxt,
|
||||
'scheduler': self,
|
||||
|
|
|
@ -539,8 +539,7 @@ class ComputeTaskManager(base.Base):
|
|||
# have a single instance.
|
||||
# TODO(sbauza): Provide directly the RequestSpec object
|
||||
# when populate_retry() accepts it
|
||||
request_spec = scheduler_utils.build_request_spec(
|
||||
context, image, instances)
|
||||
request_spec = scheduler_utils.build_request_spec(image, instances)
|
||||
scheduler_utils.populate_retry(
|
||||
filter_properties, instances[0].uuid)
|
||||
instance_uuids = [instance.uuid for instance in instances]
|
||||
|
@ -668,7 +667,7 @@ class ComputeTaskManager(base.Base):
|
|||
# old. We need to mock that the old way
|
||||
filter_properties = {}
|
||||
request_spec = scheduler_utils.build_request_spec(
|
||||
context, image, [instance])
|
||||
image, [instance])
|
||||
else:
|
||||
# NOTE(sbauza): Force_hosts/nodes needs to be reset
|
||||
# if we want to make sure that the next destination
|
||||
|
@ -831,7 +830,7 @@ class ComputeTaskManager(base.Base):
|
|||
image_meta = nova_object.obj_to_primitive(
|
||||
instance.image_meta)
|
||||
request_spec = scheduler_utils.build_request_spec(
|
||||
context, image_meta, [instance])
|
||||
image_meta, [instance])
|
||||
request_spec = objects.RequestSpec.from_primitives(
|
||||
context, request_spec, filter_properties)
|
||||
else:
|
||||
|
|
|
@ -180,11 +180,23 @@ class ResourceRequest(object):
|
|||
self._clean_empties()
|
||||
|
||||
|
||||
def build_request_spec(ctxt, image, instances, instance_type=None):
|
||||
def build_request_spec(image, instances, instance_type=None):
|
||||
"""Build a request_spec for the scheduler.
|
||||
|
||||
The request_spec assumes that all instances to be scheduled are the same
|
||||
type.
|
||||
|
||||
:param image: optional primitive image meta dict
|
||||
:param instances: list of instances; objects will be converted to
|
||||
primitives
|
||||
:param instance_type: optional flavor; objects will be converted to
|
||||
primitives
|
||||
:return: dict with the following keys::
|
||||
|
||||
'image': the image dict passed in or {}
|
||||
'instance_properties': primitive version of the first instance passed
|
||||
'instance_type': primitive version of the instance_type or None
|
||||
'num_instances': the number of instances passed in
|
||||
"""
|
||||
instance = instances[0]
|
||||
if instance_type is None:
|
||||
|
@ -218,6 +230,9 @@ def build_request_spec(ctxt, image, instances, instance_type=None):
|
|||
'instance_properties': instance,
|
||||
'instance_type': instance_type,
|
||||
'num_instances': len(instances)}
|
||||
# NOTE(mriedem): obj_to_primitive above does not serialize everything
|
||||
# in an object, like datetime fields, so we need to still call to_primitive
|
||||
# to recursively serialize the items in the request_spec dict.
|
||||
return jsonutils.to_primitive(request_spec)
|
||||
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ class CellsSchedulerTestCase(test.TestCase):
|
|||
call_info['target_cell'] = target_cell
|
||||
call_info['build_inst_kwargs'] = build_inst_kwargs
|
||||
|
||||
def fake_build_request_spec(ctxt, image, instances):
|
||||
def fake_build_request_spec(image, instances):
|
||||
request_spec = {
|
||||
'num_instances': len(instances),
|
||||
'image': image}
|
||||
|
@ -254,7 +254,7 @@ class CellsSchedulerTestCase(test.TestCase):
|
|||
def fake_rpc_build_instances(self, ctxt, **build_inst_kwargs):
|
||||
call_info['build_inst_kwargs'] = build_inst_kwargs
|
||||
|
||||
def fake_build_request_spec(ctxt, image, instances):
|
||||
def fake_build_request_spec(image, instances):
|
||||
request_spec = {
|
||||
'num_instances': len(instances),
|
||||
'image': image}
|
||||
|
@ -304,7 +304,7 @@ class CellsSchedulerTestCase(test.TestCase):
|
|||
self.assertEqual(vm_states.ERROR, inst.vm_state)
|
||||
call_info['errored_uuids'].append(inst.uuid)
|
||||
|
||||
def fake_build_request_spec(ctxt, image, instances):
|
||||
def fake_build_request_spec(image, instances):
|
||||
request_spec = {
|
||||
'num_instances': len(instances),
|
||||
'image': image}
|
||||
|
@ -350,7 +350,7 @@ class CellsSchedulerTestCase(test.TestCase):
|
|||
self.assertEqual(vm_states.ERROR, instance['vm_state'])
|
||||
call_info['errored_uuids2'].append(instance['uuid'])
|
||||
|
||||
def fake_build_request_spec(ctxt, image, instances):
|
||||
def fake_build_request_spec(image, instances):
|
||||
request_spec = {
|
||||
'num_instances': len(instances),
|
||||
'image': image}
|
||||
|
@ -415,7 +415,7 @@ class CellsSchedulerTestCase(test.TestCase):
|
|||
call_info['filt_props'] = filt_properties
|
||||
return cells
|
||||
|
||||
def fake_build_request_spec(ctxt, image, instances):
|
||||
def fake_build_request_spec(image, instances):
|
||||
request_spec = {
|
||||
'num_instances': len(instances),
|
||||
'instance_properties': instances[0],
|
||||
|
@ -534,7 +534,7 @@ class CellsSchedulerTestCase(test.TestCase):
|
|||
call_info['weight_props'] = filt_properties
|
||||
return [weights.WeightedCell(cells[0], 0.0)]
|
||||
|
||||
def fake_build_request_spec(ctxt, image, instances):
|
||||
def fake_build_request_spec(image, instances):
|
||||
request_spec = {
|
||||
'num_instances': len(instances),
|
||||
'instance_properties': instances[0],
|
||||
|
|
|
@ -1045,7 +1045,7 @@ class _BaseTaskTestCase(object):
|
|||
|
||||
self.conductor_manager.image_api.get(self.context,
|
||||
'fake_image_id', show_deleted=False).AndReturn('fake_image')
|
||||
scheduler_utils.build_request_spec(self.context, 'fake_image',
|
||||
scheduler_utils.build_request_spec('fake_image',
|
||||
mox.IgnoreArg()).AndReturn('req_spec')
|
||||
self.conductor_manager._schedule_instances(self.context,
|
||||
fake_spec, [instance.uuid]).AndReturn(
|
||||
|
@ -1145,7 +1145,7 @@ class _BaseTaskTestCase(object):
|
|||
self.mox.StubOutWithMock(self.conductor_manager.compute_rpcapi,
|
||||
'unshelve_instance')
|
||||
|
||||
scheduler_utils.build_request_spec(self.context, None,
|
||||
scheduler_utils.build_request_spec(None,
|
||||
mox.IgnoreArg()).AndReturn('req_spec')
|
||||
self.conductor_manager._schedule_instances(self.context,
|
||||
fake_spec, [instance.uuid]).AndReturn(
|
||||
|
@ -1216,8 +1216,7 @@ class _BaseTaskTestCase(object):
|
|||
instance=inst_obj,
|
||||
**rebuild_args)
|
||||
bs_mock.assert_called_once_with(
|
||||
self.context, obj_base.obj_to_primitive(inst_obj.image_meta),
|
||||
[inst_obj])
|
||||
obj_base.obj_to_primitive(inst_obj.image_meta), [inst_obj])
|
||||
fp_mock.assert_called_once_with(self.context, request_spec,
|
||||
filter_properties)
|
||||
select_dest_mock.assert_called_once_with(self.context, fake_spec,
|
||||
|
@ -2418,7 +2417,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
|||
self.mox.StubOutWithMock(self.conductor_manager.compute_rpcapi,
|
||||
'build_and_run_instance')
|
||||
|
||||
scheduler_utils.build_request_spec(self.context, image,
|
||||
scheduler_utils.build_request_spec(image,
|
||||
mox.IgnoreArg()).AndReturn(spec)
|
||||
filter_properties = {'retry': {'num_attempts': 1, 'hosts': []}}
|
||||
inst_uuids = [inst.uuid for inst in instances]
|
||||
|
|
|
@ -42,8 +42,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
|||
|
||||
with mock.patch.object(flavors, 'extract_flavor') as mock_extract:
|
||||
mock_extract.return_value = instance_type
|
||||
request_spec = scheduler_utils.build_request_spec(self.context,
|
||||
None,
|
||||
request_spec = scheduler_utils.build_request_spec(None,
|
||||
[instance])
|
||||
mock_extract.assert_called_once_with({'uuid': uuids.instance})
|
||||
self.assertEqual({}, request_spec['image'])
|
||||
|
@ -54,8 +53,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
|||
|
||||
with mock.patch.object(instance, 'get_flavor') as mock_get:
|
||||
mock_get.return_value = instance_type
|
||||
request_spec = scheduler_utils.build_request_spec(self.context,
|
||||
None,
|
||||
request_spec = scheduler_utils.build_request_spec(None,
|
||||
[instance])
|
||||
mock_get.assert_called_once_with()
|
||||
self.assertIsInstance(request_spec['instance_properties'], dict)
|
||||
|
|
Loading…
Reference in New Issue