new tests

This commit is contained in:
Sandy Walsh
2011-02-24 15:23:15 -08:00
parent 86d79a81a1
commit 507de7900b
3 changed files with 28 additions and 20 deletions

View File

@@ -25,34 +25,37 @@ FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.scheduler.api')
def _call_scheduler(method, context, params=None):
"""Generic handler for RPC calls to the scheduler.
:param params: Optional dictionary of arguments to be passed to the
scheduler worker
:retval: Result returned by scheduler worker
"""
if not params:
params = {}
queue = FLAGS.scheduler_topic
kwargs = {'method': method, 'args': params}
return rpc.call(context, queue, kwargs)
class API:
"""API for interacting with the scheduler."""
def _call_scheduler(self, method, context, params=None):
"""Generic handler for RPC calls to the scheduler.
:param params: Optional dictionary of arguments to be passed to the
scheduler worker
:retval: Result returned by scheduler worker
"""
if not params:
params = {}
queue = FLAGS.scheduler_topic
kwargs = {'method': method, 'args': params}
return rpc.call(context, queue, kwargs)
def get_zone_list(self, context):
@classmethod
def get_zone_list(cls, context):
"""Return a list of zones assoicated with this zone."""
items = self._call_scheduler('get_zone_list', context)
items = _call_scheduler('get_zone_list', context)
for item in items:
item['api_url'] = item['api_url'].replace('\\/', '/')
return items
def get_zone_capabilities(self, context, service=None):
@classmethod
def get_zone_capabilities(cls, context, service=None):
"""Returns a dict of key, value capabilities for this zone,
or for a particular class of services running in this zone."""
return self._call_scheduler('get_zone_capabilities', context=context,
return _call_scheduler('get_zone_capabilities', context=context,
params=dict(service=service))
@classmethod

View File

@@ -118,8 +118,7 @@ class ZoneManager(object):
<cap>_min and <cap>_max values."""
service_dict = self.service_states
if service:
service_dict = dict(service_name=service,
hosts=self.service_states.get(service, {}))
service_dict = {service: self.service_states.get(service, {})}
# TODO(sandy) - be smarter about fabricating this structure.
# But it's likely to change once we understand what the Best-Match

View File

@@ -104,6 +104,12 @@ class ZoneManagerTestCase(test.TestCase):
svc1_c=(5, 5), svc10_a=(99, 99),
svc10_b=(99, 99)))
caps = zm.get_zone_capabilities(self, 'svc1')
self.assertEquals(caps, dict(svc1_a=(2, 20), svc1_b=(3, 30),
svc1_c=(5, 5)))
caps = zm.get_zone_capabilities(self, 'svc10')
self.assertEquals(caps, dict(svc10_a=(99, 99), svc10_b=(99, 99)))
def test_refresh_from_db_replace_existing(self):
zm = zone_manager.ZoneManager()
zone_state = zone_manager.ZoneState()