Remove Python 2 support

Python 2 has been deprecated. This patch removes all
traces of six, unicode strings and Python 2 tweaks.

Change-Id: Ie6d62561fdaede0496052aa884021faa1927d5b8
This commit is contained in:
anguoming 2022-08-13 13:58:27 +08:00
parent 6b0409043f
commit 8f8e9fde6c
17 changed files with 41 additions and 61 deletions

View File

@ -36,7 +36,7 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
copyright = u'2015, Sahara team' copyright = '2015, Sahara team'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
@ -153,8 +153,8 @@ htmlhelp_basename = 'saharacdhplugin-testsdoc'
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]). # (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [ latex_documents = [
('index', 'doc-sahara-plugin-cdh.tex', u'Sahara CDH Plugin Documentation', ('index', 'doc-sahara-plugin-cdh.tex', 'Sahara CDH Plugin Documentation',
u'Sahara team', 'manual'), 'Sahara team', 'manual'),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -184,8 +184,8 @@ smartquotes_excludes = {'builders': ['latex']}
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
('index', 'sahara-plugin-cdh', u'sahara-plugin-cdh Documentation', ('index', 'sahara-plugin-cdh', 'sahara-plugin-cdh Documentation',
[u'Sahara team'], 1) ['Sahara team'], 1)
] ]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
@ -198,8 +198,8 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
('index', 'sahara-plugin-cdh', u'sahara-plugin-cdh Documentation', ('index', 'sahara-plugin-cdh', 'sahara-plugin-cdh Documentation',
u'Sahara team', 'sahara-plugin-cdh', 'One line description of project.', 'Sahara team', 'sahara-plugin-cdh', 'One line description of project.',
'Miscellaneous'), 'Miscellaneous'),
] ]

View File

@ -33,7 +33,7 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
copyright = u'2015, Sahara Developers' copyright = '2015, Sahara Developers'
# Release do not need a version number in the title, they # Release do not need a version number in the title, they
# cover multiple versions. # cover multiple versions.
@ -142,8 +142,8 @@ htmlhelp_basename = 'SaharaCDHReleaseNotesdoc'
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
('index', 'SaharaCDHReleaseNotes.tex', ('index', 'SaharaCDHReleaseNotes.tex',
u'Sahara CDH Plugin Release Notes Documentation', 'Sahara CDH Plugin Release Notes Documentation',
u'Sahara Developers', 'manual'), 'Sahara Developers', 'manual'),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -173,8 +173,8 @@ latex_documents = [
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
('index', 'saharacdhreleasenotes', ('index', 'saharacdhreleasenotes',
u'Sahara CDH Plugin Release Notes Documentation', 'Sahara CDH Plugin Release Notes Documentation',
[u'Sahara Developers'], 1) ['Sahara Developers'], 1)
] ]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
@ -188,8 +188,8 @@ man_pages = [
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
('index', 'SaharaCDHReleaseNotes', ('index', 'SaharaCDHReleaseNotes',
u'Sahara CDH Plugin Release Notes Documentation', 'Sahara CDH Plugin Release Notes Documentation',
u'Sahara Developers', 'SaharaCDHReleaseNotes', 'Sahara Developers', 'SaharaCDHReleaseNotes',
'One line description of project.', 'One line description of project.',
'Miscellaneous'), 'Miscellaneous'),
] ]

View File

@ -16,4 +16,3 @@ oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0
requests>=2.14.2 # Apache-2.0 requests>=2.14.2 # Apache-2.0
sahara>=10.0.0.0b1 sahara>=10.0.0.0b1
six>=1.10.0 # MIT

View File

@ -15,8 +15,6 @@
import abc import abc
import six
from sahara.plugins import conductor from sahara.plugins import conductor
from sahara.plugins import context from sahara.plugins import context
from sahara.plugins import kerberos from sahara.plugins import kerberos
@ -24,8 +22,7 @@ from sahara_plugin_cdh.plugins.cdh import db_helper as dh
from sahara_plugin_cdh.plugins.cdh import health from sahara_plugin_cdh.plugins.cdh import health
@six.add_metaclass(abc.ABCMeta) class AbstractVersionHandler(object, metaclass=abc.ABCMeta):
class AbstractVersionHandler(object):
@abc.abstractmethod @abc.abstractmethod
def get_node_processes(self): def get_node_processes(self):

View File

@ -22,12 +22,12 @@
# To satisfy the pep8 and python3 tests, we did some changes to the codes. # To satisfy the pep8 and python3 tests, we did some changes to the codes.
# We also change some importings to use Sahara inherited classes. # We also change some importings to use Sahara inherited classes.
import http.cookiejar
import posixpath import posixpath
import urllib
from oslo_log import log as logging from oslo_log import log as logging
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
import six
from six.moves import urllib
from sahara_plugin_cdh.plugins.cdh import exceptions as ex from sahara_plugin_cdh.plugins.cdh import exceptions as ex
@ -53,7 +53,7 @@ class HttpClient(object):
authhandler = urllib.request.HTTPBasicAuthHandler(self._passmgr) authhandler = urllib.request.HTTPBasicAuthHandler(self._passmgr)
# Make a cookie processor # Make a cookie processor
cookiejar = six.moves.http_cookiejar.CookieJar() cookiejar = http.cookiejar.CookieJar()
self._opener = urllib.request.build_opener( self._opener = urllib.request.build_opener(
urllib.request.HTTPErrorProcessor(), urllib.request.HTTPErrorProcessor(),
@ -130,7 +130,7 @@ class HttpClient(object):
try: try:
return self._opener.open(request) return self._opener.open(request)
except urllib.error.HTTPError as ex: except urllib.error.HTTPError as ex:
message = six.text_type(ex) message = str(ex)
try: try:
json_body = json.loads(message) json_body = json.loads(message)
message = json_body['message'] message = json_body['message']

View File

@ -27,8 +27,7 @@ import socket
from oslo_log import log as logging from oslo_log import log as logging
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
import six import urllib
from six.moves import urllib
from sahara.plugins import context from sahara.plugins import context
from sahara_plugin_cdh.i18n import _ from sahara_plugin_cdh.i18n import _
@ -80,7 +79,7 @@ class Resource(object):
except Exception as ex: except Exception as ex:
raise ex.CMApiException( raise ex.CMApiException(
_("Command %(method)s %(path)s failed: %(msg)s") _("Command %(method)s %(path)s failed: %(msg)s")
% {'method': method, 'path': path, 'msg': six.text_type(ex)}) % {'method': method, 'path': path, 'msg': str(ex)})
LOG.debug("{method} got response: {body}".format(method=method, LOG.debug("{method} got response: {body}".format(method=method,
body=body[:32])) body=body[:32]))
@ -105,13 +104,13 @@ class Resource(object):
:return: A dictionary of the JSON result. :return: A dictionary of the JSON result.
""" """
for retry in six.moves.xrange(self.retries + 1): for retry in range(self.retries + 1):
if retry: if retry:
context.sleep(self.retry_sleep) context.sleep(self.retry_sleep)
try: try:
return self.invoke("GET", relpath, params) return self.invoke("GET", relpath, params)
except (socket.error, urllib.error.URLError) as e: except (socket.error, urllib.error.URLError) as e:
if "timed out" in six.text_type(e).lower(): if "timed out" in str(e).lower():
if retry < self.retries: if retry < self.retries:
LOG.warning("Timeout issuing GET request for " LOG.warning("Timeout issuing GET request for "
"{path}. Will retry".format( "{path}. Will retry".format(

View File

@ -23,7 +23,6 @@
# We also change some importings to use Sahara inherited classes. # We also change some importings to use Sahara inherited classes.
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
import six
from sahara_plugin_cdh.plugins.cdh.client import role_config_groups from sahara_plugin_cdh.plugins.cdh.client import role_config_groups
from sahara_plugin_cdh.plugins.cdh.client import roles from sahara_plugin_cdh.plugins.cdh.client import roles
@ -193,7 +192,7 @@ class ApiService(types.BaseApiResource):
data = {} data = {}
if rt_configs: if rt_configs:
rt_list = [] rt_list = []
for rt, cfg in six.iteritems(rt_configs): for rt, cfg in rt_configs.items():
rt_data = types.config_to_api_list(cfg) rt_data = types.config_to_api_list(cfg)
rt_data['roleType'] = rt rt_data['roleType'] = rt
rt_list.append(rt_data) rt_list.append(rt_data)

View File

@ -28,7 +28,6 @@ import time
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
from oslo_utils import reflection from oslo_utils import reflection
import six
from sahara.plugins import context from sahara.plugins import context
from sahara_plugin_cdh.i18n import _ from sahara_plugin_cdh.i18n import _
@ -204,7 +203,7 @@ class BaseApiObject(object):
# We use unicode strings as keys in kwargs. # We use unicode strings as keys in kwargs.
str_attrs = {} str_attrs = {}
if attrs: if attrs:
for k, v in six.iteritems(attrs): for k, v in attrs.items():
if k not in ('self', 'resource_root'): if k not in ('self', 'resource_root'):
str_attrs[k] = v str_attrs[k] = v
BaseApiObject.__init__(obj, resource_root, **str_attrs) BaseApiObject.__init__(obj, resource_root, **str_attrs)
@ -222,7 +221,7 @@ class BaseApiObject(object):
""" """
self._resource_root = resource_root self._resource_root = resource_root
for name, attr in six.iteritems(self._get_attributes()): for name, attr in self._get_attributes().items():
object.__setattr__(self, name, None) object.__setattr__(self, name, None)
if attrs: if attrs:
self._set_attrs(attrs, from_json=False) self._set_attrs(attrs, from_json=False)
@ -234,7 +233,7 @@ class BaseApiObject(object):
read-only attributes (e.g. when deserializing from JSON) and skipping read-only attributes (e.g. when deserializing from JSON) and skipping
JSON deserialization of values. JSON deserialization of values.
""" """
for k, v in six.iteritems(attrs): for k, v in attrs.items():
attr = self._check_attr(k, allow_ro) attr = self._check_attr(k, allow_ro)
if attr and from_json: if attr and from_json:
v = attr.from_json(self._get_resource_root(), v) v = attr.from_json(self._get_resource_root(), v)
@ -279,7 +278,7 @@ class BaseApiObject(object):
def to_json_dict(self, preserve_ro=False): def to_json_dict(self, preserve_ro=False):
dic = {} dic = {}
for name, attr in six.iteritems(self._get_attributes()): for name, attr in self._get_attributes().items():
if not preserve_ro and attr and not attr.rw: if not preserve_ro and attr and not attr.rw:
continue continue
try: try:
@ -647,7 +646,7 @@ def config_to_api_list(dic):
:return: JSON dictionary of an ApiConfig list (*not* an ApiList). :return: JSON dictionary of an ApiConfig list (*not* an ApiList).
""" """
config = [] config = []
for k, v in six.iteritems(dic): for k, v in dic.items():
config.append({'name': k, 'value': v}) config.append({'name': k, 'value': v})
return {ApiList.LIST_KEY: config} return {ApiList.LIST_KEY: config}

View File

@ -15,7 +15,6 @@
import functools import functools
import six
from sahara.plugins import context from sahara.plugins import context
from sahara.plugins import exceptions as ex from sahara.plugins import exceptions as ex
@ -474,7 +473,7 @@ class ClouderaUtils(object):
'HDFS_GATEWAY': ['HDFS_NAMENODE', 'HDFS_DATANODE', 'HDFS_GATEWAY': ['HDFS_NAMENODE', 'HDFS_DATANODE',
"HDFS_SECONDARYNAMENODE"] "HDFS_SECONDARYNAMENODE"]
} }
for extra_role in six.iterkeys(extra_roles): for extra_role in extra_roles.keys():
valid_processes = extra_roles[extra_role] valid_processes = extra_roles[extra_role]
for valid in valid_processes: for valid in valid_processes:
if valid in current: if valid in current:

View File

@ -16,7 +16,6 @@
import functools import functools
from oslo_log import log as logging from oslo_log import log as logging
import six
from sahara.plugins import health_check_base from sahara.plugins import health_check_base
from sahara_plugin_cdh.i18n import _ from sahara_plugin_cdh.i18n import _
@ -70,7 +69,7 @@ class HealthStatusProvider(object):
LOG.exception(msg) LOG.exception(msg)
self._exception_store = _( self._exception_store = _(
"%(problem)s, reason: %(reason)s") % { "%(problem)s, reason: %(reason)s") % {
'problem': msg, 'reason': six.text_type(e)} 'problem': msg, 'reason': str(e)}
class ClouderaManagerHealthCheck(health_check_base.BasicHealthCheck): class ClouderaManagerHealthCheck(health_check_base.BasicHealthCheck):

View File

@ -14,7 +14,6 @@
# limitations under the License. # limitations under the License.
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
import six
from sahara_plugin_cdh.plugins.cdh.client import api_client from sahara_plugin_cdh.plugins.cdh.client import api_client
@ -65,7 +64,7 @@ def process_service(service, service_name):
def parse_config(config): def parse_config(config):
cfg = [] cfg = []
for name, value in six.iteritems(config): for name, value in config.items():
p = { p = {
'name': value.name, 'name': value.name,
'value': value.default, 'value': value.default,

View File

@ -14,7 +14,6 @@
# limitations under the License. # limitations under the License.
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
import six
from sahara_plugin_cdh.plugins.cdh.client import api_client from sahara_plugin_cdh.plugins.cdh.client import api_client
@ -65,7 +64,7 @@ def process_service(service, service_name):
def parse_config(config): def parse_config(config):
cfg = [] cfg = []
for name, value in six.iteritems(config): for name, value in config.items():
p = { p = {
'name': value.name, 'name': value.name,
'value': value.default, 'value': value.default,

View File

@ -15,8 +15,6 @@
import itertools import itertools
import six
from sahara.plugins import exceptions as ex from sahara.plugins import exceptions as ex
from sahara.plugins import testutils as tu from sahara.plugins import testutils as tu
from sahara_plugin_cdh.tests.unit import base from sahara_plugin_cdh.tests.unit import base
@ -35,7 +33,7 @@ def make_ng_dict_with_inst(counter, name, flavor, processes, count,
if not instances: if not instances:
instances = [] instances = []
for i in range(count): for i in range(count):
n = six.next(counter) n = next(counter)
instance = tu.make_inst_dict("id{0}".format(n), instance = tu.make_inst_dict("id{0}".format(n),
"fake_inst{0}".format(n), "fake_inst{0}".format(n),
management_ip='1.2.3.{0}'.format(n)) management_ip='1.2.3.{0}'.format(n))
@ -87,9 +85,9 @@ def get_fake_cluster_with_process(processes=None,
wkrs_ng[2].remove(process) wkrs_ng[2].remove(process)
other_ng_list = [] other_ng_list = []
for process, count in six.iteritems(processes): for process, count in processes.items():
if count: if count:
ng = ('service_ng{0}'.format(six.next(ng_counter)), ng = ('service_ng{0}'.format(next(ng_counter)),
1, [process], count) 1, [process], count)
other_ng_list.append(ng) other_ng_list.append(ng)
@ -97,7 +95,7 @@ def get_fake_cluster_with_process(processes=None,
ng_dict_list = [make_ng_dict_with_inst( ng_dict_list = [make_ng_dict_with_inst(
inst_counter, *args, inst_counter, *args,
id="ng_id{0}".format(six.next(ng_id_counter))) id="ng_id{0}".format(next(ng_id_counter)))
for args in ng_list] for args in ng_list]
return tu.create_cluster('test_cluster', 1, 'cdh', return tu.create_cluster('test_cluster', 1, 'cdh',

View File

@ -15,7 +15,6 @@
from unittest import mock from unittest import mock
import six
import testtools import testtools
from sahara.plugins import health_check_base as base_health from sahara.plugins import health_check_base as base_health
@ -49,7 +48,7 @@ class TestHealthCheck(unit_base.SaharaTestCase):
msg = "%s%s" % (msg, postfix) msg = "%s%s" % (msg, postfix)
all_message = "Cluster health is %(col)s. Reason: %(msg)s" % { all_message = "Cluster health is %(col)s. Reason: %(msg)s" % {
'col': col, 'msg': msg} 'col': col, 'msg': msg}
self.assertEqual(all_message, six.text_type(e)) self.assertEqual(all_message, str(e))
raise raise
@mock.patch('sahara_plugin_cdh.plugins.cdh.health.HealthStatusProvider.' @mock.patch('sahara_plugin_cdh.plugins.cdh.health.HealthStatusProvider.'

View File

@ -15,8 +15,6 @@
from unittest import mock from unittest import mock
import six
from sahara.plugins import base as pb from sahara.plugins import base as pb
from sahara_plugin_cdh.plugins.cdh.v5_11_0 import edp_engine from sahara_plugin_cdh.plugins.cdh.v5_11_0 import edp_engine
from sahara_plugin_cdh.plugins.cdh.v5_11_0 import versionhandler from sahara_plugin_cdh.plugins.cdh.v5_11_0 import versionhandler
@ -37,7 +35,7 @@ class VersionHandlerTestCase(base.SaharaTestCase):
def test_get_node_processes(self): def test_get_node_processes(self):
processes = self.vh.get_node_processes() processes = self.vh.get_node_processes()
for k, v in six.iteritems(processes): for k, v in processes.items():
for p in v: for p in v:
self.assertIsInstance(p, str) self.assertIsInstance(p, str)

View File

@ -15,8 +15,6 @@
from unittest import mock from unittest import mock
import six
from sahara.plugins import base as pb from sahara.plugins import base as pb
from sahara_plugin_cdh.plugins.cdh.v5_7_0 import edp_engine from sahara_plugin_cdh.plugins.cdh.v5_7_0 import edp_engine
from sahara_plugin_cdh.plugins.cdh.v5_7_0 import versionhandler from sahara_plugin_cdh.plugins.cdh.v5_7_0 import versionhandler
@ -37,7 +35,7 @@ class VersionHandlerTestCase(base.SaharaTestCase):
def test_get_node_processes(self): def test_get_node_processes(self):
processes = self.vh.get_node_processes() processes = self.vh.get_node_processes()
for k, v in six.iteritems(processes): for k, v in processes.items():
for p in v: for p in v:
self.assertIsInstance(p, str) self.assertIsInstance(p, str)

View File

@ -15,8 +15,6 @@
from unittest import mock from unittest import mock
import six
from sahara.plugins import base as pb from sahara.plugins import base as pb
from sahara_plugin_cdh.plugins.cdh.v5_9_0 import edp_engine from sahara_plugin_cdh.plugins.cdh.v5_9_0 import edp_engine
from sahara_plugin_cdh.plugins.cdh.v5_9_0 import versionhandler from sahara_plugin_cdh.plugins.cdh.v5_9_0 import versionhandler
@ -37,7 +35,7 @@ class VersionHandlerTestCase(base.SaharaTestCase):
def test_get_node_processes(self): def test_get_node_processes(self):
processes = self.vh.get_node_processes() processes = self.vh.get_node_processes()
for k, v in six.iteritems(processes): for k, v in processes.items():
for p in v: for p in v:
self.assertIsInstance(p, str) self.assertIsInstance(p, str)