Update tox pylint/pep8 for dcdbsync

This commit enables the check of new pylint/pep8
violations.

PYLINT - All convention related checks, except:
- missing-class-docstring
- missing-function-docstring
- missing-module-docstring
- consider-using-f-string
- invalid-name
- import-outside-toplevel
- too-many-lines
- consider-iterating-dictionary
- unnecessary-lambda-assignment

PEP8:
- E117: over-indented
- E123: closing bracket does not match indentation
  of opening bracket's line
- E125: continuation line with the same indent as the next
  logical line
- E305: expected 2 blank lines after class or function
  definition
- E402: module level import not at top of file
- E501: line too long
- H216: flag use of third party mock

Test Plan:
1. Perform `tox` command
- Pass in py39, pylint, pep8

Partial-bug: 2033294

Change-Id: Ib3b3d36b8c4f48aa6a62744e01c1de9e11c65ad9
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
This commit is contained in:
Hugo Brito 2023-08-28 17:29:13 -03:00 committed by rlima
parent a2b9bb7ab2
commit 766f052295
14 changed files with 78 additions and 76 deletions

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
@ -45,9 +45,9 @@ def setup_app(*args, **kwargs):
'errors': { 'errors': {
400: '/error', 400: '/error',
'__force_dict__': True '__force_dict__': True
}
} }
} }
}
pecan_config = pecan.configuration.conf_from_dict(config) pecan_config = pecan.configuration.conf_from_dict(config)

View File

@ -13,12 +13,11 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import pecan import pecan
from dcdbsync.api.controllers.v1 import root as v1_root from dcdbsync.api.controllers.v1 import root as v1_root
@ -45,13 +44,13 @@ class RootController(object):
{ {
"rel": "self", "rel": "self",
"href": pecan.request.application_url + "/v1.0/" "href": pecan.request.application_url + "/v1.0/"
} }
], ],
"id": "v1.0", "id": "v1.0",
"updated": "2018-11-20" "updated": "2018-11-20"
} }
] ]
} }
@index.when(method='POST') @index.when(method='POST')
@index.when(method='PUT') @index.when(method='PUT')

View File

@ -13,14 +13,15 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019-2021 Wind River Systems, Inc. # Copyright (c) 2019-2021, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import json
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import pecan import pecan
from pecan import expose from pecan import expose
from pecan import request from pecan import request
@ -31,8 +32,6 @@ from dcdbsync.common import exceptions
from dcdbsync.common.i18n import _ from dcdbsync.common.i18n import _
from dcdbsync.db.identity import api as db_api from dcdbsync.db.identity import api as db_api
import json
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -97,7 +96,7 @@ class UsersController(object):
# Insert the user into DB tables # Insert the user into DB tables
user_ref = db_api.user_create(context, payload) user_ref = db_api.user_create(context, payload)
response.status = 201 response.status = 201
return (user_ref) return user_ref
except Exception as e: except Exception as e:
LOG.exception(e) LOG.exception(e)
@ -193,7 +192,7 @@ class GroupsController(object):
# Insert the group into DB tables # Insert the group into DB tables
group_ref = db_api.group_create(context, payload) group_ref = db_api.group_create(context, payload)
response.status = 201 response.status = 201
return (group_ref) return group_ref
except Exception as e: except Exception as e:
LOG.exception(e) LOG.exception(e)

View File

@ -13,14 +13,15 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import json
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import pecan import pecan
from pecan import expose from pecan import expose
from pecan import request from pecan import request
@ -31,8 +32,6 @@ from dcdbsync.common import exceptions
from dcdbsync.common.i18n import _ from dcdbsync.common.i18n import _
from dcdbsync.db.identity import api as db_api from dcdbsync.db.identity import api as db_api
import json
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -13,14 +13,15 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import json
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import pecan import pecan
from pecan import expose from pecan import expose
from pecan import request from pecan import request
@ -31,8 +32,6 @@ from dcdbsync.common import exceptions
from dcdbsync.common.i18n import _ from dcdbsync.common.i18n import _
from dcdbsync.db.identity import api as db_api from dcdbsync.db.identity import api as db_api
import json
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -13,15 +13,16 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import base64
import json
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import base64
import pecan import pecan
from pecan import expose from pecan import expose
from pecan import request from pecan import request
@ -32,8 +33,6 @@ from dcdbsync.common import exceptions
from dcdbsync.common.i18n import _ from dcdbsync.common.i18n import _
from dcdbsync.db.identity import api as db_api from dcdbsync.db.identity import api as db_api
import json
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -13,16 +13,15 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import pecan
from dcdbsync.api.controllers.v1.identity import root from dcdbsync.api.controllers.v1.identity import root
import pecan
class Controller(object): class Controller(object):

View File

@ -13,17 +13,18 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2022 Wind River Systems, Inc. # Copyright (c) 2022, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
"""Policy Engine For DC.""" """Policy Engine For DC."""
from dcdbsync.api import policies as controller_policies
from oslo_config import cfg from oslo_config import cfg
from oslo_policy import policy from oslo_policy import policy
from webob import exc from webob import exc
from dcdbsync.api import policies as controller_policies
CONF = cfg.CONF CONF = cfg.CONF
_ENFORCER = None _ENFORCER = None

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
@ -22,23 +22,23 @@
# see http://git.openstack.org/cgit/openstack/ironic/tree/ironic/cmd/api.py # see http://git.openstack.org/cgit/openstack/ironic/tree/ironic/cmd/api.py
import logging as std_logging
import sys import sys
import eventlet import eventlet
eventlet.monkey_patch(os=False) eventlet.monkey_patch(os=False)
from oslo_config import cfg # pylint: disable=wrong-import-position
from oslo_log import log as logging from oslo_config import cfg # noqa: E402
from oslo_service import systemd from oslo_log import log as logging # noqa: E402
from oslo_service import wsgi from oslo_service import systemd # noqa: E402
from oslo_service import wsgi # noqa: E402
import logging as std_logging from dcdbsync.api import api_config # noqa: E402
from dcdbsync.api import app # noqa: E402
from dcdbsync.api import api_config from dcdbsync.common import config # noqa: E402
from dcdbsync.api import app from dcdbsync.common import messaging # noqa: E402
# pylint: enable=wrong-import-position
from dcdbsync.common import config
from dcdbsync.common import messaging
CONF = cfg.CONF CONF = cfg.CONF
config.register_options() config.register_options()

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019-2021 Wind River Systems, Inc. # Copyright (c) 2019-2021, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
@ -42,14 +42,14 @@ class DBsyncException(Exception):
def __init__(self, **kwargs): def __init__(self, **kwargs):
try: try:
super(DBsyncException, self).__init__(self.message % kwargs) # pylint: disable=exception-message-attribute super(DBsyncException, self).__init__(self.message % kwargs)
self.msg = self.message % kwargs # pylint: disable=exception-message-attribute self.msg = self.message % kwargs
except Exception: except Exception:
with excutils.save_and_reraise_exception() as ctxt: with excutils.save_and_reraise_exception() as ctxt:
if not self.use_fatal_exceptions(): if not self.use_fatal_exceptions():
ctxt.reraise = False ctxt.reraise = False
# at least get the core message out if something happened # at least get the core message out if something happened
super(DBsyncException, self).__init__(self.message) # pylint: disable=exception-message-attribute super(DBsyncException, self).__init__(self.message)
if six.PY2: if six.PY2:
def __unicode__(self): def __unicode__(self):

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2019-2022 Wind River Systems, Inc. # Copyright (c) 2019-2022, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
@ -26,7 +26,6 @@ import sys
from oslo_db.sqlalchemy import enginefacade from oslo_db.sqlalchemy import enginefacade
from oslo_log import log as logging from oslo_log import log as logging
from sqlalchemy import Table, MetaData from sqlalchemy import Table, MetaData
from sqlalchemy.sql import select from sqlalchemy.sql import select
@ -73,6 +72,7 @@ class TableRegistry(object):
) )
return table return table
registry = TableRegistry() registry = TableRegistry()
@ -345,7 +345,8 @@ def user_update(context, user_id, payload):
user_group_membership = {'user_id': new_user_id} user_group_membership = {'user_id': new_user_id}
update(conn, 'assignment', 'actor_id', user_id, assignment) update(conn, 'assignment', 'actor_id', user_id, assignment)
update(conn, 'system_assignment', 'actor_id', user_id, assignment) update(conn, 'system_assignment', 'actor_id', user_id, assignment)
update(conn, 'user_group_membership', 'user_id', user_id, user_group_membership) update(conn, 'user_group_membership', 'user_id',
user_id, user_group_membership)
return user_get(context, new_user_id) return user_get(context, new_user_id)
@ -393,12 +394,15 @@ def group_get(context, group_id):
result['group'] = group[0] result['group'] = group[0]
# user_group_membership table # user_group_membership table
user_group_memberships = query(conn, 'user_group_membership', 'group_id', group_id) user_group_memberships = query(conn, 'user_group_membership',
'group_id', group_id)
for user_group_membership in user_group_memberships: for user_group_membership in user_group_memberships:
local_user = query(conn, 'local_user', 'user_id', user_group_membership.get('user_id')) local_user = query(conn, 'local_user', 'user_id',
user_group_membership.get('user_id'))
if not local_user: if not local_user:
raise exception.UserNotFound(user_id=user_group_membership.get('user_id')) raise exception.UserNotFound(user_id=user_group_membership.get(
'user_id'))
local_user_id_list.append(local_user[0]['user_id']) local_user_id_list.append(local_user[0]['user_id'])
result['local_user_ids'] = local_user_id_list result['local_user_ids'] = local_user_id_list
@ -415,7 +419,8 @@ def group_create(context, payload):
insert(conn, 'group', group) insert(conn, 'group', group)
for local_user_id in local_user_ids: for local_user_id in local_user_ids:
user_group_membership = {'user_id': local_user_id, 'group_id': group['id']} user_group_membership = {'user_id': local_user_id,
'group_id': group['id']}
insert(conn, 'user_group_membership', user_group_membership) insert(conn, 'user_group_membership', user_group_membership)
return group_get(context, payload['group']['id']) return group_get(context, payload['group']['id'])
@ -433,16 +438,19 @@ def group_update(context, group_id, payload):
local_user_id_list = payload['local_user_ids'] local_user_id_list = payload['local_user_ids']
user_group_memberships = query(conn, 'user_group_membership', user_group_memberships = query(conn, 'user_group_membership',
'group_id', group_id) 'group_id', group_id)
existing_user_list = [user_group_membership['user_id'] for user_group_membership existing_user_list = [
in user_group_memberships] user_group_membership['user_id'] for user_group_membership in
user_group_memberships
]
existing_user_list.sort() existing_user_list.sort()
deleted = False deleted = False
if (group_id != new_group_id) or (local_user_id_list != existing_user_list): # Foreign key constraint exists on 'group_id' of user_group_membership
# Foreign key constraint exists on 'group_id' of user_group_membership table # table and 'id' of group table. So delete user group membership records
# and 'id' of group table. So delete user group membership records before # before updating group if groups IDs are different.
# updating group if groups IDs are different # Alternatively, if there is a discrepency in the user group memberships,
# Alternatively, if there is a discrepency in the user group memberships, # delete and re-create them
# delete and re-create them if (group_id != new_group_id) or (
local_user_id_list != existing_user_list):
delete(conn, 'user_group_membership', 'group_id', group_id) delete(conn, 'user_group_membership', 'group_id', group_id)
deleted = True deleted = True
# Update group table # Update group table

View File

@ -12,14 +12,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
from bs4 import BeautifulSoup
import json import json
from bs4 import BeautifulSoup
from dcdbsync.dbsyncclient import exceptions from dcdbsync.dbsyncclient import exceptions

View File

@ -14,20 +14,20 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import copy import copy
import logging
import os import os
import requests import requests
import logging from oslo_utils import importutils
from dcdbsync.dbsyncclient import exceptions from dcdbsync.dbsyncclient import exceptions
from oslo_utils import importutils
osprofiler_web = importutils.try_import("osprofiler.web") osprofiler_web = importutils.try_import("osprofiler.web")
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -14,13 +14,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# Copyright (c) 2019-2021 Wind River Systems, Inc. # Copyright (c) 2019-2021, 2024 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import keystoneauth1.identity.generic as auth_plugin import keystoneauth1.identity.generic as auth_plugin
from keystoneauth1 import session as ks_session from keystoneauth1 import session as ks_session
from oslo_utils import importutils
import six
from dcdbsync.dbsyncclient import httpclient from dcdbsync.dbsyncclient import httpclient
from dcdbsync.dbsyncclient.v1.identity import identity_group_manager as igm from dcdbsync.dbsyncclient.v1.identity import identity_group_manager as igm
@ -30,12 +32,8 @@ from dcdbsync.dbsyncclient.v1.identity import role_manager as rm
from dcdbsync.dbsyncclient.v1.identity \ from dcdbsync.dbsyncclient.v1.identity \
import token_revoke_event_manager as trem import token_revoke_event_manager as trem
from oslo_utils import importutils
osprofiler_profiler = importutils.try_import("osprofiler.profiler") osprofiler_profiler = importutils.try_import("osprofiler.profiler")
import six
_DEFAULT_DBSYNC_AGENT_URL = "http://localhost:8219/v1.0" _DEFAULT_DBSYNC_AGENT_URL = "http://localhost:8219/v1.0"
# default HTTP request timeout in seconds # default HTTP request timeout in seconds
_DEFAULT_REQUEST_TIMEOUT = 15 _DEFAULT_REQUEST_TIMEOUT = 15
@ -150,7 +148,7 @@ def authenticate(dbsync_agent_url=None, username=None,
project_name=project_name, project_name=project_name,
project_domain_name=project_domain_name, project_domain_name=project_domain_name,
project_domain_id=project_domain_id, project_domain_id=project_domain_id,
) )
elif api_key and (username or user_id): elif api_key and (username or user_id):
auth = auth_plugin.Password( auth = auth_plugin.Password(