From 480b8737e3bec677fd76b68b8887efe5cb1ab8de Mon Sep 17 00:00:00 2001 From: John Griffith Date: Mon, 17 Aug 2015 08:08:14 -0600 Subject: [PATCH] Allow 0 length name There are currently cases where nova for example creates volumes with a name of zero length. We can't just change that and break compatability. This patch just modifes the wsgi module to allow min length of zero again. Change-Id: I829a8b4d6773d1c646d07cccb36994370e1dbce9 Closes-Bug: #1485198 --- cinder/api/openstack/wsgi.py | 2 +- cinder/tests/unit/api/contrib/test_consistencygroups.py | 2 -- cinder/tests/unit/api/openstack/test_wsgi.py | 7 ++++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cinder/api/openstack/wsgi.py b/cinder/api/openstack/wsgi.py index 0c9b59b6340..7fb76813c51 100644 --- a/cinder/api/openstack/wsgi.py +++ b/cinder/api/openstack/wsgi.py @@ -1228,7 +1228,7 @@ class Controller(object): body['name'] = name.strip() try: utils.check_string_length(body['name'], 'Name', - min_length=1, max_length=255) + min_length=0, max_length=255) except exception.InvalidInput as error: raise webob.exc.HTTPBadRequest(explanation=error.msg) diff --git a/cinder/tests/unit/api/contrib/test_consistencygroups.py b/cinder/tests/unit/api/contrib/test_consistencygroups.py index 4fd83a22f47..84f4cce45fa 100644 --- a/cinder/tests/unit/api/contrib/test_consistencygroups.py +++ b/cinder/tests/unit/api/contrib/test_consistencygroups.py @@ -622,8 +622,6 @@ class ConsistencyGroupsAPITestCase(test.TestCase): self.assertEqual(400, res.status_int) self.assertEqual(400, res_dict['badRequest']['code']) - self.assertEqual('Name has a minimum character requirement of 1.', - res_dict['badRequest']['message']) db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id) diff --git a/cinder/tests/unit/api/openstack/test_wsgi.py b/cinder/tests/unit/api/openstack/test_wsgi.py index 42b18cd56f8..e462bbf03b1 100644 --- a/cinder/tests/unit/api/openstack/test_wsgi.py +++ b/cinder/tests/unit/api/openstack/test_wsgi.py @@ -1022,10 +1022,11 @@ class ValidBodyTest(test.TestCase): body) def test_validate_name_and_description_with_name_zero_length(self): + # NOTE(jdg): We allow zero length names currently, particularly + # from Nova, changes to this require an API version bump body = {'name': ""} - self.assertRaises(webob.exc.HTTPBadRequest, - self.controller.validate_name_and_description, - body) + self.controller.validate_name_and_description(body) + self.assertEqual('', body['name']) def test_validate_name_and_description_with_desc_zero_length(self): body = {'description': ""}