summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-06-15 19:45:09 +0000
committerGerrit Code Review <review@openstack.org>2013-06-15 19:45:09 +0000
commit8d5d17cc84416f2eede2bc640f4e2a52e3f27f21 (patch)
treecbaf943b0c421f00999d86651a72705a2baf8943
parente4a22480fbba7d5efb60db82f83a69ccef27f976 (diff)
parent98ff29d13af9e0c1fa96e49e68939634c24ad2c3 (diff)
downloadnova-8d5d17cc84416f2eede2bc640f4e2a52e3f27f21.tar.gz
nova-8d5d17cc84416f2eede2bc640f4e2a52e3f27f21.tar.xz
nova-8d5d17cc84416f2eede2bc640f4e2a52e3f27f21.zip
Merge "Fix to disallow server name with all blank spaces"
-rw-r--r--nova/api/openstack/compute/servers.py2
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py42
2 files changed, 44 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 67d64127a..a8e0beec7 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -580,6 +580,8 @@ class Controller(wsgi.Controller):
def _check_string_length(self, value, name, max_length=None):
try:
+ if isinstance(value, basestring):
+ value = value.strip()
utils.check_string_length(value, name, min_length=1,
max_length=max_length)
except exception.InvalidInput as e:
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 88e70efec..af8a4a276 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -1095,6 +1095,17 @@ class ServersControllerTest(test.TestCase):
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
req, FAKE_UUID, body)
+ def test_update_server_name_all_blank_spaces(self):
+ self.stubs.Set(db, 'instance_get',
+ fakes.fake_instance_get(name='server_test'))
+ req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID)
+ req.method = 'PUT'
+ req.content_type = 'application/json'
+ body = {'server': {'name': ' ' * 64}}
+ req.body = jsonutils.dumps(body)
+ self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
+ req, FAKE_UUID, body)
+
def test_update_server_access_ipv4(self):
self.stubs.Set(db, 'instance_get',
fakes.fake_instance_get(access_ipv4='0.0.0.0'))
@@ -2943,6 +2954,37 @@ class ServersControllerCreateTest(test.TestCase):
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
req, body)
+ def test_create_instance_name_all_blank_spaces(self):
+ # proper local hrefs must start with 'http://localhost/v2/'
+ image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
+ image_href = 'http://localhost/v2/images/%s' % image_uuid
+ flavor_ref = 'http://localhost/123/flavors/3'
+ body = {
+ 'server': {
+ 'name': ' ' * 64,
+ 'imageRef': image_href,
+ 'flavorRef': flavor_ref,
+ 'metadata': {
+ 'hello': 'world',
+ 'open': 'stack',
+ },
+ 'personality': [
+ {
+ "path": "/etc/banner.txt",
+ "contents": "MQ==",
+ },
+
+ ],
+ },
+ }
+
+ 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_instance(self):
# proper local hrefs must start with 'http://localhost/v2/'
image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'