浏览代码

Merge "Fix listing security groups when no rules" into stable/queens

tags/13.0.3^0
Zuul Gerrit Code Review 6 个月前
父节点
当前提交
919870a13b
共有 4 个文件被更改,包括 19 次插入4 次删除
  1. +2
    -0
      openstack_dashboard/api/neutron.py
  2. +9
    -3
      openstack_dashboard/test/test_data/neutron_data.py
  3. +3
    -1
      openstack_dashboard/test/unit/api/test_neutron.py
  4. +5
    -0
      releasenotes/notes/security-group-no-rules-list-bugfix-b77ab5aff1d3e45e.yaml

+ 2
- 0
openstack_dashboard/api/neutron.py 查看文件

@@ -205,6 +205,8 @@ class SecurityGroup(NeutronAPIDictWrapper):
def __init__(self, sg, sg_dict=None):
if sg_dict is None:
sg_dict = {sg['id']: sg['name']}
if 'security_group_rules' not in sg:
sg['security_group_rules'] = []
sg['rules'] = [SecurityGroupRule(rule, sg_dict)
for rule in sg['security_group_rules']]
super(SecurityGroup, self).__init__(sg)


+ 9
- 3
openstack_dashboard/test/test_data/neutron_data.py 查看文件

@@ -496,6 +496,10 @@ def data(TEST):
'description': 'NotDefault',
'id': '443a4d7a-4bd2-4474-9a77-02b35c9f8c95',
'name': 'another_group'}
sec_group_empty = {'tenant_id': '1',
'description': 'SG without rules',
'id': 'f205f3bc-d402-4e40-b004-c62401e19b4b',
'name': 'empty_group'}

def add_rule_to_group(secgroup, default_only=True):
rule_egress_ipv4 = {
@@ -557,18 +561,20 @@ def data(TEST):
add_rule_to_group(sec_group_1, default_only=False)
add_rule_to_group(sec_group_2)
add_rule_to_group(sec_group_3)
# NOTE: sec_group_empty is a SG without rules,
# so we don't call add_rule_to_group.

groups = [sec_group_1, sec_group_2, sec_group_3]
groups = [sec_group_1, sec_group_2, sec_group_3, sec_group_empty]
sg_name_dict = dict([(sg['id'], sg['name']) for sg in groups])
for sg in groups:
# Neutron API.
TEST.api_security_groups.add(sg)
for rule in sg['security_group_rules']:
for rule in sg.get('security_group_rules', []):
TEST.api_security_group_rules.add(copy.copy(rule))
# OpenStack Dashboard internaly API.
TEST.security_groups.add(
neutron.SecurityGroup(copy.deepcopy(sg), sg_name_dict))
for rule in sg['security_group_rules']:
for rule in sg.get('security_group_rules', []):
TEST.security_group_rules.add(
neutron.SecurityGroupRule(copy.copy(rule), sg_name_dict))



+ 3
- 1
openstack_dashboard/test/unit/api/test_neutron.py 查看文件

@@ -963,7 +963,9 @@ class NeutronApiSecurityGroupTests(NeutronApiTestBase):
def _cmp_sg(self, exp_sg, ret_sg):
self.assertEqual(exp_sg['id'], ret_sg.id)
self.assertEqual(exp_sg['name'], ret_sg.name)
exp_rules = exp_sg['security_group_rules']
# When a SG has no rules, neutron API does not contain
# 'security_group_rules' field, so .get() method needs to be used.
exp_rules = exp_sg.get('security_group_rules', [])
self.assertEqual(len(exp_rules), len(ret_sg.rules))
for (exprule, retrule) in six.moves.zip(exp_rules, ret_sg.rules):
self._cmp_sg_rule(exprule, retrule)


+ 5
- 0
releasenotes/notes/security-group-no-rules-list-bugfix-b77ab5aff1d3e45e.yaml 查看文件

@@ -0,0 +1,5 @@
---
fixes:
- |
[:bug:`1840465`] Fixed a bug where listing security groups did not work
if one or more security groups had no rules in them.

正在加载...
取消
保存