From 2c1bb9efd9287381f16979899bf25022822bf95b Mon Sep 17 00:00:00 2001 From: Haiwei Xu Date: Tue, 12 Feb 2013 01:37:27 +0000 Subject: Check the length of flavor name in "flavor-create" Fixes bug 1102280 The length of flavor name is defined 255 charaters in database. But flavor name can be more than 255 characters when a flavor is created. This patch adds the length check of flavor name. Change-Id: If9db879e5f6340594b215b057a29d03c6fef1503 --- nova/api/openstack/compute/servers.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 5858ad640..c10c6e1b3 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -563,18 +563,11 @@ class Controller(wsgi.Controller): return instance def _check_string_length(self, value, name, max_length=None): - if not isinstance(value, basestring): - msg = _("%s is not a string or unicode") % name - raise exc.HTTPBadRequest(explanation=msg) - - if not value.strip(): - msg = _("%s is an empty string") % name - raise exc.HTTPBadRequest(explanation=msg) - - if max_length and len(value) > max_length: - msg = _("%(name)s can be at most %(max_length)s " - "characters.") % locals() - raise exc.HTTPBadRequest(explanation=msg) + try: + utils.check_string_length(value, name, min_length=1, + max_length=max_length) + except exception.InvalidInput as e: + raise exc.HTTPBadRequest(explanation=str(e)) def _validate_server_name(self, value): self._check_string_length(value, 'Server name', max_length=255) -- cgit