Skip to content

Commit e83a094

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Allow creating security rules without protocol"
2 parents 6c0b966 + 82f45d9 commit e83a094

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

openstackclient/network/v2/security_group_rule.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ def update_parser_network(self, parser):
159159
help=_("IP protocol (ah, dccp, egp, esp, gre, icmp, igmp, "
160160
"ipv6-encap, ipv6-frag, ipv6-icmp, ipv6-nonxt, "
161161
"ipv6-opts, ipv6-route, ospf, pgm, rsvp, sctp, tcp, "
162-
"udp, udplite, vrrp and integer representations [0-255]; "
163-
"default: tcp)")
162+
"udp, udplite, vrrp and integer representations [0-255] "
163+
"or any; default: tcp)")
164164
)
165165
protocol_group.add_argument(
166166
'--proto',
@@ -230,14 +230,16 @@ def _get_protocol(self, parsed_args):
230230
protocol = parsed_args.protocol
231231
if parsed_args.proto is not None:
232232
protocol = parsed_args.proto
233+
if protocol == 'any':
234+
protocol = None
233235
return protocol
234236

235237
def _is_ipv6_protocol(self, protocol):
236238
# NOTE(rtheis): Neutron has deprecated protocol icmpv6.
237239
# However, while the OSC CLI doesn't document the protocol,
238240
# the code must still handle it. In addition, handle both
239241
# protocol names and numbers.
240-
if (protocol.startswith('ipv6-') or
242+
if (protocol is not None and protocol.startswith('ipv6-') or
241243
protocol in ['icmpv6', '41', '43', '44', '58', '59', '60']):
242244
return True
243245
else:

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ def test_create_proto_option(self):
211211
self.assertEqual(self.expected_columns, columns)
212212
self.assertEqual(self.expected_data, data)
213213

214+
def test_create_protocol_any(self):
215+
self._setup_security_group_rule({
216+
'protocol': None,
217+
'remote_ip_prefix': '10.0.2.0/24',
218+
})
219+
arglist = [
220+
'--proto', 'any',
221+
'--src-ip', self._security_group_rule.remote_ip_prefix,
222+
self._security_group.id,
223+
]
224+
verifylist = [
225+
('proto', 'any'),
226+
('protocol', None),
227+
('src_ip', self._security_group_rule.remote_ip_prefix),
228+
('group', self._security_group.id),
229+
]
230+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
231+
232+
columns, data = self.cmd.take_action(parsed_args)
233+
234+
self.network.create_security_group_rule.assert_called_once_with(**{
235+
'direction': self._security_group_rule.direction,
236+
'ethertype': self._security_group_rule.ether_type,
237+
'protocol': self._security_group_rule.protocol,
238+
'remote_ip_prefix': self._security_group_rule.remote_ip_prefix,
239+
'security_group_id': self._security_group.id,
240+
})
241+
self.assertEqual(self.expected_columns, columns)
242+
self.assertEqual(self.expected_data, data)
243+
214244
def test_create_remote_group(self):
215245
self._setup_security_group_rule({
216246
'port_range_max': 22,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
features:
3+
- |
4+
Add ``any`` as a ``--protocol`` option to ``security group rule create``
5+
command.
6+
[Bug `1517134 <https://bugs.launchpad.net/bugs/1712242>`_]
7+
fixes:
8+
- |
9+
It is now possible to create a security rule without specifying protocol
10+
(using ``--protocol any``), which skips sending the protocol to the API
11+
server entirely. Previously TCP was forced as default protocol when none
12+
was specified.

0 commit comments

Comments
 (0)