From 1a605cccb1fe29ae6554ad5afa3110abef11d9c2 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 17 Aug 2012 15:34:28 -0400 Subject: Return HTTP 422 on bad server update PUT request. This patch updates the /servers API and the disk config extension so that they properly handle incorrectly formatted server update/PUT requests. Includes a new test cause that verifies (with extensions enabled) that a poorly formatted PUT request to /servers returns HTTP 422 instead of a 500. Also updated the previous test_create_missing_server test to use test.TestException instead of Exception. Fixes LP Bug #1038227. Change-Id: I6b11602790778465348647bb5825b7326d50065a --- nova/api/openstack/compute/contrib/disk_config.py | 3 ++- nova/api/openstack/compute/servers.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'nova/api') 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 = {} -- cgit