From 630f4ad730b559accf6ef261a3d1c5a6cd112471 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 27 Oct 2021 11:25:42 +0200 Subject: [PATCH] Remove six from project dependencies Change-Id: I07ef144ce7af6d14004530f88318824e1545c4b9 --- requirements.txt | 1 - tobiko/common/_detail.py | 3 +- tobiko/common/_fixture.py | 32 +++++-------------- tobiko/openstack/stacks/_nova.py | 3 +- tobiko/openstack/topology/_topology.py | 5 ++- tobiko/shell/sh/_execute.py | 3 +- tobiko/shell/sh/_io.py | 6 ++-- tobiko/shell/ssh/_client.py | 5 ++- tobiko/shell/ssh/_command.py | 6 ++-- tobiko/shell/ssh/_forward.py | 7 ++-- .../functional/tripleo/test_overcloud.py | 3 +- tobiko/tests/unit/tripleo/test_config.py | 23 ++++++------- tobiko/tripleo/_overcloud.py | 3 +- tobiko/tripleo/pacemaker.py | 4 +-- tobiko/tripleo/processes.py | 4 +-- 15 files changed, 39 insertions(+), 69 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6325ce3b4..98fe45979 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,6 @@ python-novaclient>=17.2.1 # Apache-2.0 python-octaviaclient>=2.2.0 # Apache-2.0 python-openstackclient>=5.4.0 # Apache-2.0 PyYAML>=5.4.1 # MIT -six>=1.15.0 # MIT sshtunnel>=0.3.1 # MIT testtools>=2.4.0 # MIT validations-libs>=1.1.0 # Apache-2.0 diff --git a/tobiko/common/_detail.py b/tobiko/common/_detail.py index 2962fc34d..aaf7e25e6 100644 --- a/tobiko/common/_detail.py +++ b/tobiko/common/_detail.py @@ -18,7 +18,6 @@ import itertools import fixtures from oslo_log import log -import six import testtools from testtools import content @@ -97,7 +96,7 @@ def get_text_to_get_bytes(get_text): def get_bytes(): text = get_text() if text: - if isinstance(text, six.string_types): + if isinstance(text, str): yield text.encode(errors='ignore') else: for t in text: diff --git a/tobiko/common/_fixture.py b/tobiko/common/_fixture.py index ccc76e757..27d8ed819 100644 --- a/tobiko/common/_fixture.py +++ b/tobiko/common/_fixture.py @@ -21,7 +21,6 @@ import typing import fixtures from oslo_log import log -import six import testtools import tobiko @@ -88,7 +87,7 @@ def get_fixture_name(obj): def get_fixture_class(obj): '''Get fixture class''' - if isinstance(obj, six.string_types): + if isinstance(obj, str): obj = tobiko.load_object(obj) if not inspect.isclass(obj): @@ -161,7 +160,7 @@ def cleanup_fixture(obj, fixture_id=None, manager=None): def get_name_and_object(obj): '''Get (name, obj) tuple identified by given :param obj:''' - if isinstance(obj, six.string_types): + if isinstance(obj, str): return obj, tobiko.load_object(obj) else: return get_object_name(obj), obj @@ -219,8 +218,9 @@ def get_required_fixtures(obj): if required_names is None: if is_test_method(obj): # Get fixtures from default values that are fixtures + defaults = getattr(obj, '__defaults__', None) or [] required = {default - for default in six.get_function_defaults(obj) or [] + for default in defaults if is_fixture(default)} elif inspect.isclass(obj): @@ -312,7 +312,7 @@ def get_fixture_id(obj: typing.Any) -> typing.Any: def get_object_name(obj): '''Gets a fully qualified name for given :param obj:''' - if isinstance(obj, six.string_types): + if isinstance(obj, str): return obj name = getattr(obj, '__tobiko_fixture_name__', None) @@ -326,25 +326,9 @@ def get_object_name(obj): module = inspect.getmodule(obj).__name__ - if six.PY2: - # Below code is only for old Python versions - if inspect.isclass(obj): - # This doesn't work for nested classes - return module + '.' + obj.__name__ - - method_class = getattr(obj, 'im_class', None) - if method_class: - # This doesn't work for nested classes - return module + '.' + method_class.__name__ + '.' + obj.__name__ - - if inspect.isfunction(obj): - return module + '.' + obj.func_name - - else: - # Only Python 3 defines __qualname__ - name = getattr(obj, '__qualname__', None) - if name: - return module + '.' + name + name = getattr(obj, '__qualname__', None) + if name: + return module + '.' + name msg = "Unable to get fixture name from object {!r}".format(obj) raise TypeError(msg) diff --git a/tobiko/openstack/stacks/_nova.py b/tobiko/openstack/stacks/_nova.py index f5ec0daac..9a5b8a55d 100644 --- a/tobiko/openstack/stacks/_nova.py +++ b/tobiko/openstack/stacks/_nova.py @@ -21,7 +21,6 @@ import typing from abc import ABC import netaddr -import six from oslo_log import log import tobiko @@ -497,7 +496,7 @@ class SameHostServerStackFixture(PeerServerStackFixture, abc.ABC): def as_str(text): - if isinstance(text, six.string_types): + if isinstance(text, str): return text else: return text.decode() diff --git a/tobiko/openstack/topology/_topology.py b/tobiko/openstack/topology/_topology.py index 5584fda71..cad54f72b 100644 --- a/tobiko/openstack/topology/_topology.py +++ b/tobiko/openstack/topology/_topology.py @@ -16,12 +16,11 @@ from __future__ import absolute_import import collections import re import typing +from urllib import parse import weakref import netaddr from oslo_log import log -import six -from six.moves.urllib import parse import tobiko from tobiko.shell import files @@ -387,7 +386,7 @@ class OpenStackTopology(tobiko.SharedFixture): name = name or (hostname and node_name_from_hostname(hostname)) details = {} if name: - tobiko.check_valid_type(name, six.string_types) + tobiko.check_valid_type(name, str) details['name'] = name try: return self._names[name] diff --git a/tobiko/shell/sh/_execute.py b/tobiko/shell/sh/_execute.py index ae785d112..dd4038cac 100644 --- a/tobiko/shell/sh/_execute.py +++ b/tobiko/shell/sh/_execute.py @@ -19,7 +19,6 @@ import collections import enum from oslo_log import log -import six import tobiko from tobiko.shell.sh import _exception @@ -29,7 +28,7 @@ from tobiko.shell.sh import _process LOG = log.getLogger(__name__) -DATA_TYPES = six.string_types + (six.binary_type, six.text_type) +DATA_TYPES = (str, bytes) @enum.unique diff --git a/tobiko/shell/sh/_io.py b/tobiko/shell/sh/_io.py index f7b90e767..bdad5f10d 100644 --- a/tobiko/shell/sh/_io.py +++ b/tobiko/shell/sh/_io.py @@ -19,7 +19,7 @@ import io import select from oslo_log import log -import six + LOG = log.getLogger(__name__) @@ -58,7 +58,7 @@ class ShellIOBase(io.IOBase): if not data: return '' - if isinstance(data, six.string_types): + if isinstance(data, str): return data return data.decode() @@ -124,7 +124,7 @@ class ShellWritable(ShellIOBase): return True def write(self, data): - if not isinstance(data, six.binary_type): + if not isinstance(data, bytes): data = data.encode() witten_bytes = self.delegate.write(data) if witten_bytes is None: diff --git a/tobiko/shell/ssh/_client.py b/tobiko/shell/ssh/_client.py index 00f7155c9..2de9de735 100644 --- a/tobiko/shell/ssh/_client.py +++ b/tobiko/shell/ssh/_client.py @@ -29,7 +29,6 @@ import netaddr from oslo_log import log import paramiko from paramiko import common -import six import tobiko from tobiko.shell.ssh import _config @@ -76,7 +75,7 @@ def positive_int(value): def get_key_filename(value): - if isinstance(value, six.string_types): + if isinstance(value, str): value = [value] key_filename = [tobiko.tobiko_config_path(v) for v in value] return [f @@ -670,7 +669,7 @@ def ssh_proxy_sock(hostname=None, port=None, command=None, client=None, return None # Apply connect parameters to proxy command - if not isinstance(command, six.string_types): + if not isinstance(command, str): command = subprocess.list2cmdline(command) if hostname: command = command.format(hostname=hostname, port=(port or 22)) diff --git a/tobiko/shell/ssh/_command.py b/tobiko/shell/ssh/_command.py index e874e5bf6..d2490b422 100644 --- a/tobiko/shell/ssh/_command.py +++ b/tobiko/shell/ssh/_command.py @@ -17,8 +17,6 @@ from __future__ import absolute_import import subprocess -import six - from tobiko.shell.ssh import _config @@ -38,7 +36,7 @@ def ssh_command(host, username=None, port=None, command=None, host=host, config_files=config_files) command = command or host_config.default.command.split() - if isinstance(command, six.string_types): + if isinstance(command, str): command = command.split() hostname = host_config.hostname @@ -56,7 +54,7 @@ def ssh_command(host, username=None, port=None, command=None, command += ['-i', key_filename] if proxy_command: - if not isinstance(proxy_command, six.string_types): + if not isinstance(proxy_command, str): proxy_command = subprocess.list2cmdline([str(a) for a in proxy_command]) options['ProxyCommand'] = proxy_command diff --git a/tobiko/shell/ssh/_forward.py b/tobiko/shell/ssh/_forward.py index b0e978ac7..303c6d40c 100644 --- a/tobiko/shell/ssh/_forward.py +++ b/tobiko/shell/ssh/_forward.py @@ -18,10 +18,9 @@ from __future__ import absolute_import import collections import contextlib import socket +import urllib from oslo_log import log -import six -from six.moves import urllib import sshtunnel import tobiko @@ -154,7 +153,7 @@ class SSHUnixForwardHandler(sshtunnel._ForwardHandler): self.server.local_address) remote_address = self.remote_address - assert isinstance(remote_address, six.string_types) + assert isinstance(remote_address, str) command = 'sudo nc -U "{}"'.format(remote_address) chan = self.transport.open_session() @@ -303,7 +302,7 @@ def binding_url(address): return 'tcp://{hostname}:{port}'.format(hostname=hostname, port=port) - elif isinstance(address, six.string_types): + elif isinstance(address, str): return 'unix://{path}'.format(path=address) raise TypeError('Invalid address type: {!r}'.format(address)) diff --git a/tobiko/tests/functional/tripleo/test_overcloud.py b/tobiko/tests/functional/tripleo/test_overcloud.py index 82bc6385e..761bf2dce 100644 --- a/tobiko/tests/functional/tripleo/test_overcloud.py +++ b/tobiko/tests/functional/tripleo/test_overcloud.py @@ -17,7 +17,6 @@ import os import netaddr import pandas as pd -import six import testtools from tobiko import config @@ -71,7 +70,7 @@ class OvercloudNovaApiTest(testtools.TestCase): host_config = tobiko.setup_fixture( tripleo.overcloud_host_config(hostname=hostname)) self.assertEqual(hostname, host_config.host) - self.assertIsInstance(host_config.hostname, six.string_types) + self.assertIsInstance(host_config.hostname, str) netaddr.IPAddress(host_config.hostname) self.assertEqual(CONF.tobiko.tripleo.overcloud_ssh_port, host_config.port) diff --git a/tobiko/tests/unit/tripleo/test_config.py b/tobiko/tests/unit/tripleo/test_config.py index 4a7c2e7ba..71d5b052f 100644 --- a/tobiko/tests/unit/tripleo/test_config.py +++ b/tobiko/tests/unit/tripleo/test_config.py @@ -13,8 +13,6 @@ # under the License. from __future__ import absolute_import -import six - from tobiko import config from tobiko.tests import unit @@ -26,8 +24,7 @@ TIPLEO_CONF = CONF.tobiko.tripleo class TripleoConfigTest(unit.TobikoUnitTest): def test_ssh_key_filename(self): - self.assertIsInstance(TIPLEO_CONF.undercloud_ssh_key_filename, - six.string_types) + self.assertIsInstance(TIPLEO_CONF.undercloud_ssh_key_filename, str) class UndercloudConfigTest(unit.TobikoUnitTest): @@ -35,21 +32,21 @@ class UndercloudConfigTest(unit.TobikoUnitTest): def test_undercloud_ssh_hostname(self): value = TIPLEO_CONF.undercloud_ssh_hostname if value is not None: - self.assertIsInstance(value, six.string_types) + self.assertIsInstance(value, str) def test_undercloud_ssh_port(self): value = TIPLEO_CONF.undercloud_ssh_port if value is not None: self.assertIsInstance(value, int) - self.assertIn(value, six.moves.range(1, 2 ** 16)) + self.assertGreater(value, 0) + self.assertLess(value, 2 ** 16) def test_undercloud_ssh_username(self): - self.assertIsInstance(TIPLEO_CONF.undercloud_ssh_username, - six.string_types) + self.assertIsInstance(TIPLEO_CONF.undercloud_ssh_username, str) def test_undercloud_rcfile(self): for rcfile in TIPLEO_CONF.undercloud_rcfile: - self.assertIsInstance(rcfile, six.string_types) + self.assertIsInstance(rcfile, str) class OvercloudConfigTest(unit.TobikoUnitTest): @@ -58,12 +55,12 @@ class OvercloudConfigTest(unit.TobikoUnitTest): value = TIPLEO_CONF.overcloud_ssh_port if value is not None: self.assertIsInstance(value, int) - self.assertIn(value, six.moves.range(1, 2 ** 16)) + self.assertGreater(value, 0) + self.assertLess(value, 2 ** 16) def test_overcloud_ssh_username(self): - self.assertIsInstance(TIPLEO_CONF.overcloud_ssh_username, - six.string_types) + self.assertIsInstance(TIPLEO_CONF.overcloud_ssh_username, str) def test_overcloud_rcfile(self): for rcfile in TIPLEO_CONF.overcloud_rcfile: - self.assertIsInstance(rcfile, six.string_types) + self.assertIsInstance(rcfile, str) diff --git a/tobiko/tripleo/_overcloud.py b/tobiko/tripleo/_overcloud.py index a35c55034..a0b2ecb01 100644 --- a/tobiko/tripleo/_overcloud.py +++ b/tobiko/tripleo/_overcloud.py @@ -17,7 +17,6 @@ import io import os from oslo_log import log -import six import tobiko from tobiko import config @@ -199,7 +198,7 @@ class OvercloudHostConfig(tobiko.SharedFixture): self.server = server if self.host is None: self.host = server.name - tobiko.check_valid_type(self.host, six.string_types) + tobiko.check_valid_type(self.host, str) self._connect_parameters = ssh.gather_ssh_connect_parameters(**kwargs) def setup_fixture(self): diff --git a/tobiko/tripleo/pacemaker.py b/tobiko/tripleo/pacemaker.py index 19247f5c5..0e9b3ef66 100644 --- a/tobiko/tripleo/pacemaker.py +++ b/tobiko/tripleo/pacemaker.py @@ -1,10 +1,10 @@ from __future__ import absolute_import +import io import time from oslo_log import log import pandas -import six import tobiko from tobiko.tripleo import overcloud @@ -53,7 +53,7 @@ def get_pcs_resources_table(timeout=720, interval=2): expect_exit_status=None).stdout # remove the first column when it only includes '*' characters output = output.replace('*', '').strip() - stream = six.StringIO(output) + stream = io.StringIO(output) table = pandas.read_csv(stream, delim_whitespace=True, header=None) table.columns = ['resource', 'resource_type', 'resource_state', 'overcloud_node'] diff --git a/tobiko/tripleo/processes.py b/tobiko/tripleo/processes.py index 7d879aba9..45a96112c 100644 --- a/tobiko/tripleo/processes.py +++ b/tobiko/tripleo/processes.py @@ -1,11 +1,11 @@ from __future__ import absolute_import +import io import re import time from oslo_log import log import pandas -import six import tobiko from tobiko.openstack import neutron @@ -53,7 +53,7 @@ root | 11| 2| 0.0| 0|00:00:05|migration/0 |[migration/0] "\"DELIM%z\" -o \"DELIM%x\" -o \"DELIM%c\" -o \"DELIM%a\" |grep -v " "ps|sed 's/\"/''/g'", ssh_client=ssh_client).stdout - stream = six.StringIO(output) + stream = io.StringIO(output) table = pandas.read_csv(stream, sep='DELIM', header=None, skiprows=1) table.replace(to_replace=' ', value="", regex=True, inplace=True) table.columns = ['USER', 'PID', 'PPID', 'CPU', 'VSZ', 'TIME', 'PROCESS',