From 05de67a5358cf67a1703a3c0d2f916d751d8b20e Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 1 Jul 2022 19:09:45 +0900 Subject: [PATCH] Remove six Because Python 2 support was removed, we no longer need the six library which is used to make our code compatible with both Python 2 and Python 3. Change-Id: I9c956ec5623a58fceff6854a878b4b48197c1ff3 --- packstack/installer/core/drones.py | 5 ++--- packstack/installer/core/parameters.py | 3 +-- packstack/installer/run_setup.py | 18 ++++++++---------- packstack/installer/utils/shell.py | 11 +++++------ packstack/installer/utils/shortcuts.py | 3 +-- packstack/installer/utils/strings.py | 3 +-- requirements.txt | 1 - tests/installer/test_sequences.py | 6 +++--- tests/installer/test_setup_params.py | 5 ++--- 9 files changed, 23 insertions(+), 32 deletions(-) diff --git a/packstack/installer/core/drones.py b/packstack/installer/core/drones.py index 5f3828d8c..6fe85ffc7 100644 --- a/packstack/installer/core/drones.py +++ b/packstack/installer/core/drones.py @@ -13,7 +13,6 @@ # limitations under the License. import os -import six import stat import uuid import time @@ -76,7 +75,7 @@ class SshTarballTransferMixin(object): dest = self.recipe_dir[len(self.resource_dir):].lstrip('/') else: dest = '' - for marker, recipes in six.iteritems(self._recipes): + for marker, recipes in self._recipes.items(): for path in recipes: _dest = os.path.join(dest, os.path.basename(path)) pack.add(path, arcname=_dest) @@ -279,7 +278,7 @@ class Drone(object): logger = logging.getLogger() skip = skip or [] lastmarker = None - for mark, recipelist in six.iteritems(self._recipes): + for mark, recipelist in self._recipes.items(): if marker and marker != mark: logger.debug('Skipping marker %s for node %s.' % (mark, self.node)) diff --git a/packstack/installer/core/parameters.py b/packstack/installer/core/parameters.py index ea9ed385d..c6d2c3b05 100644 --- a/packstack/installer/core/parameters.py +++ b/packstack/installer/core/parameters.py @@ -17,7 +17,6 @@ Container set for groups and parameters """ from ..utils.datastructures import SortedDict -import six class Parameter(object): @@ -32,7 +31,7 @@ class Parameter(object): defaults = {}.fromkeys(self.allowed_keys) defaults.update(attributes) - for key, value in six.iteritems(defaults): + for key, value in defaults.items(): if key not in self.allowed_keys: raise KeyError('Given attribute %s is not allowed' % key) self.__dict__[key] = value diff --git a/packstack/installer/run_setup.py b/packstack/installer/run_setup.py index 6a15b67b8..dbb421034 100644 --- a/packstack/installer/run_setup.py +++ b/packstack/installer/run_setup.py @@ -11,17 +11,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -from six.moves import configparser -from six.moves import StringIO -from functools import cmp_to_key - +import configparser import copy import datetime +from functools import cmp_to_key import getpass import logging +from io import StringIO import os import re -import six import sys import traceback import types @@ -243,19 +241,19 @@ def mask(input): output = copy.deepcopy(input) if isinstance(input, dict): for key in input: - if isinstance(input[key], six.string_types): + if isinstance(input[key], str): output[key] = utils.mask_string(input[key], masked_value_set) if isinstance(input, list): for item in input: org = item orgIndex = input.index(org) - if isinstance(item, six.string_types): + if isinstance(item, str): item = utils.mask_string(item, masked_value_set) if item != org: output.remove(org) output.insert(orgIndex, item) - if isinstance(input, six.string_types): + if isinstance(input, str): output = utils.mask_string(input, masked_value_set) return output @@ -332,7 +330,7 @@ def _handleGroupCondition(config, conditionName, conditionValue): # If the condition is a string - just read it to global conf # We assume that if we get a string as a member it is the name of a member of conf_params - elif isinstance(conditionName, six.string_types): + elif isinstance(conditionName, str): conditionValue = _loadParamFromFile(config, "general", conditionName) else: # Any other type is invalid @@ -548,7 +546,7 @@ def _getConditionValue(matchMember): returnValue = False if isinstance(matchMember, types.FunctionType): returnValue = matchMember(controller.CONF) - elif isinstance(matchMember, six.string_types): + elif isinstance(matchMember, str): # we assume that if we get a string as a member it is the name # of a member of conf_params if matchMember not in controller.CONF: diff --git a/packstack/installer/utils/shell.py b/packstack/installer/utils/shell.py index 4a32b99e3..345e171e8 100644 --- a/packstack/installer/utils/shell.py +++ b/packstack/installer/utils/shell.py @@ -14,7 +14,6 @@ import re import os -import six import logging import subprocess @@ -38,7 +37,7 @@ def execute(cmd, workdir=None, can_fail=True, mask_list=None, mask_list = mask_list or [] repl_list = [("'", "'\\''")] - if not isinstance(cmd, six.string_types): + if not isinstance(cmd, str): import pipes masked = ' '.join((pipes.quote(i) for i in cmd)) else: @@ -55,9 +54,9 @@ def execute(cmd, workdir=None, can_fail=True, mask_list=None, env=environ) out, err = proc.communicate() - if not isinstance(out, six.text_type): + if not isinstance(out, str): out = out.decode('utf-8') - if not isinstance(err, six.text_type): + if not isinstance(err, str): err = err.decode('utf-8') masked_out = mask_string(out, mask_list, repl_list) masked_err = mask_string(err, mask_list, repl_list) @@ -115,9 +114,9 @@ class ScriptRunner(object): script = "function t(){ exit $? ; } \n trap t ERR \n %s" % script out, err = obj.communicate(script.encode('utf-8')) - if not isinstance(out, six.text_type): + if not isinstance(out, str): out = out.decode('utf-8') - if not isinstance(err, six.text_type): + if not isinstance(err, str): err = err.decode('utf-8') masked_out = mask_string(out, mask_list, repl_list) masked_err = mask_string(err, mask_list, repl_list) diff --git a/packstack/installer/utils/shortcuts.py b/packstack/installer/utils/shortcuts.py index c5a8d98b8..811cf3dcd 100644 --- a/packstack/installer/utils/shortcuts.py +++ b/packstack/installer/utils/shortcuts.py @@ -15,11 +15,10 @@ import grp import os import pwd -import six def host_iter(config): - for key, value in six.iteritems(config): + for key, value in config.items(): if key.endswith("_HOST"): host = value.split('/')[0] if host: diff --git a/packstack/installer/utils/strings.py b/packstack/installer/utils/strings.py index 12b876d5d..7e4f6d96e 100644 --- a/packstack/installer/utils/strings.py +++ b/packstack/installer/utils/strings.py @@ -14,7 +14,6 @@ from functools import cmp_to_key import re -import six STR_MASK = '*' * 8 @@ -45,7 +44,7 @@ def mask_string(unmasked, mask_list=None, replace_list=None): mask_list = mask_list or [] replace_list = replace_list or [] - if isinstance(unmasked, six.text_type): + if isinstance(unmasked, str): masked = unmasked.encode('utf-8') else: masked = unmasked diff --git a/requirements.txt b/requirements.txt index 840ae941f..27433009e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,3 @@ docutils>=0.11 pyOpenSSL>=16.2.0 netifaces distro -six diff --git a/tests/installer/test_sequences.py b/tests/installer/test_sequences.py index 3d8a7a755..ad7767285 100644 --- a/tests/installer/test_sequences.py +++ b/tests/installer/test_sequences.py @@ -15,7 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. -import six +import io import sys from unittest import TestCase @@ -29,7 +29,7 @@ class StepTestCase(PackstackTestCaseMixin, TestCase): def setUp(self): super(StepTestCase, self).setUp() self._stdout = sys.stdout - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() def tearDown(self): super(StepTestCase, self).tearDown() @@ -57,7 +57,7 @@ class SequenceTestCase(PackstackTestCaseMixin, TestCase): def setUp(self): super(SequenceTestCase, self).setUp() self._stdout = sys.stdout - sys.stdout = six.StringIO() + sys.stdout = io.StringIO() self.steps = [{'name': '1', 'function': lambda x, y: True, 'title': 'Step 1'}, diff --git a/tests/installer/test_setup_params.py b/tests/installer/test_setup_params.py index 81c3f48b8..7e6ddac26 100644 --- a/tests/installer/test_setup_params.py +++ b/tests/installer/test_setup_params.py @@ -19,7 +19,6 @@ Test cases for packstack.installer.core.parameters module. """ -import six from unittest import TestCase from ..test_base import PackstackTestCaseMixin @@ -50,7 +49,7 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase): initialization """ param = Parameter(self.data) - for key, value in six.iteritems(self.data): + for key, value in self.data.items(): self.assertEqual(getattr(param, key), value) def test_default_attribute(self): @@ -81,7 +80,7 @@ class GroupTestCase(PackstackTestCaseMixin, TestCase): Test packstack.installer.core.parameters.Group initialization """ group = Group(attributes=self.attrs, parameters=self.params) - for key, value in six.iteritems(self.attrs): + for key, value in self.attrs.items(): self.assertEqual(getattr(group, key), value) for param in self.params: self.assertIn(param['CONF_NAME'], group.parameters)