Skip to content

Commit 0a3cf89

Browse files
author
huangtianhua
committed
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
1 parent aec9363 commit 0a3cf89

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

novaclient/tests/unit/v2/test_shell.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,29 @@ def test_boot_nics(self):
695695
},
696696
)
697697

698+
def test_boot_with_multiple_nics(self):
699+
cmd = ('boot --image %s --flavor 1 '
700+
'--nic net-id=net_a,v4-fixed-ip=10.0.0.1 '
701+
'--nic net-id=net_b some-server' %
702+
FAKE_UUID_1)
703+
self.run_command(cmd)
704+
self.assert_called_anytime(
705+
'POST', '/servers',
706+
{
707+
'server': {
708+
'flavorRef': '1',
709+
'name': 'some-server',
710+
'imageRef': FAKE_UUID_1,
711+
'min_count': 1,
712+
'max_count': 1,
713+
'networks': [
714+
{'uuid': 'net_a', 'fixed_ip': '10.0.0.1'},
715+
{'uuid': 'net_b'}
716+
],
717+
},
718+
},
719+
)
720+
698721
def test_boot_nics_with_tag(self):
699722
cmd = ('boot --image %s --flavor 1 '
700723
'--nic net-id=a=c,v4-fixed-ip=10.0.0.1,tag=foo some-server' %

novaclient/v2/shell.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,11 @@ def _parse_nics(cs, args):
268268
supports_auto_alloc = cs.api_version >= api_versions.APIVersion('2.37')
269269
supports_nic_tags = _supports_nic_tags(cs)
270270

271-
nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "",
272-
"port-id": "", "net-name": ""}
271+
nic_keys = {'net-id', 'v4-fixed-ip', 'v6-fixed-ip', 'port-id', 'net-name'}
273272

274273
if supports_auto_alloc and supports_nic_tags:
275274
# API version >= 2.42
276-
nic_info.update({"tag": ""})
275+
nic_keys.add('tag')
277276
err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of "
278277
"the form --nic <auto,none,net-id=net-uuid,"
279278
"net-name=network-name,v4-fixed-ip=ip-addr,"
@@ -292,7 +291,7 @@ def _parse_nics(cs, args):
292291
"be used with any other --nic value."))
293292
elif not supports_auto_alloc and supports_nic_tags:
294293
# 2.36 >= API version >= 2.32
295-
nic_info.update({"tag": ""})
294+
nic_keys.add('tag')
296295
err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of "
297296
"the form --nic <net-id=net-uuid,"
298297
"net-name=network-name,v4-fixed-ip=ip-addr,"
@@ -310,6 +309,7 @@ def _parse_nics(cs, args):
310309
auto_or_none = False
311310
nics = []
312311
for nic_str in args.nics:
312+
nic_info = {}
313313
nic_info_set = False
314314
for kv_str in nic_str.split(","):
315315
if auto_or_none:
@@ -341,13 +341,13 @@ def _parse_nics(cs, args):
341341
except ValueError:
342342
raise exceptions.CommandError(err_msg % nic_str)
343343

344-
if k in nic_info:
344+
if k in nic_keys:
345345
# if user has given a net-name resolve it to network ID
346346
if k == 'net-name':
347347
k = 'net-id'
348348
v = _find_network_id(cs, v)
349349
# if some argument was given multiple times
350-
if nic_info[k]:
350+
if k in nic_info:
351351
raise exceptions.CommandError(err_msg % nic_str)
352352
nic_info[k] = v
353353
nic_info_set = True
@@ -357,15 +357,15 @@ def _parse_nics(cs, args):
357357
if auto_or_none:
358358
continue
359359

360-
if nic_info['v4-fixed-ip'] and not netutils.is_valid_ipv4(
360+
if 'v4-fixed-ip' in nic_info and not netutils.is_valid_ipv4(
361361
nic_info['v4-fixed-ip']):
362362
raise exceptions.CommandError(_("Invalid ipv4 address."))
363363

364-
if nic_info['v6-fixed-ip'] and not netutils.is_valid_ipv6(
364+
if 'v6-fixed-ip' in nic_info and not netutils.is_valid_ipv6(
365365
nic_info['v6-fixed-ip']):
366366
raise exceptions.CommandError(_("Invalid ipv6 address."))
367367

368-
if bool(nic_info['net-id']) == bool(nic_info['port-id']):
368+
if bool(nic_info.get('net-id')) == bool(nic_info.get('port-id')):
369369
raise exceptions.CommandError(err_msg % nic_str)
370370

371371
nics.append(nic_info)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- Fix an ability to boot server with multiple nics which was broken with
4+
microversion 2.42 (fix tag attribute disappearing).

0 commit comments

Comments
 (0)