Merge "Add encryption-type-update to cinderclient"
This commit is contained in:
@@ -693,8 +693,12 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
def post_types_2_encryption(self, body, **kw):
|
def post_types_2_encryption(self, body, **kw):
|
||||||
return (200, {}, {'encryption': body})
|
return (200, {}, {'encryption': body})
|
||||||
|
|
||||||
def put_types_1_encryption_1(self, body, **kw):
|
def put_types_1_encryption_provider(self, body, **kw):
|
||||||
return (200, {}, {})
|
get_body = self.get_types_1_encryption()[2]
|
||||||
|
for k, v in body.items():
|
||||||
|
if k in get_body.keys():
|
||||||
|
get_body.update([(k, v)])
|
||||||
|
return (200, {}, get_body)
|
||||||
|
|
||||||
def delete_types_1_encryption_provider(self, **kw):
|
def delete_types_1_encryption_provider(self, **kw):
|
||||||
return (202, {}, None)
|
return (202, {}, None)
|
||||||
|
@@ -609,8 +609,67 @@ class ShellTest(utils.TestCase):
|
|||||||
- one GET request to retrieve the relevant volume type information
|
- one GET request to retrieve the relevant volume type information
|
||||||
- one GET request to retrieve the relevant encryption type information
|
- one GET request to retrieve the relevant encryption type information
|
||||||
- one PUT request to update the encryption type information
|
- one PUT request to update the encryption type information
|
||||||
|
Verify that the PUT request correctly parses encryption-type-update
|
||||||
|
parameters from sys.argv
|
||||||
"""
|
"""
|
||||||
self.skipTest("Not implemented")
|
parameters = {'--provider': 'EncryptionProvider', '--cipher': 'des',
|
||||||
|
'--key-size': 1024, '--control-location': 'back-end'}
|
||||||
|
|
||||||
|
# Construct the argument string for the update call and the
|
||||||
|
# expected encryption-type body that should be produced by it
|
||||||
|
args = ' '.join(['%s %s' % (k, v) for k, v in parameters.items()])
|
||||||
|
expected = {'encryption': {'provider': 'EncryptionProvider',
|
||||||
|
'cipher': 'des',
|
||||||
|
'key_size': 1024,
|
||||||
|
'control_location': 'back-end'}}
|
||||||
|
|
||||||
|
self.run_command('encryption-type-update 1 %s' % args)
|
||||||
|
self.assert_called('GET', '/types/1/encryption')
|
||||||
|
self.assert_called_anytime('GET', '/types/1')
|
||||||
|
self.assert_called_anytime('PUT', '/types/1/encryption/provider',
|
||||||
|
body=expected)
|
||||||
|
|
||||||
|
def test_encryption_type_update_no_attributes(self):
|
||||||
|
"""
|
||||||
|
Test encryption-type-update shell command.
|
||||||
|
|
||||||
|
Verify two GETs/one PUT requests are made per command invocation:
|
||||||
|
- one GET request to retrieve the relevant volume type information
|
||||||
|
- one GET request to retrieve the relevant encryption type information
|
||||||
|
- one PUT request to update the encryption type information
|
||||||
|
"""
|
||||||
|
expected = {'encryption': {}}
|
||||||
|
self.run_command('encryption-type-update 1')
|
||||||
|
self.assert_called('GET', '/types/1/encryption')
|
||||||
|
self.assert_called_anytime('GET', '/types/1')
|
||||||
|
self.assert_called_anytime('PUT', '/types/1/encryption/provider',
|
||||||
|
body=expected)
|
||||||
|
|
||||||
|
def test_encryption_type_update_default_attributes(self):
|
||||||
|
"""
|
||||||
|
Test encryption-type-update shell command.
|
||||||
|
|
||||||
|
Verify two GETs/one PUT requests are made per command invocation:
|
||||||
|
- one GET request to retrieve the relevant volume type information
|
||||||
|
- one GET request to retrieve the relevant encryption type information
|
||||||
|
- one PUT request to update the encryption type information
|
||||||
|
Verify that the encryption-type body produced contains default None
|
||||||
|
values for all specified parameters.
|
||||||
|
"""
|
||||||
|
parameters = ['--cipher', '--key-size']
|
||||||
|
|
||||||
|
# Construct the argument string for the update call and the
|
||||||
|
# expected encryption-type body that should be produced by it
|
||||||
|
args = ' '.join(['%s' % (p) for p in parameters])
|
||||||
|
expected_pairs = [(k.strip('-').replace('-', '_'), None) for k in
|
||||||
|
parameters]
|
||||||
|
expected = {'encryption': dict(expected_pairs)}
|
||||||
|
|
||||||
|
self.run_command('encryption-type-update 1 %s' % args)
|
||||||
|
self.assert_called('GET', '/types/1/encryption')
|
||||||
|
self.assert_called_anytime('GET', '/types/1')
|
||||||
|
self.assert_called_anytime('PUT', '/types/1/encryption/provider',
|
||||||
|
body=expected)
|
||||||
|
|
||||||
def test_encryption_type_delete(self):
|
def test_encryption_type_delete(self):
|
||||||
"""
|
"""
|
||||||
|
@@ -84,8 +84,18 @@ class VolumeEncryptionTypesTest(utils.TestCase):
|
|||||||
def test_update(self):
|
def test_update(self):
|
||||||
"""
|
"""
|
||||||
Unit test for VolumeEncryptionTypesManager.update
|
Unit test for VolumeEncryptionTypesManager.update
|
||||||
|
|
||||||
|
Verify that one PUT request is made for encryption type update
|
||||||
|
Verify that an empty encryption-type update returns the original
|
||||||
|
encryption-type information.
|
||||||
"""
|
"""
|
||||||
self.skipTest("Not implemented")
|
expected = {'id': 1, 'volume_type_id': 1, 'provider': 'test',
|
||||||
|
'cipher': 'test', 'key_size': 1,
|
||||||
|
'control_location': 'front-end'}
|
||||||
|
result = cs.volume_encryption_types.update(1, {})
|
||||||
|
cs.assert_called('PUT', '/types/1/encryption/provider')
|
||||||
|
self.assertEqual(expected, result,
|
||||||
|
"empty update must yield original data")
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
"""
|
"""
|
||||||
|
@@ -1545,6 +1545,63 @@ def do_encryption_type_create(cs, args):
|
|||||||
_print_volume_encryption_type_list([result])
|
_print_volume_encryption_type_list([result])
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('volume_type',
|
||||||
|
metavar='<volume-type>',
|
||||||
|
type=str,
|
||||||
|
help="Name or ID of the volume type")
|
||||||
|
@utils.arg('--provider',
|
||||||
|
metavar='<provider>',
|
||||||
|
type=str,
|
||||||
|
required=False,
|
||||||
|
default=argparse.SUPPRESS,
|
||||||
|
help="Class providing encryption support (e.g. LuksEncryptor) "
|
||||||
|
"(Optional)")
|
||||||
|
@utils.arg('--cipher',
|
||||||
|
metavar='<cipher>',
|
||||||
|
type=str,
|
||||||
|
nargs='?',
|
||||||
|
required=False,
|
||||||
|
default=argparse.SUPPRESS,
|
||||||
|
const=None,
|
||||||
|
help="Encryption algorithm/mode to use (e.g., aes-xts-plain64). "
|
||||||
|
"Provide parameter without value to set to provider default. "
|
||||||
|
"(Optional)")
|
||||||
|
@utils.arg('--key-size',
|
||||||
|
dest='key_size',
|
||||||
|
metavar='<key-size>',
|
||||||
|
type=int,
|
||||||
|
nargs='?',
|
||||||
|
required=False,
|
||||||
|
default=argparse.SUPPRESS,
|
||||||
|
const=None,
|
||||||
|
help="Size of the encryption key, in bits (e.g., 128, 256). "
|
||||||
|
"Provide parameter without value to set to provider default. "
|
||||||
|
"(Optional)")
|
||||||
|
@utils.arg('--control-location',
|
||||||
|
dest='control_location',
|
||||||
|
metavar='<control-location>',
|
||||||
|
choices=['front-end', 'back-end'],
|
||||||
|
type=str,
|
||||||
|
required=False,
|
||||||
|
default=argparse.SUPPRESS,
|
||||||
|
help="Notional service where encryption is performed (e.g., "
|
||||||
|
"front-end=Nova). Values: 'front-end', 'back-end' (Optional)")
|
||||||
|
@utils.service_type('volumev2')
|
||||||
|
def do_encryption_type_update(cs, args):
|
||||||
|
"""Update encryption type information for a volume type (Admin Only)."""
|
||||||
|
volume_type = _find_volume_type(cs, args.volume_type)
|
||||||
|
|
||||||
|
# An argument should only be pulled if the user specified the parameter.
|
||||||
|
body = {}
|
||||||
|
for attr in ['provider', 'cipher', 'key_size', 'control_location']:
|
||||||
|
if hasattr(args, attr):
|
||||||
|
body[attr] = getattr(args, attr)
|
||||||
|
|
||||||
|
cs.volume_encryption_types.update(volume_type, body)
|
||||||
|
result = cs.volume_encryption_types.get(volume_type)
|
||||||
|
_print_volume_encryption_type_list([result])
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('volume_type',
|
@utils.arg('volume_type',
|
||||||
metavar='<volume_type>',
|
metavar='<volume_type>',
|
||||||
type=str,
|
type=str,
|
||||||
|
@@ -84,7 +84,9 @@ class VolumeEncryptionTypeManager(base.ManagerWithFind):
|
|||||||
:param specs: the encryption type specifications to update
|
:param specs: the encryption type specifications to update
|
||||||
:return: an instance of :class: VolumeEncryptionType
|
:return: an instance of :class: VolumeEncryptionType
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
body = {'encryption': specs}
|
||||||
|
return self._update("/types/%s/encryption/provider" %
|
||||||
|
base.getid(volume_type), body)
|
||||||
|
|
||||||
def delete(self, volume_type):
|
def delete(self, volume_type):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user