Enable flake8 E711 and E712 checking
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
This commit is contained in:
parent
ce7e53e5b5
commit
dda6c89202
@ -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
|
||||
|
@ -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.
|
||||
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,
|
||||
|
@ -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
|
||||
|
@ -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'])
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
4
tox.ini
4
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
|
||||
|
Loading…
Reference in New Issue
Block a user