summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/api/openstack/compute/contrib/disk_config.py3
-rw-r--r--nova/api/openstack/compute/servers.py3
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py19
3 files changed, 23 insertions, 2 deletions
diff --git a/nova/api/openstack/compute/contrib/disk_config.py b/nova/api/openstack/compute/contrib/disk_config.py
index 293be7415..903f930fc 100644
--- a/nova/api/openstack/compute/contrib/disk_config.py
+++ b/nova/api/openstack/compute/contrib/disk_config.py
@@ -148,7 +148,8 @@ class ServerDiskConfigController(wsgi.Controller):
def update(self, req, id, 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/servers.py b/nova/api/openstack/compute/servers.py
index 0c5a2e530..67a950ada 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -813,6 +813,9 @@ class Controller(wsgi.Controller):
if not body:
raise exc.HTTPUnprocessableEntity()
+ if not 'server' in body:
+ raise exc.HTTPUnprocessableEntity()
+
ctxt = req.environ['nova.context']
update_dict = {}
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 662a272f8..fd3597b68 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -4765,7 +4765,7 @@ class ServersAllExtensionsTestCase(test.TestCase):
"""Test create with malformed body"""
def fake_create(*args, **kwargs):
- raise Exception("Request should not reach the compute API.")
+ raise test.TestingException("Should not reach the compute API.")
self.stubs.Set(nova.compute.api.API, 'create', fake_create)
@@ -4777,3 +4777,20 @@ class ServersAllExtensionsTestCase(test.TestCase):
req.body = jsonutils.dumps(body)
res = req.get_response(self.app)
self.assertEqual(422, res.status_int)
+
+ def test_update_missing_server(self):
+ """Test create with malformed body"""
+
+ def fake_update(*args, **kwargs):
+ raise test.TestingException("Should not reach the compute API.")
+
+ self.stubs.Set(nova.compute.api.API, 'create', fake_update)
+
+ req = fakes.HTTPRequest.blank('/fake/servers/1')
+ req.method = 'PUT'
+ 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)