From ca9be53870529f7098b7e63415395c5551d0e605 Mon Sep 17 00:00:00 2001 From: Trevor McCasland Date: Mon, 26 Sep 2016 10:19:45 -0500 Subject: [PATCH] Throw correct error on creation of size 0 When trying to create an instance of size 0 an error is thrown stating that the size was not specified, this is not correct because I did specify it. The problem is that args.size evaluates to False because size is 0. This patch checks for size being zero instead and throws the correct error message. Change-Id: If00e83ccd919429dcfac7621dbbd9daa49f8b416 --- troveclient/tests/test_v1_shell.py | 4 ++++ troveclient/v1/shell.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/troveclient/tests/test_v1_shell.py b/troveclient/tests/test_v1_shell.py index 660b7890..58c9d4cb 100644 --- a/troveclient/tests/test_v1_shell.py +++ b/troveclient/tests/test_v1_shell.py @@ -274,6 +274,10 @@ class ShellTest(utils.TestCase): self.run_command('cluster-force-delete cls-1234') self.assert_called('DELETE', '/clusters/cls-1234') + def test_boot_fail_with_size_0(self): + self.assertRaises(exceptions.ValidationError, self.run_command, + 'create test-member-1 1 --size 0 --volume_type lvm') + def test_boot(self): self.run_command('create test-member-1 1 --size 1 --volume_type lvm') self.assert_called_anytime( diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index 712aa830..7fef8cbf 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -521,7 +521,11 @@ def do_create(cs, args): """Creates a new instance.""" flavor_id = _find_flavor(cs, args.flavor).id volume = None - if args.size: + if args.size is not None and args.size <= 0: + raise exceptions.ValidationError( + "Volume size '%s' must be an integer and greater than 0." + % args.size) + elif args.size: volume = {"size": args.size, "type": args.volume_type} restore_point = None