diff --git a/openstack_dashboard/api/cinder.py b/openstack_dashboard/api/cinder.py index df56563be1..6b7204e203 100644 --- a/openstack_dashboard/api/cinder.py +++ b/openstack_dashboard/api/cinder.py @@ -400,6 +400,10 @@ def volume_encryption_type_create(request, volume_type_id, data): specs=data) +def volume_encryption_type_delete(request, volume_type_id): + return cinderclient(request).volume_encryption_types.delete(volume_type_id) + + def volume_encryption_type_get(request, volume_type_id): return cinderclient(request).volume_encryption_types.get(volume_type_id) diff --git a/openstack_dashboard/dashboards/admin/volumes/tests.py b/openstack_dashboard/dashboards/admin/volumes/tests.py index 6dee36bd0b..c85525163f 100644 --- a/openstack_dashboard/dashboards/admin/volumes/tests.py +++ b/openstack_dashboard/dashboards/admin/volumes/tests.py @@ -75,10 +75,7 @@ class VolumeTests(test.BaseAdminViewTests): cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ .AndReturn(encryption_list) cinder.extension_supported(IsA(http.HttpRequest), - 'VolumeTypeEncryption')\ - .AndReturn(True) - cinder.extension_supported(IsA(http.HttpRequest), - 'VolumeTypeEncryption')\ + 'VolumeTypeEncryption').MultipleTimes()\ .AndReturn(True) self.mox.ReplayAll() diff --git a/openstack_dashboard/dashboards/admin/volumes/volume_types/tables.py b/openstack_dashboard/dashboards/admin/volumes/volume_types/tables.py index 3395b81266..29880f3636 100644 --- a/openstack_dashboard/dashboards/admin/volumes/volume_types/tables.py +++ b/openstack_dashboard/dashboards/admin/volumes/volume_types/tables.py @@ -84,6 +84,36 @@ class CreateVolumeTypeEncryption(tables.LinkAction): return False +class DeleteVolumeTypeEncryption(tables.DeleteAction): + name = "delete_encryption" + policy_rules = (("volume", "volume_extension:volume_type_encryption"),) + + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Encryption", + u"Delete Encryptions", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deleted Encryption", + u"Deleted Encryptions", + count + ) + + def delete(self, request, volume_type_id): + cinder.volume_encryption_type_delete(request, + volume_type_id) + + def allowed(self, request, volume_type=None): + return (_is_vol_type_enc_possible(request) and + hasattr(volume_type, 'encryption') and + hasattr(volume_type.encryption, 'provider')) + + def _is_vol_type_enc_possible(request): try: supported = cinder.extension_supported(request, @@ -126,6 +156,7 @@ class VolumeTypesTable(tables.DataTable): row_actions = (CreateVolumeTypeEncryption, ViewVolumeTypeExtras, ManageQosSpecAssociation, + DeleteVolumeTypeEncryption, DeleteVolumeType,) diff --git a/openstack_dashboard/dashboards/admin/volumes/volume_types/tests.py b/openstack_dashboard/dashboards/admin/volumes/volume_types/tests.py index 6fe03182df..94ec8c69d9 100644 --- a/openstack_dashboard/dashboards/admin/volumes/volume_types/tests.py +++ b/openstack_dashboard/dashboards/admin/volumes/volume_types/tests.py @@ -167,3 +167,38 @@ class VolumeTypeTests(test.BaseAdminViewTests): self.assertContains(res, "
%s
" % vol_enc_type.cipher, 1, 200) self.assertNoMessages() + + @test.create_stubs({cinder: ('extension_supported', + 'volume_type_list_with_qos_associations', + 'qos_spec_list', + 'volume_encryption_type_list', + 'volume_encryption_type_delete',)}) + def test_delete_volume_type_encryption(self): + volume_type = self.volume_types.first() + volume_type.id = u'1' + formData = {'action': 'volume_types__delete_encryption__%s' % + volume_type.id} + encryption_list = (self.cinder_volume_encryption_types.list()[0], + self.cinder_volume_encryption_types.list()[1]) + + cinder.extension_supported(IsA(http.HttpRequest), + 'VolumeTypeEncryption')\ + .AndReturn(True) + cinder.volume_type_list_with_qos_associations( + IsA(http.HttpRequest))\ + .AndReturn(self.volume_types.list()) + cinder.qos_spec_list(IsA(http.HttpRequest))\ + .AndReturn(self.cinder_qos_specs.list()) + cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ + .AndReturn(encryption_list) + cinder.volume_encryption_type_delete(IsA(http.HttpRequest), + volume_type.id) + self.mox.ReplayAll() + + res = self.client.post( + reverse('horizon:admin:volumes:volume_types_tab'), + formData) + + redirect = reverse('horizon:admin:volumes:volume_types_tab') + self.assertNoFormErrors(res) + self.assertRedirectsNoFollow(res, redirect)