flavor ID need converted to lowercase on Create flavor form
The flavor ID is not case sensitive, When judging whether the flavor ID exists, need to convert it to lowercase first. On behalf of pengyuesheng@gohighsec.com and review: https://review.opendev.org/c/openstack/horizon/+/651700 Change-Id: If242695590c955ed84411e89f6ca1dbdf2fa8aac Closes-Bug: #1824292
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user