From 7d91c87345b1f18b19202ba7d447ab49d8f721e7 Mon Sep 17 00:00:00 2001 From: likui Date: Tue, 22 Sep 2020 12:29:16 +0800 Subject: [PATCH] Remove six.PY3/six.PY2 The Python 2.7 Support has been removed by: https://review.opendev.org/#/c/704096/ So remove hacking rules for compatibility between python 2 and 3 Change-Id: I0e78b982b79674520c7695c0cca7352677d7b7a0 --- tempest/api/compute/servers/test_novnc.py | 11 +++-------- tempest/cmd/run.py | 7 +------ tempest/common/compute.py | 12 +++--------- tempest/lib/cli/base.py | 8 +------- tempest/lib/common/thread.py | 13 +++---------- tempest/tests/cmd/test_run.py | 7 +------ 6 files changed, 12 insertions(+), 46 deletions(-) diff --git a/tempest/api/compute/servers/test_novnc.py b/tempest/api/compute/servers/test_novnc.py index 7931ca9788..6ebdbdb086 100644 --- a/tempest/api/compute/servers/test_novnc.py +++ b/tempest/api/compute/servers/test_novnc.py @@ -26,11 +26,6 @@ from tempest.lib import decorators CONF = config.CONF -if six.PY2: - ord_func = ord -else: - ord_func = int - class NoVNCConsoleTestJSON(base.BaseV2ComputeTest): """Test novnc console""" @@ -116,14 +111,14 @@ class NoVNCConsoleTestJSON(base.BaseV2ComputeTest): # single word(4 bytes). self.assertEqual( data_length, 4, 'Expected authentication type None.') - self.assertIn(1, [ord_func(data[i]) for i in (0, 3)], + self.assertIn(1, [int(data[i]) for i in (0, 3)], 'Expected authentication type None.') else: self.assertGreaterEqual( len(data), 2, 'Expected authentication type None.') self.assertIn( 1, - [ord_func(data[i + 1]) for i in range(ord_func(data[0]))], + [int(data[i + 1]) for i in range(int(data[0]))], 'Expected authentication type None.') # Send to the server that we only support authentication # type None @@ -136,7 +131,7 @@ class NoVNCConsoleTestJSON(base.BaseV2ComputeTest): len(data), 4, 'Server did not think security was successful.') self.assertEqual( - [ord_func(i) for i in data], [0, 0, 0, 0], + [int(i) for i in data], [0, 0, 0, 0], 'Server did not think security was successful.') # Say to leave the desktop as shared as part of client initialization diff --git a/tempest/cmd/run.py b/tempest/cmd/run.py index d82b6dff72..8bebce2c9d 100644 --- a/tempest/cmd/run.py +++ b/tempest/cmd/run.py @@ -129,7 +129,6 @@ import sys from cliff import command from oslo_serialization import jsonutils as json -import six from stestr import commands from tempest import clients @@ -139,10 +138,6 @@ from tempest.cmd import workspace from tempest.common import credentials_factory as credentials from tempest import config -if six.PY2: - # Python 2 has not FileNotFoundError exception - FileNotFoundError = IOError - CONF = config.CONF SAVED_STATE_JSON = "saved_state.json" @@ -167,7 +162,7 @@ class TempestRun(command.Command): # environment variable and fall back to "python", under python3 # if it does not exist. we should set it to the python3 executable # to deal with this situation better for now. - if six.PY3 and 'PYTHON' not in os.environ: + if 'PYTHON' not in os.environ: os.environ['PYTHON'] = sys.executable def _create_stestr_conf(self): diff --git a/tempest/common/compute.py b/tempest/common/compute.py index edb9d160b5..45f6f6f131 100644 --- a/tempest/common/compute.py +++ b/tempest/common/compute.py @@ -19,7 +19,6 @@ import ssl import struct import textwrap -import six from six.moves.urllib import parse as urlparse from oslo_log import log as logging @@ -31,11 +30,6 @@ from tempest.lib.common import fixed_network from tempest.lib.common import rest_client from tempest.lib.common.utils import data_utils -if six.PY2: - ord_func = ord -else: - ord_func = int - CONF = config.CONF LOG = logging.getLogger(__name__) @@ -365,8 +359,8 @@ class _WebSocket(object): # frames less than 125 bytes here (for the negotiation) and # that only the 2nd byte contains the length, and since the # server doesn't do masking, we can just read the data length - if ord_func(header[1]) & 127 > 0: - return self._recv(ord_func(header[1]) & 127) + if int(header[1]) & 127 > 0: + return self._recv(int(header[1]) & 127) def send_frame(self, data): """Wrapper for sending data to add in the WebSocket frame format.""" @@ -383,7 +377,7 @@ class _WebSocket(object): frame_bytes.append(mask[i]) # Mask each of the actual data bytes that we are going to send for i in range(len(data)): - frame_bytes.append(ord_func(data[i]) ^ mask[i % 4]) + frame_bytes.append(int(data[i]) ^ mask[i % 4]) # Convert our integer list to a binary array of bytes frame_bytes = struct.pack('!%iB' % len(frame_bytes), * frame_bytes) self._socket.sendall(frame_bytes) diff --git a/tempest/lib/cli/base.py b/tempest/lib/cli/base.py index d8c776b0b3..c661d21cda 100644 --- a/tempest/lib/cli/base.py +++ b/tempest/lib/cli/base.py @@ -18,7 +18,6 @@ import shlex import subprocess from oslo_log import log as logging -import six from tempest.lib import base import tempest.lib.cli.output_parser @@ -55,8 +54,6 @@ def execute(cmd, action, flags='', params='', fail_ok=False, flags, action, params]) cmd = cmd.strip() LOG.info("running: '%s'", cmd) - if six.PY2: - cmd = cmd.encode('utf-8') cmd = shlex.split(cmd) stdout = subprocess.PIPE stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE @@ -67,10 +64,7 @@ def execute(cmd, action, flags='', params='', fail_ok=False, cmd, result, result_err) - if six.PY2: - return result - else: - return os.fsdecode(result) + return os.fsdecode(result) class CLIClient(object): diff --git a/tempest/lib/common/thread.py b/tempest/lib/common/thread.py index b47d40dcfb..ef0ec73672 100644 --- a/tempest/lib/common/thread.py +++ b/tempest/lib/common/thread.py @@ -13,13 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - -if six.PY2: - # module thread is removed in Python 3 - from thread import get_ident # noqa: H237,F401 - -else: - # On Python3 thread module has been deprecated and get_ident has been moved - # to threading module - from threading import get_ident # noqa: F401 +# On Python3 thread module has been deprecated and get_ident has been moved +# to threading module +from threading import get_ident # noqa: F401 diff --git a/tempest/tests/cmd/test_run.py b/tempest/tests/cmd/test_run.py index 5d9ddfae14..3c99bbe572 100644 --- a/tempest/tests/cmd/test_run.py +++ b/tempest/tests/cmd/test_run.py @@ -29,10 +29,6 @@ from tempest import config from tempest.lib.common.utils import data_utils from tempest.tests import base -if six.PY2: - # Python 2 has not FileNotFoundError exception - FileNotFoundError = IOError - DEVNULL = open(os.devnull, 'wb') atexit.register(DEVNULL.close) @@ -149,8 +145,7 @@ class TestRunReturnCode(base.TestCase): ] # NOTE(mtreinish): on python 3 the subprocess prints b'' around # stdout. - if six.PY3: - result = ["b\'" + x + "\'" for x in result] + result = ["b\'" + x + "\'" for x in result] self.assertEqual(result, tests) def test_tempest_run_with_worker_file(self):