From 036fb56ab3779ebb37804487aecbfaa69e764b3b Mon Sep 17 00:00:00 2001 From: Kevin_Zheng Date: Tue, 22 May 2018 20:00:16 +0800 Subject: [PATCH] Only run placement request filters when Placement will be called Any enabled placement request filters are processed during scheduling here: https://github.com/openstack/nova/blob/d78055/nova/scheduler/manager.py#L127 But then if we're doing a rebuild, or the driver.USES_ALLOCATION_CANDIDATES is False, we don't call placement: https://github.com/openstack/nova/blob/d78055/nova/scheduler/manager.py#L132 https://github.com/openstack/nova/blob/d78055/nova/scheduler/manager.py#L135 So we're unnecessarily processing the request spec filters (like querying the aggregates table) in those conditions. Change-Id: I8ed019c2208c28bb733aac961e855ce77f332a1e Closes-bug: #1772523 --- nova/scheduler/manager.py | 14 ++++++++------ nova/tests/unit/scheduler/test_scheduler.py | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 6d2e902a37af..5c85642ac3a5 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -123,16 +123,18 @@ class SchedulerManager(manager.Manager): request_spec, filter_properties) - try: - request_filter.process_reqspec(ctxt, spec_obj) - except exception.RequestFilterFailed as e: - raise exception.NoValidHost(reason=e.message) - - resources = utils.resources_from_request_spec(spec_obj) is_rebuild = utils.request_is_rebuild(spec_obj) alloc_reqs_by_rp_uuid, provider_summaries, allocation_request_version \ = None, None, None if self.driver.USES_ALLOCATION_CANDIDATES and not is_rebuild: + # Only process the Placement request spec filters when Placement + # is used. + try: + request_filter.process_reqspec(ctxt, spec_obj) + except exception.RequestFilterFailed as e: + raise exception.NoValidHost(reason=e.message) + + resources = utils.resources_from_request_spec(spec_obj) res = self.placement_client.get_allocation_candidates(ctxt, resources) if res is None: diff --git a/nova/tests/unit/scheduler/test_scheduler.py b/nova/tests/unit/scheduler/test_scheduler.py index da152c102a86..f9ad1045ff50 100644 --- a/nova/tests/unit/scheduler/test_scheduler.py +++ b/nova/tests/unit/scheduler/test_scheduler.py @@ -227,10 +227,12 @@ class SchedulerManagerTestCase(test.NoDBTestCase): place_res = ([], {}, None) self._test_select_destination(place_res) + @mock.patch('nova.scheduler.request_filter.process_reqspec') @mock.patch('nova.scheduler.utils.resources_from_request_spec') @mock.patch('nova.scheduler.client.report.SchedulerReportClient.' 'get_allocation_candidates') - def test_select_destination_is_rebuild(self, mock_get_ac, mock_rfrs): + def test_select_destination_is_rebuild(self, mock_get_ac, mock_rfrs, + mock_process): fake_spec = objects.RequestSpec( scheduler_hints={'_nova_check_type': ['rebuild']}) fake_spec.instance_uuid = uuids.instance @@ -242,6 +244,7 @@ class SchedulerManagerTestCase(test.NoDBTestCase): self.context, fake_spec, [fake_spec.instance_uuid], None, None, None, False) mock_get_ac.assert_not_called() + mock_process.assert_not_called() @mock.patch('nova.scheduler.utils.resources_from_request_spec') @mock.patch('nova.scheduler.client.report.SchedulerReportClient.'