diff options
| author | Jim Rollenhagen <jim@jimrollenhagen.com> | 2019-04-01 15:41:17 -0400 |
|---|---|---|
| committer | Jim Rollenhagen <jim@jimrollenhagen.com> | 2019-04-01 15:56:40 -0400 |
| commit | c53de3214ed74ffd5b53e6d1cf8a0c0fa73dac99 (patch) | |
| tree | f5c2497a394cb4e2f6ae0918e514f205ea4e5d03 | |
| parent | c684fd926a9b4d54bda147fe306d1324b3805d19 (diff) | |
| download | python-openstackclient-c53de3214ed74ffd5b53e6d1cf8a0c0fa73dac99.tar.gz | |
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
| -rw-r--r-- | openstackclient/network/v2/security_group_rule.py | 9 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_security_group_rule_network.py | 24 |
2 files changed, 33 insertions, 0 deletions
diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py index ca0e00b9..961125a9 100644 --- a/openstackclient/network/v2/security_group_rule.py +++ b/openstackclient/network/v2/security_group_rule.py @@ -73,6 +73,14 @@ def _convert_to_lowercase(string): return string.lower() +def _convert_ipvx_case(string): + if string.lower() == 'ipv4': + return 'IPv4' + if string.lower() == 'ipv6': + return 'IPv6' + return string + + def _is_icmp_protocol(protocol): # NOTE(rtheis): Neutron has deprecated protocol icmpv6. # However, while the OSC CLI doesn't document the protocol, @@ -183,6 +191,7 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne): '--ethertype', metavar='<ethertype>', choices=['IPv4', 'IPv6'], + type=_convert_ipvx_case, help=_("Ethertype of network traffic " "(IPv4, IPv6; default: based on IP protocol)") ) diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py index fe6d3649..b070ab6a 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py +++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py @@ -125,6 +125,30 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, []) + def test_lowercase_ethertype(self): + arglist = [ + '--ethertype', 'ipv4', + self._security_group.id, + ] + parsed_args = self.check_parser(self.cmd, arglist, []) + self.assertEqual('IPv4', parsed_args.ethertype) + + def test_lowercase_v6_ethertype(self): + arglist = [ + '--ethertype', 'ipv6', + self._security_group.id, + ] + parsed_args = self.check_parser(self.cmd, arglist, []) + self.assertEqual('IPv6', parsed_args.ethertype) + + def test_proper_case_ethertype(self): + arglist = [ + '--ethertype', 'IPv6', + self._security_group.id, + ] + parsed_args = self.check_parser(self.cmd, arglist, []) + self.assertEqual('IPv6', parsed_args.ethertype) + def test_create_all_protocol_options(self): arglist = [ '--protocol', 'tcp', |
