diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 893dd4ffc..15a267eaa 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -650,6 +650,30 @@ class ShellTest(utils.TestCase): }, ) + def test_boot_nic_auto_not_alone_after(self): + cmd = ('boot --image %s --flavor 1 ' + '--nic auto,tag=foo some-server' % + FAKE_UUID_1) + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + + def test_boot_nic_auto_not_alone_before(self): + cmd = ('boot --image %s --flavor 1 ' + '--nic tag=foo,auto some-server' % + FAKE_UUID_1) + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + + def test_boot_nic_none_not_alone_before(self): + cmd = ('boot --image %s --flavor 1 ' + '--nic none,tag=foo some-server' % + FAKE_UUID_1) + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + + def test_boot_nic_none_not_alone_after(self): + cmd = ('boot --image %s --flavor 1 ' + '--nic tag=foo,none some-server' % + FAKE_UUID_1) + self.assertRaises(exceptions.CommandError, self.run_command, cmd) + def test_boot_nics(self): cmd = ('boot --image %s --flavor 1 ' '--nic net-id=a=c,v4-fixed-ip=10.0.0.1 some-server' % diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 084d316e1..951f6e9ed 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -310,12 +310,30 @@ def _parse_nics(cs, args): auto_or_none = False nics = [] for nic_str in args.nics: + nic_info_set = False for kv_str in nic_str.split(","): + if auto_or_none: + # Since we start with auto_or_none being False, it being true + # means we've parsed an auto or none argument, then continued + # after the comma to another key=value pair. Since auto or none + # can only be given by themselves, raise. + raise exceptions.CommandError(_("'auto' or 'none' cannot be " + "used with any other nic " + "arguments")) try: # handle the special auto/none cases if kv_str in ('auto', 'none'): if not supports_auto_alloc: raise exceptions.CommandError(err_msg % nic_str) + if nic_info_set: + # Since we start with nic_info_set being False, it + # being true means we've parsed a key=value pair, then + # landed on a auto or none argument after the comma. + # Since auto or none can only be given by themselves, + # raise. + raise exceptions.CommandError( + _("'auto' or 'none' cannot be used with any " + "other nic arguments")) nics.append(kv_str) auto_or_none = True continue @@ -332,6 +350,7 @@ def _parse_nics(cs, args): if nic_info[k]: raise exceptions.CommandError(err_msg % nic_str) nic_info[k] = v + nic_info_set = True else: raise exceptions.CommandError(err_msg % nic_str)