]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable flake8 E711 and E712 checking
authorHenry Gessau <gessau@cisco.com>
Thu, 10 Apr 2014 02:49:50 +0000 (22:49 -0400)
committerHenry Gessau <gessau@cisco.com>
Thu, 10 Apr 2014 03:03:57 +0000 (23:03 -0400)
E711 comparison to False should be 'if cond is False:' or 'if not cond:'
     comparison to None should be 'if cond is None:' or 'if not cond:'
E712 comparison to True should be 'if cond is True:' or 'if cond:'

Most violations were in DB queries. Replace as follows:
  False -> sqlalchemy.sql.false()
  None  -> sqlalchemy.sql.null()
  True  -> sqlalchemy.sql.true()

Change-Id: Iff54747b70f504d5466cfdc6e2ec4d7a0f9ddb7c
Closes-bug: #1305377

neutron/db/db_base_plugin_v2.py
neutron/plugins/cisco/db/n1kv_db_v2.py
neutron/plugins/ml2/drivers/l2pop/db.py
neutron/plugins/nec/db/packetfilter.py
neutron/scheduler/dhcp_agent_scheduler.py
neutron/scheduler/l3_agent_scheduler.py
neutron/tests/unit/test_extension_portsecurity.py
tox.ini

index 1be937cbaea81a9eb8d5c879774300b5fa6456b6..92258b824b149ebad741cf3bf75db0a7ec6bf714 100644 (file)
@@ -20,6 +20,7 @@ from oslo.config import cfg
 from sqlalchemy import event
 from sqlalchemy import orm
 from sqlalchemy.orm import exc
+from sqlalchemy import sql
 
 from neutron.api.v2 import attributes
 from neutron.common import constants
@@ -98,7 +99,7 @@ class CommonDbMixin(object):
         if not context.is_admin and hasattr(model, 'tenant_id'):
             if hasattr(model, 'shared'):
                 query_filter = ((model.tenant_id == context.tenant_id) |
-                                (model.shared == True))
+                                (model.shared == sql.true()))
             else:
                 query_filter = (model.tenant_id == context.tenant_id)
         # Execute query hooks registered from mixins and plugins
index 5c237115c6dd22ecbc8d0a77a7f3bf872d086a32..1ee10f686b5057678c4f5e57a4afe420439e6f76 100644 (file)
@@ -22,7 +22,7 @@
 import netaddr
 import re
 from sqlalchemy.orm import exc
-from sqlalchemy.sql import and_
+from sqlalchemy import sql
 
 from neutron.api.v2 import attributes
 from neutron.common import exceptions as n_exc
@@ -447,12 +447,13 @@ def reserve_vlan(db_session, network_profile):
 
     with db_session.begin(subtransactions=True):
         alloc = (db_session.query(n1kv_models_v2.N1kvVlanAllocation).
-                 filter(and_(
+                 filter(sql.and_(
                         n1kv_models_v2.N1kvVlanAllocation.vlan_id >= seg_min,
                         n1kv_models_v2.N1kvVlanAllocation.vlan_id <= seg_max,
                         n1kv_models_v2.N1kvVlanAllocation.physical_network ==
                         network_profile['physical_network'],
-                        n1kv_models_v2.N1kvVlanAllocation.allocated == False)
+                        n1kv_models_v2.N1kvVlanAllocation.allocated ==
+                        sql.false())
                         )).first()
         if alloc:
             segment_id = alloc.vlan_id
@@ -476,12 +477,13 @@ def reserve_vxlan(db_session, network_profile):
 
     with db_session.begin(subtransactions=True):
         alloc = (db_session.query(n1kv_models_v2.N1kvVxlanAllocation).
-                 filter(and_(
+                 filter(sql.and_(
                         n1kv_models_v2.N1kvVxlanAllocation.vxlan_id >=
                         seg_min,
                         n1kv_models_v2.N1kvVxlanAllocation.vxlan_id <=
                         seg_max,
-                        n1kv_models_v2.N1kvVxlanAllocation.allocated == False)
+                        n1kv_models_v2.N1kvVxlanAllocation.allocated ==
+                        sql.false())
                         ).first())
         if alloc:
             segment_id = alloc.vxlan_id
@@ -1459,15 +1461,16 @@ class PolicyProfile_db_mixin(object):
                                  profile_type=c_const.POLICY))
             a_set = set(i.profile_id for i in a_set_q)
             b_set_q = (db_session.query(n1kv_models_v2.ProfileBinding).
-                       filter(and_(n1kv_models_v2.ProfileBinding.
-                                   tenant_id != c_const.TENANT_ID_NOT_SET,
-                                   n1kv_models_v2.ProfileBinding.
-                                   profile_type == c_const.POLICY)))
+                       filter(sql.and_(n1kv_models_v2.ProfileBinding.
+                                       tenant_id != c_const.TENANT_ID_NOT_SET,
+                                       n1kv_models_v2.ProfileBinding.
+                                       profile_type == c_const.POLICY)))
             b_set = set(i.profile_id for i in b_set_q)
             (db_session.query(n1kv_models_v2.ProfileBinding).
-             filter(and_(n1kv_models_v2.ProfileBinding.profile_id.
-                         in_(a_set & b_set), n1kv_models_v2.ProfileBinding.
-                         tenant_id == c_const.TENANT_ID_NOT_SET)).
+             filter(sql.and_(n1kv_models_v2.ProfileBinding.profile_id.
+                             in_(a_set & b_set),
+                             n1kv_models_v2.ProfileBinding.tenant_id ==
+                             c_const.TENANT_ID_NOT_SET)).
              delete(synchronize_session="fetch"))
 
     def _add_policy_profile(self,
index 6490028293a402398e6cee5963f9be4ed9a5c86c..3c4fc9bcea1d9a043589ab8a58bcee6bf6259771 100644 (file)
@@ -17,6 +17,8 @@
 # @author: Francois Eleouet, Orange
 # @author: Mathieu Rohon, Orange
 
+from sqlalchemy import sql
+
 from neutron.common import constants as const
 from neutron.db import agents_db
 from neutron.db import db_base_plugin_v2 as base_db
@@ -63,7 +65,7 @@ class L2populationDbMixin(base_db.CommonDbMixin):
                                ml2_models.PortBinding.host)
             query = query.join(models_v2.Port)
             query = query.filter(models_v2.Port.network_id == network_id,
-                                 models_v2.Port.admin_state_up == True,
+                                 models_v2.Port.admin_state_up == sql.true(),
                                  agents_db.Agent.agent_type.in_(
                                      l2_const.SUPPORTED_AGENT_TYPES))
             return query
index 0ff3cd5b0c9b2b3d14ff6191c2db0f13a543180b..b4ff68940bd0c4eb689e604ed3ad1db1263597d2 100644 (file)
@@ -18,6 +18,7 @@
 import sqlalchemy as sa
 from sqlalchemy import orm
 from sqlalchemy.orm import exc as sa_exc
+from sqlalchemy import sql
 
 from neutron.api.v2 import attributes
 from neutron.db import model_base
@@ -205,11 +206,11 @@ class PacketFilterDbMixin(object):
         query = (context.session.query(nmodels.OFCFilterMapping)
                  .join(PacketFilter,
                        nmodels.OFCFilterMapping.neutron_id == PacketFilter.id)
-                 .filter(PacketFilter.admin_state_up == True))
+                 .filter(PacketFilter.admin_state_up == sql.true()))
 
         network_id = port['network_id']
         net_pf_query = (query.filter(PacketFilter.network_id == network_id)
-                        .filter(PacketFilter.in_port == None))
+                        .filter(PacketFilter.in_port == sql.null()))
         net_filters = [(pf['neutron_id'], pf['ofc_id']) for pf in net_pf_query]
 
         port_pf_query = query.filter(PacketFilter.in_port == port['id'])
index 4feebafe9f32a4013759bf65e615903d348b8e59..98ec5904e6f25c77ab7c9368f4362683474dc217 100644 (file)
@@ -18,6 +18,7 @@
 import random
 
 from oslo.config import cfg
+from sqlalchemy import sql
 
 from neutron.common import constants
 from neutron.db import agents_db
@@ -103,7 +104,7 @@ class ChanceScheduler(object):
             query = query.filter(agents_db.Agent.agent_type ==
                                  constants.AGENT_TYPE_DHCP,
                                  agents_db.Agent.host == host,
-                                 agents_db.Agent.admin_state_up == True)
+                                 agents_db.Agent.admin_state_up == sql.true())
             dhcp_agents = query.all()
             for dhcp_agent in dhcp_agents:
                 if agents_db.AgentDbMixin.is_agent_down(
index e0cccd1ecb3b4c96b9ef582e49e3475383dfbe85..bdc8d4042db23c22c0e5754ba02498eecb4ec55f 100644 (file)
@@ -20,7 +20,7 @@ import random
 
 import six
 from sqlalchemy.orm import exc
-from sqlalchemy.sql import exists
+from sqlalchemy import sql
 
 from neutron.common import constants
 from neutron.db import agents_db
@@ -58,7 +58,7 @@ class L3Scheduler(object):
             query = query.filter(agents_db.Agent.agent_type ==
                                  constants.AGENT_TYPE_L3,
                                  agents_db.Agent.host == host,
-                                 agents_db.Agent.admin_state_up == True)
+                                 agents_db.Agent.admin_state_up == sql.true())
             try:
                 l3_agent = query.one()
             except (exc.MultipleResultsFound, exc.NoResultFound):
@@ -87,7 +87,7 @@ class L3Scheduler(object):
             else:
                 # get all routers that are not hosted
                 #TODO(gongysh) consider the disabled agent's router
-                stmt = ~exists().where(
+                stmt = ~sql.exists().where(
                     l3_db.Router.id ==
                     l3_agentschedulers_db.RouterL3AgentBinding.router_id)
                 unscheduled_router_ids = [router_id_[0] for router_id_ in
index c336db23a853ee052a1911d50ef2a9e9f0c7d531..29c4e850181374130a19c08c6ae33c7996c97846 100644 (file)
@@ -136,7 +136,7 @@ class PortSecurityTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
 
             # Port security/IP was updated off. Need to check that no security
             # groups are on port.
-            if (ret_port[psec.PORTSECURITY] != True or not has_ip):
+            if ret_port[psec.PORTSECURITY] is not True or not has_ip:
                 if has_security_groups:
                     raise psec.PortSecurityAndIPRequiredForSecurityGroups()
 
diff --git a/tox.ini b/tox.ini
index 7891beaf2c65bed5bf269abb80c5bd3e56a4bc74..423abf8798fee6b94200944694bffbf8fedfd33f 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -40,12 +40,10 @@ commands =
 commands = {posargs}
 
 [flake8]
-# E711/E712 comparison to False should be 'if cond is False:' or 'if not cond:'
-#        query = query.filter(Component.disabled == False)
 # E125 continuation line does not distinguish itself from next logical line
 # H302 import only modules
 # TODO(marun) H404 multi line docstring should start with a summary
-ignore = E711,E712,E125,H302,H404
+ignore = E125,H302,H404
 show-source = true
 builtins = _
 exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools