From 9cd42ef3ee5e8b386cb6e1941b39608ed216a04f Mon Sep 17 00:00:00 2001 From: Anton Arefiev Date: Tue, 12 May 2015 17:42:10 +0300 Subject: [PATCH] Fix condition in CheckSizeArgForCreate parser action CheckSizeArgForCreate checks that size is specified when snapshot or source volume aren't. But when size is 0, CheckSizeArgForCreate action works wrong and generates error: 'Size is a required parameter if snapshot or source volume is not specified', meanwhile user expected to see: 'Volume size '0' must be greater than 0'. Change-Id: I164970a600d6e86bd7076dd485f676a703f5e487 Closes-Bug: #1454276 --- cinderclient/tests/unit/v2/test_shell.py | 7 +++++++ cinderclient/v2/shell.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 07f44eb..0e2421a 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -334,6 +334,13 @@ class ShellTest(utils.TestCase): def test_create_size_required_if_not_snapshot_or_clone(self): self.assertRaises(SystemExit, self.run_command, 'create') + def test_create_size_zero_if_not_snapshot_or_clone(self): + expected = {'volume': {'status': 'creating', + 'size': 0}} + self.run_command('create 0') + self.assert_called_anytime('POST', '/volumes', partial_body=expected) + self.assert_called('GET', '/volumes/1234') + def test_show(self): self.run_command('show 1234') self.assert_called('GET', '/volumes/1234') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 3c13636..463f43d 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -261,8 +261,8 @@ def do_show(cs, args): class CheckSizeArgForCreate(argparse.Action): def __call__(self, parser, args, values, option_string=None): - if (values or args.snapshot_id or args.source_volid - or args.source_replica) is None: + if ((args.snapshot_id or args.source_volid or args.source_replica) + is None and values is None): parser.error('Size is a required parameter if snapshot ' 'or source volume is not specified.') setattr(args, self.dest, values)