commit 16a0486655a2c7843df0fb6524d600360dc418be Author: xuanyandong Date: Wed Sep 30 09:05:12 2020 +0800 Remove six Replace the following items with Python 3 style code. - six.string_types - six.integer_types - six.moves - six.PY2 Implements: blueprint six-removal Change-Id: I2a0624bd4b455c7e5a0617f1253efa05485dc673 diff --git a/doc/source/contributor/plugin/strategy-plugin.rst b/doc/source/contributor/plugin/strategy-plugin.rst index 1cde357..8d3942b 100644 --- a/doc/source/contributor/plugin/strategy-plugin.rst +++ b/doc/source/contributor/plugin/strategy-plugin.rst @@ -56,9 +56,6 @@ Here is an example showing how you can write a plugin called ``NewStrategy``: # filepath: thirdparty/new.py # import path: thirdparty.new import abc - - import six - from watcher._i18n import _ from watcher.decision_engine.strategy.strategies import base diff --git a/watcher/api/controllers/v1/service.py b/watcher/api/controllers/v1/service.py index 24709e1..98fcc41 100644 --- a/watcher/api/controllers/v1/service.py +++ b/watcher/api/controllers/v1/service.py @@ -19,8 +19,6 @@ Service mechanism provides ability to monitor Watcher services state. """ import datetime -import six - from oslo_config import cfg from oslo_log import log from oslo_utils import timeutils @@ -70,7 +68,7 @@ class Service(base.APIBase): service = objects.Service.get(pecan.request.context, id) last_heartbeat = (service.last_seen_up or service.updated_at or service.created_at) - if isinstance(last_heartbeat, six.string_types): + if isinstance(last_heartbeat, str): # NOTE(russellb) If this service came in over rpc via # conductor, then the timestamp will be a string and needs to be # converted back to a datetime. diff --git a/watcher/api/controllers/v1/types.py b/watcher/api/controllers/v1/types.py index fa14811..6872d31 100644 --- a/watcher/api/controllers/v1/types.py +++ b/watcher/api/controllers/v1/types.py @@ -15,7 +15,6 @@ from oslo_serialization import jsonutils from oslo_utils import strutils -import six import wsme from wsme import types as wtypes @@ -132,7 +131,7 @@ class JsonType(wtypes.UserType): def __str__(self): # These are the json serializable native types - return ' | '.join(map(str, (wtypes.text, six.integer_types, float, + return ' | '.join(map(str, (wtypes.text, int, float, BooleanType, list, dict, None))) @staticmethod diff --git a/watcher/db/sqlalchemy/models.py b/watcher/db/sqlalchemy/models.py index 2e60223..55e60bc 100644 --- a/watcher/db/sqlalchemy/models.py +++ b/watcher/db/sqlalchemy/models.py @@ -18,7 +18,6 @@ SQLAlchemy models for watcher service from oslo_db.sqlalchemy import models from oslo_serialization import jsonutils -import six.moves.urllib.parse as urlparse from sqlalchemy import Boolean from sqlalchemy import Column from sqlalchemy import DateTime @@ -33,7 +32,7 @@ from sqlalchemy import String from sqlalchemy import Text from sqlalchemy.types import TypeDecorator, TEXT from sqlalchemy import UniqueConstraint - +import urllib.parse as urlparse from watcher import conf CONF = conf.CONF diff --git a/watcher/decision_engine/strategy/strategies/host_maintenance.py b/watcher/decision_engine/strategy/strategies/host_maintenance.py index 042fade..a23ea07 100644 --- a/watcher/decision_engine/strategy/strategies/host_maintenance.py +++ b/watcher/decision_engine/strategy/strategies/host_maintenance.py @@ -18,8 +18,6 @@ # from oslo_log import log -import six - from watcher._i18n import _ from watcher.common import exception from watcher.decision_engine.model import element @@ -103,7 +101,7 @@ class HostMaintenance(base.HostMaintenanceBaseStrategy): def get_instance_state_str(self, instance): """Get instance state in string format""" - if isinstance(instance.state, six.string_types): + if isinstance(instance.state, str): return instance.state elif isinstance(instance.state, element.InstanceState): return instance.state.value @@ -116,7 +114,7 @@ class HostMaintenance(base.HostMaintenanceBaseStrategy): def get_node_status_str(self, node): """Get node status in string format""" - if isinstance(node.status, six.string_types): + if isinstance(node.status, str): return node.status elif isinstance(node.status, element.ServiceState): return node.status.value diff --git a/watcher/tests/api/test_hooks.py b/watcher/tests/api/test_hooks.py index 1653038..762850b 100644 --- a/watcher/tests/api/test_hooks.py +++ b/watcher/tests/api/test_hooks.py @@ -14,14 +14,11 @@ """Tests for the Pecan API hooks.""" -from unittest import mock - +from http import client as http_client from oslo_config import cfg import oslo_messaging as messaging from oslo_serialization import jsonutils -import six -from six.moves import http_client - +from unittest import mock from watcher.api.controllers import root from watcher.api import hooks from watcher.common import context @@ -144,7 +141,7 @@ class TestNoExceptionTracebackHook(base.FunctionalTest): # we don't care about this garbage. expected_msg = ("Remote error: %s %s" % (test_exc_type, self.MSG_WITHOUT_TRACE) + - ("\n[u'" if six.PY2 else "\n['")) + "\n['") actual_msg = jsonutils.loads( response.json['error_message'])['faultstring'] self.assertEqual(expected_msg, actual_msg)