pep8 and fixed up zone-list

This commit is contained in:
Sandy Walsh
2011-03-22 20:36:49 -07:00
parent 26ab2a8414
commit b0e7ac2996
3 changed files with 46 additions and 23 deletions

View File

@@ -55,9 +55,27 @@ def get_zone_list(context):
items = _call_scheduler('get_zone_list', context) items = _call_scheduler('get_zone_list', context)
for item in items: for item in items:
item['api_url'] = item['api_url'].replace('\\/', '/') item['api_url'] = item['api_url'].replace('\\/', '/')
if not items:
items = db.zone_get_all(context)
return items return items
def zone_get(context, zone_id):
return db.zone_get(context, zone_id)
def zone_delete(context, zone_id):
return db.zone_delete(context, zone_id)
def zone_create(context, data):
return db.zone_create(context, data)
def zone_update(context, zone_id, data):
return db.zone_update(context, zone_id, data)
def get_zone_capabilities(context, service=None): def get_zone_capabilities(context, service=None):
"""Returns a dict of key, value capabilities for this zone, """Returns a dict of key, value capabilities for this zone,
or for a particular class of services running in this zone.""" or for a particular class of services running in this zone."""
@@ -149,10 +167,8 @@ class reroute_compute(object):
def __call__(self, f): def __call__(self, f):
def wrapped_f(*args, **kwargs): def wrapped_f(*args, **kwargs):
LOG.debug(_("IN DECORATOR ..."))
collection, context, item_id = \ collection, context, item_id = \
self.get_collection_context_and_id(args, kwargs) self.get_collection_context_and_id(args, kwargs)
LOG.debug(_("IN DECORATOR 2..."))
try: try:
# Call the original function ... # Call the original function ...
return f(*args, **kwargs) return f(*args, **kwargs)

View File

@@ -58,8 +58,9 @@ class ZoneState(object):
child zone.""" child zone."""
self.last_seen = datetime.now() self.last_seen = datetime.now()
self.attempt = 0 self.attempt = 0
self.name = zone_metadata["name"] self.name = zone_metadata.get("name", "n/a")
self.capabilities = zone_metadata["capabilities"] self.capabilities = ", ".join(["%s=%s" % (k, v)
for k, v in zone_metadata.iteritems() if k != 'name'])
self.is_active = True self.is_active = True
def to_dict(self): def to_dict(self):

View File

@@ -949,6 +949,7 @@ class FakeZone(object):
self.username = username self.username = username
self.password = password self.password = password
def zone_get_all(context): def zone_get_all(context):
return [ return [
FakeZone('http://example.com', 'bob', 'xxx'), FakeZone('http://example.com', 'bob', 'xxx'),
@@ -957,7 +958,7 @@ def zone_get_all(context):
class FakeRerouteCompute(api.reroute_compute): class FakeRerouteCompute(api.reroute_compute):
def _call_child_zones(self, zones, function): def _call_child_zones(self, zones, function):
return [ ] return []
def get_collection_context_and_id(self, args, kwargs): def get_collection_context_and_id(self, args, kwargs):
return ("servers", None, 1) return ("servers", None, 1)
@@ -982,6 +983,7 @@ class FakeResource(object):
def pause(self): def pause(self):
pass pass
class ZoneRedirectTest(test.TestCase): class ZoneRedirectTest(test.TestCase):
def setUp(self): def setUp(self):
super(ZoneRedirectTest, self).setUp() super(ZoneRedirectTest, self).setUp()
@@ -1034,18 +1036,19 @@ class ZoneRedirectTest(test.TestCase):
decorator = api.reroute_compute("foo") decorator = api.reroute_compute("foo")
self.assertEquals(decorator.unmarshall_result([]), {}) self.assertEquals(decorator.unmarshall_result([]), {})
self.assertEquals(decorator.unmarshall_result( self.assertEquals(decorator.unmarshall_result(
[FakeResource(dict(a=1, b=2)),]), [FakeResource(dict(a=1, b=2)), ]),
dict(server=dict(a=1, b=2))) dict(server=dict(a=1, b=2)))
self.assertEquals(decorator.unmarshall_result( self.assertEquals(decorator.unmarshall_result(
[FakeResource(dict(a=1, _b=2)),]), [FakeResource(dict(a=1, _b=2)), ]),
dict(server=dict(a=1,))) dict(server=dict(a=1,)))
self.assertEquals(decorator.unmarshall_result( self.assertEquals(decorator.unmarshall_result(
[FakeResource(dict(a=1, manager=2)),]), [FakeResource(dict(a=1, manager=2)), ]),
dict(server=dict(a=1,))) dict(server=dict(a=1,)))
self.assertEquals(decorator.unmarshall_result( self.assertEquals(decorator.unmarshall_result(
[FakeResource(dict(_a=1, manager=2)),]), [FakeResource(dict(_a=1, manager=2)), ]),
dict(server={})) dict(server={}))
class FakeServerCollection(object): class FakeServerCollection(object):
def get(self, instance_id): def get(self, instance_id):
return FakeResource(dict(a=10, b=20)) return FakeResource(dict(a=10, b=20))
@@ -1053,6 +1056,7 @@ class FakeServerCollection(object):
def find(self, name): def find(self, name):
return FakeResource(dict(a=11, b=22)) return FakeResource(dict(a=11, b=22))
class FakeEmptyServerCollection(object): class FakeEmptyServerCollection(object):
def get(self, f): def get(self, f):
raise novaclient.NotFound(1) raise novaclient.NotFound(1)
@@ -1060,10 +1064,12 @@ class FakeEmptyServerCollection(object):
def find(self, name): def find(self, name):
raise novaclient.NotFound(2) raise novaclient.NotFound(2)
class FakeNovaClient(object): class FakeNovaClient(object):
def __init__(self, collection): def __init__(self, collection):
self.servers = collection self.servers = collection
class DynamicNovaClientTest(test.TestCase): class DynamicNovaClientTest(test.TestCase):
def test_issue_novaclient_command_found(self): def test_issue_novaclient_command_found(self):
zone = FakeZone('http://example.com', 'bob', 'xxx') zone = FakeZone('http://example.com', 'bob', 'xxx')