From 316d56462c23cffba3ad99bc1e306a81781c39f8 Mon Sep 17 00:00:00 2001 From: "jeremy.zhang" Date: Wed, 22 Mar 2017 14:31:28 +0800 Subject: [PATCH] Add test case for update volume encryption type Including: [1] Add update encryption type api to v2 encryption types client [2] Add release note [3] Modify test case: test_volume_type_encryption_create_get_delete Change-Id: I60ee36b4d751eafc875e073e30a4f426ebd2a0d7 --- ...ryption-types-client-f3093532a0bcf9a1.yaml | 6 ++ tempest/api/volume/admin/test_volume_types.py | 64 +++++++++++-------- .../volume/v2/encryption_types_client.py | 14 ++++ 3 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 releasenotes/notes/add-update-encryption-type-to-encryption-types-client-f3093532a0bcf9a1.yaml diff --git a/releasenotes/notes/add-update-encryption-type-to-encryption-types-client-f3093532a0bcf9a1.yaml b/releasenotes/notes/add-update-encryption-type-to-encryption-types-client-f3093532a0bcf9a1.yaml new file mode 100644 index 0000000000..c95e77c906 --- /dev/null +++ b/releasenotes/notes/add-update-encryption-type-to-encryption-types-client-f3093532a0bcf9a1.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add update encryption type API to the v2 encryption_types_client library. + This feature enables the possibility to update an encryption type for an + existing volume type. diff --git a/tempest/api/volume/admin/test_volume_types.py b/tempest/api/volume/admin/test_volume_types.py index f75c940c19..19cb476452 100644 --- a/tempest/api/volume/admin/test_volume_types.py +++ b/tempest/api/volume/admin/test_volume_types.py @@ -123,43 +123,55 @@ class VolumeTypesV2Test(base.BaseVolumeAdminTest): fetched_volume_type['os-volume-type-access:is_public']) @decorators.idempotent_id('7830abd0-ff99-4793-a265-405684a54d46') - def test_volume_type_encryption_create_get_delete(self): - # Create/get/delete encryption type. - provider = "LuksEncryptor" - control_location = "front-end" - body = self.create_volume_type() + def test_volume_type_encryption_create_get_update_delete(self): + # Create/get/update/delete encryption type. + create_kwargs = {'provider': 'LuksEncryptor', + 'control_location': 'front-end'} + volume_type_id = self.create_volume_type()['id'] + # Create encryption type encryption_type = \ self.admin_encryption_types_client.create_encryption_type( - body['id'], provider=provider, - control_location=control_location)['encryption'] + volume_type_id, **create_kwargs)['encryption'] self.assertIn('volume_type_id', encryption_type) - self.assertEqual(provider, encryption_type['provider'], - "The created encryption_type provider is not equal " - "to the requested provider") - self.assertEqual(control_location, encryption_type['control_location'], - "The created encryption_type control_location is not " - "equal to the requested control_location") + for key in create_kwargs: + self.assertEqual(create_kwargs[key], encryption_type[key], + 'The created encryption_type %s is different ' + 'from the requested encryption_type' % key) # Get encryption type + encrypt_type_id = encryption_type['volume_type_id'] fetched_encryption_type = ( self.admin_encryption_types_client.show_encryption_type( - encryption_type['volume_type_id'])) - self.assertEqual(provider, - fetched_encryption_type['provider'], - 'The fetched encryption_type provider is different ' - 'from the created encryption_type') - self.assertEqual(control_location, - fetched_encryption_type['control_location'], - 'The fetched encryption_type control_location is ' - 'different from the created encryption_type') + encrypt_type_id)) + for key in create_kwargs: + self.assertEqual(create_kwargs[key], fetched_encryption_type[key], + 'The fetched encryption_type %s is different ' + 'from the created encryption_type' % key) + + # Update encryption type + update_kwargs = {'key_size': 128, + 'provider': 'SomeProvider', + 'cipher': 'aes-xts-plain64', + 'control_location': 'back-end'} + self.admin_encryption_types_client.update_encryption_type( + encrypt_type_id, **update_kwargs) + updated_encryption_type = ( + self.admin_encryption_types_client.show_encryption_type( + encrypt_type_id)) + for key in update_kwargs: + self.assertEqual(update_kwargs[key], updated_encryption_type[key], + 'The fetched encryption_type %s is different ' + 'from the updated encryption_type' % key) # Delete encryption type - type_id = encryption_type['volume_type_id'] - self.admin_encryption_types_client.delete_encryption_type(type_id) - self.admin_encryption_types_client.wait_for_resource_deletion(type_id) + self.admin_encryption_types_client.delete_encryption_type( + encrypt_type_id) + self.admin_encryption_types_client.wait_for_resource_deletion( + encrypt_type_id) deleted_encryption_type = ( - self.admin_encryption_types_client.show_encryption_type(type_id)) + self.admin_encryption_types_client.show_encryption_type( + encrypt_type_id)) self.assertEmpty(deleted_encryption_type) @decorators.idempotent_id('cf9f07c6-db9e-4462-a243-5933ad65e9c8') diff --git a/tempest/lib/services/volume/v2/encryption_types_client.py b/tempest/lib/services/volume/v2/encryption_types_client.py index 8b01f115b6..eeff537452 100755 --- a/tempest/lib/services/volume/v2/encryption_types_client.py +++ b/tempest/lib/services/volume/v2/encryption_types_client.py @@ -67,3 +67,17 @@ class EncryptionTypesClient(rest_client.RestClient): "/types/%s/encryption/provider" % volume_type_id) self.expected_success(202, resp.status) return rest_client.ResponseBody(resp, body) + + def update_encryption_type(self, volume_type_id, **kwargs): + """Update an encryption type for an existing volume type. + + TODO: Current api-site doesn't contain this API description. + After fixing the api-site, we need to fix here also for putting + the link to api-site. + """ + url = "/types/%s/encryption/provider" % volume_type_id + put_body = json.dumps({'encryption': kwargs}) + resp, body = self.put(url, put_body) + body = json.loads(body) + self.expected_success(200, resp.status) + return rest_client.ResponseBody(resp, body)