Skip to content

Commit c53de32

Browse files
Ignore case in security group rule --ethertype
Currently, this only allows 'IPv4' or 'IPv6', but one can imagine a user frequently typing e.g. 'ipv6' and getting frustrated. Allow any case, while still keeping correct case for the choices and the value sent to Neutron. Change-Id: I70ce1f43d32aad01b174437d03c984a5b608b161
1 parent c684fd9 commit c53de32

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

openstackclient/network/v2/security_group_rule.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ def _convert_to_lowercase(string):
7373
return string.lower()
7474

7575

76+
def _convert_ipvx_case(string):
77+
if string.lower() == 'ipv4':
78+
return 'IPv4'
79+
if string.lower() == 'ipv6':
80+
return 'IPv6'
81+
return string
82+
83+
7684
def _is_icmp_protocol(protocol):
7785
# NOTE(rtheis): Neutron has deprecated protocol icmpv6.
7886
# However, while the OSC CLI doesn't document the protocol,
@@ -183,6 +191,7 @@ def update_parser_network(self, parser):
183191
'--ethertype',
184192
metavar='<ethertype>',
185193
choices=['IPv4', 'IPv6'],
194+
type=_convert_ipvx_case,
186195
help=_("Ethertype of network traffic "
187196
"(IPv4, IPv6; default: based on IP protocol)")
188197
)

openstackclient/tests/unit/network/v2/test_security_group_rule_network.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ def test_create_bad_ethertype(self):
125125
self.assertRaises(tests_utils.ParserException,
126126
self.check_parser, self.cmd, arglist, [])
127127

128+
def test_lowercase_ethertype(self):
129+
arglist = [
130+
'--ethertype', 'ipv4',
131+
self._security_group.id,
132+
]
133+
parsed_args = self.check_parser(self.cmd, arglist, [])
134+
self.assertEqual('IPv4', parsed_args.ethertype)
135+
136+
def test_lowercase_v6_ethertype(self):
137+
arglist = [
138+
'--ethertype', 'ipv6',
139+
self._security_group.id,
140+
]
141+
parsed_args = self.check_parser(self.cmd, arglist, [])
142+
self.assertEqual('IPv6', parsed_args.ethertype)
143+
144+
def test_proper_case_ethertype(self):
145+
arglist = [
146+
'--ethertype', 'IPv6',
147+
self._security_group.id,
148+
]
149+
parsed_args = self.check_parser(self.cmd, arglist, [])
150+
self.assertEqual('IPv6', parsed_args.ethertype)
151+
128152
def test_create_all_protocol_options(self):
129153
arglist = [
130154
'--protocol', 'tcp',

0 commit comments

Comments
 (0)