Remote security group name not displayed for rule
The 'security group rule list' command was updated to display the remote security group name for a security group rule. This was done via a new 'Remote Security Group' column. The output of the 'security group rule create' and 'security group show' commands was also updated to include 'remote_security_group' information instead of the raw 'group' information returned from the API layer. Change-Id: I5f9600338c8331966d2c658109a24b502c538106 Closes-Bug: #1520003
This commit is contained in:
parent
785caf503f
commit
079123bb0b
@ -54,6 +54,11 @@ def _xform_security_group_rule(sgroup):
|
||||
info['ip_protocol'] = ''
|
||||
elif info['ip_protocol'].lower() == 'icmp':
|
||||
info['port_range'] = ''
|
||||
group = info.pop('group')
|
||||
if 'name' in group:
|
||||
info['remote_security_group'] = group['name']
|
||||
else:
|
||||
info['remote_security_group'] = ''
|
||||
return info
|
||||
|
||||
|
||||
@ -299,6 +304,7 @@ class ListSecurityGroupRule(lister.Lister):
|
||||
"IP Protocol",
|
||||
"IP Range",
|
||||
"Port Range",
|
||||
"Remote Security Group",
|
||||
)
|
||||
return (column_headers,
|
||||
(utils.get_item_properties(
|
||||
|
@ -28,13 +28,6 @@ security_group_description = 'nothing but net'
|
||||
security_group_rule_id = '1'
|
||||
security_group_rule_cidr = '0.0.0.0/0'
|
||||
|
||||
SECURITY_GROUP = {
|
||||
'id': security_group_id,
|
||||
'name': security_group_name,
|
||||
'description': security_group_description,
|
||||
'tenant_id': identity_fakes.project_id,
|
||||
}
|
||||
|
||||
SECURITY_GROUP_RULE = {
|
||||
'id': security_group_rule_id,
|
||||
'group': {},
|
||||
@ -55,6 +48,26 @@ SECURITY_GROUP_RULE_ICMP = {
|
||||
'to_port': -1,
|
||||
}
|
||||
|
||||
SECURITY_GROUP_RULE_REMOTE_GROUP = {
|
||||
'id': security_group_rule_id,
|
||||
'group': {"tenant_id": "14", "name": "default"},
|
||||
'ip_protocol': 'tcp',
|
||||
'ip_range': {},
|
||||
'parent_group_id': security_group_id,
|
||||
'from_port': 80,
|
||||
'to_port': 80,
|
||||
}
|
||||
|
||||
SECURITY_GROUP = {
|
||||
'id': security_group_id,
|
||||
'name': security_group_name,
|
||||
'description': security_group_description,
|
||||
'tenant_id': identity_fakes.project_id,
|
||||
'rules': [SECURITY_GROUP_RULE,
|
||||
SECURITY_GROUP_RULE_ICMP,
|
||||
SECURITY_GROUP_RULE_REMOTE_GROUP],
|
||||
}
|
||||
|
||||
|
||||
class FakeSecurityGroupRuleResource(fakes.FakeResource):
|
||||
|
||||
@ -122,21 +135,21 @@ class TestSecurityGroupRuleCreate(TestSecurityGroupRule):
|
||||
)
|
||||
|
||||
collist = (
|
||||
'group',
|
||||
'id',
|
||||
'ip_protocol',
|
||||
'ip_range',
|
||||
'parent_group_id',
|
||||
'port_range',
|
||||
'remote_security_group',
|
||||
)
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
{},
|
||||
security_group_rule_id,
|
||||
'tcp',
|
||||
security_group_rule_cidr,
|
||||
security_group_id,
|
||||
'0:0',
|
||||
'',
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
@ -174,21 +187,21 @@ class TestSecurityGroupRuleCreate(TestSecurityGroupRule):
|
||||
)
|
||||
|
||||
collist = (
|
||||
'group',
|
||||
'id',
|
||||
'ip_protocol',
|
||||
'ip_range',
|
||||
'parent_group_id',
|
||||
'port_range',
|
||||
'remote_security_group',
|
||||
)
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
{},
|
||||
security_group_rule_id,
|
||||
'tcp',
|
||||
security_group_rule_cidr,
|
||||
security_group_id,
|
||||
'20:21',
|
||||
'',
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
@ -196,6 +209,7 @@ class TestSecurityGroupRuleCreate(TestSecurityGroupRule):
|
||||
sg_rule = copy.deepcopy(SECURITY_GROUP_RULE)
|
||||
sg_rule['from_port'] = 22
|
||||
sg_rule['to_port'] = 22
|
||||
sg_rule['ip_range'] = {}
|
||||
sg_rule['group'] = {'name': security_group_name}
|
||||
self.sg_rules_mock.create.return_value = FakeSecurityGroupRuleResource(
|
||||
None,
|
||||
@ -229,21 +243,21 @@ class TestSecurityGroupRuleCreate(TestSecurityGroupRule):
|
||||
)
|
||||
|
||||
collist = (
|
||||
'group',
|
||||
'id',
|
||||
'ip_protocol',
|
||||
'ip_range',
|
||||
'parent_group_id',
|
||||
'port_range',
|
||||
'remote_security_group',
|
||||
)
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
{'name': security_group_name},
|
||||
security_group_rule_id,
|
||||
'tcp',
|
||||
security_group_rule_cidr,
|
||||
'',
|
||||
security_group_id,
|
||||
'22:22',
|
||||
security_group_name,
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
@ -280,21 +294,21 @@ class TestSecurityGroupRuleCreate(TestSecurityGroupRule):
|
||||
)
|
||||
|
||||
collist = (
|
||||
'group',
|
||||
'id',
|
||||
'ip_protocol',
|
||||
'ip_range',
|
||||
'parent_group_id',
|
||||
'port_range',
|
||||
'remote_security_group',
|
||||
)
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
{},
|
||||
security_group_rule_id,
|
||||
'udp',
|
||||
security_group_rule_cidr,
|
||||
security_group_id,
|
||||
'0:0',
|
||||
'',
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
@ -334,21 +348,21 @@ class TestSecurityGroupRuleCreate(TestSecurityGroupRule):
|
||||
)
|
||||
|
||||
collist = (
|
||||
'group',
|
||||
'id',
|
||||
'ip_protocol',
|
||||
'ip_range',
|
||||
'parent_group_id',
|
||||
'port_range',
|
||||
'remote_security_group',
|
||||
)
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = (
|
||||
{},
|
||||
security_group_rule_id,
|
||||
'icmp',
|
||||
sg_rule_cidr,
|
||||
security_group_id,
|
||||
'',
|
||||
'',
|
||||
)
|
||||
self.assertEqual(datalist, data)
|
||||
|
||||
@ -362,3 +376,62 @@ class TestSecurityGroupRuleCreate(TestSecurityGroupRule):
|
||||
|
||||
self.assertRaises(utils.ParserException,
|
||||
self.check_parser, self.cmd, arglist, [])
|
||||
|
||||
|
||||
class TestSecurityGroupRuleList(TestSecurityGroupRule):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSecurityGroupRuleList, self).setUp()
|
||||
|
||||
self.secgroups_mock.get.return_value = FakeSecurityGroupRuleResource(
|
||||
None,
|
||||
copy.deepcopy(SECURITY_GROUP),
|
||||
loaded=True,
|
||||
)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = security_group.ListSecurityGroupRule(self.app, None)
|
||||
|
||||
def test_security_group_rule_list(self):
|
||||
|
||||
arglist = [
|
||||
security_group_name,
|
||||
]
|
||||
verifylist = [
|
||||
('group', security_group_name),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
collist = (
|
||||
'ID',
|
||||
'IP Protocol',
|
||||
'IP Range',
|
||||
'Port Range',
|
||||
'Remote Security Group',
|
||||
)
|
||||
self.assertEqual(collist, columns)
|
||||
datalist = ((
|
||||
security_group_rule_id,
|
||||
'tcp',
|
||||
security_group_rule_cidr,
|
||||
'0:0',
|
||||
'',
|
||||
), (
|
||||
security_group_rule_id,
|
||||
'icmp',
|
||||
security_group_rule_cidr,
|
||||
'',
|
||||
'',
|
||||
), (
|
||||
security_group_rule_id,
|
||||
'tcp',
|
||||
'',
|
||||
'80:80',
|
||||
'default',
|
||||
),
|
||||
)
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
5
releasenotes/notes/bug-1520003-505af921c8afffc9.yaml
Normal file
5
releasenotes/notes/bug-1520003-505af921c8afffc9.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Add remote security group to `os security group rule list`
|
||||
[Bug `1520003 <https://bugs.launchpad.net/bugs/1520003>`_]
|
Loading…
Reference in New Issue
Block a user