Merge "Optimize AZ lookup during schedule_and_build_instances"
This commit is contained in:
commit
6a322186f7
@ -1214,6 +1214,7 @@ class ComputeTaskManager(base.Base):
|
|||||||
host_mapping_cache = {}
|
host_mapping_cache = {}
|
||||||
cell_mapping_cache = {}
|
cell_mapping_cache = {}
|
||||||
instances = []
|
instances = []
|
||||||
|
host_az = {} # host=az cache to optimize multi-create
|
||||||
|
|
||||||
for (build_request, request_spec, host_list) in six.moves.zip(
|
for (build_request, request_spec, host_list) in six.moves.zip(
|
||||||
build_requests, request_specs, host_lists):
|
build_requests, request_specs, host_lists):
|
||||||
@ -1259,9 +1260,11 @@ class ComputeTaskManager(base.Base):
|
|||||||
rc.delete_allocation_for_instance(context, instance.uuid)
|
rc.delete_allocation_for_instance(context, instance.uuid)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
instance.availability_zone = (
|
if host.service_host not in host_az:
|
||||||
availability_zones.get_host_availability_zone(
|
host_az[host.service_host] = (
|
||||||
context, host.service_host))
|
availability_zones.get_host_availability_zone(
|
||||||
|
context, host.service_host))
|
||||||
|
instance.availability_zone = host_az[host.service_host]
|
||||||
with obj_target_cell(instance, cell):
|
with obj_target_cell(instance, cell):
|
||||||
instance.create()
|
instance.create()
|
||||||
instances.append(instance)
|
instances.append(instance)
|
||||||
|
@ -1626,7 +1626,9 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
|||||||
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
||||||
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
|
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
|
||||||
@mock.patch('nova.objects.HostMapping.get_by_host')
|
@mock.patch('nova.objects.HostMapping.get_by_host')
|
||||||
def test_schedule_and_build_multiple_instances(self,
|
@mock.patch('nova.availability_zones.get_host_availability_zone',
|
||||||
|
return_value='nova')
|
||||||
|
def test_schedule_and_build_multiple_instances(self, mock_get_az,
|
||||||
get_hostmapping,
|
get_hostmapping,
|
||||||
select_destinations,
|
select_destinations,
|
||||||
build_and_run_instance):
|
build_and_run_instance):
|
||||||
@ -1679,6 +1681,11 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
|||||||
build_and_run_instance.side_effect = _build_and_run_instance
|
build_and_run_instance.side_effect = _build_and_run_instance
|
||||||
self.conductor.schedule_and_build_instances(**params)
|
self.conductor.schedule_and_build_instances(**params)
|
||||||
self.assertEqual(3, build_and_run_instance.call_count)
|
self.assertEqual(3, build_and_run_instance.call_count)
|
||||||
|
# We're processing 4 instances over 2 hosts, so we should only lookup
|
||||||
|
# the AZ per host once.
|
||||||
|
mock_get_az.assert_has_calls([
|
||||||
|
mock.call(self.ctxt, 'host1'), mock.call(self.ctxt, 'host2')],
|
||||||
|
any_order=True)
|
||||||
|
|
||||||
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
||||||
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
|
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
|
||||||
|
Loading…
Reference in New Issue
Block a user