]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Python 3: do not compare int and NoneType
authorCyril Roelandt <cyril@redhat.com>
Wed, 5 Aug 2015 09:22:24 +0000 (11:22 +0200)
committerCyril Roelandt <cyril@redhat.com>
Wed, 5 Aug 2015 09:24:57 +0000 (11:24 +0200)
This is an invalid operation in Python 3, even though it works in Python 2.

Change-Id: I89d654c6acea10b53d19e50199565badf011e705
Blueprint:neutron-python3

neutron/api/api_common.py
neutron/db/securitygroups_db.py

index 595c592bd72bd463938e9e5634ae97adb6d99cd5..5b7032092cc16c88367244ea458a3425d046d151 100644 (file)
@@ -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
index 49b4f0913c4f87d86bfff8f6007cd9f5130740fa..19805ea812486ff8e78df0f5932269da402c6787 100644 (file)
@@ -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