Merge "flavor ID need converted to lowercase on Create flavor form"

This commit is contained in:
Zuul 2025-05-06 13:10:48 +00:00 committed by Gerrit Code Review
commit b49a914c39
2 changed files with 29 additions and 3 deletions

View File

@ -359,6 +359,29 @@ class CreateFlavorWorkflowTests(BaseFlavorWorkflowTests):
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest(),
None)
@test.create_mocks({api.keystone: ('tenant_list',),
api.nova: ('flavor_list',)})
def test_create_existing_flavor_id_ignore_case(self):
flavor = self.flavors.first()
projects = self.tenants.list()
self.mock_tenant_list.return_value = [projects, False]
self.mock_flavor_list.return_value = self.flavors.list()
workflow_data = self._get_workflow_data(flavor)
# Name is okay.
workflow_data['name'] = 'newflavorname'
# Convert flavor.id to uppercase
workflow_data['flavor_id'] = flavor.id.upper()
url = reverse(constants.FLAVORS_CREATE_URL)
res = self.client.post(url, workflow_data)
self.assertFormErrors(res)
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
self.mock_flavor_list.assert_called_once_with(test.IsHttpRequest(),
None)
@test.create_mocks({api.keystone: ('tenant_list',),
api.nova: ('flavor_list',
'flavor_create',

View File

@ -28,9 +28,11 @@ from openstack_dashboard import api
class CreateFlavorInfoAction(workflows.Action):
_flavor_id_regex = (r'^[a-zA-Z0-9. _-]+$')
_flavor_id_help_text = _("Flavor id can only contain alphanumeric "
_flavor_id_help_text = _("Flavor ID can only contain alphanumeric "
"characters, underscores, periods, hyphens, "
"spaces. Use 'auto' to automatically generate ID.")
"spaces. Pay attention that ID is not case "
"sensitive. Use 'auto' to automatically "
"generate ID.")
name = forms.CharField(
label=_("Name"),
max_length=255)
@ -89,7 +91,8 @@ class CreateFlavorInfoAction(workflows.Action):
error_msg = _('The name "%s" is already used by '
'another flavor.') % name
self._errors['name'] = self.error_class([error_msg])
if (flavor.id != 'auto') and (flavor.id == flavor_id):
if (flavor.id != 'auto' and
flavor.id.lower() == flavor_id.lower()):
error_msg = _('The ID "%s" is already used by '
'another flavor.') % flavor_id
self._errors['flavor_id'] = self.error_class([error_msg])