From 2cdb5a1f17635a51be2f67ab55a7da840ecdfb51 Mon Sep 17 00:00:00 2001 From: Hugo Brito Date: Mon, 24 Jun 2024 15:46:48 -0300 Subject: [PATCH] Remove the six library This commit removes the six library from the repo, as the only supported Python version is 3.9. Test Plan: PASS: Success on tox command. Story: 2011149 Task: 50418 Change-Id: I407e3a3d96b407cf00cca8bbcd1b5312d099b908 Signed-off-by: Hugo Brito --- distributedcloud/.pylintrc | 2 +- distributedcloud/dccommon/drivers/base.py | 7 +-- distributedcloud/dccommon/exceptions.py | 6 -- distributedcloud/dccommon/kubeoperator.py | 3 +- distributedcloud/dccommon/subcloud_install.py | 6 +- .../dcdbsync/common/exceptions.py | 6 -- .../dcdbsync/dbsyncclient/client.py | 6 +- .../dcdbsync/dbsyncclient/v1/client.py | 4 +- .../dcmanager/api/controllers/restcomm.py | 6 +- distributedcloud/dcmanager/audit/auditor.py | 15 +---- distributedcloud/dcmanager/audit/service.py | 9 +-- distributedcloud/dcmanager/common/context.py | 2 +- .../dcmanager/common/exceptions.py | 6 -- distributedcloud/dcmanager/common/utils.py | 5 +- distributedcloud/dcmanager/manager/service.py | 5 +- .../dcmanager/orchestrator/service.py | 4 +- .../dcmanager/orchestrator/states/base.py | 5 +- distributedcloud/dcmanager/state/service.py | 3 +- .../common/test_phased_subcloud_deploy.py | 61 +++++++++++-------- .../unit/manager/test_subcloud_manager.py | 2 +- .../states/kube_rootca/test_upload_cert.py | 4 +- .../dcorch/api/proxy/apps/parser.py | 7 +-- .../dcorch/api/proxy/common/utils.py | 13 ++-- distributedcloud/dcorch/common/exceptions.py | 6 -- distributedcloud/dcorch/common/utils.py | 3 +- distributedcloud/dcorch/drivers/base.py | 7 +-- .../dcorch/engine/quota_manager.py | 2 +- distributedcloud/dcorch/engine/service.py | 9 ++- .../dcorch/engine/sync_services/compute.py | 5 +- distributedcloud/requirements.txt | 1 - 30 files changed, 81 insertions(+), 139 deletions(-) diff --git a/distributedcloud/.pylintrc b/distributedcloud/.pylintrc index e419bee31..164d52b2a 100644 --- a/distributedcloud/.pylintrc +++ b/distributedcloud/.pylintrc @@ -113,7 +113,7 @@ ignore-mixin-members=yes # List of module names for which member attributes should not be checked # (useful for modules/projects where namespaces are manipulated during runtime # and thus existing member attributes cannot be deduced by static analysis -ignored-modules=distutils,eventlet.green.subprocess,six,six.moves +ignored-modules=distutils,eventlet.green.subprocess # List of classes names for which member attributes should not be checked # (useful for classes with attributes dynamically set). diff --git a/distributedcloud/dccommon/drivers/base.py b/distributedcloud/dccommon/drivers/base.py index 1dc1473b5..505638c15 100644 --- a/distributedcloud/dccommon/drivers/base.py +++ b/distributedcloud/dccommon/drivers/base.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2021 Wind River Systems, Inc. +# Copyright (c) 2017-2021, 2024 Wind River Systems, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at @@ -16,16 +16,13 @@ Base class for all drivers. """ import abc -import six from oslo_log import log as logging LOG = logging.getLogger(__name__) -class DriverBase(object): - - six.add_metaclass(abc.ABCMeta) +class DriverBase(object, metaclass=abc.ABCMeta): """Base class for all drivers.""" def __init__(self, context): diff --git a/distributedcloud/dccommon/exceptions.py b/distributedcloud/dccommon/exceptions.py index 50bce0840..027d377ff 100644 --- a/distributedcloud/dccommon/exceptions.py +++ b/distributedcloud/dccommon/exceptions.py @@ -18,9 +18,7 @@ """ DC Orchestrator base exception handling. """ -import six -from oslo_utils import encodeutils from oslo_utils import excutils from dcorch.common.i18n import _ @@ -47,10 +45,6 @@ class DCCommonException(Exception): # at least get the core message out if something happened super(DCCommonException, self).__init__(self.message) - if six.PY2: - def __unicode__(self): - return encodeutils.exception_to_unicode(self.msg) - def use_fatal_exceptions(self): return False diff --git a/distributedcloud/dccommon/kubeoperator.py b/distributedcloud/dccommon/kubeoperator.py index a91971632..1cf6135b6 100644 --- a/distributedcloud/dccommon/kubeoperator.py +++ b/distributedcloud/dccommon/kubeoperator.py @@ -3,13 +3,14 @@ # SPDX-License-Identifier: Apache-2.0 # +import http.client as httplib + from kubernetes import __version__ as K8S_MODULE_VERSION from kubernetes import client from kubernetes.client import Configuration from kubernetes.client.rest import ApiException from kubernetes import config from oslo_log import log as logging -from six.moves import http_client as httplib LOG = logging.getLogger(__name__) diff --git a/distributedcloud/dccommon/subcloud_install.py b/distributedcloud/dccommon/subcloud_install.py index 54f68ef92..1b0b7902b 100644 --- a/distributedcloud/dccommon/subcloud_install.py +++ b/distributedcloud/dccommon/subcloud_install.py @@ -19,14 +19,14 @@ import shutil import socket import tempfile import threading +import urllib.error as urllib_error +from urllib import parse +from urllib import request from eventlet.green import subprocess import netaddr from oslo_config import cfg from oslo_log import log as logging -from six.moves.urllib import error as urllib_error -from six.moves.urllib import parse -from six.moves.urllib import request from dccommon import consts from dccommon.drivers.openstack.sdk_platform import ( diff --git a/distributedcloud/dcdbsync/common/exceptions.py b/distributedcloud/dcdbsync/common/exceptions.py index bc3756359..680d4ea63 100644 --- a/distributedcloud/dcdbsync/common/exceptions.py +++ b/distributedcloud/dcdbsync/common/exceptions.py @@ -22,9 +22,7 @@ """ DBsync agent base exception handling. """ -import six -from oslo_utils import encodeutils from oslo_utils import excutils from dcdbsync.common.i18n import _ @@ -51,10 +49,6 @@ class DBsyncException(Exception): # at least get the core message out if something happened super(DBsyncException, self).__init__(self.message) - if six.PY2: - def __unicode__(self): - return encodeutils.exception_to_unicode(self.msg) - def use_fatal_exceptions(self): return False diff --git a/distributedcloud/dcdbsync/dbsyncclient/client.py b/distributedcloud/dcdbsync/dbsyncclient/client.py index 87729c911..0dd83a72e 100644 --- a/distributedcloud/dcdbsync/dbsyncclient/client.py +++ b/distributedcloud/dcdbsync/dbsyncclient/client.py @@ -12,13 +12,11 @@ # See the License for the specific language governing permissions and # 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 # -import six - from dcdbsync.dbsyncclient.v1 import client as client_v1 @@ -28,7 +26,7 @@ def Client(dbsync_agent_url=None, username=None, api_key=None, auth_token=None, user_id=None, cacert=None, insecure=False, profile=None, auth_type='keystone', client_id=None, client_secret=None, session=None, **kwargs): - if dbsync_agent_url and not isinstance(dbsync_agent_url, six.string_types): + if dbsync_agent_url and not isinstance(dbsync_agent_url, str): raise RuntimeError('DC DBsync agent url should be a string.') return client_v1.Client( diff --git a/distributedcloud/dcdbsync/dbsyncclient/v1/client.py b/distributedcloud/dcdbsync/dbsyncclient/v1/client.py index dce7b940c..5740e64c4 100644 --- a/distributedcloud/dcdbsync/dbsyncclient/v1/client.py +++ b/distributedcloud/dcdbsync/dbsyncclient/v1/client.py @@ -22,7 +22,6 @@ import keystoneauth1.identity.generic as auth_plugin from keystoneauth1 import session as ks_session from oslo_utils import importutils -import six from dcdbsync.dbsyncclient import httpclient from dcdbsync.dbsyncclient.v1.identity import identity_group_manager as igm @@ -49,8 +48,7 @@ class Client(object): profile=None, auth_type='keystone', client_id=None, client_secret=None, session=None, **kwargs): """Communicates with Keystone to fetch necessary values.""" - if dbsync_agent_url and not isinstance(dbsync_agent_url, - six.string_types): + if dbsync_agent_url and not isinstance(dbsync_agent_url, str): raise RuntimeError('DC DBsync agent url should be a string.') if auth_url or session: diff --git a/distributedcloud/dcmanager/api/controllers/restcomm.py b/distributedcloud/dcmanager/api/controllers/restcomm.py index a95b5bf93..0903161af 100644 --- a/distributedcloud/dcmanager/api/controllers/restcomm.py +++ b/distributedcloud/dcmanager/api/controllers/restcomm.py @@ -1,5 +1,5 @@ # Copyright (c) 2015 Huawei Tech. Co., Ltd. -# Copyright (c) 2017-2022 Wind River Systems, Inc. +# Copyright (c) 2017-2022, 2024 Wind River Systems, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -19,7 +19,6 @@ import abc from pecan import expose from pecan import request -import six import dcmanager.common.context as k_context @@ -74,8 +73,7 @@ def _is_generic_handler(obj): return "generic_handler" in data.keys() -@six.add_metaclass(abc.ABCMeta) -class GenericPathController(object): +class GenericPathController(object, metaclass=abc.ABCMeta): """A controller that allows path parameters to be equal to handler names. The _route method provides a custom route resolution that checks if the diff --git a/distributedcloud/dcmanager/audit/auditor.py b/distributedcloud/dcmanager/audit/auditor.py index bcfbc3583..fd39656db 100644 --- a/distributedcloud/dcmanager/audit/auditor.py +++ b/distributedcloud/dcmanager/audit/auditor.py @@ -5,17 +5,13 @@ # import abc -import six from dccommon import consts as dccommon_consts -class Auditor(object): +class Auditor(object, metaclass=abc.ABCMeta): """Abstract class that manages tasks related to types of audits.""" - # todo(abailey): determine if add_metaclass is still required - six.add_metaclass(abc.ABCMeta) - def __init__(self, context, dcmanager_state_rpc_client, endpoint_type): self.context = context self.state_rpc_client = dcmanager_state_rpc_client @@ -44,12 +40,3 @@ class Auditor(object): @abc.abstractmethod def get_regionone_audit_data(self): """Query RegionOne for audit information to compare against.""" - - @abc.abstractmethod - def subcloud_audit(self, subcloud_name, region_one_audit_data): - """Query Subcloud audit information and compare with regionone data - - This method is responsible for calling: - - set_sc_endpoint_in_sync - - set_sc_endpoint_out_of_sync - """ diff --git a/distributedcloud/dcmanager/audit/service.py b/distributedcloud/dcmanager/audit/service.py index fcb9a405c..dfe9ec20e 100644 --- a/distributedcloud/dcmanager/audit/service.py +++ b/distributedcloud/dcmanager/audit/service.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2023 Wind River Systems, Inc. +# Copyright (c) 2020-2024 Wind River Systems, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -19,7 +19,6 @@ from oslo_config import cfg from oslo_log import log as logging import oslo_messaging from oslo_service import service -import six from dcmanager.audit.subcloud_audit_manager import SubcloudAuditManager from dcmanager.audit.subcloud_audit_worker_manager import SubcloudAuditWorkerManager @@ -95,7 +94,7 @@ class DCManagerAuditService(service.Service): self._rpc_server.wait() LOG.info("Engine service stopped successfully") except Exception as ex: - LOG.error("Failed to stop engine service: %s", six.text_type(ex)) + LOG.error("Failed to stop engine service: %s", str(ex)) def stop(self): self._stop_rpc_server() @@ -219,9 +218,7 @@ class DCManagerAuditWorkerService(service.Service): self._rpc_server.wait() LOG.info("Audit-worker RPC service stopped successfully") except Exception as ex: - LOG.error( - "Failed to stop audit-worker RPC service: %s", six.text_type(ex) - ) + LOG.error("Failed to stop audit-worker RPC service: %s", str(ex)) def stop(self): self._stop_rpc_server() diff --git a/distributedcloud/dcmanager/common/context.py b/distributedcloud/dcmanager/common/context.py index 328327b1b..d4c75706f 100644 --- a/distributedcloud/dcmanager/common/context.py +++ b/distributedcloud/dcmanager/common/context.py @@ -16,6 +16,7 @@ import re import time +from urllib.parse import urlparse from oslo_context import context as base_context from oslo_log import log @@ -23,7 +24,6 @@ from oslo_utils import encodeutils from oslo_utils import uuidutils import pecan from pecan import hooks -from six.moves.urllib.parse import urlparse from dcmanager.api.policies import base as base_policy from dcmanager.api import policy diff --git a/distributedcloud/dcmanager/common/exceptions.py b/distributedcloud/dcmanager/common/exceptions.py index 3c9bf0031..d5e9fdab9 100644 --- a/distributedcloud/dcmanager/common/exceptions.py +++ b/distributedcloud/dcmanager/common/exceptions.py @@ -19,9 +19,7 @@ """ DC Manager base exception handling. """ -import six -from oslo_utils import encodeutils from oslo_utils import excutils from dcmanager.common.i18n import _ @@ -48,10 +46,6 @@ class DCManagerException(Exception): # at least get the core message out if something happened super(DCManagerException, self).__init__(self.message) - if six.PY2: - def __unicode__(self): - return encodeutils.exception_to_unicode(self.msg) - def use_fatal_exceptions(self): return False diff --git a/distributedcloud/dcmanager/common/utils.py b/distributedcloud/dcmanager/common/utils.py index ca349e8b7..2985c9143 100644 --- a/distributedcloud/dcmanager/common/utils.py +++ b/distributedcloud/dcmanager/common/utils.py @@ -37,7 +37,6 @@ from oslo_log import log as logging from oslo_serialization import base64 import pecan import requests -import six.moves import tsconfig.tsconfig as tsc import yaml @@ -100,7 +99,7 @@ def get_import_path(cls): # Returns a iterator of tuples containing batch_size number of objects in each def get_batch_projects(batch_size, project_list, fillvalue=None): args = [iter(project_list)] * batch_size - return six.moves.zip_longest(fillvalue=fillvalue, *args) + return itertools.zip_longest(fillvalue=fillvalue, *args) def validate_address_str(ip_address_str, network): @@ -739,7 +738,7 @@ def get_region_from_subcloud_address(payload): stderr=subprocess.STDOUT).decode('utf-8') if len(task) < 1: err_cause = ("Malformed subcloud region") - return (subcloud_region, err_cause) + return subcloud_region, err_cause subcloud_region = str(task.split("=")[1]).strip() except Exception as e: # check_output() will raise CalledProcessError if the called diff --git a/distributedcloud/dcmanager/manager/service.py b/distributedcloud/dcmanager/manager/service.py index 8e47db7c4..91e32e9a0 100644 --- a/distributedcloud/dcmanager/manager/service.py +++ b/distributedcloud/dcmanager/manager/service.py @@ -18,8 +18,6 @@ import functools import os import threading -import six - from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -379,8 +377,7 @@ class DCManagerService(service.Service): self._rpc_server.wait() LOG.info('RPC service stopped successfully') except Exception as ex: - LOG.error('Failed to stop RPC service: %s', - six.text_type(ex)) + LOG.error('Failed to stop RPC service: %s', str(ex)) def stop(self): SubprocessCleanup.shutdown_cleanup(origin="service") diff --git a/distributedcloud/dcmanager/orchestrator/service.py b/distributedcloud/dcmanager/orchestrator/service.py index 2ab612640..18f70ae53 100644 --- a/distributedcloud/dcmanager/orchestrator/service.py +++ b/distributedcloud/dcmanager/orchestrator/service.py @@ -20,7 +20,6 @@ from oslo_config import cfg from oslo_log import log as logging import oslo_messaging from oslo_service import service -import six from dccommon.subprocess_cleanup import SubprocessCleanup from dcmanager.common import consts @@ -92,8 +91,7 @@ class DCManagerOrchestratorService(service.Service): self._rpc_server = None LOG.info('RPC service stopped successfully') except Exception as ex: - LOG.error('Failed to stop engine service: %s', - six.text_type(ex)) + LOG.error('Failed to stop engine service: %s', str(ex)) def stop(self): """Stop anything initiated by start""" diff --git a/distributedcloud/dcmanager/orchestrator/states/base.py b/distributedcloud/dcmanager/orchestrator/states/base.py index 571ba3fdb..04250146a 100644 --- a/distributedcloud/dcmanager/orchestrator/states/base.py +++ b/distributedcloud/dcmanager/orchestrator/states/base.py @@ -3,8 +3,8 @@ # # SPDX-License-Identifier: Apache-2.0 # + import abc -import six from oslo_log import log as logging @@ -25,8 +25,7 @@ from dcmanager.common import utils LOG = logging.getLogger(__name__) -@six.add_metaclass(abc.ABCMeta) -class BaseState(object): +class BaseState(object, metaclass=abc.ABCMeta): def __init__(self, next_state, region_name): super(BaseState, self).__init__() diff --git a/distributedcloud/dcmanager/state/service.py b/distributedcloud/dcmanager/state/service.py index 816261233..a89f15d2b 100644 --- a/distributedcloud/dcmanager/state/service.py +++ b/distributedcloud/dcmanager/state/service.py @@ -23,7 +23,6 @@ from oslo_config import cfg from oslo_log import log as logging import oslo_messaging from oslo_service import service -import six from dccommon import consts as dccommon_consts from dcmanager.audit import rpcapi as dcmanager_audit_rpc_client @@ -100,7 +99,7 @@ class DCManagerStateService(service.Service): self._rpc_server.wait() LOG.info("Engine service stopped successfully") except Exception as ex: - LOG.error("Failed to stop engine service: %s", six.text_type(ex)) + LOG.error("Failed to stop engine service: %s", str(ex)) def stop(self): LOG.info("Stopping %s", self.__class__.__name__) diff --git a/distributedcloud/dcmanager/tests/unit/common/test_phased_subcloud_deploy.py b/distributedcloud/dcmanager/tests/unit/common/test_phased_subcloud_deploy.py index 9e8cc7d9d..86c62ceaf 100644 --- a/distributedcloud/dcmanager/tests/unit/common/test_phased_subcloud_deploy.py +++ b/distributedcloud/dcmanager/tests/unit/common/test_phased_subcloud_deploy.py @@ -11,7 +11,6 @@ import os import mock from oslo_utils import timeutils -import six from dccommon import consts as dccommon_consts from dcmanager.common import consts @@ -170,12 +169,15 @@ def test_validate_admin_config_subnet_small(self): admin_end_address = "192.168.205.50" admin_gateway_address = "192.168.205.1" - six.assertRaisesRegex( - self, Exception, "Subnet too small*", - psd_common.validate_admin_network_config, admin_subnet, admin_start_address, - admin_end_address, admin_gateway_address, existing_networks=None, - operation=None - ) + with self.assertRaisesRegex(Exception, "Subnet too small*"): + psd_common.validate_admin_network_config( + admin_subnet, + admin_start_address, + admin_end_address, + admin_gateway_address, + existing_networks=None, + operation=None, + ) def test_validate_admin_config_start_address_outOfSubnet(self): @@ -184,12 +186,15 @@ def test_validate_admin_config_start_address_outOfSubnet(self): admin_end_address = "192.168.205.50" admin_gateway_address = "192.168.205.1" - six.assertRaisesRegex( - self, Exception, "Address must be in subnet*", - psd_common.validate_admin_network_config, - admin_subnet, admin_start_address, admin_end_address, admin_gateway_address, - existing_networks=None, operation=None - ) + with self.assertRaisesRegex(Exception, "Address must be in subnet*"): + psd_common.validate_admin_network_config( + admin_subnet, + admin_start_address, + admin_end_address, + admin_gateway_address, + existing_networks=None, + operation=None, + ) def test_validate_admin_config_end_address_outOfSubnet(self): @@ -198,19 +203,25 @@ def test_validate_admin_config_end_address_outOfSubnet(self): admin_end_address = "192.168.205.50" admin_gateway_address = "192.168.205.1" - six.assertRaisesRegex( - self, Exception, "Address must be in subnet*", - psd_common.validate_admin_network_config, - admin_subnet, admin_start_address, admin_end_address, admin_gateway_address, - existing_networks=None, operation=None - ) + with self.assertRaisesRegex(Exception, "Address must be in subnet*"): + psd_common.validate_admin_network_config( + admin_subnet, + admin_start_address, + admin_end_address, + admin_gateway_address, + existing_networks=None, + operation=None, + ) admin_end_address = "192.168.205.12" admin_gateway_address = "192.168.205.50" - six.assertRaisesRegex( - self, Exception, "Address must be in subnet*", - psd_common.validate_admin_network_config, admin_subnet, admin_start_address, - admin_end_address, admin_gateway_address, existing_networks=None, - operation=None - ) + with self.assertRaisesRegex(Exception, "Address must be in subnet*"): + psd_common.validate_admin_network_config( + admin_subnet, + admin_start_address, + admin_end_address, + admin_gateway_address, + existing_networks=None, + operation=None, + ) diff --git a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py index c520c2229..7e77c3055 100644 --- a/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py +++ b/distributedcloud/dcmanager/tests/unit/manager/test_subcloud_manager.py @@ -25,6 +25,7 @@ from os import path as os_path import sys import threading import time +from urllib import request import uuid import yaml @@ -33,7 +34,6 @@ import mock import netaddr from oslo_concurrency import lockutils from oslo_utils import timeutils -from six.moves.urllib import request from tsconfig.tsconfig import SW_VERSION from dccommon import consts as dccommon_consts diff --git a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py index d1e0fa8c6..0fb9376d4 100644 --- a/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py +++ b/distributedcloud/dcmanager/tests/unit/orchestrator/states/kube_rootca/test_upload_cert.py @@ -55,7 +55,7 @@ class TestUploadCertStage(TestKubeRootCaUpgradeState): ERROR_UPLOADING_CERT mock_open = mock.mock_open(read_data='test') - with mock.patch('six.moves.builtins.open', mock_open): + with mock.patch('builtins.open', mock_open): # invoke the strategy state operation on the orch thread self.worker.perform_state_action(self.strategy_step) @@ -77,7 +77,7 @@ class TestUploadCertStage(TestKubeRootCaUpgradeState): SUCCESS_UPLOADING_CERT mock_open = mock.mock_open(read_data='test') - with mock.patch('six.moves.builtins.open', mock_open): + with mock.patch('builtins.open', mock_open): # invoke the strategy state operation on the orch thread self.worker.perform_state_action(self.strategy_step) diff --git a/distributedcloud/dcorch/api/proxy/apps/parser.py b/distributedcloud/dcorch/api/proxy/apps/parser.py index a2344423c..a78133caf 100644 --- a/distributedcloud/dcorch/api/proxy/apps/parser.py +++ b/distributedcloud/dcorch/api/proxy/apps/parser.py @@ -17,7 +17,6 @@ import json from xml import etree as et from oslo_log import log -import six import webob from dcorch.api.proxy.common.service import Middleware @@ -91,8 +90,7 @@ class ParseError(Middleware): ''] state['headers'].append(('Content-Type', 'application/xml')) else: - if six.PY3: - app_iter = [i.decode('utf-8') for i in app_iter] + app_iter = [i.decode('utf-8') for i in app_iter] # Parse explanation field from webob.exc and add it as # 'faulstring' to be processed by cgts-client fault = None @@ -107,8 +105,7 @@ class ParseError(Middleware): else: body = [json.dumps({'error_message': json.dumps({'faultstring': fault})})] - if six.PY3: - body = [item.encode('utf-8') for item in body] + body = [item.encode('utf-8') for item in body] state['headers'].append(('Content-Type', 'application/json')) state['headers'].append(('Content-Length', str(len(body[0])))) else: diff --git a/distributedcloud/dcorch/api/proxy/common/utils.py b/distributedcloud/dcorch/api/proxy/common/utils.py index ec84ab64a..c5572fef2 100644 --- a/distributedcloud/dcorch/api/proxy/common/utils.py +++ b/distributedcloud/dcorch/api/proxy/common/utils.py @@ -13,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +from urllib.parse import urlparse + import base64 from cryptography import fernet -import msgpack -import psutil -import six -from six.moves.urllib.parse import urlparse - from keystoneauth1 import exceptions as keystone_exceptions +import msgpack from oslo_log import log as logging +import psutil from dccommon import consts as dccommon_consts from dccommon.drivers.openstack import sdk_platform as sdk @@ -118,7 +117,7 @@ def get_operation_type(environ): def get_id_from_query_string(environ, id): - import six.moves.urllib.parse as six_urlparse + import urllib.parse as six_urlparse params = six_urlparse.parse_qs(environ.get('QUERY_STRING', '')) return params.get(id, [None])[0] @@ -201,7 +200,7 @@ def _unpack_token(fernet_token, fernet_keys): crypt = fernet.MultiFernet(fernet_instances) # attempt to decode the token - token = _restore_padding(six.binary_type(fernet_token)) + token = _restore_padding(bytes(fernet_token)) serialized_payload = crypt.decrypt(token) payload = msgpack.unpackb(serialized_payload) diff --git a/distributedcloud/dcorch/common/exceptions.py b/distributedcloud/dcorch/common/exceptions.py index b1528f0f9..d2f977f19 100644 --- a/distributedcloud/dcorch/common/exceptions.py +++ b/distributedcloud/dcorch/common/exceptions.py @@ -21,9 +21,7 @@ """ DC Orchestrator base exception handling. """ -import six -from oslo_utils import encodeutils from oslo_utils import excutils from dcorch.common.i18n import _ @@ -50,10 +48,6 @@ class OrchestratorException(Exception): # at least get the core message out if something happened super(OrchestratorException, self).__init__(self.message) - if six.PY2: - def __unicode__(self): - return encodeutils.exception_to_unicode(self.msg) - def use_fatal_exceptions(self): return False diff --git a/distributedcloud/dcorch/common/utils.py b/distributedcloud/dcorch/common/utils.py index 412f240ad..ffd1b9f99 100644 --- a/distributedcloud/dcorch/common/utils.py +++ b/distributedcloud/dcorch/common/utils.py @@ -19,7 +19,6 @@ import uuid from oslo_db import exception as oslo_db_exception from oslo_log import log as logging -import six.moves from dccommon import consts as dccommon_consts from dcorch.common import consts @@ -39,7 +38,7 @@ def get_import_path(cls): # Returns a iterator of tuples containing batch_size number of objects in each def get_batch_projects(batch_size, project_list, fillvalue=None): args = [iter(project_list)] * batch_size - return six.moves.zip_longest(fillvalue=fillvalue, *args) + return itertools.zip_longest(fillvalue=fillvalue, *args) # to do validate the quota limits diff --git a/distributedcloud/dcorch/drivers/base.py b/distributedcloud/dcorch/drivers/base.py index 6548f9f3d..54876f4ca 100644 --- a/distributedcloud/dcorch/drivers/base.py +++ b/distributedcloud/dcorch/drivers/base.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022 Wind River Systems, Inc. +# Copyright (c) 2020-2022, 2024 Wind River Systems, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at @@ -16,16 +16,13 @@ Base class for all drivers. """ import abc -import six from oslo_log import log as logging LOG = logging.getLogger(__name__) -class DriverBase(object): - - six.add_metaclass(abc.ABCMeta) +class DriverBase(object, metaclass=abc.ABCMeta): """Base class for all drivers.""" def __init__(self, context): diff --git a/distributedcloud/dcorch/engine/quota_manager.py b/distributedcloud/dcorch/engine/quota_manager.py index 2800b6353..8f97a696a 100644 --- a/distributedcloud/dcorch/engine/quota_manager.py +++ b/distributedcloud/dcorch/engine/quota_manager.py @@ -16,12 +16,12 @@ import collections import copy +from queue import Queue import re import threading from oslo_config import cfg from oslo_log import log as logging -from six.moves.queue import Queue from dccommon import consts as dccommon_consts from dccommon import endpoint_cache diff --git a/distributedcloud/dcorch/engine/service.py b/distributedcloud/dcorch/engine/service.py index de6ed205e..574cd6557 100644 --- a/distributedcloud/dcorch/engine/service.py +++ b/distributedcloud/dcorch/engine/service.py @@ -22,7 +22,6 @@ from oslo_log import log as logging import oslo_messaging from oslo_service import service from oslo_utils import uuidutils -import six from dccommon import consts as dccommon_consts from dcorch.common import consts @@ -147,7 +146,7 @@ class EngineService(service.Service): self._rpc_server.wait() LOG.info("Engine service stopped successfully") except Exception as ex: - LOG.error(f"Failed to stop engine service: {six.text_type(ex)}") + LOG.error(f"Failed to stop engine service: {str(ex)}") def stop(self): self._stop_rpc_server() @@ -290,7 +289,7 @@ class EngineWorkerService(service.Service): endpoint_type_list=endpoint_type_list) except Exception as ex: LOG.warning('Add subcloud endpoint type failed for %s: %s', - subcloud_name, six.text_type(ex)) + subcloud_name, str(ex)) raise @request_context @@ -302,7 +301,7 @@ class EngineWorkerService(service.Service): endpoint_type_list=endpoint_type_list) except Exception as ex: LOG.warning('Remove subcloud endpoint type failed for %s: %s', - subcloud_name, six.text_type(ex)) + subcloud_name, str(ex)) raise @request_context @@ -339,7 +338,7 @@ class EngineWorkerService(service.Service): self._rpc_server.wait() LOG.info('Engine-worker service stopped successfully') except Exception as ex: - LOG.error(f"Failed to stop engine-worker service: {six.text_type(ex)}") + LOG.error(f"Failed to stop engine-worker service: {str(ex)}") def stop(self): self._stop_rpc_server() diff --git a/distributedcloud/dcorch/engine/sync_services/compute.py b/distributedcloud/dcorch/engine/sync_services/compute.py index d4e813b84..89eda2e75 100644 --- a/distributedcloud/dcorch/engine/sync_services/compute.py +++ b/distributedcloud/dcorch/engine/sync_services/compute.py @@ -14,13 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six - from keystoneauth1 import exceptions as keystone_exceptions from novaclient import client as novaclient from novaclient import exceptions as novaclient_exceptions from novaclient import utils as novaclient_utils - from oslo_log import log as logging from oslo_serialization import jsonutils @@ -215,7 +212,7 @@ class ComputeSyncThread(SyncThread): newflavor = self.sc_nova_client.flavors.create( name, ram, vcpus, disk, **kwargs) except novaclient_exceptions.Conflict as e: - if "already exists" in six.text_type(e): + if "already exists" in str(e): # FlavorExists or FlavorIdExists. LOG.info("Flavor {} already exists in subcloud" .format(name), extra=self.log_extra) diff --git a/distributedcloud/requirements.txt b/distributedcloud/requirements.txt index b1ca37ab4..4bfe2d64a 100644 --- a/distributedcloud/requirements.txt +++ b/distributedcloud/requirements.txt @@ -39,7 +39,6 @@ requests_toolbelt # Apache-2.0 retrying!=1.3.0,>=1.2.3 # Apache-2.0 routes>=2.3.1 # MIT sh # MIT -six>=1.9.0 # MIT sqlalchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT sqlalchemy-migrate>=0.11.0 # Apache-2.0 webob>=1.7.1 # MIT