summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-03-22 20:36:49 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-03-22 20:36:49 -0700
commit209da18033a49062bbcfaf7739db5959be87b142 (patch)
treea05b2626a9c5c1c346a5833fc4aca76089b82369 /nova
parent2a38aa7583be37ece6c42ba9307c2db0232dbed3 (diff)
downloadnova-209da18033a49062bbcfaf7739db5959be87b142.tar.gz
nova-209da18033a49062bbcfaf7739db5959be87b142.tar.xz
nova-209da18033a49062bbcfaf7739db5959be87b142.zip
pep8 and fixed up zone-list
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/servers.py2
-rw-r--r--nova/api/openstack/zones.py18
-rw-r--r--nova/db/api.py4
-rw-r--r--nova/scheduler/api.py24
-rw-r--r--nova/scheduler/zone_manager.py5
-rw-r--r--nova/tests/test_scheduler.py40
6 files changed, 53 insertions, 40 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 199d89c6d..db6a1de97 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -91,10 +91,8 @@ class Controller(wsgi.Controller):
def show(self, req, id):
""" Returns server details by server id """
try:
- LOG.debug(_("***SHOW"))
instance = self.compute_api.routing_get(
req.environ['nova.context'], id)
- LOG.debug(_("***SHOW OUT %s" % instance))
builder = servers_views.get_view_builder(req)
return builder.build(instance, is_detail=True)
except exception.NotFound:
diff --git a/nova/api/openstack/zones.py b/nova/api/openstack/zones.py
index d129cf34f..6ce27e9a9 100644
--- a/nova/api/openstack/zones.py
+++ b/nova/api/openstack/zones.py
@@ -15,7 +15,6 @@
import common
-from nova import db
from nova import flags
from nova import log as logging
from nova import wsgi
@@ -39,7 +38,8 @@ def _exclude_keys(item, keys):
def _scrub_zone(zone):
- return _filter_keys(zone, ('id', 'api_url'))
+ return _exclude_keys(zone, ('username', 'password', 'created_at',
+ 'deleted', 'deleted_at', 'updated_at'))
class Controller(wsgi.Controller):
@@ -54,12 +54,8 @@ class Controller(wsgi.Controller):
# Ask the ZoneManager in the Scheduler for most recent data,
# or fall-back to the database ...
items = api.get_zone_list(req.environ['nova.context'])
- if not items:
- items = db.zone_get_all(req.environ['nova.context'])
-
items = common.limited(items, req)
- items = [_exclude_keys(item, ['username', 'password'])
- for item in items]
+ items = [_scrub_zone(item) for item in items]
return dict(zones=items)
def detail(self, req):
@@ -82,23 +78,23 @@ class Controller(wsgi.Controller):
def show(self, req, id):
"""Return data about the given zone id"""
zone_id = int(id)
- zone = db.zone_get(req.environ['nova.context'], zone_id)
+ zone = api.zone_get(req.environ['nova.context'], zone_id)
return dict(zone=_scrub_zone(zone))
def delete(self, req, id):
zone_id = int(id)
- db.zone_delete(req.environ['nova.context'], zone_id)
+ api.zone_delete(req.environ['nova.context'], zone_id)
return {}
def create(self, req):
context = req.environ['nova.context']
env = self._deserialize(req.body, req.get_content_type())
- zone = db.zone_create(context, env["zone"])
+ zone = api.zone_create(context, env["zone"])
return dict(zone=_scrub_zone(zone))
def update(self, req, id):
context = req.environ['nova.context']
env = self._deserialize(req.body, req.get_content_type())
zone_id = int(id)
- zone = db.zone_update(context, zone_id, env["zone"])
+ zone = api.zone_update(context, zone_id, env["zone"])
return dict(zone=_scrub_zone(zone))
diff --git a/nova/db/api.py b/nova/db/api.py
index a4cdb2ae2..7aedaa772 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -34,7 +34,6 @@ The underlying driver is loaded as a :class:`LazyPluggable`.
from nova import exception
from nova import flags
-from nova import log as logging
from nova import utils
@@ -53,9 +52,6 @@ IMPL = utils.LazyPluggable(FLAGS['db_backend'],
sqlalchemy='nova.db.sqlalchemy.api')
-LOG = logging.getLogger('server')
-
-
class NoMoreAddresses(exception.Error):
"""No more available addresses."""
pass
diff --git a/nova/scheduler/api.py b/nova/scheduler/api.py
index bd64f9b9b..c1417dfe4 100644
--- a/nova/scheduler/api.py
+++ b/nova/scheduler/api.py
@@ -55,9 +55,27 @@ def get_zone_list(context):
items = _call_scheduler('get_zone_list', context)
for item in items:
item['api_url'] = item['api_url'].replace('\\/', '/')
+ if not items:
+ items = db.zone_get_all(context)
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):
"""Returns a dict of key, value capabilities for 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 wrapped_f(*args, **kwargs):
- LOG.debug(_("IN DECORATOR ..."))
collection, context, item_id = \
self.get_collection_context_and_id(args, kwargs)
- LOG.debug(_("IN DECORATOR 2..."))
try:
# Call the original function ...
return f(*args, **kwargs)
@@ -181,7 +197,7 @@ class reroute_compute(object):
"""Ask the child zones to perform this operation.
Broken out for testing."""
return child_zone_helper(zones, function)
-
+
def get_collection_context_and_id(self, args, kwargs):
"""Returns a tuple of (novaclient collection name, security
context and resource id. Derived class should override this."""
@@ -212,7 +228,7 @@ class reroute_compute(object):
del server[k]
reduced_response.append(dict(server=server))
- if reduced_response:
+ if reduced_response:
return reduced_response[0] # first for now.
return {}
diff --git a/nova/scheduler/zone_manager.py b/nova/scheduler/zone_manager.py
index d32cc2e8f..198f9d4cc 100644
--- a/nova/scheduler/zone_manager.py
+++ b/nova/scheduler/zone_manager.py
@@ -58,8 +58,9 @@ class ZoneState(object):
child zone."""
self.last_seen = datetime.now()
self.attempt = 0
- self.name = zone_metadata["name"]
- self.capabilities = zone_metadata["capabilities"]
+ self.name = zone_metadata.get("name", "n/a")
+ self.capabilities = ", ".join(["%s=%s" % (k, v)
+ for k, v in zone_metadata.iteritems() if k != 'name'])
self.is_active = True
def to_dict(self):
diff --git a/nova/tests/test_scheduler.py b/nova/tests/test_scheduler.py
index 277ffe367..6df74dd61 100644
--- a/nova/tests/test_scheduler.py
+++ b/nova/tests/test_scheduler.py
@@ -949,6 +949,7 @@ class FakeZone(object):
self.username = username
self.password = password
+
def zone_get_all(context):
return [
FakeZone('http://example.com', 'bob', 'xxx'),
@@ -957,8 +958,8 @@ def zone_get_all(context):
class FakeRerouteCompute(api.reroute_compute):
def _call_child_zones(self, zones, function):
- return [ ]
-
+ return []
+
def get_collection_context_and_id(self, args, kwargs):
return ("servers", None, 1)
@@ -982,6 +983,7 @@ class FakeResource(object):
def pause(self):
pass
+
class ZoneRedirectTest(test.TestCase):
def setUp(self):
super(ZoneRedirectTest, self).setUp()
@@ -1024,27 +1026,28 @@ class ZoneRedirectTest(test.TestCase):
def test_get_collection_context_and_id(self):
decorator = api.reroute_compute("foo")
self.assertEquals(decorator.get_collection_context_and_id(
- (None, 10, 20), {}), ("servers", 10, 20))
+ (None, 10, 20), {}), ("servers", 10, 20))
self.assertEquals(decorator.get_collection_context_and_id(
- (None, 11,), dict(instance_id=21)), ("servers", 11, 21))
+ (None, 11,), dict(instance_id=21)), ("servers", 11, 21))
self.assertEquals(decorator.get_collection_context_and_id(
(None,), dict(context=12, instance_id=22)), ("servers", 12, 22))
def test_unmarshal_single_server(self):
decorator = api.reroute_compute("foo")
- self.assertEquals(decorator.unmarshall_result([]), {})
+ self.assertEquals(decorator.unmarshall_result([]), {})
self.assertEquals(decorator.unmarshall_result(
- [FakeResource(dict(a=1, b=2)),]),
- dict(server=dict(a=1, b=2)))
+ [FakeResource(dict(a=1, b=2)), ]),
+ dict(server=dict(a=1, b=2)))
self.assertEquals(decorator.unmarshall_result(
- [FakeResource(dict(a=1, _b=2)),]),
- dict(server=dict(a=1,)))
+ [FakeResource(dict(a=1, _b=2)), ]),
+ dict(server=dict(a=1,)))
self.assertEquals(decorator.unmarshall_result(
- [FakeResource(dict(a=1, manager=2)),]),
- dict(server=dict(a=1,)))
+ [FakeResource(dict(a=1, manager=2)), ]),
+ dict(server=dict(a=1,)))
self.assertEquals(decorator.unmarshall_result(
- [FakeResource(dict(_a=1, manager=2)),]),
- dict(server={}))
+ [FakeResource(dict(_a=1, manager=2)), ]),
+ dict(server={}))
+
class FakeServerCollection(object):
def get(self, instance_id):
@@ -1053,6 +1056,7 @@ class FakeServerCollection(object):
def find(self, name):
return FakeResource(dict(a=11, b=22))
+
class FakeEmptyServerCollection(object):
def get(self, f):
raise novaclient.NotFound(1)
@@ -1060,10 +1064,12 @@ class FakeEmptyServerCollection(object):
def find(self, name):
raise novaclient.NotFound(2)
+
class FakeNovaClient(object):
def __init__(self, collection):
self.servers = collection
+
class DynamicNovaClientTest(test.TestCase):
def test_issue_novaclient_command_found(self):
zone = FakeZone('http://example.com', 'bob', 'xxx')
@@ -1078,17 +1084,17 @@ class DynamicNovaClientTest(test.TestCase):
self.assertEquals(api._issue_novaclient_command(
FakeNovaClient(FakeServerCollection()),
zone, "servers", "pause", 100), None)
-
+
def test_issue_novaclient_command_not_found(self):
zone = FakeZone('http://example.com', 'bob', 'xxx')
self.assertEquals(api._issue_novaclient_command(
FakeNovaClient(FakeEmptyServerCollection()),
- zone, "servers", "get", 100), None)
+ zone, "servers", "get", 100), None)
self.assertEquals(api._issue_novaclient_command(
FakeNovaClient(FakeEmptyServerCollection()),
- zone, "servers", "find", "name"), None)
+ zone, "servers", "find", "name"), None)
self.assertEquals(api._issue_novaclient_command(
FakeNovaClient(FakeEmptyServerCollection()),
- zone, "servers", "any", "name"), None)
+ zone, "servers", "any", "name"), None)