fix bug of fail to create volume type encryption from dashboard

Due to the commit https://review.openstack.org/#/c/573093/,
the body of create and update from dashboard for volume
type encryption does not match the schemas of it's API.

The schemas url is https://github.com/openstack/cinder/blob
/master/cinder/api/schemas/volume_type_encryption.py

So that, pop the volume_type_id and name from the data to
match the schemas.

Change-Id: I032e59251a0d54cd09ead8cf3b0ac2527d9261db
Closes-Bug: #1783467
This commit is contained in:
zhubx007 2018-07-25 12:12:27 +08:00 committed by Akihiro Motoki
parent 9a66accb1c
commit 633897ae54
2 changed files with 26 additions and 8 deletions

View File

@ -115,13 +115,16 @@ class CreateVolumeTypeEncryption(forms.SelfHandlingForm):
if data['cipher'] == u'': if data['cipher'] == u'':
data['cipher'] = None data['cipher'] = None
volume_type_id = data.pop('volume_type_id')
volume_type_name = data.pop('name')
# Create encryption for the volume type # Create encryption for the volume type
volume_type = cinder.\ volume_type = cinder.\
volume_encryption_type_create(request, volume_encryption_type_create(request,
data['volume_type_id'], volume_type_id,
data) data)
messages.success(request, _('Successfully created encryption for ' messages.success(request, _('Successfully created encryption for '
'volume type: %s') % data['name']) 'volume type: %s') % volume_type_name)
return volume_type return volume_type
except Exception: except Exception:
redirect = reverse("horizon:admin:volume_types:index") redirect = reverse("horizon:admin:volume_types:index")
@ -138,13 +141,16 @@ class UpdateVolumeTypeEncryption(CreateVolumeTypeEncryption):
if data['cipher'] == u'': if data['cipher'] == u'':
data['cipher'] = None data['cipher'] = None
volume_type_id = data.pop('volume_type_id')
volume_type_name = data.pop('name')
# Update encryption for the volume type # Update encryption for the volume type
volume_type = cinder.\ volume_type = cinder.\
volume_encryption_type_update(request, volume_encryption_type_update(request,
data['volume_type_id'], volume_type_id,
data) data)
messages.success(request, _('Successfully updated encryption for ' messages.success(request, _('Successfully updated encryption for '
'volume type: %s') % data['name']) 'volume type: %s') % volume_type_name)
return volume_type return volume_type
except NotImplementedError: except NotImplementedError:
messages.error(request, _('Updating encryption is not ' messages.error(request, _('Updating encryption is not '

View File

@ -192,10 +192,16 @@ class VolumeTypeTests(test.BaseAdminViewTests):
'admin/volume_types/create_volume_type_encryption.html') 'admin/volume_types/create_volume_type_encryption.html')
self.mock_volume_type_list.assert_called_once_with( self.mock_volume_type_list.assert_called_once_with(
test.IsHttpRequest()) test.IsHttpRequest())
expected = {
'provider': u'a-provider',
'control_location': u'front-end',
'cipher': u'a-cipher',
'key_size': 512,
}
self.mock_volume_encryption_type_create.assert_called_once_with( self.mock_volume_encryption_type_create.assert_called_once_with(
test.IsHttpRequest(), test.IsHttpRequest(),
formData['volume_type_id'], volume_type1.id,
formData) expected)
@test.create_mocks({api.cinder: ('volume_encryption_type_get', @test.create_mocks({api.cinder: ('volume_encryption_type_get',
'volume_type_list',)}) 'volume_type_list',)})
@ -327,10 +333,16 @@ class VolumeTypeTests(test.BaseAdminViewTests):
test.IsHttpRequest(), volume_type.id) test.IsHttpRequest(), volume_type.id)
self.mock_volume_type_list.assert_called_once_with( self.mock_volume_type_list.assert_called_once_with(
test.IsHttpRequest()) test.IsHttpRequest())
expected = {
'provider': u'a-provider',
'control_location': u'front-end',
'cipher': u'a-cipher',
'key_size': 256,
}
self.mock_volume_encryption_type_update.assert_called_once_with( self.mock_volume_encryption_type_update.assert_called_once_with(
test.IsHttpRequest(), test.IsHttpRequest(),
formData['volume_type_id'], volume_type.id,
formData) expected)
@test.create_mocks({api.cinder: ('volume_type_get', @test.create_mocks({api.cinder: ('volume_type_get',
'volume_type_access_list', 'volume_type_access_list',