make the driver.Scheduler as abstract class
method select_destinations is the abstract method, every subclass of Scheduler should override, so add abstractmethod decorator Change-Id: Ib9edd7ac9fc024543efb0b878431fa8351c68a45
This commit is contained in:
committed by
venkatesh
parent
f5e3c7d54a
commit
865d6e518f
@@ -19,11 +19,13 @@
|
||||
Scheduler base class that all Schedulers should inherit from
|
||||
"""
|
||||
|
||||
import abc
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from nova import db
|
||||
from nova.i18n import _
|
||||
from nova import servicegroup
|
||||
|
||||
scheduler_driver_opts = [
|
||||
@@ -36,6 +38,7 @@ CONF = cfg.CONF
|
||||
CONF.register_opts(scheduler_driver_opts)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Scheduler(object):
|
||||
"""The base class that all Scheduler classes should inherit from."""
|
||||
|
||||
@@ -56,11 +59,11 @@ class Scheduler(object):
|
||||
for service in services
|
||||
if self.servicegroup_api.service_is_up(service)]
|
||||
|
||||
@abc.abstractmethod
|
||||
def select_destinations(self, context, request_spec, filter_properties):
|
||||
"""Must override select_destinations method.
|
||||
|
||||
:return: A list of dicts with 'host', 'nodename' and 'limits' as keys
|
||||
that satisfies the request_spec and filter_properties.
|
||||
"""
|
||||
msg = _("Driver must implement select_destinations")
|
||||
raise NotImplementedError(msg)
|
||||
return []
|
||||
|
||||
@@ -19,6 +19,7 @@ Fakes For Scheduler tests.
|
||||
import six
|
||||
|
||||
from nova import objects
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import host_manager
|
||||
|
||||
NUMA_TOPOLOGY = objects.NUMATopology(
|
||||
@@ -96,3 +97,9 @@ class FakeHostState(host_manager.HostState):
|
||||
self.instances = {}
|
||||
for (key, val) in six.iteritems(attribute_dict):
|
||||
setattr(self, key, val)
|
||||
|
||||
|
||||
class FakeScheduler(driver.Scheduler):
|
||||
|
||||
def select_destinations(self, context, request_spec, filter_properties):
|
||||
return []
|
||||
|
||||
@@ -21,20 +21,20 @@ import mock
|
||||
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import host_manager
|
||||
from nova.scheduler import manager
|
||||
from nova import servicegroup
|
||||
from nova import test
|
||||
from nova.tests.unit import fake_server_actions
|
||||
from nova.tests.unit.scheduler import fakes
|
||||
|
||||
|
||||
class SchedulerManagerTestCase(test.NoDBTestCase):
|
||||
"""Test case for scheduler manager."""
|
||||
|
||||
manager_cls = manager.SchedulerManager
|
||||
driver_cls = driver.Scheduler
|
||||
driver_cls_name = 'nova.scheduler.driver.Scheduler'
|
||||
driver_cls = fakes.FakeScheduler
|
||||
driver_cls_name = 'nova.tests.unit.scheduler.fakes.FakeScheduler'
|
||||
|
||||
@mock.patch.object(host_manager.HostManager, '_init_instance_info')
|
||||
@mock.patch.object(host_manager.HostManager, '_init_aggregates')
|
||||
@@ -109,7 +109,7 @@ class SchedulerTestCase(test.NoDBTestCase):
|
||||
"""Test case for base scheduler driver class."""
|
||||
|
||||
# So we can subclass this test and re-use tests if we need.
|
||||
driver_cls = driver.Scheduler
|
||||
driver_cls = fakes.FakeScheduler
|
||||
|
||||
@mock.patch.object(host_manager.HostManager, '_init_instance_info')
|
||||
@mock.patch.object(host_manager.HostManager, '_init_aggregates')
|
||||
@@ -138,19 +138,9 @@ class SchedulerTestCase(test.NoDBTestCase):
|
||||
self.assertEqual(result, ['host2'])
|
||||
|
||||
|
||||
class SchedulerDriverBaseTestCase(SchedulerTestCase):
|
||||
"""Test cases for base scheduler driver class methods
|
||||
that will fail if the driver is changed.
|
||||
"""
|
||||
|
||||
def test_unimplemented_select_destinations(self):
|
||||
self.assertRaises(NotImplementedError,
|
||||
self.driver.select_destinations, self.context, {}, {})
|
||||
|
||||
|
||||
class SchedulerInstanceGroupData(test.NoDBTestCase):
|
||||
|
||||
driver_cls = driver.Scheduler
|
||||
driver_cls = fakes.FakeScheduler
|
||||
|
||||
def setUp(self):
|
||||
super(SchedulerInstanceGroupData, self).setUp()
|
||||
|
||||
Reference in New Issue
Block a user