Stop using six library
Since we've dropped support for Python 2.7, it's time to look at the bright future that Python 3.x will bring and stop forcing compatibility with older versions. This patch removes the six library from requirements, not looking back. Change-Id: I41ef2d06dcdfe2fb3fd47fe877149ec9a29e37fb
This commit is contained in:
parent
77de3d5bb9
commit
a2c976077a
@ -23,7 +23,6 @@ from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.common import exception
|
||||
from ironic_staging_drivers.common.i18n import _
|
||||
@ -98,7 +97,7 @@ class Client(object):
|
||||
def __init__(self, address, protocol, username, password):
|
||||
port = AMT_PROTOCOL_PORT_MAP[protocol]
|
||||
path = '/wsman'
|
||||
if isinstance(protocol, six.text_type):
|
||||
if isinstance(protocol, str):
|
||||
protocol = protocol.encode()
|
||||
self.client = pywsman.Client(address, port, path, protocol,
|
||||
username, password)
|
||||
@ -167,7 +166,7 @@ def parse_driver_info(node):
|
||||
for param in REQUIRED_PROPERTIES:
|
||||
value = info.get(param)
|
||||
if value:
|
||||
if isinstance(value, six.text_type):
|
||||
if isinstance(value, str):
|
||||
value = value.encode()
|
||||
d_info[param[4:]] = value
|
||||
else:
|
||||
|
@ -27,7 +27,6 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_service import loopingcall
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.common.i18n import _
|
||||
from ironic_staging_drivers.common import utils
|
||||
@ -114,8 +113,8 @@ def _parse_driver_info(node):
|
||||
def _get_connection(driver_info):
|
||||
# NOTE: python-iboot wants username and password as strings (not unicode)
|
||||
return iboot.iBootInterface(driver_info['address'],
|
||||
six.binary_type(driver_info['username']),
|
||||
six.binary_type(driver_info['password']),
|
||||
bytes(driver_info['username']),
|
||||
bytes(driver_info['password']),
|
||||
port=driver_info['port'],
|
||||
num_relays=driver_info['relay_id'])
|
||||
|
||||
|
@ -13,11 +13,11 @@
|
||||
import binascii
|
||||
import collections
|
||||
import datetime
|
||||
import functools
|
||||
import struct
|
||||
|
||||
from ironic.common import exception as ironic_exception
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.common import exception
|
||||
from ironic_staging_drivers.common.i18n import _
|
||||
@ -146,7 +146,7 @@ _INIT_TIMESTAMP_MAX = 0x20000000
|
||||
|
||||
def _handle_parsing_error(func):
|
||||
"""Decorator for handling errors in raw output data."""
|
||||
@six.wraps(func)
|
||||
@functools.wraps(func)
|
||||
def wrapper(raw_data):
|
||||
msg = _('Data from Intel Node Manager %s')
|
||||
|
||||
@ -504,7 +504,7 @@ def parse_statistics(raw_data):
|
||||
# there is not "bad time" in standard, reset to start the epoch
|
||||
statistics['timestamp'] = _INVALID_TIME
|
||||
LOG.warning('Invalid timestamp in Node Nanager statistics '
|
||||
'data: %s', six.text_type(e))
|
||||
'data: %s', str(e))
|
||||
else:
|
||||
statistics['timestamp'] = isotime
|
||||
|
||||
@ -534,8 +534,7 @@ def parse_slave_and_channel(file_path):
|
||||
with open(file_path, 'rb') as bin_fp:
|
||||
data_str = binascii.hexlify(bin_fp.read())
|
||||
|
||||
if six.PY3:
|
||||
data_str = data_str.decode()
|
||||
data_str = data_str.decode()
|
||||
oem_id_index = data_str.find(prefix)
|
||||
if oem_id_index != -1:
|
||||
ret = data_str[oem_id_index + len(prefix):
|
||||
|
@ -22,7 +22,6 @@ from jsonschema import exceptions as json_schema_exc
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.common.i18n import _
|
||||
from ironic_staging_drivers.intel_nm import nm_commands
|
||||
@ -115,7 +114,7 @@ def _execute_nm_command(task, data, command_func, parse_func=None):
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception('Can not obtain Intel Node Manager address for '
|
||||
'node %(node)s: %(err)s',
|
||||
{'node': task.node.uuid, 'err': six.text_type(e)})
|
||||
{'node': task.node.uuid, 'err': str(e)})
|
||||
driver_info = task.node.driver_info
|
||||
driver_info['ipmi_bridging'] = 'single'
|
||||
driver_info['ipmi_target_channel'] = channel
|
||||
@ -129,7 +128,7 @@ def _execute_nm_command(task, data, command_func, parse_func=None):
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception('Error in returned data for node %(node)s: '
|
||||
'%(err)s', {'node': task.node.uuid,
|
||||
'err': six.text_type(e)})
|
||||
'err': str(e)})
|
||||
|
||||
|
||||
class IntelNMVendorPassthru(base.VendorInterface):
|
||||
|
@ -28,7 +28,6 @@ from ironic.drivers import base
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.common import exception as staging_exception
|
||||
|
||||
@ -130,13 +129,14 @@ def _getvm(driver_info):
|
||||
password = driver_info['ovirt_password']
|
||||
insecure = driver_info['ovirt_insecure']
|
||||
ca_file = driver_info['ovirt_ca_file']
|
||||
name = six.ensure_str(
|
||||
name = str.encode(
|
||||
driver_info['ovirt_vm_name'], encoding='ascii', errors='ignore')
|
||||
url = "https://%s/ovirt-engine/api" % address
|
||||
try:
|
||||
# pycurl.Curl.setopt doesn't support unicode strings,
|
||||
# attempt to turn `url` into an all-ASCII string
|
||||
url = six.ensure_str(url, encoding='ascii', errors='strict')
|
||||
# attempt to turn `url` into an all-ASCII string;
|
||||
# in Python 3.x setopt accepts bytes as it should.
|
||||
url = str.encode(url, encoding='ascii', errors='strict')
|
||||
|
||||
except UnicodeEncodeError:
|
||||
LOG.warning("oVirt URL '%(url)s' contains non-ascii characters, "
|
||||
|
@ -21,11 +21,11 @@ respective external libraries' actually being present.
|
||||
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
import mock
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.tests.unit.amt import pywsman_mocks_specs
|
||||
|
||||
@ -38,4 +38,4 @@ if not pywsman:
|
||||
# Now that the external library has been mocked, if anything had already
|
||||
# loaded any of the drivers, reload them.
|
||||
if 'ironic_staging_drivers.amt' in sys.modules:
|
||||
six.moves.reload_module(sys.modules['ironic_staging_drivers.amt'])
|
||||
importlib.reload(sys.modules['ironic_staging_drivers.amt'])
|
||||
|
@ -21,7 +21,6 @@ from ironic.conductor import task_manager
|
||||
from ironic.tests.unit.db import base as db_base
|
||||
from ironic.tests.unit.objects import utils as obj_utils
|
||||
import mock
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.ovirt import ovirt as ovirt_power
|
||||
|
||||
@ -65,11 +64,11 @@ class OVirtDriverTestCase(db_base.DbTestCase):
|
||||
ovirt_power._getvm(driver_info)
|
||||
ovirt_power.sdk.Connection.assert_called_with(
|
||||
ca_file=None, insecure='False', password='changeme',
|
||||
url='https://127.0.0.1/ovirt-engine/api',
|
||||
url=b'https://127.0.0.1/ovirt-engine/api',
|
||||
username='jhendrix@internal'
|
||||
)
|
||||
url = ovirt_power.sdk.Connection.mock_calls[0][-1]['url']
|
||||
self.assertIsInstance(url, six.string_types)
|
||||
self.assertIsInstance(url, bytes)
|
||||
|
||||
@mock.patch.object(ovirt_power, "sdk", create=True)
|
||||
def test_getvm_unicode(self, sdk):
|
||||
@ -83,7 +82,7 @@ class OVirtDriverTestCase(db_base.DbTestCase):
|
||||
username='jhendrix@internal'
|
||||
)
|
||||
url = ovirt_power.sdk.Connection.mock_calls[0][-1]['url']
|
||||
self.assertIsInstance(url, six.text_type)
|
||||
self.assertIsInstance(url, str)
|
||||
|
||||
def test_get_properties(self):
|
||||
expected = list(ovirt_power.PROPERTIES.keys())
|
||||
|
@ -25,11 +25,11 @@ Current list of mocked libraries:
|
||||
- iboot
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
import mock
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from ironic_staging_drivers.tests.unit import third_party_driver_mock_specs \
|
||||
as mock_specs
|
||||
@ -46,8 +46,7 @@ if not iboot:
|
||||
# if anything has loaded the iboot driver yet, reload it now that the
|
||||
# external library has been mocked
|
||||
if 'ironic_staging_drivers.iboot.power' in sys.modules:
|
||||
six.moves.reload_module(
|
||||
sys.modules['ironic_staging_drivers.iboot.power'])
|
||||
importlib.reload(sys.modules['ironic_staging_drivers.iboot.power'])
|
||||
|
||||
# attempt to load the external 'libvirt' library, which is required by
|
||||
# the optional drivers.modules.libvirt module
|
||||
@ -60,8 +59,7 @@ if not libvirt:
|
||||
# if anything has loaded the libvirt driver yet, reload it now that the
|
||||
# external library has been mocked
|
||||
if 'ironic_staging_drivers.libvirt.power' in sys.modules:
|
||||
six.moves.reload_module(
|
||||
sys.modules['ironic_staging_drivers.libvirt.power'])
|
||||
importlib.reload(sys.modules['ironic_staging_drivers.libvirt.power'])
|
||||
|
||||
# attempt to load the external 'ovirtsdk4' library, which is required by
|
||||
# the optional drivers.modules.ovirt module
|
||||
|
@ -70,7 +70,6 @@ requestsexceptions==1.4.0
|
||||
restructuredtext-lint==1.1.3
|
||||
rfc3986==1.1.0
|
||||
Routes==2.4.1
|
||||
six==1.12.0
|
||||
snowballstemmer==1.2.1
|
||||
Sphinx==1.6.2
|
||||
sphinxcontrib-websupport==1.0.1
|
||||
|
@ -9,6 +9,5 @@ oslo.config>=5.2.0 # Apache-2.0
|
||||
oslo.i18n>=3.15.3 # Apache-2.0
|
||||
oslo.log>=3.36.0 # Apache-2.0
|
||||
oslo.utils>=3.33.0 # Apache-2.0
|
||||
six>=1.12.0 # MIT
|
||||
jsonschema>=2.6.0 # MIT
|
||||
oslo.service!=1.28.1,>=1.24.0 # Apache-2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user