compute: Fix '--network none/auto' handling

This should lookup a network called 'none' or 'auto', not do the
equivalent on '--nic none' or '--nic auto'. Correct this.

Change-Id: I3c5acc49bfe8162d8fb6110603da56d56090b78f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Story: 2010385
Task: 46658
This commit is contained in:
Stephen Finucane 2022-10-26 18:17:38 +03:00
parent 681934a96a
commit ed0d568b94
2 changed files with 43 additions and 17 deletions

View File

@ -721,11 +721,6 @@ class NICAction(argparse.Action):
if getattr(namespace, self.dest, None) is None: if getattr(namespace, self.dest, None) is None:
setattr(namespace, self.dest, []) setattr(namespace, self.dest, [])
# Handle the special auto/none cases
if values in ('auto', 'none'):
getattr(namespace, self.dest).append(values)
return
if self.key: if self.key:
if ',' in values or '=' in values: if ',' in values or '=' in values:
msg = _( msg = _(
@ -735,6 +730,12 @@ class NICAction(argparse.Action):
raise argparse.ArgumentTypeError(msg % values) raise argparse.ArgumentTypeError(msg % values)
values = '='.join([self.key, values]) values = '='.join([self.key, values])
else:
# Handle the special auto/none cases but only when a key isn't set
# (otherwise those could be valid values for the key)
if values in ('auto', 'none'):
getattr(namespace, self.dest).append(values)
return
# We don't include 'tag' here by default since that requires a # We don't include 'tag' here by default since that requires a
# particular microversion # particular microversion

View File

@ -1675,6 +1675,7 @@ class TestServerCreate(TestServer):
'--nic', 'net-id=net1,v4-fixed-ip=10.0.0.2', '--nic', 'net-id=net1,v4-fixed-ip=10.0.0.2',
'--port', 'port1', '--port', 'port1',
'--network', 'net1', '--network', 'net1',
'--network', 'auto', # this is a network called 'auto'
'--nic', 'port-id=port2', '--nic', 'port-id=port2',
self.new_server.name, self.new_server.name,
] ]
@ -1683,24 +1684,40 @@ class TestServerCreate(TestServer):
('flavor', 'flavor1'), ('flavor', 'flavor1'),
('nics', [ ('nics', [
{ {
'net-id': 'net1', 'port-id': '', 'net-id': 'net1',
'v4-fixed-ip': '', 'v6-fixed-ip': '', 'port-id': '',
'v4-fixed-ip': '',
'v6-fixed-ip': '',
}, },
{ {
'net-id': 'net1', 'port-id': '', 'net-id': 'net1',
'v4-fixed-ip': '10.0.0.2', 'v6-fixed-ip': '', 'port-id': '',
'v4-fixed-ip': '10.0.0.2',
'v6-fixed-ip': '',
}, },
{ {
'net-id': '', 'port-id': 'port1', 'net-id': '',
'v4-fixed-ip': '', 'v6-fixed-ip': '', 'port-id': 'port1',
'v4-fixed-ip': '',
'v6-fixed-ip': '',
}, },
{ {
'net-id': 'net1', 'port-id': '', 'net-id': 'net1',
'v4-fixed-ip': '', 'v6-fixed-ip': '', 'port-id': '',
'v4-fixed-ip': '',
'v6-fixed-ip': '',
}, },
{ {
'net-id': '', 'port-id': 'port2', 'net-id': 'auto',
'v4-fixed-ip': '', 'v6-fixed-ip': '', 'port-id': '',
'v4-fixed-ip': '',
'v6-fixed-ip': '',
},
{
'net-id': '',
'port-id': 'port2',
'v4-fixed-ip': '',
'v6-fixed-ip': '',
}, },
]), ]),
('config_drive', False), ('config_drive', False),
@ -1729,12 +1746,16 @@ class TestServerCreate(TestServer):
"port2": port2_resource}[port_id]) "port2": port2_resource}[port_id])
# Mock sdk APIs. # Mock sdk APIs.
_network = mock.Mock(id='net1_uuid') _network_1 = mock.Mock(id='net1_uuid')
_network_auto = mock.Mock(id='auto_uuid')
_port1 = mock.Mock(id='port1_uuid') _port1 = mock.Mock(id='port1_uuid')
_port2 = mock.Mock(id='port2_uuid') _port2 = mock.Mock(id='port2_uuid')
find_network = mock.Mock() find_network = mock.Mock()
find_port = mock.Mock() find_port = mock.Mock()
find_network.return_value = _network find_network.side_effect = lambda net_id, ignore_missing: {
"net1": _network_1,
"auto": _network_auto,
}[net_id]
find_port.side_effect = (lambda port_id, ignore_missing: find_port.side_effect = (lambda port_id, ignore_missing:
{"port1": _port1, {"port1": _port1,
"port2": _port2}[port_id]) "port2": _port2}[port_id])
@ -1775,6 +1796,10 @@ class TestServerCreate(TestServer):
'v4-fixed-ip': '', 'v4-fixed-ip': '',
'v6-fixed-ip': '', 'v6-fixed-ip': '',
'port-id': ''}, 'port-id': ''},
{'net-id': 'auto_uuid',
'v4-fixed-ip': '',
'v6-fixed-ip': '',
'port-id': ''},
{'net-id': '', {'net-id': '',
'v4-fixed-ip': '', 'v4-fixed-ip': '',
'v6-fixed-ip': '', 'v6-fixed-ip': '',