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
This commit is contained in:
Anton Arefiev 2015-05-12 17:42:10 +03:00
parent 4f7bb8f3d7
commit 9cd42ef3ee
2 changed files with 9 additions and 2 deletions

View File

@ -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')

View File

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