From b7a29b7825799187678953a6052ce784ec285604 Mon Sep 17 00:00:00 2001 From: ankitagrawal Date: Thu, 4 Jun 2015 05:15:06 -0700 Subject: [PATCH] Fixed error message for negative values of min_disk and min_ram In case of v1 api if min_disk or min_ram is passed with a negative value to the image create command, it returns 400 response with error message formatted to HTML entity. Eliminated special characters (>=) from error message, so it will not cause any encoding issues. Also with this change the error message for v1 api will be identical to v2 api. Closes-Bug: 1461776 Change-Id: I71a3cc3ed6bf14f3c0273df053667f1cbf99e98f --- glance/common/utils.py | 4 +--- glance/tests/unit/v1/test_api.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/glance/common/utils.py b/glance/common/utils.py index 1923be4117..af614d57a9 100644 --- a/glance/common/utils.py +++ b/glance/common/utils.py @@ -318,9 +318,7 @@ def get_image_meta_from_headers(response): param=key, extra_msg=extra) if result[key] < 0 and result[key] is not None: - extra = (_("Image %(key)s must be >= 0 " - "('%(value)s' specified).") - % {'key': key, 'value': result[key]}) + extra = _('Cannot be a negative value.') raise exception.InvalidParameterValue(value=result[key], param=key, extra_msg=extra) diff --git a/glance/tests/unit/v1/test_api.py b/glance/tests/unit/v1/test_api.py index 0a0b47fe3f..ce6d2c515e 100644 --- a/glance/tests/unit/v1/test_api.py +++ b/glance/tests/unit/v1/test_api.py @@ -506,7 +506,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): expected = "Cannot convert image size 'invalid' to an integer." exec_bad_size_test('invalid', expected) - expected = "Image size must be >= 0 ('-10' specified)." + expected = "Cannot be a negative value." exec_bad_size_test(-10, expected) def test_bad_image_name(self):