From 4858315286aa0bc3902e1e7ae6459d25c16afae4 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Wed, 5 Oct 2022 17:13:39 -0400 Subject: [PATCH] Fix misplaced comparison constant warnings Use "value > constant" syntax and not vice-versa. Also removed disable of misplaced-comparison-constant in .pylintrc so future ones are caught. Trivialfix Change-Id: I733864e7437213bfb6edde24f207b2c9861998c6 --- .pylintrc | 1 - neutron/agent/l3/namespaces.py | 4 ++-- neutron/ipam/requests.py | 2 +- neutron/objects/subnet.py | 4 ++-- .../plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py | 2 +- .../ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py | 2 +- neutron/services/portforwarding/pf_plugin.py | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.pylintrc b/.pylintrc index a62bd91ed60..9309e45a8e8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -57,7 +57,6 @@ disable= consider-using-enumerate, invalid-name, len-as-condition, - misplaced-comparison-constant, missing-docstring, singleton-comparison, superfluous-parens, diff --git a/neutron/agent/l3/namespaces.py b/neutron/agent/l3/namespaces.py index d36fdd53cc6..a6a95e5ea3a 100644 --- a/neutron/agent/l3/namespaces.py +++ b/neutron/agent/l3/namespaces.py @@ -45,7 +45,7 @@ def get_prefix_from_ns_name(ns_name): :returns: The prefix ending with a '-' or None if there is no '-' """ dash_index = ns_name.find('-') - if 0 <= dash_index: + if dash_index >= 0: return ns_name[:dash_index + 1] @@ -56,7 +56,7 @@ def get_id_from_ns_name(ns_name): :returns: Identifier or None if there is no - to end the prefix """ dash_index = ns_name.find('-') - if 0 <= dash_index: + if dash_index >= 0: return ns_name[dash_index + 1:] diff --git a/neutron/ipam/requests.py b/neutron/ipam/requests.py index 5152cb4b5b2..3fb81032444 100644 --- a/neutron/ipam/requests.py +++ b/neutron/ipam/requests.py @@ -68,7 +68,7 @@ class SubnetRequest(object, metaclass=abc.ABCMeta): if previous and pool.first <= previous.last: raise ValueError(_("Ranges must not overlap")) previous = pool - if 1 < len(allocation_pools): + if len(allocation_pools) > 1: # Checks that all the ranges are in the same IP version. # IPRange sorts first by ip version so we can get by with just # checking the first and the last range having sorted them diff --git a/neutron/objects/subnet.py b/neutron/objects/subnet.py index 13bd482749f..2f875430379 100644 --- a/neutron/objects/subnet.py +++ b/neutron/objects/subnet.py @@ -349,7 +349,7 @@ class Subnet(base.NeutronDbObject): segment_ids = {subnet.segment_id for subnet, mapping in results if mapping} - if 1 < len(segment_ids): + if len(segment_ids) > 1: raise segment_exc.HostConnectedToMultipleSegments( host=host, network_id=network_id) @@ -395,7 +395,7 @@ class Subnet(base.NeutronDbObject): if subnet and subnet.segment_id not in segment_ids: segment_ids.append(subnet.segment_id) - if 1 < len(segment_ids) and not allow_multiple_segments: + if len(segment_ids) > 1 and not allow_multiple_segments: raise segment_exc.FixedIpsSubnetsNotOnSameSegment() if allow_multiple_segments: diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py index b42989b99b4..6f3047b8aeb 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py @@ -292,7 +292,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer): num_acls_to_add = len(neutron_acls) num_acls_to_remove = len(ovn_acls) + num_acls_to_remove_from_ls - if 0 != num_acls_to_add or 0 != num_acls_to_remove: + if num_acls_to_add != 0 or num_acls_to_remove != 0: LOG.warning('ACLs-to-be-added %(add)d ' 'ACLs-to-be-removed %(remove)d', {'add': num_acls_to_add, diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py index c0dcff354a8..e3daf2b2d90 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py @@ -705,7 +705,7 @@ class OvnIdlDistributedLock(BaseOvnIdl): self.update_tables(tables, row.schema[0]) - if 'Chassis_Private' == self.driver.agent_chassis_table: + if self.driver.agent_chassis_table == 'Chassis_Private': if 'Chassis_Private' not in self.tables: self.driver.agent_chassis_table = 'Chassis' else: diff --git a/neutron/services/portforwarding/pf_plugin.py b/neutron/services/portforwarding/pf_plugin.py index 9e3ff33825e..334fc4dfc16 100644 --- a/neutron/services/portforwarding/pf_plugin.py +++ b/neutron/services/portforwarding/pf_plugin.py @@ -555,7 +555,7 @@ class PortForwardingPlugin(fip_pf.PortForwardingPluginBase): range_b = list(map(int, str(range_b).split(':'))) invalid_port = next((port for port in (range_a + range_b) - if 65535 < port or port < 1), None) + if port > 65535 or port < 1), None) if invalid_port: raise lib_exc.BadRequest(resource=apidef.RESOURCE_NAME,