diff --git a/neutron/api/api_common.py b/neutron/api/api_common.py index 595c592bd72..5b7032092cc 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 c9497504d0e..fe065c81ed9 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