summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorSirisha Devineni <sirisha_devineni@persistent.co.in>2012-09-14 23:04:37 +0530
committerSirisha Devineni <sirisha_devineni@persistent.co.in>2012-09-18 14:30:39 +0530
commitf4906f07cd49e4deae79018d7f586b16266859eb (patch)
tree0408d8bf90f5c35a84ed50541475cc5dda9155f0 /nova/tests
parent5fc0dbb912e688c1844856d8d7764ebedf7b6b2d (diff)
Raise BadRequest while creating server with invalid personality
Handle UnicodeDecodeError raises from compute api while trying to create server with invalid personality content and throw it as HTTPBadRequest Fixed bug 1050409 Change-Id: I27d47bbc9ed89abfa9827512fbfb3b16a0d87160
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index aa8f6132b..d5f1170e6 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -2803,6 +2803,43 @@ class ServersControllerCreateTest(test.TestCase):
# The fact that the action doesn't raise is enough validation
self.controller.create(req, body)
+ def test_create_instance_invalid_personality(self):
+
+ def fake_create(*args, **kwargs):
+ codec = 'utf8'
+ content = 'b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA=='
+ start_position = 19
+ end_position = 20
+ msg = 'invalid start byte'
+ raise UnicodeDecodeError(codec, content, start_position,
+ end_position, msg)
+
+ self.stubs.Set(nova.compute.api.API,
+ 'create',
+ fake_create)
+ image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
+ flavor_ref = 'http://localhost/v2/flavors/3'
+ body = {
+ 'server': {
+ 'name': 'server_test',
+ 'imageRef': image_uuid,
+ 'flavorRef': flavor_ref,
+ 'personality': [
+ {
+ "path": "/etc/banner.txt",
+ "contents": "b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA==",
+ },
+ ],
+ },
+ }
+
+ 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_location(self):
selfhref = 'http://localhost/v2/fake/servers/%s' % FAKE_UUID
bookhref = 'http://localhost/fake/servers/%s' % FAKE_UUID