Skip to content

Commit 5988ee6

Browse files
author
Dean Troyer
committed
Fix security group rule list for NEtwork v2
Fix the formatting of Port Range in the security group rule list command for Network v2 to handle SDK changes. Change-Id: Id954cbfaedbb74f60125ebda91f80db751759933
1 parent 1880527 commit 5988ee6

2 files changed

Lines changed: 26 additions & 22 deletions

File tree

openstackclient/network/v2/security_group_rule.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ def _format_network_port_range(rule):
5151
# - Single port: '80:80'
5252
# - No port range: ''
5353
port_range = ''
54-
if _is_icmp_protocol(rule.protocol):
55-
if rule.port_range_min:
56-
port_range += 'type=' + str(rule.port_range_min)
57-
if rule.port_range_max:
58-
port_range += ':code=' + str(rule.port_range_max)
59-
elif rule.port_range_min or rule.port_range_max:
60-
port_range_min = str(rule.port_range_min)
61-
port_range_max = str(rule.port_range_max)
62-
if rule.port_range_min is None:
54+
if _is_icmp_protocol(rule['protocol']):
55+
if rule['port_range_min']:
56+
port_range += 'type=' + str(rule['port_range_min'])
57+
if rule['port_range_max']:
58+
port_range += ':code=' + str(rule['port_range_max'])
59+
elif rule['port_range_min'] or rule['port_range_max']:
60+
port_range_min = str(rule['port_range_min'])
61+
port_range_max = str(rule['port_range_max'])
62+
if rule['port_range_min'] is None:
6363
port_range_min = port_range_max
64-
if rule.port_range_max is None:
64+
if rule['port_range_max'] is None:
6565
port_range_max = port_range_min
6666
port_range = port_range_min + ':' + port_range_max
6767
return port_range
@@ -423,6 +423,16 @@ def take_action_compute(self, client, parsed_args):
423423
class ListSecurityGroupRule(common.NetworkAndComputeLister):
424424
_description = _("List security group rules")
425425

426+
def _format_network_security_group_rule(self, rule):
427+
"""Transform the SDK SecurityGroupRule object to a dict
428+
429+
The SDK object gets in the way of reformatting columns...
430+
Create port_range column from port_range_min and port_range_max
431+
"""
432+
rule = rule.to_dict()
433+
rule['port_range'] = _format_network_port_range(rule)
434+
return rule
435+
426436
def update_parser_common(self, parser):
427437
parser.add_argument(
428438
'group',
@@ -508,7 +518,7 @@ def take_action_network(self, client, parsed_args):
508518
'id',
509519
'protocol',
510520
'remote_ip_prefix',
511-
'port_range_min',
521+
'port_range',
512522
)
513523
if parsed_args.long:
514524
columns = columns + ('direction', 'ethertype',)
@@ -535,16 +545,13 @@ def take_action_network(self, client, parsed_args):
535545
if parsed_args.protocol is not None:
536546
query['protocol'] = parsed_args.protocol
537547

538-
rules = list(client.security_group_rules(**query))
539-
540-
# Reformat the rules to display a port range instead
541-
# of just the port range minimum. This maintains
542-
# output compatibility with compute.
543-
for rule in rules:
544-
rule.port_range_min = _format_network_port_range(rule)
548+
rules = [
549+
self._format_network_security_group_rule(r)
550+
for r in client.security_group_rules(**query)
551+
]
545552

546553
return (column_headers,
547-
(utils.get_item_properties(
554+
(utils.get_dict_properties(
548555
s, columns,
549556
) for s in rules))
550557

openstackclient/tests/functional/network/v2/test_security_group_rule.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import uuid
1414

15-
import testtools
16-
1715
from openstackclient.tests.functional import base
1816

1917

@@ -54,7 +52,6 @@ def tearDownClass(cls):
5452
cls.SECURITY_GROUP_NAME)
5553
cls.assertOutput('', raw_output)
5654

57-
@testtools.skip('broken SDK testing')
5855
def test_security_group_rule_list(self):
5956
opts = self.get_opts(self.ID_HEADER)
6057
raw_output = self.openstack('security group rule list ' +

0 commit comments

Comments
 (0)