From 69f0090b65be88c93691f89dc1cd3e9f8e2a5ee0 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Fri, 24 Mar 2017 13:39:56 -0400 Subject: [PATCH] Handle dashes in encryption-type-create arguments encryption-type-create currently takes args "--key_size" and "--control_location". Our standard is to use dashes rather than underscores for arguments like this, because it's easier to type them. Additionally, encryption-type-update already uses "--key-size" and "--control-location" for the same args. This adds the dashed versions to the CLI and makes them the default shown in the help. The underscore versions are retained for compatibility. Also removes redundant "(Optional)" text for arguments listed under "Optional Arguments". This matches other commands. Change-Id: I1bd2b7657ec577b9775eacd163cfdf6eb6b6eab2 --- cinderclient/tests/unit/v2/test_shell.py | 11 +++++++++++ cinderclient/v2/shell.py | 25 +++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 742e9d916..2d0e01417 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -834,6 +834,17 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/types/2/encryption', body=expected) self.assert_called_anytime('GET', '/types/2') + @ddt.data('--key-size 512 --control-location front-end', + '--key_size 512 --control_location front-end') # old style + def test_encryption_type_create_with_args(self, arg): + expected = {'encryption': {'cipher': None, + 'key_size': 512, + 'provider': 'TestProvider', + 'control_location': 'front-end'}} + self.run_command('encryption-type-create 2 TestProvider ' + arg) + self.assert_called('POST', '/types/2/encryption', body=expected) + self.assert_called_anytime('GET', '/types/2') + def test_encryption_type_update(self): """ Test encryption-type-update shell command. diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 42dcb6fc0..a6c16f675 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -1685,14 +1685,19 @@ def do_encryption_type_show(cs, args): default=None, help='The encryption algorithm or mode. ' 'For example, aes-xts-plain64. Default=None.') -@utils.arg('--key_size', +@utils.arg('--key-size', metavar='', type=int, required=False, default=None, help='Size of encryption key, in bits. ' 'For example, 128 or 256. Default=None.') -@utils.arg('--control_location', +@utils.arg('--key_size', + type=int, + required=False, + default=None, + help=argparse.SUPPRESS) +@utils.arg('--control-location', metavar='', choices=['front-end', 'back-end'], type=str, @@ -1701,6 +1706,11 @@ def do_encryption_type_show(cs, args): help='Notional service where encryption is performed. ' 'Valid values are "front-end" or "back-end." ' 'For example, front-end=Nova. Default is "front-end."') +@utils.arg('--control_location', + type=str, + required=False, + default='front-end', + help=argparse.SUPPRESS) def do_encryption_type_create(cs, args): """Creates encryption type for a volume type. Admin only.""" volume_type = shell_utils.find_volume_type(cs, args.volume_type) @@ -1725,8 +1735,7 @@ def do_encryption_type_create(cs, args): type=str, required=False, default=argparse.SUPPRESS, - help="Class providing encryption support (e.g. LuksEncryptor) " - "(Optional)") + help="Class providing encryption support (e.g. LuksEncryptor)") @utils.arg('--cipher', metavar='', type=str, @@ -1735,8 +1744,7 @@ def do_encryption_type_create(cs, args): 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)") + "Provide parameter without value to set to provider default.") @utils.arg('--key-size', dest='key_size', metavar='', @@ -1746,8 +1754,7 @@ def do_encryption_type_create(cs, args): 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)") + "Provide parameter without value to set to provider default. ") @utils.arg('--control-location', dest='control_location', metavar='', @@ -1756,7 +1763,7 @@ def do_encryption_type_create(cs, args): required=False, default=argparse.SUPPRESS, help="Notional service where encryption is performed (e.g., " - "front-end=Nova). Values: 'front-end', 'back-end' (Optional)") + "front-end=Nova). Values: 'front-end', 'back-end'") def do_encryption_type_update(cs, args): """Update encryption type information for a volume type (Admin Only).""" volume_type = shell_utils.find_volume_type(cs, args.volume_type)