Browse Source

Merge "python3: Fix handling of other protocol in SG rule"

tags/15.0.0.0b2
Zuul 5 months ago
parent
commit
ea51592827

+ 2
- 2
openstack_dashboard/api/neutron.py View File

@@ -432,9 +432,9 @@ class SecurityGroupManager(object):
432 432
         """
433 433
         if not cidr:
434 434
             cidr = None
435
-        if from_port < 0:
435
+        if isinstance(from_port, int) and from_port < 0:
436 436
             from_port = None
437
-        if to_port < 0:
437
+        if isinstance(to_port, int) and to_port < 0:
438 438
             to_port = None
439 439
         if isinstance(ip_protocol, int) and ip_protocol < 0:
440 440
             ip_protocol = None

+ 12
- 1
openstack_dashboard/test/test_data/neutron_data.py View File

@@ -550,6 +550,16 @@ def data(TEST):
550 550
             'tenant_id': secgroup['tenant_id'],
551 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 563
         rule_all_tcp = {
554 564
             'id': uuidutils.generate_uuid(),
555 565
             'direction': u'egress', 'ethertype': u'IPv4',
@@ -563,7 +573,8 @@ def data(TEST):
563 573
 
564 574
         rules = []
565 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 578
         rules += [rule_egress_ipv4, rule_egress_ipv6]
568 579
         secgroup['security_group_rules'] = rules
569 580
 

+ 11
- 3
openstack_dashboard/test/unit/api/test_neutron.py View File

@@ -1250,9 +1250,17 @@ class NeutronApiSecurityGroupTests(test.APIMockTestCase):
1250 1250
     def test_security_group_rule_create_without_desc(self):
1251 1251
         self._test_security_group_rule_create(with_desc=False)
1252 1252
 
1253
-    def _test_security_group_rule_create(self, with_desc):
1254
-        sg_rule = [r for r in self.api_security_group_rules.list()
1255
-                   if r['protocol'] == 'tcp' and r['remote_ip_prefix']][0]
1253
+    def test_security_group_rule_create_with_custom_protocol(self):
1254
+        self._test_security_group_rule_create(custom_ip_proto=True)
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 1264
         sg_id = sg_rule['security_group_id']
1257 1265
         secgroup = [sg for sg in self.api_security_groups.list()
1258 1266
                     if sg['id'] == sg_id][0]

Loading…
Cancel
Save