From: Cyril Roelandt Date: Wed, 5 Aug 2015 09:22:24 +0000 (+0200) Subject: Python 3: do not compare int and NoneType X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a0b2c0f9d1ce515332ba1e42267a17c30a75ea5a;p=openstack-build%2Fneutron-build.git Python 3: do not compare int and NoneType This is an invalid operation in Python 3, even though it works in Python 2. Change-Id: I89d654c6acea10b53d19e50199565badf011e705 Blueprint:neutron-python3 --- diff --git a/neutron/api/api_common.py b/neutron/api/api_common.py index 595c592bd..5b7032092 100644 --- a/neutron/api/api_common.py +++ b/neutron/api/api_common.py @@ -273,7 +273,17 @@ class SortingEmulatedHelper(SortingHelper): def sort(self, items): def cmp_func(obj1, obj2): for key, direction in self.sort_dict: - ret = (obj1[key] > obj2[key]) - (obj1[key] < obj2[key]) + o1 = obj1[key] + o2 = obj2[key] + + if o1 is None and o2 is None: + ret = 0 + elif o1 is None and o2 is not None: + ret = -1 + elif o1 is not None and o2 is None: + ret = 1 + else: + ret = (o1 > o2) - (o1 < o2) if ret: return ret * (1 if direction else -1) return 0 diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 49b4f0913..19805ea81 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -430,6 +430,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): ip_proto = self._get_ip_proto_number(rule['protocol']) if ip_proto in [constants.PROTO_NUM_TCP, constants.PROTO_NUM_UDP]: if (rule['port_range_min'] is not None and + rule['port_range_max'] is not None and rule['port_range_min'] <= rule['port_range_max']): pass else: @@ -437,7 +438,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): elif ip_proto == constants.PROTO_NUM_ICMP: for attr, field in [('port_range_min', 'type'), ('port_range_max', 'code')]: - if rule[attr] > 255: + if rule[attr] is not None and rule[attr] > 255: raise ext_sg.SecurityGroupInvalidIcmpValue( field=field, attr=attr, value=rule[attr]) if (rule['port_range_min'] is None and