diff options
| author | Brian Waldon <brian.waldon@rackspace.com> | 2011-06-13 16:00:14 -0400 |
|---|---|---|
| committer | Brian Waldon <brian.waldon@rackspace.com> | 2011-06-13 16:00:14 -0400 |
| commit | befc7bcc88547916ab59d5fec5e8dd6e01ccf49f (patch) | |
| tree | 510f1eb68d4853c2f4e6ea7a8ad3192d279cb67d | |
| parent | 83df6e50fa90620dd7510e1a06d9128d4de7cb29 (diff) | |
| parent | 06591f13dcf130d8fb035466bfbe5650acfddb28 (diff) | |
| download | nova-befc7bcc88547916ab59d5fec5e8dd6e01ccf49f.tar.gz nova-befc7bcc88547916ab59d5fec5e8dd6e01ccf49f.tar.xz nova-befc7bcc88547916ab59d5fec5e8dd6e01ccf49f.zip | |
merging trunk, fixing pep8
| -rw-r--r-- | nova/api/ec2/cloud.py | 11 | ||||
| -rw-r--r-- | nova/api/openstack/server_metadata.py | 11 | ||||
| -rw-r--r-- | nova/api/openstack/wsgi.py | 2 | ||||
| -rw-r--r-- | nova/exception.py | 4 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_server_metadata.py | 25 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_wsgi.py | 1 | ||||
| -rw-r--r-- | nova/tests/test_cloud.py | 12 |
7 files changed, 60 insertions, 6 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 316298c39..e1c65ae40 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -39,6 +39,7 @@ from nova import flags from nova import ipv6 from nova import log as logging from nova import network +from nova import rpc from nova import utils from nova import volume from nova.api.ec2 import ec2utils @@ -872,8 +873,14 @@ class CloudController(object): def allocate_address(self, context, **kwargs): LOG.audit(_("Allocate address"), context=context) - public_ip = self.network_api.allocate_floating_ip(context) - return {'publicIp': public_ip} + try: + public_ip = self.network_api.allocate_floating_ip(context) + return {'publicIp': public_ip} + except rpc.RemoteError as ex: + if ex.exc_type == 'NoMoreAddresses': + raise exception.NoMoreFloatingIps() + else: + raise def release_address(self, context, public_ip, **kwargs): LOG.audit(_("Release address %s"), public_ip, context=context) diff --git a/nova/api/openstack/server_metadata.py b/nova/api/openstack/server_metadata.py index b38b84a2a..57666f6b7 100644 --- a/nova/api/openstack/server_metadata.py +++ b/nova/api/openstack/server_metadata.py @@ -37,12 +37,18 @@ class Controller(object): meta_dict[key] = value return dict(metadata=meta_dict) + def _check_body(self, body): + if body == None or body == "": + expl = _('No Request Body') + raise exc.HTTPBadRequest(explanation=expl) + def index(self, req, server_id): """ Returns the list of metadata for a given instance """ context = req.environ['nova.context'] return self._get_metadata(context, server_id) def create(self, req, server_id, body): + self._check_body(body) context = req.environ['nova.context'] metadata = body.get('metadata') try: @@ -51,9 +57,10 @@ class Controller(object): metadata) except quota.QuotaError as error: self._handle_quota_error(error) - return req.body + return body def update(self, req, server_id, id, body): + self._check_body(body) context = req.environ['nova.context'] if not id in body: expl = _('Request body and URI mismatch') @@ -68,7 +75,7 @@ class Controller(object): except quota.QuotaError as error: self._handle_quota_error(error) - return req.body + return body def show(self, req, server_id, id): """ Return a single metadata item """ diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 6cb73d8bf..b0e2cab2c 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -225,7 +225,7 @@ class XMLDictSerializer(DictSerializer): if not xmlns and self.xmlns: node.setAttribute('xmlns', self.xmlns) - return node.toprettyxml(indent=' ') + return node.toprettyxml(indent=' ', encoding='utf-8') def _to_xml_node(self, doc, metadata, nodename, data): """Recursive method to convert data members to XML nodes.""" diff --git a/nova/exception.py b/nova/exception.py index 69b3e0359..1571dd032 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -376,6 +376,10 @@ class NoFloatingIpsDefinedForInstance(NoFloatingIpsDefined): message = _("Zero floating ips defined for instance %(instance_id)s.") +class NoMoreFloatingIps(NotFound): + message = _("Zero floating ips available.") + + class KeypairNotFound(NotFound): message = _("Keypair %(keypair_name)s not found for user %(user_id)s") diff --git a/nova/tests/api/openstack/test_server_metadata.py b/nova/tests/api/openstack/test_server_metadata.py index c4d1d4fd8..b583d40fe 100644 --- a/nova/tests/api/openstack/test_server_metadata.py +++ b/nova/tests/api/openstack/test_server_metadata.py @@ -89,6 +89,7 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual('value1', res_dict['metadata']['key1']) def test_index_no_data(self): @@ -99,6 +100,7 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual(0, len(res_dict['metadata'])) def test_show(self): @@ -109,6 +111,7 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual('value5', res_dict['key5']) def test_show_meta_not_found(self): @@ -140,8 +143,19 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual('value1', res_dict['metadata']['key1']) + def test_create_empty_body(self): + self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', + return_create_instance_metadata) + req = webob.Request.blank('/v1.1/servers/1/meta') + req.environ['api.version'] = '1.1' + req.method = 'POST' + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(400, res.status_int) + def test_update_item(self): self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', return_create_instance_metadata) @@ -152,9 +166,20 @@ class ServerMetaDataTest(unittest.TestCase): req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) res_dict = json.loads(res.body) self.assertEqual('value1', res_dict['key1']) + def test_update_item_empty_body(self): + self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', + return_create_instance_metadata) + req = webob.Request.blank('/v1.1/servers/1/meta/key1') + req.environ['api.version'] = '1.1' + req.method = 'PUT' + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(400, res.status_int) + def test_update_item_too_many_keys(self): self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', return_create_instance_metadata) diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py index 5ec7712dd..2fa50ac9b 100644 --- a/nova/tests/api/openstack/test_wsgi.py +++ b/nova/tests/api/openstack/test_wsgi.py @@ -96,7 +96,6 @@ class DictSerializerTest(test.TestCase): self.assertEqual(serializer.serialize({}, None), 'trousers') - class XMLDictSerializerTest(test.TestCase): def test_xml(self): input_dict = dict(servers=dict(a=(2, 3))) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index ba133c860..13046f861 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -115,6 +115,18 @@ class CloudTestCase(test.TestCase): public_ip=address) db.floating_ip_destroy(self.context, address) + def test_allocate_address(self): + address = "10.10.10.10" + allocate = self.cloud.allocate_address + db.floating_ip_create(self.context, + {'address': address, + 'host': self.network.host}) + self.assertEqual(allocate(self.context)['publicIp'], address) + db.floating_ip_destroy(self.context, address) + self.assertRaises(exception.NoMoreFloatingIps, + allocate, + self.context) + def test_associate_disassociate_address(self): """Verifies associate runs cleanly without raising an exception""" address = "10.10.10.10" |
