From 84f5778fc5ee2c9fe9c373e8df69beb61d01f1c9 Mon Sep 17 00:00:00 2001 From: zhurong Date: Thu, 16 Apr 2020 04:34:44 -0700 Subject: [PATCH] Remove six usage Change-Id: Ia6b08e81f8df43e67bed0fbd082d7d7edd178fbc --- lower-constraints.txt | 1 - muranoagent/execution_plan_runner.py | 6 ++---- muranoagent/execution_result.py | 4 +--- muranoagent/executors/chef_puppet_executor_base.py | 3 +-- muranoagent/files_manager.py | 2 +- muranoagent/tests/unit/executors/test_chef.py | 4 ++-- muranoagent/tests/unit/executors/test_puppet.py | 8 ++++---- muranoagent/tests/unit/test_files_manager.py | 4 ++-- muranoagent/validation.py | 4 +--- requirements.txt | 1 - 10 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 7f7c9879..c1abd8f8 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -69,7 +69,6 @@ requestsexceptions==1.4.0 rfc3986==1.1.0 Routes==2.4.1 semantic-version==2.6.0 -six==1.11.0 smmap2==2.0.3 snowballstemmer==1.2.1 Sphinx==1.6.5 diff --git a/muranoagent/execution_plan_runner.py b/muranoagent/execution_plan_runner.py index bd14b333..b0b95844 100644 --- a/muranoagent/execution_plan_runner.py +++ b/muranoagent/execution_plan_runner.py @@ -15,8 +15,6 @@ import sys -import six - from muranoagent import bunch from muranoagent import files_manager as fm from muranoagent import script_runner @@ -35,7 +33,7 @@ class ExecutionPlanRunner(object): "args": bunch.Bunch(self._execution_plan.get('Parameters') or {}) } script_globals.update(self._script_funcs) - six.exec_(self._main_script, script_globals) + exec(self._main_script, script_globals) if '__execution_plan_exception' in script_globals: raise script_globals['__execution_plan_exception'] return script_globals['__execution_plan_result'] @@ -43,7 +41,7 @@ class ExecutionPlanRunner(object): @staticmethod def _unindent(script, initial_indent): lines = script.expandtabs(4).split('\n') - min_indent = six.MAXSIZE + min_indent = sys.maxsize for line in lines: indent = -1 for i, c in enumerate(line): diff --git a/muranoagent/execution_result.py b/muranoagent/execution_result.py index 5e7c348f..9d6d4a63 100644 --- a/muranoagent/execution_result.py +++ b/muranoagent/execution_result.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six - from oslo_utils import timeutils from oslo_utils import uuidutils @@ -48,7 +46,7 @@ class ExecutionResult(object): if isinstance(error, int): error_code = error elif isinstance(error, Exception): - message = six.text_type(error) + message = str(error) if isinstance(error, exc.AgentException): error_code = error.error_code additional_info = error.additional_data diff --git a/muranoagent/executors/chef_puppet_executor_base.py b/muranoagent/executors/chef_puppet_executor_base.py index 4b1feda4..d30d25e1 100644 --- a/muranoagent/executors/chef_puppet_executor_base.py +++ b/muranoagent/executors/chef_puppet_executor_base.py @@ -18,7 +18,6 @@ import os import subprocess from oslo_log import log as logging -import six from muranoagent import bunch import muranoagent.exceptions @@ -74,7 +73,7 @@ class ChefPuppetExecutorBase(object): retcode = process.poll() if stdout is not None: - if not isinstance(stdout, six.text_type): + if not isinstance(stdout, str): stdout = stdout.decode('utf-8') LOG.debug(u"'{0}' execution stdout: " u"'{1}'".format(self.module_name, stdout)) diff --git a/muranoagent/files_manager.py b/muranoagent/files_manager.py index 84d935fc..2a9f83f7 100644 --- a/muranoagent/files_manager.py +++ b/muranoagent/files_manager.py @@ -23,7 +23,7 @@ import subprocess from oslo_log import log as logging from oslo_utils import encodeutils -from six.moves import urllib +import urllib from muranoagent.common import config diff --git a/muranoagent/tests/unit/executors/test_chef.py b/muranoagent/tests/unit/executors/test_chef.py index cfdb63ab..4254c016 100644 --- a/muranoagent/tests/unit/executors/test_chef.py +++ b/muranoagent/tests/unit/executors/test_chef.py @@ -46,7 +46,7 @@ class TestChefExecutor(base.MuranoAgentTestCase, fixtures.TestWithFixtures): self.assertEqual(json.loads(node), self.get_node_atts()) @mock.patch('subprocess.Popen') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch('os.path.exists') @mock.patch('os.path.isdir') def test_cookbook(self, mock_isdir, mock_exist, open_mock, @@ -69,7 +69,7 @@ class TestChefExecutor(base.MuranoAgentTestCase, fixtures.TestWithFixtures): self.chef_executor.run('test') @mock.patch('subprocess.Popen') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch('os.path.exists') @mock.patch('os.path.isdir') def test_cookbook_error(self, mock_isdir, mock_exist, open_mock, diff --git a/muranoagent/tests/unit/executors/test_puppet.py b/muranoagent/tests/unit/executors/test_puppet.py index 69aba24f..d05dbac5 100644 --- a/muranoagent/tests/unit/executors/test_puppet.py +++ b/muranoagent/tests/unit/executors/test_puppet.py @@ -44,7 +44,7 @@ class TestPuppetExecutor(base.MuranoAgentTestCase, fixtures.TestWithFixtures): node = self.puppet_executor._create_hiera_data('cookbook', atts) self.assertEqual(node, self.get_hieradata()) - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') def test_generate_files(self, open_mock): self._open_mock(open_mock) atts = { @@ -54,13 +54,13 @@ class TestPuppetExecutor(base.MuranoAgentTestCase, fixtures.TestWithFixtures): self.puppet_executor._generate_files('cookbook', 'recipe', atts) - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') def test_configure_puppet(self, open_mock): self._open_mock(open_mock) self.puppet_executor._configure_puppet() @mock.patch('subprocess.Popen') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') def test_module(self, open_mock, mock_subproc_popen): # # setup @@ -80,7 +80,7 @@ class TestPuppetExecutor(base.MuranoAgentTestCase, fixtures.TestWithFixtures): self.puppet_executor.run('test') @mock.patch('subprocess.Popen') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') def test_module_error(self, open_mock, mock_subproc_popen): # # setup diff --git a/muranoagent/tests/unit/test_files_manager.py b/muranoagent/tests/unit/test_files_manager.py index b238c3eb..73ddc948 100644 --- a/muranoagent/tests/unit/test_files_manager.py +++ b/muranoagent/tests/unit/test_files_manager.py @@ -69,7 +69,7 @@ class TestFileManager(base.MuranoAgentTestCase): @mock.patch('os.path.isdir') @mock.patch('os.mkdir') @mock.patch('os.makedirs') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch('requests.get') def test_execution_plan_type_downloable(self, mock_requests, open_mock, mock_makedir, @@ -136,7 +136,7 @@ class TestFileManager(base.MuranoAgentTestCase): for file in template.get('Files'): files.put_file(file, 'deploy') - @mock.patch('six.moves.builtins.open') + @mock.patch('builtins.open') @mock.patch('os.path.lexists') @mock.patch('os.path.isdir') @mock.patch('os.makedirs') diff --git a/muranoagent/validation.py b/muranoagent/validation.py index 38dff441..84547e5d 100644 --- a/muranoagent/validation.py +++ b/muranoagent/validation.py @@ -14,7 +14,6 @@ # limitations under the License. import semantic_version -import six from muranoagent import exceptions as exc @@ -54,8 +53,7 @@ def validate_plan(plan): def _validate_script(name, script, plan_format_version, plan): for attr in ('Type', 'EntryPoint'): - if attr not in script or not isinstance(script[attr], - six.string_types): + if attr not in script or not isinstance(script[attr], str): raise exc.IncorrectFormat( 2, 'Incorrect {0} entry in script {1}'.format( attr, name)) diff --git a/requirements.txt b/requirements.txt index ac43401a..7bf3c932 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,6 @@ oslo.log>=3.37.0 # Apache-2.0 oslo.service>=1.30.0 # Apache-2.0 oslo.utils>=3.36.0 # Apache-2.0 PyYAML>=3.12 # MIT -six>=1.11.0 # MIT semantic-version>=2.6.0 # BSD requests>=2.18.4 # Apache-2.0 cryptography>=2.1.4 # BSD/Apache-2.0