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
This commit is contained in:
jeremy.zhang 2017-03-22 14:31:28 +08:00
parent 4411b2992c
commit 316d56462c
3 changed files with 58 additions and 26 deletions

View File

@ -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.

View File

@ -123,43 +123,55 @@ class VolumeTypesV2Test(base.BaseVolumeAdminTest):
fetched_volume_type['os-volume-type-access:is_public']) fetched_volume_type['os-volume-type-access:is_public'])
@decorators.idempotent_id('7830abd0-ff99-4793-a265-405684a54d46') @decorators.idempotent_id('7830abd0-ff99-4793-a265-405684a54d46')
def test_volume_type_encryption_create_get_delete(self): def test_volume_type_encryption_create_get_update_delete(self):
# Create/get/delete encryption type. # Create/get/update/delete encryption type.
provider = "LuksEncryptor" create_kwargs = {'provider': 'LuksEncryptor',
control_location = "front-end" 'control_location': 'front-end'}
body = self.create_volume_type() volume_type_id = self.create_volume_type()['id']
# Create encryption type # Create encryption type
encryption_type = \ encryption_type = \
self.admin_encryption_types_client.create_encryption_type( self.admin_encryption_types_client.create_encryption_type(
body['id'], provider=provider, volume_type_id, **create_kwargs)['encryption']
control_location=control_location)['encryption']
self.assertIn('volume_type_id', encryption_type) self.assertIn('volume_type_id', encryption_type)
self.assertEqual(provider, encryption_type['provider'], for key in create_kwargs:
"The created encryption_type provider is not equal " self.assertEqual(create_kwargs[key], encryption_type[key],
"to the requested provider") 'The created encryption_type %s is different '
self.assertEqual(control_location, encryption_type['control_location'], 'from the requested encryption_type' % key)
"The created encryption_type control_location is not "
"equal to the requested control_location")
# Get encryption type # Get encryption type
encrypt_type_id = encryption_type['volume_type_id']
fetched_encryption_type = ( fetched_encryption_type = (
self.admin_encryption_types_client.show_encryption_type( self.admin_encryption_types_client.show_encryption_type(
encryption_type['volume_type_id'])) encrypt_type_id))
self.assertEqual(provider, for key in create_kwargs:
fetched_encryption_type['provider'], self.assertEqual(create_kwargs[key], fetched_encryption_type[key],
'The fetched encryption_type provider is different ' 'The fetched encryption_type %s is different '
'from the created encryption_type') 'from the created encryption_type' % key)
self.assertEqual(control_location,
fetched_encryption_type['control_location'], # Update encryption type
'The fetched encryption_type control_location is ' update_kwargs = {'key_size': 128,
'different from the created encryption_type') '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 # Delete encryption type
type_id = encryption_type['volume_type_id'] self.admin_encryption_types_client.delete_encryption_type(
self.admin_encryption_types_client.delete_encryption_type(type_id) encrypt_type_id)
self.admin_encryption_types_client.wait_for_resource_deletion(type_id) self.admin_encryption_types_client.wait_for_resource_deletion(
encrypt_type_id)
deleted_encryption_type = ( 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) self.assertEmpty(deleted_encryption_type)
@decorators.idempotent_id('cf9f07c6-db9e-4462-a243-5933ad65e9c8') @decorators.idempotent_id('cf9f07c6-db9e-4462-a243-5933ad65e9c8')

View File

@ -67,3 +67,17 @@ class EncryptionTypesClient(rest_client.RestClient):
"/types/%s/encryption/provider" % volume_type_id) "/types/%s/encryption/provider" % volume_type_id)
self.expected_success(202, resp.status) self.expected_success(202, resp.status)
return rest_client.ResponseBody(resp, body) 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)