diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-08-16 01:37:18 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-08-16 01:37:18 +0000 |
| commit | 46d7641466f9eb6313f2d45494a66d581a66407e (patch) | |
| tree | a4e0d429e0c0c0c2a43394e24153a918aef4a182 | |
| parent | bc115f003ddf7b8a825f0303bdf290a19c39f134 (diff) | |
| parent | 00f0b170ec15299b20c345fa1f66f21185c2dc79 (diff) | |
Merge "Update disk config to check for 'server' in req."
4 files changed, 30 insertions, 22 deletions
diff --git a/nova/api/openstack/compute/contrib/disk_config.py b/nova/api/openstack/compute/contrib/disk_config.py index 961457c46..293be7415 100644 --- a/nova/api/openstack/compute/contrib/disk_config.py +++ b/nova/api/openstack/compute/contrib/disk_config.py @@ -139,7 +139,8 @@ class ServerDiskConfigController(wsgi.Controller): def create(self, req, body): context = req.environ['nova.context'] if authorize(context): - self._set_disk_config(body['server']) + if 'server' in body: + self._set_disk_config(body['server']) resp_obj = (yield) self._show(req, resp_obj) diff --git a/nova/api/openstack/compute/contrib/scheduler_hints.py b/nova/api/openstack/compute/contrib/scheduler_hints.py index 4bff779a5..e8d65a741 100644 --- a/nova/api/openstack/compute/contrib/scheduler_hints.py +++ b/nova/api/openstack/compute/contrib/scheduler_hints.py @@ -49,10 +49,7 @@ class SchedulerHintsController(wsgi.Controller): if 'server' in body: body['server']['scheduler_hints'] = hints - yield - else: - msg = _("Missing server attribute") - raise webob.exc.HTTPBadRequest(reason=msg) + yield class Scheduler_hints(extensions.ExtensionDescriptor): diff --git a/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py b/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py index afb6d966b..c651444f4 100644 --- a/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py +++ b/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py @@ -94,20 +94,3 @@ class SchedulerHintsTestCase(test.TestCase): req.body = jsonutils.dumps(body) res = req.get_response(self.app) self.assertEqual(400, res.status_int) - - def test_create_missing_server(self): - """Test create with malformed body""" - - def fake_create(*args, **kwargs): - raise Exception("Request should not reach the compute API.") - - self.stubs.Set(nova.compute.api.API, 'create', fake_create) - - req = fakes.HTTPRequest.blank('/fake/servers') - req.method = 'POST' - req.content_type = 'application/json' - body = {'os:scheduler_hints': {'a': 'b'}} - - req.body = jsonutils.dumps(body) - res = req.get_response(self.app) - self.assertEqual(400, res.status_int) diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index c37a64f8f..662a272f8 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -4750,3 +4750,30 @@ class ServerXMLSerializationTest(test.TestCase): str(ip['version'])) self.assertEqual(str(ip_elem.get('addr')), str(ip['addr'])) + + +class ServersAllExtensionsTestCase(test.TestCase): + """ + Servers tests using default API router with all extensions enabled. + """ + + def setUp(self): + super(ServersAllExtensionsTestCase, self).setUp() + self.app = nova.api.openstack.compute.APIRouter() + + def test_create_missing_server(self): + """Test create with malformed body""" + + def fake_create(*args, **kwargs): + raise Exception("Request should not reach the compute API.") + + self.stubs.Set(nova.compute.api.API, 'create', fake_create) + + req = fakes.HTTPRequest.blank('/fake/servers') + req.method = 'POST' + req.content_type = 'application/json' + body = {'foo': {'a': 'b'}} + + req.body = jsonutils.dumps(body) + res = req.get_response(self.app) + self.assertEqual(422, res.status_int) |
