Improve field validation/error handling for flavor creation

Currently, if a user tries to create a new flavor or rename a flavor
to a name that already exists, a field validation error will be shown
that tells the user that the name is already being used by another
flavor.

It seems, however, that the validation does not catch the case where the
user enters a flavor name that is the same string but just with
uppercase/lowercase differences.  Since this is not caught during the
form validation, nova runs into an error later and thus throws an
exception that leaves the user with a generic error message like
"Unable to create flavor".

To improve the form field validation and prevent the error from ever
occurring in Nova, I switched the name comparisons to use the .lower()
method.  This was done for both Creating and Editing Flavor names.

Change-Id: I44dcd98978e57282b44fdab8f134500eb9b03881
Closes-Bug: #1179607
This commit is contained in:
Lucas Palm 2016-01-12 10:12:58 -06:00
parent 2b6f9525a8
commit b5d2726554

View File

@ -76,9 +76,9 @@ class CreateFlavorInfoAction(workflows.Action):
msg = _('Unable to get flavor list')
exceptions.check_message(["Connection", "refused"], msg)
raise
if flavors is not None:
if flavors is not None and name is not None:
for flavor in flavors:
if flavor.name == name:
if flavor.name.lower() == name.lower():
raise forms.ValidationError(
_('The name "%s" is already used by another flavor.')
% name
@ -246,9 +246,10 @@ class UpdateFlavorInfoAction(CreateFlavorInfoAction):
exceptions.check_message(["Connection", "refused"], msg)
raise
# Check if there is no flavor with the same name
if flavors is not None:
if flavors is not None and name is not None:
for flavor in flavors:
if flavor.name == name and flavor.id != flavor_id:
if (flavor.name.lower() == name.lower() and
flavor.id != flavor_id):
raise forms.ValidationError(
_('The name "%s" is already used by another '
'flavor.') % name)