From c84e98d6b6288d91dca0563e473de264c264e61b Mon Sep 17 00:00:00 2001 From: likui Date: Wed, 14 Oct 2020 13:42:40 +0800 Subject: [PATCH] Remove six Replace the following items with Python 3 style code. - six.PY2 - six.add_metaclass - six.string_types - six.text_type - six.moves - six.StringIO - six.wraps - six.integer_types Story: 2008305 Task: 41191 Change-Id: I68710421b69d4049c9e990451da491dc14251fb5 --- .../collector/checks/services_checks.py | 2 +- monasca_agent/collector/checks_d/apache.py | 3 +-- .../collector/checks_d/cadvisor_host.py | 4 ++-- monasca_agent/collector/checks_d/cert_check.py | 2 +- monasca_agent/collector/checks_d/couch.py | 3 +-- monasca_agent/collector/checks_d/couchbase.py | 2 +- monasca_agent/collector/checks_d/crash.py | 3 +-- monasca_agent/collector/checks_d/elastic.py | 2 +- monasca_agent/collector/checks_d/haproxy.py | 2 +- monasca_agent/collector/checks_d/http_check.py | 2 +- monasca_agent/collector/checks_d/jenkins.py | 4 +--- .../collector/checks_d/kafka_consumer.py | 5 ++--- .../collector/checks_d/kyototycoon.py | 3 +-- monasca_agent/collector/checks_d/lighttpd.py | 2 +- monasca_agent/collector/checks_d/mysql.py | 4 +--- monasca_agent/collector/checks_d/nginx.py | 3 +-- monasca_agent/collector/checks_d/rabbitmq.py | 3 +-- monasca_agent/collector/checks_d/solidfire.py | 4 ++-- .../collector/checks_d/supervisord.py | 3 +-- .../collector/checks_d/swift_recon.py | 7 +++---- monasca_agent/collector/checks_d/zk.py | 2 +- monasca_agent/collector/daemon.py | 4 ++-- .../collector/virt/libvirt/inspector.py | 3 +-- monasca_agent/common/config.py | 6 ++---- monasca_agent/common/emitter.py | 12 +++++------- monasca_agent/common/keystone.py | 4 +--- monasca_agent/common/util.py | 3 +-- monasca_agent/forwarder/daemon.py | 6 ++---- monasca_setup/detection/plugins/apache.py | 3 +-- monasca_setup/detection/plugins/congestion.py | 3 +-- monasca_setup/detection/plugins/mon.py | 2 +- monasca_setup/detection/plugins/mysql.py | 2 +- monasca_setup/detection/plugins/ovs.py | 2 +- monasca_setup/detection/plugins/process.py | 3 +-- monasca_setup/detection/plugins/rabbitmq.py | 3 +-- monasca_setup/detection/plugins/vcenter.py | 3 +-- monasca_setup/detection/service_plugin.py | 3 +-- monasca_setup/main.py | 3 +-- requirements.txt | 1 - tests/detection/test_kibana.py | 5 ++--- tests/detection/test_mon.py | 18 +++++------------- tests/detection/test_ovs.py | 2 +- tests/test_aggregator.py | 7 +++---- tests/test_config.py | 3 +-- .../performance/benchmark_aggregator.py | 2 -- tests_to_fix/test_elastic.py | 3 +-- tests_to_fix/test_haproxy.py | 2 +- tests_to_fix/test_laconic.py | 2 +- tests_to_fix/test_monstatsd.py | 1 - tests_to_fix/test_postfix.py | 1 - tests_to_fix/test_system.py | 2 -- tests_to_fix/test_transaction.py | 2 -- tests_to_fix/test_zookeeper.py | 3 +-- 53 files changed, 66 insertions(+), 118 deletions(-) diff --git a/monasca_agent/collector/checks/services_checks.py b/monasca_agent/collector/checks/services_checks.py index 9686958e..9c372901 100644 --- a/monasca_agent/collector/checks/services_checks.py +++ b/monasca_agent/collector/checks/services_checks.py @@ -17,7 +17,7 @@ import threading import eventlet import multiprocessing -from six.moves.queue import Queue +from queue import Queue import monasca_agent.collector.checks diff --git a/monasca_agent/collector/checks_d/apache.py b/monasca_agent/collector/checks_d/apache.py index aae0e22f..52cbe61a 100644 --- a/monasca_agent/collector/checks_d/apache.py +++ b/monasca_agent/collector/checks_d/apache.py @@ -15,8 +15,7 @@ import logging import socket - -from six.moves import urllib +import urllib # project import monasca_agent.collector.checks as checks diff --git a/monasca_agent/collector/checks_d/cadvisor_host.py b/monasca_agent/collector/checks_d/cadvisor_host.py index 2fe7d81a..0f0f72d5 100644 --- a/monasca_agent/collector/checks_d/cadvisor_host.py +++ b/monasca_agent/collector/checks_d/cadvisor_host.py @@ -13,8 +13,8 @@ import requests -from six.moves.urllib.parse import urlparse -from six.moves.urllib.parse import urlunparse +from urllib.parse import urlparse +from urllib.parse import urlunparse from monasca_agent.collector.checks import AgentCheck from monasca_agent.collector.checks import utils diff --git a/monasca_agent/collector/checks_d/cert_check.py b/monasca_agent/collector/checks_d/cert_check.py index a3be2180..1b5a7f4a 100644 --- a/monasca_agent/collector/checks_d/cert_check.py +++ b/monasca_agent/collector/checks_d/cert_check.py @@ -15,7 +15,7 @@ from datetime import datetime import socket import ssl -from six.moves.urllib.parse import urlparse +from urllib.parse import urlparse from monasca_agent.collector.checks import AgentCheck diff --git a/monasca_agent/collector/checks_d/couch.py b/monasca_agent/collector/checks_d/couch.py index cf1c6289..c28e80dc 100644 --- a/monasca_agent/collector/checks_d/couch.py +++ b/monasca_agent/collector/checks_d/couch.py @@ -12,8 +12,7 @@ # under the License. import json - -from six.moves import urllib +import urllib from monasca_agent.collector.checks import AgentCheck from monasca_agent.common.util import headers diff --git a/monasca_agent/collector/checks_d/couchbase.py b/monasca_agent/collector/checks_d/couchbase.py index cac42f82..ca15fe0c 100644 --- a/monasca_agent/collector/checks_d/couchbase.py +++ b/monasca_agent/collector/checks_d/couchbase.py @@ -14,8 +14,8 @@ import json import re import sys +import urllib -from six.moves import urllib from monasca_agent.collector.checks import AgentCheck from monasca_agent.collector.checks.utils import add_basic_auth diff --git a/monasca_agent/collector/checks_d/crash.py b/monasca_agent/collector/checks_d/crash.py index fec65b86..b99c65a7 100644 --- a/monasca_agent/collector/checks_d/crash.py +++ b/monasca_agent/collector/checks_d/crash.py @@ -16,7 +16,6 @@ import os import re from datetime import datetime -from six import text_type import monasca_agent.collector.checks as checks @@ -78,7 +77,7 @@ class Crash(checks.AgentCheck): # Return the date-/timestamp of the most recent crash if dump_count == 1: - value_meta = {'latest': text_type(dt)} + value_meta = {'latest': str(dt)} log.debug('dump_count: %s', dump_count) self.gauge('crash.dump_count', dump_count, dimensions=dimensions, diff --git a/monasca_agent/collector/checks_d/elastic.py b/monasca_agent/collector/checks_d/elastic.py index 486f5f2c..d0e6ea4c 100644 --- a/monasca_agent/collector/checks_d/elastic.py +++ b/monasca_agent/collector/checks_d/elastic.py @@ -15,8 +15,8 @@ import json import socket import subprocess import sys +import urllib -from six.moves import urllib from monasca_agent.collector.checks import AgentCheck from monasca_agent.collector.checks.utils import add_basic_auth diff --git a/monasca_agent/collector/checks_d/haproxy.py b/monasca_agent/collector/checks_d/haproxy.py index 0614a265..d3f7d99b 100644 --- a/monasca_agent/collector/checks_d/haproxy.py +++ b/monasca_agent/collector/checks_d/haproxy.py @@ -12,7 +12,7 @@ # under the License. from collections import defaultdict -from six.moves import urllib +import urllib from monasca_agent.collector.checks import AgentCheck diff --git a/monasca_agent/collector/checks_d/http_check.py b/monasca_agent/collector/checks_d/http_check.py index 220f33f2..58beb67a 100644 --- a/monasca_agent/collector/checks_d/http_check.py +++ b/monasca_agent/collector/checks_d/http_check.py @@ -22,9 +22,9 @@ import socket import sys import time +from http import client as http_client from httplib2 import Http from httplib2 import HttpLib2Error -from six.moves import http_client import monasca_agent.collector.checks.services_checks as services_checks import monasca_agent.common.config as cfg diff --git a/monasca_agent/collector/checks_d/jenkins.py b/monasca_agent/collector/checks_d/jenkins.py index 73da3464..27bb0438 100644 --- a/monasca_agent/collector/checks_d/jenkins.py +++ b/monasca_agent/collector/checks_d/jenkins.py @@ -16,8 +16,6 @@ from glob import glob import os import time -from six import moves - try: from xml.etree.ElementTree import ElementTree except ImportError: @@ -103,7 +101,7 @@ class Jenkins(AgentCheck): if len(dirs) > 0: dirs = sorted(dirs, reverse=True) # We try to get the last valid build - for index in moves.range(0, len(dirs) - 1): + for index in range(0, len(dirs) - 1): dir_name = dirs[index] try: timestamp = self._extract_timestamp(dir_name) diff --git a/monasca_agent/collector/checks_d/kafka_consumer.py b/monasca_agent/collector/checks_d/kafka_consumer.py index 48d5482f..e68758f8 100644 --- a/monasca_agent/collector/checks_d/kafka_consumer.py +++ b/monasca_agent/collector/checks_d/kafka_consumer.py @@ -14,7 +14,6 @@ import collections import logging -import six import monasca_agent.collector.checks as checks @@ -66,11 +65,11 @@ class KafkaCheck(checks.AgentCheck): try: for group, topics in raw_val.items(): - assert isinstance(group, six.string_types) + assert isinstance(group, str) if isinstance(topics, dict): self.log.info("Found old config format, discarding partition list") topics = list(topics.keys()) - assert isinstance(topics[0], six.string_types) + assert isinstance(topics[0], str) consumer_groups[group] = topics return consumer_groups except Exception as e: diff --git a/monasca_agent/collector/checks_d/kyototycoon.py b/monasca_agent/collector/checks_d/kyototycoon.py index c4c2390b..fbe3d74d 100644 --- a/monasca_agent/collector/checks_d/kyototycoon.py +++ b/monasca_agent/collector/checks_d/kyototycoon.py @@ -13,8 +13,7 @@ from collections import defaultdict import re - -from six.moves import urllib +import urllib from monasca_agent.collector.checks import AgentCheck diff --git a/monasca_agent/collector/checks_d/lighttpd.py b/monasca_agent/collector/checks_d/lighttpd.py index a81448a9..64e86511 100644 --- a/monasca_agent/collector/checks_d/lighttpd.py +++ b/monasca_agent/collector/checks_d/lighttpd.py @@ -11,7 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. -from six.moves import urllib +import urllib from monasca_agent.collector.checks import AgentCheck from monasca_agent.collector.checks.utils import add_basic_auth diff --git a/monasca_agent/collector/checks_d/mysql.py b/monasca_agent/collector/checks_d/mysql.py index 090a2394..1463449f 100644 --- a/monasca_agent/collector/checks_d/mysql.py +++ b/monasca_agent/collector/checks_d/mysql.py @@ -17,8 +17,6 @@ import subprocess import sys import traceback -from six import text_type - import monasca_agent.collector.checks as checks GAUGE = "gauge" @@ -256,7 +254,7 @@ class MySql(checks.AgentCheck): return self._collect_type(key, dict, float) def _collect_string(self, key, dict): - return self._collect_type(key, dict, text_type) + return self._collect_type(key, dict, str) def _collect_type(self, key, dict, the_type): self.log.debug("Collecting data with %s" % key) diff --git a/monasca_agent/collector/checks_d/nginx.py b/monasca_agent/collector/checks_d/nginx.py index de325d52..1a252ce6 100644 --- a/monasca_agent/collector/checks_d/nginx.py +++ b/monasca_agent/collector/checks_d/nginx.py @@ -12,8 +12,7 @@ # under the License. import re - -from six.moves import urllib +import urllib from monasca_agent.collector.checks import AgentCheck from monasca_agent.collector.checks.utils import add_basic_auth diff --git a/monasca_agent/collector/checks_d/rabbitmq.py b/monasca_agent/collector/checks_d/rabbitmq.py index 53b7e29f..dddc8e63 100644 --- a/monasca_agent/collector/checks_d/rabbitmq.py +++ b/monasca_agent/collector/checks_d/rabbitmq.py @@ -13,8 +13,7 @@ import json import re - -from six.moves import urllib +import urllib import monasca_agent.collector.checks as checks diff --git a/monasca_agent/collector/checks_d/solidfire.py b/monasca_agent/collector/checks_d/solidfire.py index e9cee92d..12b5ed7b 100644 --- a/monasca_agent/collector/checks_d/solidfire.py +++ b/monasca_agent/collector/checks_d/solidfire.py @@ -10,13 +10,13 @@ # License for the specific language governing permissions and limitations # under the License. +import functools import json import logging import time import requests from requests.packages.urllib3 import exceptions -import six import warnings import monasca_agent.collector.checks as checks @@ -186,7 +186,7 @@ class SolidFire(checks.AgentCheck): def retry(exc_tuple, tries=5, delay=1, backoff=2): # Retry decorator used for issuing API requests. def retry_dec(f): - @six.wraps(f) + @functools.wraps(f) def func_retry(*args, **kwargs): _tries, _delay = tries, delay while _tries > 1: diff --git a/monasca_agent/collector/checks_d/supervisord.py b/monasca_agent/collector/checks_d/supervisord.py index 48f2ad18..3a58840b 100644 --- a/monasca_agent/collector/checks_d/supervisord.py +++ b/monasca_agent/collector/checks_d/supervisord.py @@ -18,8 +18,7 @@ import itertools import re import socket import time - -from six.moves import xmlrpc_client +from xmlrpc import client as xmlrpc_client # 3p import supervisor.xmlrpc diff --git a/monasca_agent/collector/checks_d/swift_recon.py b/monasca_agent/collector/checks_d/swift_recon.py index 42959b19..7b88e35d 100644 --- a/monasca_agent/collector/checks_d/swift_recon.py +++ b/monasca_agent/collector/checks_d/swift_recon.py @@ -1,8 +1,7 @@ import json import os -import six -from six.moves import urllib import socket +import urllib import monasca_agent.collector.checks as checks @@ -32,7 +31,7 @@ class SwiftRecon(checks.AgentCheck): url = base_url + recon_type try: body = urllib.request.urlopen(url, timeout=timeout).read() - if six.PY3 and isinstance(body, six.binary_type): + if isinstance(body, bytes): body = body.decode('utf8') content = json.loads(body) self.log.debug("-> %s: %s" % (url, content)) @@ -180,7 +179,7 @@ class SwiftRecon(checks.AgentCheck): continue dimensions['device'] = drive['device'] for stat in ('mounted', 'size', 'used', 'avail'): - if isinstance(drive[stat], six.string_types) and \ + if isinstance(drive[stat], str) and \ not drive[stat].isdigit(): continue self.gauge('swift_recon.disk_usage.{0}'.format(stat), diff --git a/monasca_agent/collector/checks_d/zk.py b/monasca_agent/collector/checks_d/zk.py index 66e2b86c..d73e262b 100644 --- a/monasca_agent/collector/checks_d/zk.py +++ b/monasca_agent/collector/checks_d/zk.py @@ -39,8 +39,8 @@ import re import socket import struct +from io import StringIO from oslo_utils import encodeutils -from six import StringIO from monasca_agent.collector.checks import AgentCheck diff --git a/monasca_agent/collector/daemon.py b/monasca_agent/collector/daemon.py index f846783e..c09debf8 100644 --- a/monasca_agent/collector/daemon.py +++ b/monasca_agent/collector/daemon.py @@ -14,11 +14,11 @@ # Core modules import glob +import io import logging import os import pstats import signal -import six import sys import time @@ -137,7 +137,7 @@ class CollectorDaemon(monasca_agent.common.daemon.Daemon): if config.get('profile', False) and profiled: try: profiler.disable() - s = six.StringIO() + s = io.StringIO() ps = pstats.Stats(profiler, stream=s).sort_stats("cumulative") ps.print_stats() log.debug(s.getvalue()) diff --git a/monasca_agent/collector/virt/libvirt/inspector.py b/monasca_agent/collector/virt/libvirt/inspector.py index 559be05e..439841ac 100644 --- a/monasca_agent/collector/virt/libvirt/inspector.py +++ b/monasca_agent/collector/virt/libvirt/inspector.py @@ -20,7 +20,6 @@ import logging from lxml import etree from oslo_config import cfg from oslo_utils import units -import six from monasca_agent.collector.virt import inspector as virt_inspector @@ -87,7 +86,7 @@ class LibvirtInspector(virt_inspector.Inspector): return self._get_connection().lookupByUUIDString(instance.UUIDString()) except Exception as ex: if not libvirt or not isinstance(ex, libvirt.libvirtError): - raise virt_inspector.InspectorException(six.text_type(ex)) + raise virt_inspector.InspectorException(str(ex)) error_code = ex.get_error_code() if (error_code == libvirt.VIR_ERR_SYSTEM_ERROR and ex.get_error_domain() in (libvirt.VIR_FROM_REMOTE, diff --git a/monasca_agent/common/config.py b/monasca_agent/common/config.py index 4b1d0bf3..355ffefc 100644 --- a/monasca_agent/common/config.py +++ b/monasca_agent/common/config.py @@ -14,7 +14,6 @@ import logging import os -import six import yaml from monasca_agent.common import exceptions @@ -30,8 +29,7 @@ log = logging.getLogger(__name__) # Make this a singleton class so we don't get the config every time # the class is created -@six.add_metaclass(singleton.Singleton) -class Config(object): +class Config(object, metaclass=singleton.Singleton): def __init__(self, configFile=None): # importing it here, in order to avoid a circular import @@ -107,7 +105,7 @@ class Config(object): def get_config(self, sections='Main'): """Get the config info.""" section_list = [] - if isinstance(sections, six.string_types): + if isinstance(sections, str): section_list.append(sections) elif isinstance(sections, list): section_list.extend(sections) diff --git a/monasca_agent/common/emitter.py b/monasca_agent/common/emitter.py index d03d7a3f..f73faa21 100644 --- a/monasca_agent/common/emitter.py +++ b/monasca_agent/common/emitter.py @@ -13,11 +13,10 @@ from hashlib import md5 import json -from six.moves.urllib.error import HTTPError -from six.moves.urllib.request import build_opener -from six.moves.urllib.request import ProxyHandler -from six.moves.urllib.request import Request -from six import PY3 +from urllib.error import HTTPError +from urllib.request import build_opener +from urllib.request import ProxyHandler +from urllib.request import Request def post_headers(payload): @@ -41,8 +40,7 @@ def http_emitter(message, log, url): partial_payload.append(measurement) payload = json.dumps(partial_payload) - if PY3: - payload = payload.encode('utf-8') + payload = payload.encode('utf-8') url = "%s/intake" % url headers = post_headers(payload) diff --git a/monasca_agent/common/keystone.py b/monasca_agent/common/keystone.py index 59b2e31d..f2dff6c2 100644 --- a/monasca_agent/common/keystone.py +++ b/monasca_agent/common/keystone.py @@ -17,7 +17,6 @@ import logging from keystoneauth1 import identity from keystoneauth1 import session from keystoneclient import discover -import six from monasca_agent.common import singleton from monasca_agent import version as ma_version @@ -244,8 +243,7 @@ def get_args(config): return clean_args -@six.add_metaclass(singleton.Singleton) -class Keystone(object): +class Keystone(object, metaclass=singleton.Singleton): def __init__(self, config): self._config = get_args(config) diff --git a/monasca_agent/common/util.py b/monasca_agent/common/util.py index bc9b553b..6a597f63 100644 --- a/monasca_agent/common/util.py +++ b/monasca_agent/common/util.py @@ -34,7 +34,6 @@ import logging import logging.handlers from numbers import Number from oslo_utils import encodeutils -from six import integer_types log = logging.getLogger(__name__) @@ -45,7 +44,7 @@ VALID_HOSTNAME_RFC_1123_PATTERN = re.compile( MAX_HOSTNAME_LEN = 255 LOGGING_MAX_BYTES = 5 * 1024 * 1024 -NumericTypes = (float,) + integer_types +NumericTypes = (float,) + (int,) import monasca_agent.common.config as configuration from monasca_agent.common.exceptions import PathNotFound diff --git a/monasca_agent/forwarder/daemon.py b/monasca_agent/forwarder/daemon.py index 01b866b0..e8824109 100644 --- a/monasca_agent/forwarder/daemon.py +++ b/monasca_agent/forwarder/daemon.py @@ -24,8 +24,6 @@ import signal import socket import sys -from six import text_type - # set up logging before importing any other components import monasca_agent.common.util as util util.initialize_logging('forwarder') @@ -222,10 +220,10 @@ def main(): skip_ssl_validation = False use_simple_http_client = False - if text_type(tornado.options.options.sslcheck) == u"0": + if str(tornado.options.options.sslcheck) == u"0": skip_ssl_validation = True - if text_type(tornado.options.options.use_simple_http_client) == u"1": + if str(tornado.options.options.use_simple_http_client) == u"1": use_simple_http_client = True # If we don't have any arguments, run the server. diff --git a/monasca_setup/detection/plugins/apache.py b/monasca_setup/detection/plugins/apache.py index d602f79f..ab60d054 100644 --- a/monasca_setup/detection/plugins/apache.py +++ b/monasca_setup/detection/plugins/apache.py @@ -15,8 +15,7 @@ import logging import os - -from six.moves import urllib +import urllib import monasca_setup.agent_config import monasca_setup.detection diff --git a/monasca_setup/detection/plugins/congestion.py b/monasca_setup/detection/plugins/congestion.py index 8f367ca3..9644e5c8 100644 --- a/monasca_setup/detection/plugins/congestion.py +++ b/monasca_setup/detection/plugins/congestion.py @@ -11,11 +11,10 @@ # License for the specific language governing permissions and limitations # under the License. +import configparser import logging import os -from six.moves import configparser - from monasca_agent.common.psutil_wrapper import psutil import monasca_setup.agent_config import monasca_setup.detection diff --git a/monasca_setup/detection/plugins/mon.py b/monasca_setup/detection/plugins/mon.py index b00bab11..a29cb40d 100644 --- a/monasca_setup/detection/plugins/mon.py +++ b/monasca_setup/detection/plugins/mon.py @@ -20,11 +20,11 @@ uses statsd. """ +import configparser import logging import re import yaml -from six.moves import configparser import monasca_setup.agent_config import monasca_setup.detection diff --git a/monasca_setup/detection/plugins/mysql.py b/monasca_setup/detection/plugins/mysql.py index e5bb2564..6cd04a03 100644 --- a/monasca_setup/detection/plugins/mysql.py +++ b/monasca_setup/detection/plugins/mysql.py @@ -11,9 +11,9 @@ # License for the specific language governing permissions and limitations # under the License. +import configparser import logging import os -from six.moves import configparser import monasca_setup.agent_config import monasca_setup.detection diff --git a/monasca_setup/detection/plugins/ovs.py b/monasca_setup/detection/plugins/ovs.py index d6d754dd..86785a7c 100644 --- a/monasca_setup/detection/plugins/ovs.py +++ b/monasca_setup/detection/plugins/ovs.py @@ -11,13 +11,13 @@ # License for the specific language governing permissions and limitations # under the License. +import configparser import logging import os import re from oslo_config import cfg from oslo_utils import importutils -from six.moves import configparser from monasca_setup import agent_config from monasca_setup import detection diff --git a/monasca_setup/detection/plugins/process.py b/monasca_setup/detection/plugins/process.py index c437f302..b2bc042b 100644 --- a/monasca_setup/detection/plugins/process.py +++ b/monasca_setup/detection/plugins/process.py @@ -15,7 +15,6 @@ import json import logging import yaml -import six import monasca_setup.agent_config import monasca_setup.detection @@ -136,7 +135,7 @@ class ProcessCheck(monasca_setup.detection.Plugin): if found_process_names: process_item['found_process_names'] = found_process_names if 'exact_match' in process_item: - if isinstance(process_item['exact_match'], six.string_types): + if isinstance(process_item['exact_match'], str): process_item['exact_match'] = ( process_item['exact_match'].lower() == 'true') else: diff --git a/monasca_setup/detection/plugins/rabbitmq.py b/monasca_setup/detection/plugins/rabbitmq.py index 75f7e9af..346528f7 100644 --- a/monasca_setup/detection/plugins/rabbitmq.py +++ b/monasca_setup/detection/plugins/rabbitmq.py @@ -12,8 +12,7 @@ # under the License. import logging - -from six.moves import urllib +import urllib import monasca_setup.agent_config import monasca_setup.detection diff --git a/monasca_setup/detection/plugins/vcenter.py b/monasca_setup/detection/plugins/vcenter.py index 23c30932..023e0750 100644 --- a/monasca_setup/detection/plugins/vcenter.py +++ b/monasca_setup/detection/plugins/vcenter.py @@ -11,10 +11,9 @@ # License for the specific language governing permissions and limitations # under the License. +import configparser import logging -from six.moves import configparser - from monasca_agent.common.psutil_wrapper import psutil import monasca_setup.agent_config from monasca_setup.detection import Plugin diff --git a/monasca_setup/detection/service_plugin.py b/monasca_setup/detection/service_plugin.py index 563cccb2..c212261c 100644 --- a/monasca_setup/detection/service_plugin.py +++ b/monasca_setup/detection/service_plugin.py @@ -12,8 +12,7 @@ # under the License. import logging - -from six.moves import urllib +import urllib from monasca_setup import agent_config from monasca_setup.detection.plugin import Plugin diff --git a/monasca_setup/main.py b/monasca_setup/main.py index 853623dd..623d0887 100644 --- a/monasca_setup/main.py +++ b/monasca_setup/main.py @@ -26,7 +26,6 @@ import socket import subprocess import sys -import six from monasca_setup import agent_config from monasca_setup.service.detection import detect_init @@ -288,7 +287,7 @@ def parse_arguments(parser): parser.add_argument( '--monasca_url', help="Monasca API url, if not defined the url is pulled from keystone", - type=six.text_type, + type=str, default='') parser.add_argument( '--service_type', diff --git a/requirements.txt b/requirements.txt index 7a24a1b9..798d7685 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,6 @@ python-memcached>=1.56 # PSF python-monascaclient>=1.7.0 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0 redis>=2.10.0 # MIT -six>=1.10.0 # MIT stevedore>=1.20.0 # Apache-2.0 tornado>=4.5.3 # Apache-2.0 # NOTE(sdague): before allowing in >= 0.21 please be sure diff --git a/tests/detection/test_kibana.py b/tests/detection/test_kibana.py index 72b9ad2f..9065524c 100644 --- a/tests/detection/test_kibana.py +++ b/tests/detection/test_kibana.py @@ -18,7 +18,6 @@ from unittest import mock import unittest import psutil import json -import six from monasca_setup.detection.plugins import kibana @@ -91,7 +90,7 @@ class KibanaDetectionTest(unittest.TestCase): for instance in kibana_check['instances']: self.assertIn('metrics', instance) self.assertEqual(list, type(instance['metrics'])) - six.assertCountEqual(self, _KIBANA_METRICS, instance['metrics']) + self.assertCountEqual(_KIBANA_METRICS, instance['metrics']) def _verify_process_conf(self, process_check, kibana_user): # minimize check here, do not check how process should work @@ -249,6 +248,6 @@ class KibanaDetectionTest(unittest.TestCase): conf = self.kibana_plugin.build_config() self.assertIsNotNone(conf) - six.assertCountEqual(self, ['kibana', 'process'], conf.keys()) + self.assertCountEqual(['kibana', 'process'], conf.keys()) self._verify_kibana_conf(conf['kibana'], kibana_url) self._verify_process_conf(conf['process'], kibana_user) diff --git a/tests/detection/test_mon.py b/tests/detection/test_mon.py index 5bd1aee4..ee354793 100644 --- a/tests/detection/test_mon.py +++ b/tests/detection/test_mon.py @@ -17,7 +17,7 @@ import unittest import logging import psutil -import six +import configparser from monasca_setup.detection.plugins import mon @@ -187,8 +187,6 @@ class TestMonPersisterDetectionPlugin(unittest.TestCase): ) mod = "builtins.open" - if six.PY2: - mod = "__builtin__.open" with mock.patch( mod, @@ -220,7 +218,7 @@ class TestMonPersisterDetectionPlugin(unittest.TestCase): rcf.assert_called_once_with(config_file) self.assertTrue(iih.get_bound_port.called_once) - @mock.patch('six.moves.configparser.RawConfigParser') + @mock.patch('configparser.RawConfigParser') def test_should_detect_python_persister_has_config(self, _): # NOTE(trebskit) this cannot use mocking the read of the file # because when either RawConfigParser or mock_open messes up with @@ -261,8 +259,6 @@ class TestMonPersisterDetectionPlugin(unittest.TestCase): ) mod = "builtins.open" - if six.PY2: - mod = "__builtin__.open" with mock.patch( mod, @@ -501,8 +497,6 @@ class TestMonAPIDetectionPlugin(unittest.TestCase): ) mod = "builtins.open" - if six.PY2: - mod = "__builtin__.open" with mock.patch( mod, @@ -513,7 +507,7 @@ class TestMonAPIDetectionPlugin(unittest.TestCase): self.assertTrue(self._mon_api.available) - @mock.patch('six.moves.configparser.RawConfigParser') + @mock.patch('configparser.RawConfigParser') def test_should_detect_python_api_has_config(self, rcp): expected_port = 6666 actual_port = 6666 @@ -535,7 +529,7 @@ class TestMonAPIDetectionPlugin(unittest.TestCase): self._detect(retval=[fake_processes]) self.assertTrue(self._mon_api.available) - @mock.patch('six.moves.configparser.RawConfigParser') + @mock.patch('configparser.RawConfigParser') def test_should_not_detect_if_port_dont_match(self, rcp): expected_port = 6666 actual_port = 8070 @@ -569,7 +563,7 @@ class TestMonAPIDetectionPlugin(unittest.TestCase): def test_build_java_config_with_hibernate(self): self._run_java_build_config(hibernate_enabled=True) - @mock.patch('six.moves.configparser.RawConfigParser') + @mock.patch('configparser.RawConfigParser') def test_build_python_config(self, rcp): expected_port = 8070 @@ -620,8 +614,6 @@ class TestMonAPIDetectionPlugin(unittest.TestCase): ) mod = "builtins.open" - if six.PY2: - mod = "__builtin__.open" with mock.patch( mod, diff --git a/tests/detection/test_ovs.py b/tests/detection/test_ovs.py index 89648cfa..919bb9c7 100644 --- a/tests/detection/test_ovs.py +++ b/tests/detection/test_ovs.py @@ -11,6 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. +import configparser import logging import os import psutil @@ -19,7 +20,6 @@ from unittest import mock from unittest import TestCase from oslo_config import cfg -from six.moves import configparser from monasca_setup.detection import utils from monasca_setup.detection.plugins.ovs import Ovs diff --git a/tests/test_aggregator.py b/tests/test_aggregator.py index 8bd56595..d8373a97 100644 --- a/tests/test_aggregator.py +++ b/tests/test_aggregator.py @@ -13,7 +13,6 @@ import unittest -import six import monasca_agent.common.aggregator as aggregator import monasca_agent.common.metrics as metrics_pkg @@ -66,7 +65,7 @@ class TestMetricsAggregator(unittest.TestCase): value_meta=value_meta) def testValidMetricUnicodeDimensionValue(self): - dimensions = {six.unichr(2440): 'B', 'B': 'C', 'D': 'E'} + dimensions = {chr(2440): 'B', 'B': 'C', 'D': 'E'} value_meta = {"This is a test": "test, test, test"} self.submit_metric("Foo", 5, @@ -74,7 +73,7 @@ class TestMetricsAggregator(unittest.TestCase): value_meta=value_meta) def testValidMetricUnicodeDimensionKey(self): - dimensions = {'A': 'B', 'B': six.unichr(920), 'D': 'E'} + dimensions = {'A': 'B', 'B': chr(920), 'D': 'E'} value_meta = {"This is a test": "test, test, test"} self.submit_metric("Foo", 5, @@ -84,7 +83,7 @@ class TestMetricsAggregator(unittest.TestCase): def testValidMetricUnicodeMetricName(self): dimensions = {'A': 'B', 'B': 'C', 'D': 'E'} value_meta = {"This is a test": "test, test, test"} - self.submit_metric(six.unichr(6021), + self.submit_metric(chr(6021), 5, dimensions=dimensions, value_meta=value_meta) diff --git a/tests/test_config.py b/tests/test_config.py index 6967c098..2b7a0cf5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -14,7 +14,6 @@ import os.path from unittest import mock -import six import tempfile import unittest @@ -129,5 +128,5 @@ class TestConfig(unittest.TestCase): def test_verify_common_config_opts(self): opts = util.get_parsed_args(prog='test') opts_dict = vars(opts[0]) - six.assertCountEqual(self, ['config_file', 'clean', 'verbose'], + self.assertCountEqual(['config_file', 'clean', 'verbose'], opts_dict.keys()) diff --git a/tests_to_fix/performance/benchmark_aggregator.py b/tests_to_fix/performance/benchmark_aggregator.py index 3e0373ff..8ae3c8bd 100644 --- a/tests_to_fix/performance/benchmark_aggregator.py +++ b/tests_to_fix/performance/benchmark_aggregator.py @@ -14,8 +14,6 @@ Performance tests for the agent/dogstatsd metrics aggregator. """ -from six.moves import range - from monasca_agent.common.aggregator import MetricsAggregator diff --git a/tests_to_fix/test_elastic.py b/tests_to_fix/test_elastic.py index 95bc9ffc..468b1bf1 100644 --- a/tests_to_fix/test_elastic.py +++ b/tests_to_fix/test_elastic.py @@ -11,6 +11,7 @@ # under the License. import unittest +import urllib import logging logging.basicConfig() import subprocess @@ -18,8 +19,6 @@ import time from nose.plugins.skip import SkipTest from tests.common import load_check -from six.moves import urllib - PORT = 9200 MAX_WAIT = 150 diff --git a/tests_to_fix/test_haproxy.py b/tests_to_fix/test_haproxy.py index ff707297..d4824b58 100644 --- a/tests_to_fix/test_haproxy.py +++ b/tests_to_fix/test_haproxy.py @@ -15,13 +15,13 @@ import subprocess import time import tempfile import os +import urllib import logging from tests.common import load_check, kill_subprocess from nose.plugins.attrib import attr from nose.plugins.skip import SkipTest -from six.moves import urllib logging.basicConfig() diff --git a/tests_to_fix/test_laconic.py b/tests_to_fix/test_laconic.py index 89b11066..a681901d 100644 --- a/tests_to_fix/test_laconic.py +++ b/tests_to_fix/test_laconic.py @@ -11,11 +11,11 @@ # under the License. import logging +from io import StringIO import unittest from collector.checks import LaconicFilter -from six.moves import cStringIO as StringIO class TestLaconic(unittest.TestCase): diff --git a/tests_to_fix/test_monstatsd.py b/tests_to_fix/test_monstatsd.py index e3741ce9..673575b0 100644 --- a/tests_to_fix/test_monstatsd.py +++ b/tests_to_fix/test_monstatsd.py @@ -15,7 +15,6 @@ import time import unittest import nose.tools as nt -from six.moves import range from monasca_agent.common.aggregator import MetricsAggregator diff --git a/tests_to_fix/test_postfix.py b/tests_to_fix/test_postfix.py index cd02176f..ba56782e 100644 --- a/tests_to_fix/test_postfix.py +++ b/tests_to_fix/test_postfix.py @@ -19,7 +19,6 @@ import binascii import re import shutil from nose.plugins.skip import SkipTest -from six.moves import range class TestPostfix(unittest.TestCase): # diff --git a/tests_to_fix/test_system.py b/tests_to_fix/test_system.py index 76b67308..949b667e 100644 --- a/tests_to_fix/test_system.py +++ b/tests_to_fix/test_system.py @@ -10,13 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. -from functools import reduce import logging import platform import re import unittest -from six.moves import reduce logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__file__) diff --git a/tests_to_fix/test_transaction.py b/tests_to_fix/test_transaction.py index cef8d893..d9ae7b8e 100644 --- a/tests_to_fix/test_transaction.py +++ b/tests_to_fix/test_transaction.py @@ -13,8 +13,6 @@ import unittest from datetime import timedelta, datetime -from six.moves import range - from monasca_agent.forwarder.transaction import Transaction, TransactionManager from monasca_agent.forwarder.daemon import MAX_QUEUE_SIZE, THROTTLING_DELAY diff --git a/tests_to_fix/test_zookeeper.py b/tests_to_fix/test_zookeeper.py index b2587de9..da5f3f21 100644 --- a/tests_to_fix/test_zookeeper.py +++ b/tests_to_fix/test_zookeeper.py @@ -11,8 +11,7 @@ # under the License. import unittest - -from six import StringIO +from io import StringIO from tests.common import get_check