tests fixed and pep8'ed
This commit is contained in:
@@ -292,11 +292,15 @@ def choose_driver(driver_name=None):
|
|||||||
class HostFilterScheduler(zone_aware_scheduler.ZoneAwareScheduler):
|
class HostFilterScheduler(zone_aware_scheduler.ZoneAwareScheduler):
|
||||||
"""The HostFilterScheduler uses the HostFilter drivers to filter
|
"""The HostFilterScheduler uses the HostFilter drivers to filter
|
||||||
hosts for weighing. The particular driver used may be passed in
|
hosts for weighing. The particular driver used may be passed in
|
||||||
as an argument or the default will be used."""
|
as an argument or the default will be used.
|
||||||
|
|
||||||
|
request_spec = {'filter_driver': <Filter Driver name>,
|
||||||
|
'instance_type': <InstanceType dict>}
|
||||||
|
"""
|
||||||
|
|
||||||
def filter_hosts(self, num, request_spec):
|
def filter_hosts(self, num, request_spec):
|
||||||
"""Filter the full host list (from the ZoneManager)"""
|
"""Filter the full host list (from the ZoneManager)"""
|
||||||
driver_name = request_spec.get("filter_driver", None)
|
driver_name = request_spec.get('filter_driver', None)
|
||||||
driver = choose_driver(driver_name)
|
driver = choose_driver(driver_name)
|
||||||
|
|
||||||
# TODO(sandy): We're only using InstanceType-based specs
|
# TODO(sandy): We're only using InstanceType-based specs
|
||||||
@@ -309,4 +313,4 @@ class HostFilterScheduler(zone_aware_scheduler.ZoneAwareScheduler):
|
|||||||
def weigh_hosts(self, num, request_spec, hosts):
|
def weigh_hosts(self, num, request_spec, hosts):
|
||||||
"""Derived classes must override this method and return
|
"""Derived classes must override this method and return
|
||||||
a lists of hosts in [{weight, hostname}] format."""
|
a lists of hosts in [{weight, hostname}] format."""
|
||||||
return []
|
return [dict(weight=1, hostname=hostname) for host, caps in hosts]
|
||||||
|
|||||||
@@ -59,20 +59,25 @@ class ZoneAwareScheduler(driver.Scheduler):
|
|||||||
for item in build_plan:
|
for item in build_plan:
|
||||||
self.provision_instance(context, topic, item)
|
self.provision_instance(context, topic, item)
|
||||||
|
|
||||||
|
# Returning None short-circuits the routing to Compute (since
|
||||||
|
# we've already done it here)
|
||||||
|
return None
|
||||||
|
|
||||||
def provision_instance(context, topic, item):
|
def provision_instance(context, topic, item):
|
||||||
"""Create the requested instance in this Zone or a child zone."""
|
"""Create the requested instance in this Zone or a child zone."""
|
||||||
pass
|
return None
|
||||||
|
|
||||||
def select(self, context, request_spec, *args, **kwargs):
|
def select(self, context, request_spec, *args, **kwargs):
|
||||||
"""Select returns a list of weights and zone/host information
|
"""Select returns a list of weights and zone/host information
|
||||||
corresponding to the best hosts to service the request. Any
|
corresponding to the best hosts to service the request. Any
|
||||||
child zone information has been encrypted so as not to reveal
|
child zone information has been encrypted so as not to reveal
|
||||||
anything about the children."""
|
anything about the children."""
|
||||||
return self._schedule(context, "compute", request_spec, *args, **kwargs)
|
return self._schedule(context, "compute", request_spec,
|
||||||
|
*args, **kwargs)
|
||||||
|
|
||||||
# TODO(sandy): We're only focused on compute instances right now,
|
# TODO(sandy): We're only focused on compute instances right now,
|
||||||
# so we don't implement the default "schedule()" method required
|
# so we don't implement the default "schedule()" method required
|
||||||
# of Schedulers.
|
# of Schedulers.
|
||||||
def schedule(self, context, topic, request_spec, *args, **kwargs):
|
def schedule(self, context, topic, request_spec, *args, **kwargs):
|
||||||
"""The schedule() contract requires we return the one
|
"""The schedule() contract requires we return the one
|
||||||
best-suited host for this request.
|
best-suited host for this request.
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ class HostFilterTestCase(test.TestCase):
|
|||||||
'nova.scheduler.host_filter.AllHostsFilter')
|
'nova.scheduler.host_filter.AllHostsFilter')
|
||||||
# Test valid driver ...
|
# Test valid driver ...
|
||||||
driver = host_filter.choose_driver(
|
driver = host_filter.choose_driver(
|
||||||
'nova.scheduler.host_filter.FlavorFilter')
|
'nova.scheduler.host_filter.InstanceTypeFilter')
|
||||||
self.assertEquals(driver._full_name(),
|
self.assertEquals(driver._full_name(),
|
||||||
'nova.scheduler.host_filter.FlavorFilter')
|
'nova.scheduler.host_filter.InstanceTypeFilter')
|
||||||
# Test invalid driver ...
|
# Test invalid driver ...
|
||||||
try:
|
try:
|
||||||
host_filter.choose_driver('does not exist')
|
host_filter.choose_driver('does not exist')
|
||||||
@@ -103,11 +103,12 @@ class HostFilterTestCase(test.TestCase):
|
|||||||
for host, capabilities in hosts:
|
for host, capabilities in hosts:
|
||||||
self.assertTrue(host.startswith('host'))
|
self.assertTrue(host.startswith('host'))
|
||||||
|
|
||||||
def test_flavor_driver(self):
|
def test_instance_type_driver(self):
|
||||||
driver = host_filter.FlavorFilter()
|
driver = host_filter.InstanceTypeFilter()
|
||||||
# filter all hosts that can support 50 ram and 500 disk
|
# filter all hosts that can support 50 ram and 500 disk
|
||||||
name, cooked = driver.instance_type_to_filter(self.instance_type)
|
name, cooked = driver.instance_type_to_filter(self.instance_type)
|
||||||
self.assertEquals('nova.scheduler.host_filter.FlavorFilter', name)
|
self.assertEquals('nova.scheduler.host_filter.InstanceTypeFilter',
|
||||||
|
name)
|
||||||
hosts = driver.filter_hosts(self.zone_manager, cooked)
|
hosts = driver.filter_hosts(self.zone_manager, cooked)
|
||||||
self.assertEquals(6, len(hosts))
|
self.assertEquals(6, len(hosts))
|
||||||
just_hosts = [host for host, caps in hosts]
|
just_hosts = [host for host, caps in hosts]
|
||||||
|
|||||||
Reference in New Issue
Block a user