From 2a2920e1314d6198f8bc6dd74912891a14cbfe73 Mon Sep 17 00:00:00 2001 From: Artom Lifshitz <alifshit@redhat.com> Date: Thu, 1 Jun 2017 16:13:48 -0400 Subject: [PATCH] Error out if nic auto or none are not alone Previously, the client would allow a boot command containing, for example, --nic auto,tag=foo, giving the impression that the auto nic would receive a tag. This is not the case. Instead of silently ignoring the tag argument in such a case, this patch makes the client error out with a warning message. Change-Id: Id7ef67435fa7a3f49c9abcb751f5fa9458388f13 Closes-bug: 1695088 --- novaclient/tests/unit/v2/test_shell.py | 24 ++++++++++++++++++++++++ novaclient/v2/shell.py | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index f5b469abd..8ecd64158 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -640,6 +640,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 07b4724cc..10285d6af 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -298,12 +298,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 @@ -320,6 +338,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)