Skip to content

Commit 79e6708

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Remote security group name not displayed for rule"
2 parents 1ee5191 + 079123b commit 79e6708

3 files changed

Lines changed: 102 additions & 18 deletions

File tree

openstackclient/compute/v2/security_group.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def _xform_security_group_rule(sgroup):
5454
info['ip_protocol'] = ''
5555
elif info['ip_protocol'].lower() == 'icmp':
5656
info['port_range'] = ''
57+
group = info.pop('group')
58+
if 'name' in group:
59+
info['remote_security_group'] = group['name']
60+
else:
61+
info['remote_security_group'] = ''
5762
return info
5863

5964

@@ -299,6 +304,7 @@ def take_action(self, parsed_args):
299304
"IP Protocol",
300305
"IP Range",
301306
"Port Range",
307+
"Remote Security Group",
302308
)
303309
return (column_headers,
304310
(utils.get_item_properties(

openstackclient/tests/compute/v2/test_security_group_rule.py

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@
2828
security_group_rule_id = '1'
2929
security_group_rule_cidr = '0.0.0.0/0'
3030

31-
SECURITY_GROUP = {
32-
'id': security_group_id,
33-
'name': security_group_name,
34-
'description': security_group_description,
35-
'tenant_id': identity_fakes.project_id,
36-
}
37-
3831
SECURITY_GROUP_RULE = {
3932
'id': security_group_rule_id,
4033
'group': {},
@@ -55,6 +48,26 @@
5548
'to_port': -1,
5649
}
5750

51+
SECURITY_GROUP_RULE_REMOTE_GROUP = {
52+
'id': security_group_rule_id,
53+
'group': {"tenant_id": "14", "name": "default"},
54+
'ip_protocol': 'tcp',
55+
'ip_range': {},
56+
'parent_group_id': security_group_id,
57+
'from_port': 80,
58+
'to_port': 80,
59+
}
60+
61+
SECURITY_GROUP = {
62+
'id': security_group_id,
63+
'name': security_group_name,
64+
'description': security_group_description,
65+
'tenant_id': identity_fakes.project_id,
66+
'rules': [SECURITY_GROUP_RULE,
67+
SECURITY_GROUP_RULE_ICMP,
68+
SECURITY_GROUP_RULE_REMOTE_GROUP],
69+
}
70+
5871

5972
class FakeSecurityGroupRuleResource(fakes.FakeResource):
6073

@@ -122,21 +135,21 @@ def test_security_group_rule_create_no_options(self):
122135
)
123136

124137
collist = (
125-
'group',
126138
'id',
127139
'ip_protocol',
128140
'ip_range',
129141
'parent_group_id',
130142
'port_range',
143+
'remote_security_group',
131144
)
132145
self.assertEqual(collist, columns)
133146
datalist = (
134-
{},
135147
security_group_rule_id,
136148
'tcp',
137149
security_group_rule_cidr,
138150
security_group_id,
139151
'0:0',
152+
'',
140153
)
141154
self.assertEqual(datalist, data)
142155

@@ -174,28 +187,29 @@ def test_security_group_rule_create_ftp(self):
174187
)
175188

176189
collist = (
177-
'group',
178190
'id',
179191
'ip_protocol',
180192
'ip_range',
181193
'parent_group_id',
182194
'port_range',
195+
'remote_security_group',
183196
)
184197
self.assertEqual(collist, columns)
185198
datalist = (
186-
{},
187199
security_group_rule_id,
188200
'tcp',
189201
security_group_rule_cidr,
190202
security_group_id,
191203
'20:21',
204+
'',
192205
)
193206
self.assertEqual(datalist, data)
194207

195208
def test_security_group_rule_create_ssh(self):
196209
sg_rule = copy.deepcopy(SECURITY_GROUP_RULE)
197210
sg_rule['from_port'] = 22
198211
sg_rule['to_port'] = 22
212+
sg_rule['ip_range'] = {}
199213
sg_rule['group'] = {'name': security_group_name}
200214
self.sg_rules_mock.create.return_value = FakeSecurityGroupRuleResource(
201215
None,
@@ -229,21 +243,21 @@ def test_security_group_rule_create_ssh(self):
229243
)
230244

231245
collist = (
232-
'group',
233246
'id',
234247
'ip_protocol',
235248
'ip_range',
236249
'parent_group_id',
237250
'port_range',
251+
'remote_security_group',
238252
)
239253
self.assertEqual(collist, columns)
240254
datalist = (
241-
{'name': security_group_name},
242255
security_group_rule_id,
243256
'tcp',
244-
security_group_rule_cidr,
257+
'',
245258
security_group_id,
246259
'22:22',
260+
security_group_name,
247261
)
248262
self.assertEqual(datalist, data)
249263

@@ -280,21 +294,21 @@ def test_security_group_rule_create_udp(self):
280294
)
281295

282296
collist = (
283-
'group',
284297
'id',
285298
'ip_protocol',
286299
'ip_range',
287300
'parent_group_id',
288301
'port_range',
302+
'remote_security_group',
289303
)
290304
self.assertEqual(collist, columns)
291305
datalist = (
292-
{},
293306
security_group_rule_id,
294307
'udp',
295308
security_group_rule_cidr,
296309
security_group_id,
297310
'0:0',
311+
'',
298312
)
299313
self.assertEqual(datalist, data)
300314

@@ -334,21 +348,21 @@ def test_security_group_rule_create_icmp(self):
334348
)
335349

336350
collist = (
337-
'group',
338351
'id',
339352
'ip_protocol',
340353
'ip_range',
341354
'parent_group_id',
342355
'port_range',
356+
'remote_security_group',
343357
)
344358
self.assertEqual(collist, columns)
345359
datalist = (
346-
{},
347360
security_group_rule_id,
348361
'icmp',
349362
sg_rule_cidr,
350363
security_group_id,
351364
'',
365+
'',
352366
)
353367
self.assertEqual(datalist, data)
354368

@@ -362,3 +376,62 @@ def test_security_group_rule_create_src_invalid(self):
362376

363377
self.assertRaises(utils.ParserException,
364378
self.check_parser, self.cmd, arglist, [])
379+
380+
381+
class TestSecurityGroupRuleList(TestSecurityGroupRule):
382+
383+
def setUp(self):
384+
super(TestSecurityGroupRuleList, self).setUp()
385+
386+
self.secgroups_mock.get.return_value = FakeSecurityGroupRuleResource(
387+
None,
388+
copy.deepcopy(SECURITY_GROUP),
389+
loaded=True,
390+
)
391+
392+
# Get the command object to test
393+
self.cmd = security_group.ListSecurityGroupRule(self.app, None)
394+
395+
def test_security_group_rule_list(self):
396+
397+
arglist = [
398+
security_group_name,
399+
]
400+
verifylist = [
401+
('group', security_group_name),
402+
]
403+
404+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
405+
406+
# DisplayCommandBase.take_action() returns two tuples
407+
columns, data = self.cmd.take_action(parsed_args)
408+
409+
collist = (
410+
'ID',
411+
'IP Protocol',
412+
'IP Range',
413+
'Port Range',
414+
'Remote Security Group',
415+
)
416+
self.assertEqual(collist, columns)
417+
datalist = ((
418+
security_group_rule_id,
419+
'tcp',
420+
security_group_rule_cidr,
421+
'0:0',
422+
'',
423+
), (
424+
security_group_rule_id,
425+
'icmp',
426+
security_group_rule_cidr,
427+
'',
428+
'',
429+
), (
430+
security_group_rule_id,
431+
'tcp',
432+
'',
433+
'80:80',
434+
'default',
435+
),
436+
)
437+
self.assertEqual(datalist, tuple(data))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Add remote security group to `os security group rule list`
5+
[Bug `1520003 <https://bugs.launchpad.net/bugs/1520003>`_]

0 commit comments

Comments
 (0)