summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-08-14 05:11:01 +0000
committerGerrit Code Review <review@openstack.org>2012-08-14 05:11:01 +0000
commit338564dbc577504ff7d08a20eb21b616bd39a1fe (patch)
tree07f4e8010d86402b175d4f6a56bb1fd55dfd1b99 /nova
parent7af16893514bd27be51cf5e425679ddcce07688a (diff)
parent197a354300df7f947d080aac964dbd2c774768f0 (diff)
downloadnova-338564dbc577504ff7d08a20eb21b616bd39a1fe.tar.gz
nova-338564dbc577504ff7d08a20eb21b616bd39a1fe.tar.xz
nova-338564dbc577504ff7d08a20eb21b616bd39a1fe.zip
Merge "Fix HTTP 500 on bad server create"
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/compute/contrib/scheduler_hints.py9
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py17
2 files changed, 24 insertions, 2 deletions
diff --git a/nova/api/openstack/compute/contrib/scheduler_hints.py b/nova/api/openstack/compute/contrib/scheduler_hints.py
index 86b7564bd..4bff779a5 100644
--- a/nova/api/openstack/compute/contrib/scheduler_hints.py
+++ b/nova/api/openstack/compute/contrib/scheduler_hints.py
@@ -46,8 +46,13 @@ class SchedulerHintsController(wsgi.Controller):
@wsgi.extends
def create(self, req, body):
hints = self._extract_scheduler_hints(body)
- body['server']['scheduler_hints'] = hints
- yield
+
+ if 'server' in body:
+ body['server']['scheduler_hints'] = hints
+ yield
+ else:
+ msg = _("Missing server attribute")
+ raise webob.exc.HTTPBadRequest(reason=msg)
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 c651444f4..afb6d966b 100644
--- a/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py
+++ b/nova/tests/api/openstack/compute/contrib/test_scheduler_hints.py
@@ -94,3 +94,20 @@ 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)