Add request filter functionality to scheduler

This adds a pre-placement step where we can call a number of modular
"request filters" to modify the request_spec before we move on to
construct the call to placement to get allocation candidates.

No filters are added at this time, this just adds the infrastructure.

Related to blueprint placement-req-filter

Change-Id: I1535158a0dbd4a8527bb987e085e9391e5b0fde4
This commit is contained in:
Dan Smith 2018-02-14 11:46:27 -08:00
parent cd15c3d6ec
commit 5f36cafacd
4 changed files with 79 additions and 0 deletions

View File

@ -1396,6 +1396,10 @@ class NoValidHost(NovaException):
msg_fmt = _("No valid host was found. %(reason)s")
class RequestFilterFailed(NovaException):
msg_fmt = _("Scheduling failed: %(reason)s")
class MaxRetriesExceeded(NoValidHost):
msg_fmt = _("Exceeded maximum number of retries. %(reason)s")

View File

@ -35,6 +35,7 @@ from nova import objects
from nova.objects import host_mapping as host_mapping_obj
from nova import quota
from nova.scheduler import client as scheduler_client
from nova.scheduler import request_filter
from nova.scheduler import utils
@ -115,6 +116,12 @@ class SchedulerManager(manager.Manager):
spec_obj = objects.RequestSpec.from_primitives(ctxt,
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)
alloc_reqs_by_rp_uuid, provider_summaries, allocation_request_version \
= None, None, None

View File

@ -0,0 +1,33 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
import nova.conf
CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)
ALL_REQUEST_FILTERS = [
]
def process_reqspec(ctxt, request_spec):
"""Process an objects.ReqestSpec before calling placement.
:param ctxt: A RequestContext
:param request_spec: An objects.RequestSpec to be inspected/modified
"""
for filter in ALL_REQUEST_FILTERS:
filter(ctxt, request_spec)

View File

@ -0,0 +1,35 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from nova import context as nova_context
from nova.scheduler import request_filter
from nova import test
from nova.tests import uuidsentinel as uuids
class TestRequestFilter(test.NoDBTestCase):
def setUp(self):
super(TestRequestFilter, self).setUp()
self.context = nova_context.RequestContext(user_id=uuids.user,
project_id=uuids.project)
def test_process_reqspec(self):
fake_filters = [mock.MagicMock(), mock.MagicMock()]
with mock.patch('nova.scheduler.request_filter.ALL_REQUEST_FILTERS',
new=fake_filters):
request_filter.process_reqspec(mock.sentinel.context,
mock.sentinel.reqspec)
for filter in fake_filters:
filter.assert_called_once_with(mock.sentinel.context,
mock.sentinel.reqspec)