diff --git a/api-ref/source/os-server-tags.inc b/api-ref/source/os-server-tags.inc index 69afbed4eb5f..c672ccedc875 100644 --- a/api-ref/source/os-server-tags.inc +++ b/api-ref/source/os-server-tags.inc @@ -13,6 +13,8 @@ Tags have the following restrictions: - Tag is a Unicode bytestring no longer than 60 characters. +- Tag is a non-empty string. + - Tags are case sensitive. - '/' is not allowed to be in a tag name diff --git a/nova/api/openstack/compute/server_tags.py b/nova/api/openstack/compute/server_tags.py index d21061d3c976..521c2affa83d 100644 --- a/nova/api/openstack/compute/server_tags.py +++ b/nova/api/openstack/compute/server_tags.py @@ -94,9 +94,9 @@ class ServerTagsController(wsgi.Controller): try: jsonschema.validate(id, parameter_types.tag) except jsonschema.ValidationError as e: - msg = (_("Tag '%(tag)s' is invalid. It must be a string without " - "characters '/' and ','. Validation error message: " - "%(err)s") % {'tag': id, 'err': e.message}) + msg = (_("Tag '%(tag)s' is invalid. It must be a non empty string " + "without characters '/' and ','. Validation error " + "message: %(err)s") % {'tag': id, 'err': e.message}) raise webob.exc.HTTPBadRequest(explanation=msg) try: diff --git a/nova/api/validation/parameter_types.py b/nova/api/validation/parameter_types.py index 7340139cfef8..f417965c217a 100644 --- a/nova/api/validation/parameter_types.py +++ b/nova/api/validation/parameter_types.py @@ -399,6 +399,6 @@ personality = { tag = { "type": "string", - "maxLength": tag.MAX_TAG_LENGTH, + "minLength": 1, "maxLength": tag.MAX_TAG_LENGTH, "pattern": "^[^,/]*$" } diff --git a/nova/tests/unit/api/openstack/compute/test_server_tags.py b/nova/tests/unit/api/openstack/compute/test_server_tags.py index 06e325c1ef68..28d3fab54cf3 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_tags.py +++ b/nova/tests/unit/api/openstack/compute/test_server_tags.py @@ -121,6 +121,12 @@ class ServerTagsTest(test.TestCase): self.controller.update_all, req, UUID, body={'tags': [1]}) + def test_update_all_tags_with_one_tag_empty_string(self): + req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'PUT') + self.assertRaises(exception.ValidationError, + self.controller.update_all, + req, UUID, body={'tags': ['tag1', '']}) + def test_update_all_too_long_tag(self): self.stub_out('nova.api.openstack.common.get_instance', return_server) req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'PUT')