diff --git a/openstack_dashboard/dashboards/admin/volume_types/extras/forms.py b/openstack_dashboard/dashboards/admin/volume_types/extras/forms.py index 8366eef3f7..e667efc63d 100644 --- a/openstack_dashboard/dashboards/admin/volume_types/extras/forms.py +++ b/openstack_dashboard/dashboards/admin/volume_types/extras/forms.py @@ -34,6 +34,20 @@ class CreateExtraSpec(forms.SelfHandlingForm): error_messages=KEY_ERROR_MESSAGES) value = forms.CharField(max_length=255, label=_("Value")) + def clean(self): + data = super(CreateExtraSpec, self).clean() + type_id = self.initial['type_id'] + extra_list = api.cinder.volume_type_extra_get(self.request, + type_id) + for extra in extra_list: + if extra.key.lower() == data['key'].lower(): + error_msg = _('Key with name "%s" already exists. Use Edit to ' + 'update the value, else create key with ' + 'different name.') % data['key'] + raise forms.ValidationError(error_msg) + + return data + def handle(self, request, data): type_id = self.initial['type_id'] try: diff --git a/openstack_dashboard/dashboards/admin/volume_types/extras/tests.py b/openstack_dashboard/dashboards/admin/volume_types/extras/tests.py index 1c09ba36d5..caf038bfab 100644 --- a/openstack_dashboard/dashboards/admin/volume_types/extras/tests.py +++ b/openstack_dashboard/dashboards/admin/volume_types/extras/tests.py @@ -54,7 +54,8 @@ class VolTypeExtrasTests(test.BaseAdminViewTests): self.mock_volume_type_extra_get.assert_called_once_with( test.IsHttpRequest(), vol_type.id) - @test.create_mocks({api.cinder: ('volume_type_extra_set', )}) + @test.create_mocks({api.cinder: ('volume_type_extra_set', + 'volume_type_extra_get')}) def test_extra_create_post(self): vol_type = self.cinder_volume_types.first() create_url = reverse(