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
This commit is contained in:
Joe Gordon 2014-05-01 11:27:00 -07:00
parent 1e7ad37b8a
commit 28c89580af
4 changed files with 50 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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