Merge "Added in doubt default pool filter to scheduler"
This commit is contained in:
commit
6bab307396
56
designate/scheduler/filters/in_doubt_default_pool_filter.py
Normal file
56
designate/scheduler/filters/in_doubt_default_pool_filter.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Copyright 2017 SAP SE
|
||||
#
|
||||
# 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_config import cfg
|
||||
|
||||
from designate.scheduler.filters import base
|
||||
from designate import objects
|
||||
|
||||
cfg.CONF.register_opts([
|
||||
cfg.StrOpt('default_pool_id',
|
||||
default='794ccc2c-d751-44fe-b57f-8894c9f5c842',
|
||||
help="The name of the default pool"),
|
||||
], group='service:central')
|
||||
|
||||
|
||||
class InDoubtDefaultPoolFilter(base.Filter):
|
||||
"""If the previous filter(s) didn't make a clear selection of one pool
|
||||
and if the default pool is in the set of multiple pools, this filter will
|
||||
select the default pool.
|
||||
|
||||
This filter will pass through the pool list, if there are one or
|
||||
less pools available to schedule to, or if the default pool is
|
||||
not in the set of multiple pools.
|
||||
|
||||
.. note::
|
||||
|
||||
This should be used as one of the last filters.
|
||||
|
||||
"""
|
||||
|
||||
name = 'in_doubt_default_pool'
|
||||
"""Name to enable in the ``[designate:central:scheduler].filters`` option
|
||||
list
|
||||
"""
|
||||
|
||||
def filter(self, context, pools, zone):
|
||||
if len(pools):
|
||||
default_pool_id = cfg.CONF['service:central'].default_pool_id
|
||||
default_pool = objects.Pool(id=default_pool_id)
|
||||
|
||||
if default_pool in pools:
|
||||
pools = objects.PoolList()
|
||||
pools.append(default_pool)
|
||||
|
||||
return pools
|
@ -23,6 +23,7 @@ from designate.scheduler.filters import default_pool_filter
|
||||
from designate.scheduler.filters import fallback_filter
|
||||
from designate.scheduler.filters import pool_id_attribute_filter
|
||||
from designate.scheduler.filters import attribute_filter
|
||||
from designate.scheduler.filters import in_doubt_default_pool_filter
|
||||
from designate import objects
|
||||
from designate import context
|
||||
from designate import policy
|
||||
@ -421,3 +422,36 @@ class SchedulerAttributeFilterTest(SchedulerFilterTest):
|
||||
pools = self.test_filter.filter(self.context, pools, self.zone)
|
||||
|
||||
self.assertEqual(0, len(pools))
|
||||
|
||||
|
||||
class SchedulerInDoubtDefaultPoolFilterTest(SchedulerFilterTest):
|
||||
|
||||
FILTER = in_doubt_default_pool_filter.InDoubtDefaultPoolFilter
|
||||
|
||||
def test_pools_with_default(self):
|
||||
pools = objects.PoolList.from_list(
|
||||
[
|
||||
{"id": "794ccc2c-d751-44fe-b57f-8894c9f5c842"},
|
||||
{"id": "5fabcd37-262c-4cf3-8625-7f419434b6df"}
|
||||
]
|
||||
)
|
||||
pools = self.test_filter.filter(self.context, pools, self.zone)
|
||||
|
||||
self.assertEqual(pools[0].id, "794ccc2c-d751-44fe-b57f-8894c9f5c842")
|
||||
|
||||
def test_pools_without_default(self):
|
||||
pools = objects.PoolList.from_list(
|
||||
[
|
||||
{"id": "24702e43-8a52-440f-ab74-19fc16048860"},
|
||||
{"id": "5fabcd37-262c-4cf3-8625-7f419434b6df"}
|
||||
]
|
||||
)
|
||||
pools = self.test_filter.filter(self.context, pools, self.zone)
|
||||
|
||||
self.assertEqual(2, len(pools))
|
||||
|
||||
def test_no_pools(self):
|
||||
pools = objects.PoolList()
|
||||
pools = self.test_filter.filter(self.context, pools, self.zone)
|
||||
|
||||
self.assertEqual(0, len(pools))
|
||||
|
@ -102,3 +102,10 @@ Default Pool Filter
|
||||
.. autoclass:: designate.scheduler.filters.default_pool_filter.DefaultPoolFilter
|
||||
:members: name
|
||||
:show-inheritance:
|
||||
|
||||
In Doubt Default Pool Filter
|
||||
----------------------------
|
||||
|
||||
.. autoclass:: designate.scheduler.filters.in_doubt_default_pool_filter.InDoubtDefaultPoolFilter
|
||||
:members: name
|
||||
:show-inheritance:
|
||||
|
@ -117,6 +117,7 @@ designate.scheduler.filters =
|
||||
random = designate.scheduler.filters.random_filter:RandomFilter
|
||||
pool_id_attribute = designate.scheduler.filters.pool_id_attribute_filter:PoolIDAttributeFilter
|
||||
default_pool = designate.scheduler.filters.default_pool_filter:DefaultPoolFilter
|
||||
in_doubt_default_pool = designate.scheduler.filters.in_doubt_default_pool_filter:InDoubtDefaultPoolFilter
|
||||
|
||||
designate.manage =
|
||||
database = designate.manage.database:DatabaseCommands
|
||||
|
Loading…
Reference in New Issue
Block a user