summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-01-11 16:26:08 +0000
committerGerrit Code Review <review@openstack.org>2019-01-11 16:26:08 +0000
commitea51592827bdf330045253c9d5640f010b520661 (patch)
tree6312448936e924883ae7d9f12d4d6905c00340b7
parenta6f54f27080466f75dccedb579ddb305ebd85a30 (diff)
parentccb21ca7a9906523a972e32df904744885183234 (diff)
Merge "python3: Fix handling of other protocol in SG rule"
-rw-r--r--openstack_dashboard/api/neutron.py4
-rw-r--r--openstack_dashboard/test/test_data/neutron_data.py13
-rw-r--r--openstack_dashboard/test/unit/api/test_neutron.py14
3 files changed, 25 insertions, 6 deletions
diff --git a/openstack_dashboard/api/neutron.py b/openstack_dashboard/api/neutron.py
index 0fbf867..4220d60 100644
--- a/openstack_dashboard/api/neutron.py
+++ b/openstack_dashboard/api/neutron.py
@@ -432,9 +432,9 @@ class SecurityGroupManager(object):
432 """ 432 """
433 if not cidr: 433 if not cidr:
434 cidr = None 434 cidr = None
435 if from_port < 0: 435 if isinstance(from_port, int) and from_port < 0:
436 from_port = None 436 from_port = None
437 if to_port < 0: 437 if isinstance(to_port, int) and to_port < 0:
438 to_port = None 438 to_port = None
439 if isinstance(ip_protocol, int) and ip_protocol < 0: 439 if isinstance(ip_protocol, int) and ip_protocol < 0:
440 ip_protocol = None 440 ip_protocol = None
diff --git a/openstack_dashboard/test/test_data/neutron_data.py b/openstack_dashboard/test/test_data/neutron_data.py
index cc43b39..f558174 100644
--- a/openstack_dashboard/test/test_data/neutron_data.py
+++ b/openstack_dashboard/test/test_data/neutron_data.py
@@ -550,6 +550,16 @@ def data(TEST):
550 'tenant_id': secgroup['tenant_id'], 550 'tenant_id': secgroup['tenant_id'],
551 'description': 'Ingress HTTP from SG #1', 551 'description': 'Ingress HTTP from SG #1',
552 } 552 }
553 rule_ip_proto = {
554 'id': uuidutils.generate_uuid(),
555 'direction': u'ingress', 'ethertype': u'IPv4',
556 'port_range_min': None, 'port_range_max': None,
557 'protocol': u'99', 'remote_group_id': None,
558 'remote_ip_prefix': u'0.0.0.0/24',
559 'security_group_id': secgroup['id'],
560 'tenant_id': secgroup['tenant_id'],
561 'description': 'Ingress custom IP protocol 99',
562 }
553 rule_all_tcp = { 563 rule_all_tcp = {
554 'id': uuidutils.generate_uuid(), 564 'id': uuidutils.generate_uuid(),
555 'direction': u'egress', 'ethertype': u'IPv4', 565 'direction': u'egress', 'ethertype': u'IPv4',
@@ -563,7 +573,8 @@ def data(TEST):
563 573
564 rules = [] 574 rules = []
565 if not default_only: 575 if not default_only:
566 rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp] 576 rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp,
577 rule_ip_proto]
567 rules += [rule_egress_ipv4, rule_egress_ipv6] 578 rules += [rule_egress_ipv4, rule_egress_ipv6]
568 secgroup['security_group_rules'] = rules 579 secgroup['security_group_rules'] = rules
569 580
diff --git a/openstack_dashboard/test/unit/api/test_neutron.py b/openstack_dashboard/test/unit/api/test_neutron.py
index c024706..a5a69bd 100644
--- a/openstack_dashboard/test/unit/api/test_neutron.py
+++ b/openstack_dashboard/test/unit/api/test_neutron.py
@@ -1250,9 +1250,17 @@ class NeutronApiSecurityGroupTests(test.APIMockTestCase):
1250 def test_security_group_rule_create_without_desc(self): 1250 def test_security_group_rule_create_without_desc(self):
1251 self._test_security_group_rule_create(with_desc=False) 1251 self._test_security_group_rule_create(with_desc=False)
1252 1252
1253 def _test_security_group_rule_create(self, with_desc): 1253 def test_security_group_rule_create_with_custom_protocol(self):
1254 sg_rule = [r for r in self.api_security_group_rules.list() 1254 self._test_security_group_rule_create(custom_ip_proto=True)
1255 if r['protocol'] == 'tcp' and r['remote_ip_prefix']][0] 1255
1256 def _test_security_group_rule_create(self, with_desc=False,
1257 custom_ip_proto=False):
1258 if custom_ip_proto:
1259 sg_rule = [r for r in self.api_security_group_rules.list()
1260 if r['protocol'] == '99'][0]
1261 else:
1262 sg_rule = [r for r in self.api_security_group_rules.list()
1263 if r['protocol'] == 'tcp' and r['remote_ip_prefix']][0]
1256 sg_id = sg_rule['security_group_id'] 1264 sg_id = sg_rule['security_group_id']
1257 secgroup = [sg for sg in self.api_security_groups.list() 1265 secgroup = [sg for sg in self.api_security_groups.list()
1258 if sg['id'] == sg_id][0] 1266 if sg['id'] == sg_id][0]