Skip to content

Commit 16f18d4

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "compute: Fix '--network none/auto' handling"
2 parents 348eb79 + ed0d568 commit 16f18d4

2 files changed

Lines changed: 43 additions & 17 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,6 @@ def __call__(self, parser, namespace, values, option_string=None):
721721
if getattr(namespace, self.dest, None) is None:
722722
setattr(namespace, self.dest, [])
723723

724-
# Handle the special auto/none cases
725-
if values in ('auto', 'none'):
726-
getattr(namespace, self.dest).append(values)
727-
return
728-
729724
if self.key:
730725
if ',' in values or '=' in values:
731726
msg = _(
@@ -735,6 +730,12 @@ def __call__(self, parser, namespace, values, option_string=None):
735730
raise argparse.ArgumentTypeError(msg % values)
736731

737732
values = '='.join([self.key, values])
733+
else:
734+
# Handle the special auto/none cases but only when a key isn't set
735+
# (otherwise those could be valid values for the key)
736+
if values in ('auto', 'none'):
737+
getattr(namespace, self.dest).append(values)
738+
return
738739

739740
# We don't include 'tag' here by default since that requires a
740741
# particular microversion

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,7 @@ def test_server_create_with_network(self):
16751675
'--nic', 'net-id=net1,v4-fixed-ip=10.0.0.2',
16761676
'--port', 'port1',
16771677
'--network', 'net1',
1678+
'--network', 'auto', # this is a network called 'auto'
16781679
'--nic', 'port-id=port2',
16791680
self.new_server.name,
16801681
]
@@ -1683,24 +1684,40 @@ def test_server_create_with_network(self):
16831684
('flavor', 'flavor1'),
16841685
('nics', [
16851686
{
1686-
'net-id': 'net1', 'port-id': '',
1687-
'v4-fixed-ip': '', 'v6-fixed-ip': '',
1687+
'net-id': 'net1',
1688+
'port-id': '',
1689+
'v4-fixed-ip': '',
1690+
'v6-fixed-ip': '',
16881691
},
16891692
{
1690-
'net-id': 'net1', 'port-id': '',
1691-
'v4-fixed-ip': '10.0.0.2', 'v6-fixed-ip': '',
1693+
'net-id': 'net1',
1694+
'port-id': '',
1695+
'v4-fixed-ip': '10.0.0.2',
1696+
'v6-fixed-ip': '',
16921697
},
16931698
{
1694-
'net-id': '', 'port-id': 'port1',
1695-
'v4-fixed-ip': '', 'v6-fixed-ip': '',
1699+
'net-id': '',
1700+
'port-id': 'port1',
1701+
'v4-fixed-ip': '',
1702+
'v6-fixed-ip': '',
16961703
},
16971704
{
1698-
'net-id': 'net1', 'port-id': '',
1699-
'v4-fixed-ip': '', 'v6-fixed-ip': '',
1705+
'net-id': 'net1',
1706+
'port-id': '',
1707+
'v4-fixed-ip': '',
1708+
'v6-fixed-ip': '',
17001709
},
17011710
{
1702-
'net-id': '', 'port-id': 'port2',
1703-
'v4-fixed-ip': '', 'v6-fixed-ip': '',
1711+
'net-id': 'auto',
1712+
'port-id': '',
1713+
'v4-fixed-ip': '',
1714+
'v6-fixed-ip': '',
1715+
},
1716+
{
1717+
'net-id': '',
1718+
'port-id': 'port2',
1719+
'v4-fixed-ip': '',
1720+
'v6-fixed-ip': '',
17041721
},
17051722
]),
17061723
('config_drive', False),
@@ -1729,12 +1746,16 @@ def test_server_create_with_network(self):
17291746
"port2": port2_resource}[port_id])
17301747

17311748
# Mock sdk APIs.
1732-
_network = mock.Mock(id='net1_uuid')
1749+
_network_1 = mock.Mock(id='net1_uuid')
1750+
_network_auto = mock.Mock(id='auto_uuid')
17331751
_port1 = mock.Mock(id='port1_uuid')
17341752
_port2 = mock.Mock(id='port2_uuid')
17351753
find_network = mock.Mock()
17361754
find_port = mock.Mock()
1737-
find_network.return_value = _network
1755+
find_network.side_effect = lambda net_id, ignore_missing: {
1756+
"net1": _network_1,
1757+
"auto": _network_auto,
1758+
}[net_id]
17381759
find_port.side_effect = (lambda port_id, ignore_missing:
17391760
{"port1": _port1,
17401761
"port2": _port2}[port_id])
@@ -1775,6 +1796,10 @@ def test_server_create_with_network(self):
17751796
'v4-fixed-ip': '',
17761797
'v6-fixed-ip': '',
17771798
'port-id': ''},
1799+
{'net-id': 'auto_uuid',
1800+
'v4-fixed-ip': '',
1801+
'v6-fixed-ip': '',
1802+
'port-id': ''},
17781803
{'net-id': '',
17791804
'v4-fixed-ip': '',
17801805
'v6-fixed-ip': '',

0 commit comments

Comments
 (0)