From 38388f892ba2dda4af6bf697f549c2a0d5b3e29c Mon Sep 17 00:00:00 2001 From: Peter Hamilton Date: Tue, 19 Nov 2013 08:11:58 -0500 Subject: [PATCH] Add encryption-type-delete to cinderclient This modification adds support for deleting volume encryption types. The encryption-type-delete command accepts a single argument, the name or ID of the volume type whose associated encryption type should be deleted. The encryption type may only be deleted if the associated volume type is unused. blueprint encrypt-cinder-volumes Change-Id: Ie189e7ec91f5a8adc9d3496911de2811ad40f282 --- cinderclient/tests/v1/fakes.py | 3 +++ cinderclient/tests/v1/test_shell.py | 8 +++++++- cinderclient/tests/v1/test_volume_encryption_types.py | 7 ++++++- cinderclient/tests/v2/fakes.py | 3 +++ cinderclient/tests/v2/test_shell.py | 8 +++++++- cinderclient/tests/v2/test_volume_encryption_types.py | 7 ++++++- cinderclient/v1/shell.py | 11 +++++++++++ cinderclient/v1/volume_encryption_types.py | 3 ++- cinderclient/v2/shell.py | 11 +++++++++++ cinderclient/v2/volume_encryption_types.py | 3 ++- 10 files changed, 58 insertions(+), 6 deletions(-) diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index 111683ad2..9c556ead9 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -468,6 +468,9 @@ class FakeHTTPClient(base_client.HTTPClient): def put_types_1_encryption_1(self, body, **kw): return (200, {}, {}) + def delete_types_1_encryption_provider(self, **kw): + return (202, {}, None) + # # Set/Unset metadata # diff --git a/cinderclient/tests/v1/test_shell.py b/cinderclient/tests/v1/test_shell.py index 1df55859e..7476536c8 100644 --- a/cinderclient/tests/v1/test_shell.py +++ b/cinderclient/tests/v1/test_shell.py @@ -275,8 +275,14 @@ class ShellTest(utils.TestCase): def test_encryption_type_delete(self): """ Test encryption-type-delete shell command. + + Verify one GET/one DELETE requests are made per command invocation: + - one GET request to retrieve the relevant volume type information + - one DELETE request to delete the encryption type information """ - self.skipTest("Not implemented") + self.run_command('encryption-type-delete 1') + self.assert_called('DELETE', '/types/1/encryption/provider') + self.assert_called_anytime('GET', '/types/1') def test_migrate_volume(self): self.run_command('migrate 1234 fakehost --force-host-copy=True') diff --git a/cinderclient/tests/v1/test_volume_encryption_types.py b/cinderclient/tests/v1/test_volume_encryption_types.py index d9af7d80c..0d9868c0f 100644 --- a/cinderclient/tests/v1/test_volume_encryption_types.py +++ b/cinderclient/tests/v1/test_volume_encryption_types.py @@ -91,5 +91,10 @@ class VolumeEncryptionTypesTest(utils.TestCase): def test_delete(self): """ Unit test for VolumeEncryptionTypesManager.delete + + Verify that one DELETE request is made for encryption type deletion + Verify that encryption type deletion returns None """ - self.skipTest("Not implemented") + result = cs.volume_encryption_types.delete(1) + cs.assert_called('DELETE', '/types/1/encryption/provider') + self.assertIsNone(result, "delete result must be None") diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index 5804d0f06..bc88805c9 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -475,6 +475,9 @@ class FakeHTTPClient(base_client.HTTPClient): def put_types_1_encryption_1(self, body, **kw): return (200, {}, {}) + def delete_types_1_encryption_provider(self, **kw): + return (202, {}, None) + # # Set/Unset metadata # diff --git a/cinderclient/tests/v2/test_shell.py b/cinderclient/tests/v2/test_shell.py index 44fb2b17e..9fc19d137 100644 --- a/cinderclient/tests/v2/test_shell.py +++ b/cinderclient/tests/v2/test_shell.py @@ -253,8 +253,14 @@ class ShellTest(utils.TestCase): def test_encryption_type_delete(self): """ Test encryption-type-delete shell command. + + Verify one GET/one DELETE requests are made per command invocation: + - one GET request to retrieve the relevant volume type information + - one DELETE request to delete the encryption type information """ - self.skipTest("Not implemented") + self.run_command('encryption-type-delete 1') + self.assert_called('DELETE', '/types/1/encryption/provider') + self.assert_called_anytime('GET', '/types/1') def test_migrate_volume(self): self.run_command('migrate 1234 fakehost --force-host-copy=True') diff --git a/cinderclient/tests/v2/test_volume_encryption_types.py b/cinderclient/tests/v2/test_volume_encryption_types.py index 96a0c02a4..0d609ea3f 100644 --- a/cinderclient/tests/v2/test_volume_encryption_types.py +++ b/cinderclient/tests/v2/test_volume_encryption_types.py @@ -91,5 +91,10 @@ class VolumeEncryptionTypesTest(utils.TestCase): def test_delete(self): """ Unit test for VolumeEncryptionTypesManager.delete + + Verify that one DELETE request is made for encryption type deletion + Verify that encryption type deletion returns None """ - self.skipTest("Not implemented") + result = cs.volume_encryption_types.delete(1) + cs.assert_called('DELETE', '/types/1/encryption/provider') + self.assertIsNone(result, "delete result must be None") diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index 0012388b0..f6c52a8e0 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -1116,6 +1116,17 @@ def do_encryption_type_create(cs, args): _print_volume_encryption_type_list([result]) +@utils.arg('volume_type', + metavar='', + type=str, + help="Name or ID of the volume type") +@utils.service_type('volume') +def do_encryption_type_delete(cs, args): + """Delete the encryption type for a volume type (Admin Only).""" + volume_type = _find_volume_type(cs, args.volume_type) + cs.volume_encryption_types.delete(volume_type) + + @utils.arg('volume', metavar='', help='ID of the volume to migrate') @utils.arg('host', metavar='', help='Destination host') @utils.arg('--force-host-copy', metavar='', diff --git a/cinderclient/v1/volume_encryption_types.py b/cinderclient/v1/volume_encryption_types.py index b97c6f02a..62892f54a 100644 --- a/cinderclient/v1/volume_encryption_types.py +++ b/cinderclient/v1/volume_encryption_types.py @@ -93,4 +93,5 @@ class VolumeEncryptionTypeManager(base.ManagerWithFind): :param volume_type: the volume type whose encryption type information must be deleted """ - raise NotImplementedError() + return self._delete("/types/%s/encryption/provider" % + base.getid(volume_type)) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index bce7585a0..2919d100a 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -1211,6 +1211,17 @@ def do_encryption_type_create(cs, args): _print_volume_encryption_type_list([result]) +@utils.arg('volume_type', + metavar='', + type=str, + help="Name or ID of the volume type") +@utils.service_type('volumev2') +def do_encryption_type_delete(cs, args): + """Delete the encryption type for a volume type (Admin Only).""" + volume_type = _find_volume_type(cs, args.volume_type) + cs.volume_encryption_types.delete(volume_type) + + def _print_qos_specs(qos_specs): utils.print_dict(qos_specs._info) diff --git a/cinderclient/v2/volume_encryption_types.py b/cinderclient/v2/volume_encryption_types.py index b97c6f02a..62892f54a 100644 --- a/cinderclient/v2/volume_encryption_types.py +++ b/cinderclient/v2/volume_encryption_types.py @@ -93,4 +93,5 @@ class VolumeEncryptionTypeManager(base.ManagerWithFind): :param volume_type: the volume type whose encryption type information must be deleted """ - raise NotImplementedError() + return self._delete("/types/%s/encryption/provider" % + base.getid(volume_type))