diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 8f485c86f3..59ace79773 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -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 diff --git a/neutron/plugins/cisco/db/n1kv_db_v2.py b/neutron/plugins/cisco/db/n1kv_db_v2.py index 5c237115c6..1ee10f686b 100644 --- a/neutron/plugins/cisco/db/n1kv_db_v2.py +++ b/neutron/plugins/cisco/db/n1kv_db_v2.py @@ -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, diff --git a/neutron/plugins/ml2/drivers/l2pop/db.py b/neutron/plugins/ml2/drivers/l2pop/db.py index 6490028293..3c4fc9bcea 100644 --- a/neutron/plugins/ml2/drivers/l2pop/db.py +++ b/neutron/plugins/ml2/drivers/l2pop/db.py @@ -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 diff --git a/neutron/plugins/nec/db/packetfilter.py b/neutron/plugins/nec/db/packetfilter.py index 0ff3cd5b0c..b4ff68940b 100644 --- a/neutron/plugins/nec/db/packetfilter.py +++ b/neutron/plugins/nec/db/packetfilter.py @@ -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']) diff --git a/neutron/scheduler/dhcp_agent_scheduler.py b/neutron/scheduler/dhcp_agent_scheduler.py index 4feebafe9f..98ec5904e6 100644 --- a/neutron/scheduler/dhcp_agent_scheduler.py +++ b/neutron/scheduler/dhcp_agent_scheduler.py @@ -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( diff --git a/neutron/scheduler/l3_agent_scheduler.py b/neutron/scheduler/l3_agent_scheduler.py index 5a0e2dcafa..df125ce173 100644 --- a/neutron/scheduler/l3_agent_scheduler.py +++ b/neutron/scheduler/l3_agent_scheduler.py @@ -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 diff --git a/neutron/tests/unit/test_extension_portsecurity.py b/neutron/tests/unit/test_extension_portsecurity.py index c336db23a8..29c4e85018 100644 --- a/neutron/tests/unit/test_extension_portsecurity.py +++ b/neutron/tests/unit/test_extension_portsecurity.py @@ -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 7891beaf2c..423abf8798 100644 --- 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