Fix new pylint issues

new pylint 2.9.0 provides some new checkers and detects new errors with
existing checkers:
- consider-using-enumerate (disabled)
- consider-using-from-import
- arguments-renamed (disabled)
- consider-using-with
- consider-using-dict-items

Change-Id: I4651f8bdaca13486a1dc6408f445d41779a95653
This commit is contained in:
Gregory Thiemonge 2021-06-30 11:06:56 +02:00
parent d10c9c2f9a
commit 4a9de5b27a
9 changed files with 17 additions and 15 deletions

View File

@ -56,7 +56,9 @@ disable=
multiple-statements, multiple-statements,
duplicate-except, duplicate-except,
keyword-arg-before-vararg, keyword-arg-before-vararg,
useless-object-inheritance useless-object-inheritance,
arguments-renamed,
consider-using-enumerate
[BASIC] [BASIC]
# Variable names can be 1 to 31 characters long, with lowercase and underscores # Variable names can be 1 to 31 characters long, with lowercase and underscores

View File

@ -520,17 +520,16 @@ class UpdateHealthDb:
session, db_pool_id, db_pool_dict, pools, session, db_pool_id, db_pool_dict, pools,
lb_status, processed_pools, potential_offline_pools) lb_status, processed_pools, potential_offline_pools)
for pool_id in potential_offline_pools: for pool_id, pool in potential_offline_pools.items():
# Skip if we eventually found a status for this pool # Skip if we eventually found a status for this pool
if pool_id in processed_pools: if pool_id in processed_pools:
continue continue
try: try:
# If the database doesn't already show the pool offline, update # If the database doesn't already show the pool offline, update
if potential_offline_pools[pool_id] != constants.OFFLINE: if pool != constants.OFFLINE:
self._update_status( self._update_status(
session, self.pool_repo, constants.POOL, session, self.pool_repo, constants.POOL,
pool_id, constants.OFFLINE, pool_id, constants.OFFLINE, pool)
potential_offline_pools[pool_id])
except sqlalchemy.orm.exc.NoResultFound: except sqlalchemy.orm.exc.NoResultFound:
LOG.error("Pool %s is not in DB", pool_id) LOG.error("Pool %s is not in DB", pool_id)

View File

@ -276,8 +276,8 @@ class ListenersController(base.BaseController):
# new listener # new listener
disallowed_protocols = [ disallowed_protocols = [
p p
for p in constants.L4_PROTOCOL_MAP for p, l4_p in constants.L4_PROTOCOL_MAP.items()
if constants.L4_PROTOCOL_MAP[p] == l4_protocol if l4_p == l4_protocol
] ]
for db_l in db_listeners: for db_l in db_listeners:

View File

@ -37,7 +37,7 @@ from octavia.common import data_models
from octavia.common import exceptions from octavia.common import exceptions
from octavia.common import stats from octavia.common import stats
from octavia.common import utils from octavia.common import utils
import octavia.common.validate as validate from octavia.common import validate
from octavia.db import api as db_api from octavia.db import api as db_api
from octavia.db import prepare as db_prepare from octavia.db import prepare as db_prepare
from octavia.i18n import _ from octavia.i18n import _

View File

@ -29,7 +29,7 @@ from octavia.api.v2.types import member as member_types
from octavia.common import constants from octavia.common import constants
from octavia.common import data_models from octavia.common import data_models
from octavia.common import exceptions from octavia.common import exceptions
import octavia.common.validate as validate from octavia.common import validate
from octavia.db import api as db_api from octavia.db import api as db_api
from octavia.db import prepare as db_prepare from octavia.db import prepare as db_prepare

View File

@ -45,7 +45,8 @@ class LocalCertGenerator(cert_gen.CertGenerator):
if not ca_cert: if not ca_cert:
LOG.info("Using CA Certificate from config.") LOG.info("Using CA Certificate from config.")
try: try:
ca_cert = open(CONF.certificates.ca_certificate, 'rb').read() with open(CONF.certificates.ca_certificate, 'rb') as fp:
fp.read()
except IOError as e: except IOError as e:
raise exceptions.CertificateGenerationException( raise exceptions.CertificateGenerationException(
msg="Failed to load CA Certificate {0}." msg="Failed to load CA Certificate {0}."
@ -54,7 +55,8 @@ class LocalCertGenerator(cert_gen.CertGenerator):
if not ca_key: if not ca_key:
LOG.info("Using CA Private Key from config.") LOG.info("Using CA Private Key from config.")
try: try:
ca_key = open(CONF.certificates.ca_private_key, 'rb').read() with open(CONF.certificates.ca_private_key, 'rb') as fp:
fp.read()
except IOError as e: except IOError as e:
raise exceptions.CertificateGenerationException( raise exceptions.CertificateGenerationException(
msg="Failed to load CA Private Key {0}." msg="Failed to load CA Private Key {0}."

View File

@ -30,10 +30,9 @@ class BaseDataModel(object):
"""Converts a data model to a dictionary.""" """Converts a data model to a dictionary."""
calling_classes = calling_classes or [] calling_classes = calling_classes or []
ret = {} ret = {}
for attr in self.__dict__: for attr, value in self.__dict__.items():
if attr.startswith('_') or not kwargs.get(attr, True): if attr.startswith('_') or not kwargs.get(attr, True):
continue continue
value = self.__dict__[attr]
if attr == 'tags': if attr == 'tags':
# tags is a list, it doesn't need recurse # tags is a list, it doesn't need recurse
ret[attr] = value ret[attr] = value

View File

@ -26,7 +26,7 @@ from taskflow.types import failure
from octavia.common import constants from octavia.common import constants
from octavia.common import data_models from octavia.common import data_models
import octavia.common.tls_utils.cert_parser as cert_parser from octavia.common.tls_utils import cert_parser
from octavia.common import utils from octavia.common import utils
from octavia.controller.worker import task_utils as task_utilities from octavia.controller.worker import task_utils as task_utilities
from octavia.db import api as db_apis from octavia.db import api as db_apis

View File

@ -27,7 +27,7 @@ from taskflow.types import failure
from octavia.api.drivers import utils as provider_utils from octavia.api.drivers import utils as provider_utils
from octavia.common import constants from octavia.common import constants
from octavia.common import data_models from octavia.common import data_models
import octavia.common.tls_utils.cert_parser as cert_parser from octavia.common.tls_utils import cert_parser
from octavia.common import utils from octavia.common import utils
from octavia.controller.worker import task_utils as task_utilities from octavia.controller.worker import task_utils as task_utilities
from octavia.db import api as db_apis from octavia.db import api as db_apis