From a1c00740c5b709a7d2bc4289fa6e28eac7909b8f Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Wed, 9 Aug 2017 14:39:51 +0800 Subject: [PATCH] Allow boot server with multiple nics Trying to boot a server while specifying multiple --nic parameters leads to an error: Invalid nic argument. This patch fixes it. Change-Id: I662fd366df8e79db1966d45a9e090087dbace4b0 Closes-Bug: #1706597 (cherry picked from commit 0a3cf89c67a3fb78876137506fe57e645f4fabe4) --- novaclient/tests/unit/v2/test_shell.py | 23 +++++++++++++++++++ novaclient/v2/shell.py | 18 +++++++-------- ...g-with-multiple-nics-c6e5885b948d35ba.yaml | 4 ++++ 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/fix-booting-with-multiple-nics-c6e5885b948d35ba.yaml diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 2a1514552..7b33d90fd 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -695,6 +695,29 @@ class ShellTest(utils.TestCase): }, ) + def test_boot_with_multiple_nics(self): + cmd = ('boot --image %s --flavor 1 ' + '--nic net-id=net_a,v4-fixed-ip=10.0.0.1 ' + '--nic net-id=net_b some-server' % + FAKE_UUID_1) + self.run_command(cmd) + self.assert_called_anytime( + 'POST', '/servers', + { + 'server': { + 'flavorRef': '1', + 'name': 'some-server', + 'imageRef': FAKE_UUID_1, + 'min_count': 1, + 'max_count': 1, + 'networks': [ + {'uuid': 'net_a', 'fixed_ip': '10.0.0.1'}, + {'uuid': 'net_b'} + ], + }, + }, + ) + def test_boot_nics_with_tag(self): cmd = ('boot --image %s --flavor 1 ' '--nic net-id=a=c,v4-fixed-ip=10.0.0.1,tag=foo some-server' % diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 63c665901..46b50abcc 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -268,12 +268,11 @@ def _parse_nics(cs, args): supports_auto_alloc = cs.api_version >= api_versions.APIVersion('2.37') supports_nic_tags = _supports_nic_tags(cs) - nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "", - "port-id": "", "net-name": ""} + nic_keys = {'net-id', 'v4-fixed-ip', 'v6-fixed-ip', 'port-id', 'net-name'} if supports_auto_alloc and supports_nic_tags: # API version >= 2.42 - nic_info.update({"tag": ""}) + nic_keys.add('tag') err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of " "the form --nic = API version >= 2.32 - nic_info.update({"tag": ""}) + nic_keys.add('tag') err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of " "the form --nic