Modernized scheduler tests
* Renamed folder test_scheduler to scheduler. * Cleanedup tests and standardized them. Change-Id: I68d54277dfb7c1cbc14db4e1739137b9a6982b42
This commit is contained in:
+39
-53
@@ -11,36 +11,26 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Unit-test Pool Scheduler
|
||||
"""
|
||||
import testtools
|
||||
from mock import Mock
|
||||
from oslotest import base as test
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as cfg_fixture
|
||||
|
||||
from designate import scheduler
|
||||
from designate import objects
|
||||
from designate import context
|
||||
from designate import exceptions
|
||||
from designate import objects
|
||||
from designate import scheduler
|
||||
from designate import tests
|
||||
|
||||
|
||||
class SchedulerTest(test.BaseTestCase):
|
||||
class SchedulerTest(tests.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SchedulerTest, self).setUp()
|
||||
|
||||
self.context = context.DesignateContext()
|
||||
self.CONF = self.useFixture(cfg_fixture.Config(cfg.CONF)).conf
|
||||
|
||||
def test_default_operation(self):
|
||||
zone = objects.Zone(
|
||||
self.context = self.get_context()
|
||||
self.zone = objects.Zone(
|
||||
name="example.com.",
|
||||
type="PRIMARY",
|
||||
email="hostmaster@example.com"
|
||||
)
|
||||
|
||||
def test_default_operation(self):
|
||||
attrs = {
|
||||
'find_pools.return_value': objects.PoolList.from_list(
|
||||
[{"id": "794ccc2c-d751-44fe-b57f-8894c9f5c842"}])
|
||||
@@ -49,17 +39,13 @@ class SchedulerTest(test.BaseTestCase):
|
||||
|
||||
test_scheduler = scheduler.get_scheduler(storage=mock_storage)
|
||||
|
||||
zone.pool_id = test_scheduler.schedule_zone(self.context, zone)
|
||||
self.zone.pool_id = test_scheduler.schedule_zone(self.context,
|
||||
self.zone)
|
||||
|
||||
self.assertEqual(zone.pool_id, "794ccc2c-d751-44fe-b57f-8894c9f5c842")
|
||||
self.assertEqual(self.zone.pool_id,
|
||||
"794ccc2c-d751-44fe-b57f-8894c9f5c842")
|
||||
|
||||
def test_multiple_pools(self):
|
||||
zone = objects.Zone(
|
||||
name="example.com.",
|
||||
type="PRIMARY",
|
||||
email="hostmaster@example.com"
|
||||
)
|
||||
|
||||
attrs = {
|
||||
'find_pools.return_value': objects.PoolList.from_list(
|
||||
[
|
||||
@@ -73,10 +59,11 @@ class SchedulerTest(test.BaseTestCase):
|
||||
|
||||
test_scheduler = scheduler.get_scheduler(storage=mock_storage)
|
||||
|
||||
zone.pool_id = test_scheduler.schedule_zone(self.context, zone)
|
||||
self.zone.pool_id = test_scheduler.schedule_zone(self.context,
|
||||
self.zone)
|
||||
|
||||
self.assertIn(
|
||||
zone.pool_id,
|
||||
self.zone.pool_id,
|
||||
[
|
||||
"794ccc2c-d751-44fe-b57f-8894c9f5c842",
|
||||
"5fabcd37-262c-4cf3-8625-7f419434b6df",
|
||||
@@ -84,10 +71,26 @@ class SchedulerTest(test.BaseTestCase):
|
||||
)
|
||||
|
||||
def test_no_pools(self):
|
||||
zone = objects.Zone(
|
||||
name="example.com.",
|
||||
type="PRIMARY",
|
||||
email="hostmaster@example.com"
|
||||
attrs = {
|
||||
'find_pools.return_value': objects.PoolList()
|
||||
}
|
||||
mock_storage = Mock(**attrs)
|
||||
|
||||
self.CONF.set_override(
|
||||
'scheduler_filters', ['random'], 'service:central'
|
||||
)
|
||||
|
||||
test_scheduler = scheduler.get_scheduler(storage=mock_storage)
|
||||
|
||||
self.assertRaisesRegex(
|
||||
exceptions.NoValidPoolFound,
|
||||
'There are no pools that matched your request',
|
||||
test_scheduler.schedule_zone, self.context, self.zone,
|
||||
)
|
||||
|
||||
def test_no_filters_enabled(self):
|
||||
self.CONF.set_override(
|
||||
'scheduler_filters', [], 'service:central'
|
||||
)
|
||||
|
||||
attrs = {
|
||||
@@ -95,25 +98,8 @@ class SchedulerTest(test.BaseTestCase):
|
||||
}
|
||||
mock_storage = Mock(**attrs)
|
||||
|
||||
cfg.CONF.set_override(
|
||||
'scheduler_filters',
|
||||
['random'],
|
||||
'service:central')
|
||||
|
||||
test_scheduler = scheduler.get_scheduler(storage=mock_storage)
|
||||
|
||||
with testtools.ExpectedException(exceptions.NoValidPoolFound):
|
||||
test_scheduler.schedule_zone(self.context, zone)
|
||||
|
||||
def test_no_filters_enabled(self):
|
||||
|
||||
cfg.CONF.set_override(
|
||||
'scheduler_filters', [], 'service:central')
|
||||
|
||||
attrs = {
|
||||
'find_pools.return_value': objects.PoolList()
|
||||
}
|
||||
mock_storage = Mock(**attrs)
|
||||
|
||||
with testtools.ExpectedException(exceptions.NoFiltersConfigured):
|
||||
scheduler.get_scheduler(storage=mock_storage)
|
||||
self.assertRaisesRegex(
|
||||
exceptions.NoFiltersConfigured,
|
||||
'There are no scheduling filters configured',
|
||||
scheduler.get_scheduler, mock_storage,
|
||||
)
|
||||
+12
-26
@@ -11,32 +11,24 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Unit-test Pool Scheduler
|
||||
"""
|
||||
import fixtures
|
||||
import testtools
|
||||
from mock import Mock
|
||||
from oslotest import base as test
|
||||
|
||||
from designate import exceptions
|
||||
from designate import objects
|
||||
from designate import policy
|
||||
from designate import tests
|
||||
from designate.scheduler.filters import attribute_filter
|
||||
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
|
||||
from designate import exceptions
|
||||
from designate.scheduler.filters import pool_id_attribute_filter
|
||||
|
||||
|
||||
class SchedulerFilterTest(test.BaseTestCase):
|
||||
|
||||
class SchedulerFilterTest(tests.TestCase):
|
||||
def setUp(self):
|
||||
super(SchedulerFilterTest, self).setUp()
|
||||
|
||||
self.context = context.DesignateContext()
|
||||
|
||||
self.context = self.get_context()
|
||||
self.zone = objects.Zone(
|
||||
name="example.com.",
|
||||
type="PRIMARY",
|
||||
@@ -49,12 +41,10 @@ class SchedulerFilterTest(test.BaseTestCase):
|
||||
}
|
||||
|
||||
mock_storage = Mock(**attrs)
|
||||
|
||||
self.test_filter = self.FILTER(storage=mock_storage)
|
||||
|
||||
|
||||
class SchedulerDefaultPoolFilterTest(SchedulerFilterTest):
|
||||
|
||||
FILTER = default_pool_filter.DefaultPoolFilter
|
||||
|
||||
def test_default_operation(self):
|
||||
@@ -84,7 +74,6 @@ class SchedulerDefaultPoolFilterTest(SchedulerFilterTest):
|
||||
|
||||
|
||||
class SchedulerFallbackFilterTest(SchedulerFilterTest):
|
||||
|
||||
FILTER = fallback_filter.FallbackFilter
|
||||
|
||||
def test_default_operation(self):
|
||||
@@ -123,12 +112,10 @@ class SchedulerFallbackFilterTest(SchedulerFilterTest):
|
||||
|
||||
|
||||
class SchedulerPoolIDAttributeFilterTest(SchedulerFilterTest):
|
||||
|
||||
FILTER = pool_id_attribute_filter.PoolIDAttributeFilter
|
||||
|
||||
def setUp(self):
|
||||
super(SchedulerPoolIDAttributeFilterTest, self).setUp()
|
||||
|
||||
self.zone = objects.Zone(
|
||||
name="example.com.",
|
||||
type="PRIMARY",
|
||||
@@ -197,8 +184,10 @@ class SchedulerPoolIDAttributeFilterTest(SchedulerFilterTest):
|
||||
side_effect=exceptions.Forbidden
|
||||
))
|
||||
|
||||
with testtools.ExpectedException(exceptions.Forbidden):
|
||||
self.test_filter.filter(self.context, pools, self.zone)
|
||||
self.assertRaises(
|
||||
exceptions.Forbidden,
|
||||
self.test_filter.filter, self.context, pools, self.zone,
|
||||
)
|
||||
|
||||
policy.check.assert_called_once_with(
|
||||
'zone_create_forced_pool',
|
||||
@@ -207,12 +196,10 @@ class SchedulerPoolIDAttributeFilterTest(SchedulerFilterTest):
|
||||
|
||||
|
||||
class SchedulerAttributeFilterTest(SchedulerFilterTest):
|
||||
|
||||
FILTER = attribute_filter.AttributeFilter
|
||||
|
||||
def setUp(self):
|
||||
super(SchedulerAttributeFilterTest, self).setUp()
|
||||
|
||||
self.zone = objects.Zone(
|
||||
name="example.com.",
|
||||
type="PRIMARY",
|
||||
@@ -425,7 +412,6 @@ class SchedulerAttributeFilterTest(SchedulerFilterTest):
|
||||
|
||||
|
||||
class SchedulerInDoubtDefaultPoolFilterTest(SchedulerFilterTest):
|
||||
|
||||
FILTER = in_doubt_default_pool_filter.InDoubtDefaultPoolFilter
|
||||
|
||||
def test_pools_with_default(self):
|
||||
Reference in New Issue
Block a user