python3: Fix handling of other protocol in SG rule
In python3 we cannot compare None with an integer, while this works in python2. Change-Id: I1321ea68f08241db377a58ed6a22306c63aba204 Closes-Bug: #1789402
This commit is contained in:
parent
06ab7a5047
commit
ccb21ca7a9
|
@ -432,9 +432,9 @@ class SecurityGroupManager(object):
|
|||
"""
|
||||
if not cidr:
|
||||
cidr = None
|
||||
if from_port < 0:
|
||||
if isinstance(from_port, int) and from_port < 0:
|
||||
from_port = None
|
||||
if to_port < 0:
|
||||
if isinstance(to_port, int) and to_port < 0:
|
||||
to_port = None
|
||||
if isinstance(ip_protocol, int) and ip_protocol < 0:
|
||||
ip_protocol = None
|
||||
|
|
|
@ -548,6 +548,16 @@ def data(TEST):
|
|||
'tenant_id': secgroup['tenant_id'],
|
||||
'description': 'Ingress HTTP from SG #1',
|
||||
}
|
||||
rule_ip_proto = {
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'direction': u'ingress', 'ethertype': u'IPv4',
|
||||
'port_range_min': None, 'port_range_max': None,
|
||||
'protocol': u'99', 'remote_group_id': None,
|
||||
'remote_ip_prefix': u'0.0.0.0/24',
|
||||
'security_group_id': secgroup['id'],
|
||||
'tenant_id': secgroup['tenant_id'],
|
||||
'description': 'Ingress custom IP protocol 99',
|
||||
}
|
||||
rule_all_tcp = {
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'direction': u'egress', 'ethertype': u'IPv4',
|
||||
|
@ -561,7 +571,8 @@ def data(TEST):
|
|||
|
||||
rules = []
|
||||
if not default_only:
|
||||
rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp]
|
||||
rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp,
|
||||
rule_ip_proto]
|
||||
rules += [rule_egress_ipv4, rule_egress_ipv6]
|
||||
secgroup['security_group_rules'] = rules
|
||||
|
||||
|
|
|
@ -1250,7 +1250,15 @@ class NeutronApiSecurityGroupTests(test.APIMockTestCase):
|
|||
def test_security_group_rule_create_without_desc(self):
|
||||
self._test_security_group_rule_create(with_desc=False)
|
||||
|
||||
def _test_security_group_rule_create(self, with_desc):
|
||||
def test_security_group_rule_create_with_custom_protocol(self):
|
||||
self._test_security_group_rule_create(custom_ip_proto=True)
|
||||
|
||||
def _test_security_group_rule_create(self, with_desc=False,
|
||||
custom_ip_proto=False):
|
||||
if custom_ip_proto:
|
||||
sg_rule = [r for r in self.api_security_group_rules.list()
|
||||
if r['protocol'] == '99'][0]
|
||||
else:
|
||||
sg_rule = [r for r in self.api_security_group_rules.list()
|
||||
if r['protocol'] == 'tcp' and r['remote_ip_prefix']][0]
|
||||
sg_id = sg_rule['security_group_id']
|
||||
|
|
Loading…
Reference in New Issue