summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSatyanarayana Patibandla <satya.patibandla@tcs.com>2013-04-27 18:18:44 -0400
committerSatyanarayana Patibandla <satya.patibandla@tcs.com>2013-05-20 02:16:17 +0530
commit53226b3262a95e4e62472416c125ee3ebd58b52e (patch)
tree9151b6cdf5486b7aa596a1ef9ea0aaedc0e9fd7e
parenteebcd6f2058d78c87dd2ee0a9a90f21f33f44e97 (diff)
downloadnova-53226b3262a95e4e62472416c125ee3ebd58b52e.tar.gz
nova-53226b3262a95e4e62472416c125ee3ebd58b52e.tar.xz
nova-53226b3262a95e4e62472416c125ee3ebd58b52e.zip
Added validation for networks parameter value
A validation check is added for networks parameter value. In server create request body, if networks parameter value is not stored in a list then 'Bad networks format' error is thrown with bad request exception.A new test case is added to verify whether it is returning bad request exception when invalid syntax is used. Fixes: bug #1175683 Change-Id: I457a1626c56281f89d8c4a606ccc0d0e3aea05fa
-rw-r--r--nova/api/openstack/compute/servers.py3
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py21
2 files changed, 24 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 166c8b10e..a63a39860 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -791,6 +791,9 @@ class Controller(wsgi.Controller):
requested_networks = server_dict.get('networks')
if requested_networks is not None:
+ if not isinstance(requested_networks, list):
+ expl = _('Bad networks format')
+ raise exc.HTTPBadRequest(explanation=expl)
requested_networks = self._get_requested_networks(
requested_networks)
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 22aecf020..4253c2d57 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -1857,6 +1857,27 @@ class ServersControllerCreateTest(test.TestCase):
req,
body)
+ def test_create_server_with_invalid_networks_parameter(self):
+ self.ext_mgr.extensions = {'os-networks': 'fake'}
+ image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
+ flavor_ref = 'http://localhost/123/flavors/3'
+ body = {
+ 'server': {
+ 'name': 'server_test',
+ 'imageRef': image_href,
+ 'flavorRef': flavor_ref,
+ 'networks': {'uuid': '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'},
+ }
+ }
+ req = fakes.HTTPRequest.blank('/v2/fake/servers')
+ req.method = 'POST'
+ req.body = jsonutils.dumps(body)
+ req.headers["content-type"] = "application/json"
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller.create,
+ req,
+ body)
+
def test_create_server_with_deleted_image(self):
image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
# Get the fake image service so we can set the status to deleted