From e51a14bc93fc8a0661a3dfab548bad8c19ff2085 Mon Sep 17 00:00:00 2001 From: Takashi NATSUME Date: Thu, 30 Nov 2017 16:19:42 +0900 Subject: [PATCH] [placement] Fix an error message in API validation Fix the error message in validation of the following API when the name exceeds max character length(255). * PUT /traits/{name} Change-Id: I2bbbadd7842bf4652d3c32ae3e5c74e2e159990b Closes-Bug: #1735343 --- nova/api/openstack/placement/handlers/trait.py | 6 +++--- .../api/openstack/placement/gabbits/traits.yaml | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/nova/api/openstack/placement/handlers/trait.py b/nova/api/openstack/placement/handlers/trait.py index 0f131b92f1e7..50fc6b7dafd8 100644 --- a/nova/api/openstack/placement/handlers/trait.py +++ b/nova/api/openstack/placement/handlers/trait.py @@ -99,9 +99,9 @@ def put_trait(req): jsonschema.validate(name, CUSTOM_TRAIT) except jsonschema.ValidationError: raise webob.exc.HTTPBadRequest( - _('The trait is invalid. A valid trait must include prefix ' - '"CUSTOM_" and use following characters: "A"-"Z", "0"-"9" and ' - '"_"')) + _('The trait is invalid. A valid trait must be no longer than ' + '255 characters, start with the prefix "CUSTOM_" and use ' + 'following characters: "A"-"Z", "0"-"9" and "_"')) trait = rp_obj.Trait(context) trait.name = name diff --git a/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml b/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml index 6cdadf13840d..6300db6d3d19 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml @@ -13,13 +13,19 @@ tests: PUT: /traits/TRAIT_X status: 400 response_strings: - - 'The trait is invalid. A valid trait must include prefix \"CUSTOM_\" and use following characters: \"A\"-\"Z\", \"0\"-\"9\" and \"_\"' + - 'The trait is invalid. A valid trait must be no longer than 255 characters, start with the prefix \"CUSTOM_\" and use following characters: \"A\"-\"Z\", \"0\"-\"9\" and \"_\"' - name: create a trait with invalid characters PUT: /traits/CUSTOM_ABC:1 status: 400 response_strings: - - 'The trait is invalid. A valid trait must include prefix \"CUSTOM_\" and use following characters: \"A\"-\"Z\", \"0\"-\"9\" and \"_\"' + - 'The trait is invalid. A valid trait must be no longer than 255 characters, start with the prefix \"CUSTOM_\" and use following characters: \"A\"-\"Z\", \"0\"-\"9\" and \"_\"' + +- name: create a trait with name exceed max characters + PUT: /traits/CUSTOM_ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNO + status: 400 + response_strings: + - 'The trait is invalid. A valid trait must be no longer than 255 characters, start with the prefix \"CUSTOM_\" and use following characters: \"A\"-\"Z\", \"0\"-\"9\" and \"_\"' - name: create a trait PUT: /traits/CUSTOM_TRAIT_1