Merge "Remove six.PY3/six.PY2"

This commit is contained in:
Zuul 2020-11-27 01:52:40 +00:00 committed by Gerrit Code Review
commit 05628f2e91
6 changed files with 12 additions and 46 deletions

View File

@ -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

View File

@ -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):

View File

@ -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__)
@ -371,8 +365,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."""
@ -389,7 +383,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)

View File

@ -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):

View File

@ -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

View File

@ -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):