From 28c89580af7230d40ed994b405b8b956560f23e8 Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Thu, 1 May 2014 11:27:00 -0700 Subject: [PATCH] Allow the default value of 1 to be set for boot multiple Allow one to call the following with their default values of 1: * nova boot --num-instances 1 * nova boot --min-count 1 * nova boot --max-count 1 Don't allow min_count>max_count. This is the only place where if a user passes in the default value the CLI will return an error. Change-Id: I805b3f0c778e9c70c5817624fb696a746dfe3d5b --- novaclient/tests/v1_1/test_shell.py | 17 +++++++++++++++-- novaclient/tests/v3/test_shell.py | 17 +++++++++++++++-- novaclient/v1_1/shell.py | 16 ++++++++++------ novaclient/v3/shell.py | 16 ++++++++++------ 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index d01155b24..883ac90c8 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -585,8 +585,6 @@ class ShellTest(utils.TestCase): }) def test_boot_invalid_num_instances(self): - cmd = 'boot --image 1 --flavor 1 --num-instances 1 server' - self.assertRaises(exceptions.CommandError, self.run_command, cmd) cmd = 'boot --image 1 --flavor 1 --num-instances 0 server' self.assertRaises(exceptions.CommandError, self.run_command, cmd) @@ -610,6 +608,19 @@ class ShellTest(utils.TestCase): } }) self.run_command('boot --image 1 --flavor 1 --min-count 3 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavorRef': '1', + 'name': 'server', + 'imageRef': '1', + 'min_count': 3, + 'max_count': 3, + } + }) + self.run_command('boot --image 1 --flavor 1 ' + '--min-count 3 --max-count 3 server') self.assert_called_anytime( 'POST', '/servers', { @@ -634,6 +645,8 @@ class ShellTest(utils.TestCase): 'max_count': 5, } }) + cmd = 'boot --image 1 --flavor 1 --min-count 3 --max-count 1 serv' + self.assertRaises(exceptions.CommandError, self.run_command, cmd) @mock.patch('novaclient.v1_1.shell._poll_for_status') def test_boot_with_poll(self, poll_method): diff --git a/novaclient/tests/v3/test_shell.py b/novaclient/tests/v3/test_shell.py index a18d97d10..a62d1df55 100644 --- a/novaclient/tests/v3/test_shell.py +++ b/novaclient/tests/v3/test_shell.py @@ -484,8 +484,6 @@ class ShellTest(utils.TestCase): }) def test_boot_invalid_num_instances(self): - cmd = 'boot --image 1 --flavor 1 --num-instances 1 server' - self.assertRaises(exceptions.CommandError, self.run_command, cmd) cmd = 'boot --image 1 --flavor 1 --num-instances 0 server' self.assertRaises(exceptions.CommandError, self.run_command, cmd) @@ -509,6 +507,19 @@ class ShellTest(utils.TestCase): } }) self.run_command('boot --image 1 --flavor 1 --min-count 3 server') + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavor_ref': '1', + 'name': 'server', + 'image_ref': '1', + 'os-multiple-create:min_count': 3, + 'os-multiple-create:max_count': 3, + } + }) + self.run_command('boot --image 1 --flavor 1 ' + '--min-count 3 --max-count 3 server') self.assert_called_anytime( 'POST', '/servers', { @@ -533,6 +544,8 @@ class ShellTest(utils.TestCase): 'os-multiple-create:max_count': 5, } }) + cmd = 'boot --image 1 --flavor 1 --min-count 3 --max-count 1 serv' + self.assertRaises(exceptions.CommandError, self.run_command, cmd) @mock.patch('novaclient.v3.shell._poll_for_status') def test_boot_with_poll(self, poll_method): diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 54774b6c4..0142cb802 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -151,22 +151,26 @@ def _boot(cs, args): # Don't let user mix num_instances and max_count/min_count. if (args.num_instances is not None and args.min_count is None and args.max_count is None): - if args.num_instances <= 1: - raise exceptions.CommandError(_("num_instances should be > 1")) + if args.num_instances < 1: + raise exceptions.CommandError(_("num_instances should be >= 1")) max_count = args.num_instances elif (args.num_instances is not None and (args.min_count is not None or args.max_count is not None)): raise exceptions.CommandError(_("Don't mix num-instances and " "max/min-count")) if args.min_count is not None: - if args.min_count <= 1: - raise exceptions.CommandError(_("min_count should be > 1")) + if args.min_count < 1: + raise exceptions.CommandError(_("min_count should be >= 1")) min_count = args.min_count max_count = min_count if args.max_count is not None: - if args.max_count <= 1: - raise exceptions.CommandError(_("max_count should be > 1")) + if args.max_count < 1: + raise exceptions.CommandError(_("max_count should be >= 1")) max_count = args.max_count + if (args.min_count is not None and args.max_count is not None and + args.min_count > args.max_count): + raise exceptions.CommandError(_( + "min_count should be <= max_count")) flavor = _find_flavor(cs, args.flavor) diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index 1d9c76c6d..967a893b8 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -87,22 +87,26 @@ def _boot(cs, args): # Don't let user mix num_instances and max_count/min_count. if (args.num_instances is not None and args.min_count is None and args.max_count is None): - if args.num_instances <= 1: - raise exceptions.CommandError("num_instances should be > 1") + if args.num_instances < 1: + raise exceptions.CommandError("num_instances should be >= 1") max_count = args.num_instances elif (args.num_instances is not None and (args.min_count is not None or args.max_count is not None)): raise exceptions.CommandError("Don't mix num-instances and " "max/min-count") if args.min_count is not None: - if args.min_count <= 1: - raise exceptions.CommandError("min_count should be > 1") + if args.min_count < 1: + raise exceptions.CommandError("min_count should be >= 1") min_count = args.min_count max_count = min_count if args.max_count is not None: - if args.max_count <= 1: - raise exceptions.CommandError("max_count should be > 1") + if args.max_count < 1: + raise exceptions.CommandError("max_count should be >= 1") max_count = args.max_count + if (args.min_count is not None and args.max_count is not None and + args.min_count > args.max_count): + raise exceptions.CommandError( + "min_count should be <= max_count") flavor = _find_flavor(cs, args.flavor)