Merge "Exclude current volume_type from Volume retype list"

This commit is contained in:
Jenkins 2015-06-15 20:56:12 +00:00 committed by Gerrit Code Review
commit a8c1133df1
2 changed files with 8 additions and 42 deletions

View File

@ -756,26 +756,21 @@ class RetypeForm(forms.SelfHandlingForm):
try:
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:
redirect_url = reverse("horizon:project:volumes:index")
error_message = _('Unable to retrieve the volume type list.')
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']
types_list = [(t.name, t.name)
for t in volume_types
if t.name != origin_type]
if cleaned_volume_type == origin_type:
error_message = _(
'New volume type must be different from '
'the original volume type "%s".') % cleaned_volume_type
raise ValidationError(error_message)
return cleaned_volume_type
if types_list:
types_list.insert(0, ("", _("Select a new volume type")))
else:
types_list.insert(0, ("", _("No other volume types available")))
self.fields['volume_type'].choices = sorted(types_list)
def handle(self, request, data):
volume_id = self.initial['id']

View File

@ -1406,35 +1406,6 @@ class VolumeViewTests(test.TestCase):
redirect_url = VOLUME_INDEX_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):
self._test_encryption(False)