Exclude current volume_type from Volume retype list
Instead of adding an extra check and throw error messages when the new volume_type is same with the current one, we should exclude it from the choices list. Change-Id: Id91c42ed4a73cc7d5aca34242bf4457a58e8496c Closes-Bug: #1461856
This commit is contained in:
parent
59e772ad4a
commit
03308e6863
@ -756,26 +756,21 @@ class RetypeForm(forms.SelfHandlingForm):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
volume_types = cinder.volume_type_list(request)
|
volume_types = cinder.volume_type_list(request)
|
||||||
self.fields['volume_type'].choices = [(t.name, t.name)
|
|
||||||
for t in volume_types]
|
|
||||||
self.fields['volume_type'].initial = self.initial['volume_type']
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
redirect_url = reverse("horizon:project:volumes:index")
|
redirect_url = reverse("horizon:project:volumes:index")
|
||||||
error_message = _('Unable to retrieve the volume type list.')
|
error_message = _('Unable to retrieve the volume type list.')
|
||||||
exceptions.handle(request, error_message, redirect=redirect_url)
|
exceptions.handle(request, error_message, redirect=redirect_url)
|
||||||
|
|
||||||
def clean_volume_type(self):
|
|
||||||
cleaned_volume_type = self.cleaned_data['volume_type']
|
|
||||||
origin_type = self.initial['volume_type']
|
origin_type = self.initial['volume_type']
|
||||||
|
types_list = [(t.name, t.name)
|
||||||
|
for t in volume_types
|
||||||
|
if t.name != origin_type]
|
||||||
|
|
||||||
if cleaned_volume_type == origin_type:
|
if types_list:
|
||||||
error_message = _(
|
types_list.insert(0, ("", _("Select a new volume type")))
|
||||||
'New volume type must be different from '
|
else:
|
||||||
'the original volume type "%s".') % cleaned_volume_type
|
types_list.insert(0, ("", _("No other volume types available")))
|
||||||
raise ValidationError(error_message)
|
self.fields['volume_type'].choices = sorted(types_list)
|
||||||
|
|
||||||
return cleaned_volume_type
|
|
||||||
|
|
||||||
def handle(self, request, data):
|
def handle(self, request, data):
|
||||||
volume_id = self.initial['id']
|
volume_id = self.initial['id']
|
||||||
|
@ -1406,35 +1406,6 @@ class VolumeViewTests(test.TestCase):
|
|||||||
redirect_url = VOLUME_INDEX_URL
|
redirect_url = VOLUME_INDEX_URL
|
||||||
self.assertRedirectsNoFollow(res, redirect_url)
|
self.assertRedirectsNoFollow(res, redirect_url)
|
||||||
|
|
||||||
@test.create_stubs({cinder: ('volume_get',
|
|
||||||
'volume_type_list')})
|
|
||||||
def test_retype_volume_same_type(self):
|
|
||||||
volume = self.cinder_volumes.get(name='my_volume2')
|
|
||||||
|
|
||||||
volume_type = self.cinder_volume_types.get(name='vol_type_2')
|
|
||||||
|
|
||||||
form_data = {'id': volume.id,
|
|
||||||
'name': volume.name,
|
|
||||||
'volume_type': volume_type.name,
|
|
||||||
'migration_policy': 'on-demand'}
|
|
||||||
|
|
||||||
cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
|
|
||||||
|
|
||||||
cinder.volume_type_list(
|
|
||||||
IsA(http.HttpRequest)).AndReturn(self.cinder_volume_types.list())
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
url = reverse('horizon:project:volumes:volumes:retype',
|
|
||||||
args=[volume.id])
|
|
||||||
res = self.client.post(url, form_data)
|
|
||||||
|
|
||||||
self.assertFormError(res,
|
|
||||||
'form',
|
|
||||||
'volume_type',
|
|
||||||
'New volume type must be different from the '
|
|
||||||
'original volume type "%s".' % volume_type.name)
|
|
||||||
|
|
||||||
def test_encryption_false(self):
|
def test_encryption_false(self):
|
||||||
self._test_encryption(False)
|
self._test_encryption(False)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user