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: I4795417aa649be75ba7162a8cf30eacbb88c7b5e
This commit is contained in:
Riccardo Pittau 2019-11-28 17:10:40 +01:00
parent 8e246f4482
commit ca7a46b113
14 changed files with 60 additions and 88 deletions

View File

@ -19,6 +19,7 @@ import select
import socket import socket
import threading import threading
import time import time
from urllib import parse as urlparse
from wsgiref import simple_server from wsgiref import simple_server
from ironic_lib import exception as lib_exc from ironic_lib import exception as lib_exc
@ -29,7 +30,6 @@ from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_utils import netutils from oslo_utils import netutils
import pkg_resources import pkg_resources
from six.moves.urllib import parse as urlparse
from stevedore import extension from stevedore import extension
from ironic_python_agent.api import app from ironic_python_agent.api import app

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
from wsme import types as wtypes from wsme import types as wtypes
@ -67,7 +66,7 @@ class MultiType(wtypes.UserType):
type=self.types, value=type(value))) type=self.types, value=type(value)))
json_type = MultiType(list, dict, six.integer_types, wtypes.text) json_type = MultiType(list, dict, int, wtypes.text)
class APIBase(wtypes.Base): class APIBase(wtypes.Base):

View File

@ -19,7 +19,6 @@ import threading
from oslo_log import log from oslo_log import log
from oslo_utils import uuidutils from oslo_utils import uuidutils
import six
from ironic_python_agent import encoding from ironic_python_agent import encoding
from ironic_python_agent import errors from ironic_python_agent import errors
@ -90,8 +89,7 @@ class SyncCommandResult(BaseCommandResult):
super(SyncCommandResult, self).__init__(command_name, super(SyncCommandResult, self).__init__(command_name,
command_params) command_params)
if isinstance(result_or_error, (bytes, str)):
if isinstance(result_or_error, (bytes, six.text_type)):
result_key = 'result' if success else 'error' result_key = 'result' if success else 'error'
result_or_error = {result_key: result_or_error} result_or_error = {result_key: result_or_error}
@ -159,7 +157,7 @@ class AsyncCommandResult(BaseCommandResult):
try: try:
result = self.execute_method(**self.command_params) result = self.execute_method(**self.command_params)
if isinstance(result, (bytes, six.text_type)): if isinstance(result, (bytes, str)):
result = {'result': '{}: {}'.format(self.command_name, result)} result = {'result': '{}: {}'.format(self.command_name, result)}
LOG.info('Command: %(name)s, result: %(result)s', LOG.info('Command: %(name)s, result: %(result)s',
{'name': self.command_name, 'result': result}) {'name': self.command_name, 'result': result})
@ -282,7 +280,7 @@ def async_command(command_name, validator=None):
def async_decorator(func): def async_decorator(func):
func.command_name = command_name func.command_name = command_name
@six.wraps(func) @functools.wraps(func)
def wrapper(self, **command_params): def wrapper(self, **command_params):
# Run a validator before passing everything off to async. # Run a validator before passing everything off to async.
# validators should raise exceptions or return silently. # validators should raise exceptions or return silently.
@ -311,7 +309,7 @@ def sync_command(command_name, validator=None):
def sync_decorator(func): def sync_decorator(func):
func.command_name = command_name func.command_name = command_name
@six.wraps(func) @functools.wraps(func)
def wrapper(self, **command_params): def wrapper(self, **command_params):
# Run a validator before invoking the function. # Run a validator before invoking the function.
# validators should raise exceptions or return silently. # validators should raise exceptions or return silently.

View File

@ -16,6 +16,7 @@ import hashlib
import os import os
import tempfile import tempfile
import time import time
from urllib import parse as urlparse
from ironic_lib import disk_utils from ironic_lib import disk_utils
from ironic_lib import exception from ironic_lib import exception
@ -23,8 +24,6 @@ from oslo_concurrency import processutils
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
import requests import requests
import six
from six.moves.urllib import parse as urlparse
from ironic_python_agent import errors from ironic_python_agent import errors
from ironic_python_agent.extensions import base from ironic_python_agent.extensions import base
@ -97,8 +96,8 @@ def _fetch_checksum(checksum, image_info):
return lines[0] return lines[0]
# FIXME(dtantsur): can we assume the same name for all images? # FIXME(dtantsur): can we assume the same name for all images?
expected_fname = os.path.basename( expected_fname = os.path.basename(urlparse.urlparse(
urlparse.urlparse(image_info['urls'][0]).path) image_info['urls'][0]).path)
for line in lines: for line in lines:
checksum, fname = line.strip().split(None, 1) checksum, fname = line.strip().split(None, 1)
# The star symbol designates binary mode, which is the same as text # The star symbol designates binary mode, which is the same as text
@ -393,7 +392,7 @@ def _validate_image_info(ext, image_info=None, **kwargs):
'Image \'urls\' must be a list with at least one element.') 'Image \'urls\' must be a list with at least one element.')
if 'checksum' in image_info: if 'checksum' in image_info:
if (not isinstance(image_info['checksum'], six.string_types) if (not isinstance(image_info['checksum'], str)
or not image_info['checksum']): or not image_info['checksum']):
raise errors.InvalidCommandParamsError( raise errors.InvalidCommandParamsError(
'Image \'checksum\' must be a non-empty string.') 'Image \'checksum\' must be a non-empty string.')
@ -402,11 +401,11 @@ def _validate_image_info(ext, image_info=None, **kwargs):
os_hash_algo = image_info.get('os_hash_algo') os_hash_algo = image_info.get('os_hash_algo')
os_hash_value = image_info.get('os_hash_value') os_hash_value = image_info.get('os_hash_value')
if os_hash_algo or os_hash_value: if os_hash_algo or os_hash_value:
if (not isinstance(os_hash_algo, six.string_types) or if (not isinstance(os_hash_algo, str) or
not os_hash_algo): not os_hash_algo):
raise errors.InvalidCommandParamsError( raise errors.InvalidCommandParamsError(
'Image \'os_hash_algo\' must be a non-empty string.') 'Image \'os_hash_algo\' must be a non-empty string.')
if (not isinstance(os_hash_value, six.string_types) or if (not isinstance(os_hash_value, str) or
not os_hash_value): not os_hash_value):
raise errors.InvalidCommandParamsError( raise errors.InvalidCommandParamsError(
'Image \'os_hash_value\' must be a non-empty string.') 'Image \'os_hash_value\' must be a non-empty string.')

View File

@ -31,7 +31,6 @@ from oslo_log import log
import pint import pint
import psutil import psutil
import pyudev import pyudev
import six
import stevedore import stevedore
import yaml import yaml
@ -510,8 +509,7 @@ class BootInfo(encoding.SerializableComparable):
self.pxe_interface = pxe_interface self.pxe_interface = pxe_interface
@six.add_metaclass(abc.ABCMeta) class HardwareManager(object, metaclass=abc.ABCMeta):
class HardwareManager(object):
@abc.abstractmethod @abc.abstractmethod
def evaluate_hardware_support(self): def evaluate_hardware_support(self):
pass pass
@ -1865,11 +1863,8 @@ def _get_managers():
# There will always be at least one extension available (the # There will always be at least one extension available (the
# GenericHardwareManager). # GenericHardwareManager).
if six.PY2: extensions = sorted(extension_manager,
extensions = sorted(extension_manager, _compare_extensions) key=functools.cmp_to_key(_compare_extensions))
else:
extensions = sorted(extension_manager,
key=functools.cmp_to_key(_compare_extensions))
preferred_managers = [] preferred_managers = []

View File

@ -150,7 +150,7 @@ class TestStandbyExtension(base.IronicAgentTest):
expected_loc = os.path.join(tempfile.gettempdir(), 'fake_id') expected_loc = os.path.join(tempfile.gettempdir(), 'fake_id')
self.assertEqual(expected_loc, location) self.assertEqual(expected_loc, location)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('ironic_python_agent.utils.execute', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True)
def test_write_image(self, execute_mock, open_mock): def test_write_image(self, execute_mock, open_mock):
image_info = _build_fake_image_info() image_info = _build_fake_image_info()
@ -175,7 +175,7 @@ class TestStandbyExtension(base.IronicAgentTest):
execute_mock.assert_called_once_with(*command, check_exit_code=[0]) execute_mock.assert_called_once_with(*command, check_exit_code=[0])
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True) @mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('ironic_python_agent.utils.execute', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True)
@mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True) @mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True)
@mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True) @mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True)
@ -221,7 +221,7 @@ class TestStandbyExtension(base.IronicAgentTest):
cpu_arch=cpu_arch) cpu_arch=cpu_arch)
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True) @mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('ironic_python_agent.utils.execute', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True)
@mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True) @mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True)
@mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True) @mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True)
@ -271,7 +271,7 @@ class TestStandbyExtension(base.IronicAgentTest):
self.assertIsNone(node_uuid) self.assertIsNone(node_uuid)
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True) @mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('ironic_python_agent.utils.execute', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True)
@mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True) @mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True)
@mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True) @mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True)
@ -296,7 +296,7 @@ class TestStandbyExtension(base.IronicAgentTest):
self.assertFalse(work_on_disk_mock.called) self.assertFalse(work_on_disk_mock.called)
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True) @mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('ironic_python_agent.utils.execute', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True)
@mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True) @mock.patch('ironic_lib.disk_utils.work_on_disk', autospec=True)
@mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True) @mock.patch('ironic_lib.disk_utils.get_image_mb', autospec=True)
@ -340,7 +340,7 @@ class TestStandbyExtension(base.IronicAgentTest):
self.assertEqual(expected_uuid, work_on_disk_mock.return_value) self.assertEqual(expected_uuid, work_on_disk_mock.return_value)
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_download_image(self, requests_mock, open_mock, md5_mock): def test_download_image(self, requests_mock, open_mock, md5_mock):
image_info = _build_fake_image_info() image_info = _build_fake_image_info()
@ -363,7 +363,7 @@ class TestStandbyExtension(base.IronicAgentTest):
self.assertEqual(2, write.call_count) self.assertEqual(2, write.call_count)
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
@mock.patch.dict(os.environ, {}) @mock.patch.dict(os.environ, {})
def test_download_image_proxy( def test_download_image_proxy(
@ -403,7 +403,7 @@ class TestStandbyExtension(base.IronicAgentTest):
image_info) image_info)
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_download_image_verify_fails(self, requests_mock, open_mock, def test_download_image_verify_fails(self, requests_mock, open_mock,
md5_mock): md5_mock):
@ -417,7 +417,7 @@ class TestStandbyExtension(base.IronicAgentTest):
image_info) image_info)
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_verify_image_success(self, requests_mock, open_mock, md5_mock): def test_verify_image_success(self, requests_mock, open_mock, md5_mock):
image_info = _build_fake_image_info() image_info = _build_fake_image_info()
@ -430,7 +430,7 @@ class TestStandbyExtension(base.IronicAgentTest):
image_download.verify_image(image_location) image_download.verify_image(image_location)
@mock.patch('hashlib.new', autospec=True) @mock.patch('hashlib.new', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_verify_image_success_with_new_hash_fields(self, requests_mock, def test_verify_image_success_with_new_hash_fields(self, requests_mock,
open_mock, open_mock,
@ -448,7 +448,7 @@ class TestStandbyExtension(base.IronicAgentTest):
hashlib_mock.assert_called_with('sha512') hashlib_mock.assert_called_with('sha512')
@mock.patch('hashlib.new', autospec=True) @mock.patch('hashlib.new', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_verify_image_success_without_md5(self, requests_mock, def test_verify_image_success_without_md5(self, requests_mock,
open_mock, hashlib_mock): open_mock, hashlib_mock):
@ -466,7 +466,7 @@ class TestStandbyExtension(base.IronicAgentTest):
hashlib_mock.assert_called_with('sha512') hashlib_mock.assert_called_with('sha512')
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_verify_image_success_with_md5_fallback(self, requests_mock, def test_verify_image_success_with_md5_fallback(self, requests_mock,
open_mock, md5_mock): open_mock, md5_mock):
@ -482,7 +482,7 @@ class TestStandbyExtension(base.IronicAgentTest):
image_download.verify_image(image_location) image_download.verify_image(image_location)
@mock.patch('hashlib.new', autospec=True) @mock.patch('hashlib.new', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_verify_image_failure_with_new_hash_fields(self, requests_mock, def test_verify_image_failure_with_new_hash_fields(self, requests_mock,
open_mock, open_mock,
@ -502,7 +502,7 @@ class TestStandbyExtension(base.IronicAgentTest):
hashlib_mock.assert_called_with('sha512') hashlib_mock.assert_called_with('sha512')
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_verify_image_failure(self, requests_mock, open_mock, md5_mock): def test_verify_image_failure(self, requests_mock, open_mock, md5_mock):
image_info = _build_fake_image_info() image_info = _build_fake_image_info()
@ -517,7 +517,7 @@ class TestStandbyExtension(base.IronicAgentTest):
image_location) image_location)
@mock.patch('hashlib.new', autospec=True) @mock.patch('hashlib.new', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_verify_image_failure_without_fallback(self, requests_mock, def test_verify_image_failure_without_fallback(self, requests_mock,
open_mock, hashlib_mock): open_mock, hashlib_mock):
@ -1047,7 +1047,7 @@ class TestStandbyExtension(base.IronicAgentTest):
write_mock.assert_called_once_with(image_info, device) write_mock.assert_called_once_with(image_info, device)
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_stream_raw_image_onto_device(self, requests_mock, open_mock, def test_stream_raw_image_onto_device(self, requests_mock, open_mock,
md5_mock): md5_mock):
@ -1070,7 +1070,7 @@ class TestStandbyExtension(base.IronicAgentTest):
file_mock.write.assert_has_calls(expected_calls) file_mock.write.assert_has_calls(expected_calls)
@mock.patch('hashlib.md5', autospec=True) @mock.patch('hashlib.md5', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch('requests.get', autospec=True) @mock.patch('requests.get', autospec=True)
def test_stream_raw_image_onto_device_write_error(self, requests_mock, def test_stream_raw_image_onto_device_write_error(self, requests_mock,
open_mock, md5_mock): open_mock, md5_mock):

View File

@ -84,7 +84,7 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
mock_exists.return_value = True mock_exists.return_value = True
mock_listdir.return_value = ['foo', 'bar'] mock_listdir.return_value = ['foo', 'bar']
write_mock = mock.mock_open() write_mock = mock.mock_open()
with mock.patch('six.moves.builtins.open', write_mock, create=True): with mock.patch('builtins.open', write_mock, create=True):
cna._disable_embedded_lldp_agent_in_cna_card() cna._disable_embedded_lldp_agent_in_cna_card()
write_mock().write.assert_called_with('lldp stop') write_mock().write.assert_called_with('lldp stop')
self.assertFalse(mock_log.warning.called) self.assertFalse(mock_log.warning.called)
@ -107,7 +107,7 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
listdir_dict = ['foo', 'bar'] listdir_dict = ['foo', 'bar']
mock_listdir.return_value = listdir_dict mock_listdir.return_value = listdir_dict
write_mock = mock.mock_open() write_mock = mock.mock_open()
with mock.patch('six.moves.builtins.open', write_mock, create=True): with mock.patch('builtins.open', write_mock, create=True):
write_mock.side_effect = IOError('fake error') write_mock.side_effect = IOError('fake error')
cna._disable_embedded_lldp_agent_in_cna_card() cna._disable_embedded_lldp_agent_in_cna_card()
expected_log_message = ('Failed to disable the embedded LLDP on ' expected_log_message = ('Failed to disable the embedded LLDP on '

View File

@ -24,7 +24,6 @@ from oslo_concurrency import processutils
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import units from oslo_utils import units
import pyudev import pyudev
import six
from stevedore import extension from stevedore import extension
from ironic_python_agent import errors from ironic_python_agent import errors
@ -933,7 +932,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@mock.patch('netifaces.ifaddresses', autospec=True) @mock.patch('netifaces.ifaddresses', autospec=True)
@mock.patch('os.listdir', autospec=True) @mock.patch('os.listdir', autospec=True)
@mock.patch('os.path.exists', autospec=True) @mock.patch('os.path.exists', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True) @mock.patch.object(utils, 'execute', autospec=True)
@mock.patch.object(netutils, 'get_mac_addr', autospec=True) @mock.patch.object(netutils, 'get_mac_addr', autospec=True)
@mock.patch.object(netutils, 'interface_has_carrier', autospec=True) @mock.patch.object(netutils, 'interface_has_carrier', autospec=True)
@ -974,7 +973,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@mock.patch('netifaces.ifaddresses', autospec=True) @mock.patch('netifaces.ifaddresses', autospec=True)
@mock.patch('os.listdir', autospec=True) @mock.patch('os.listdir', autospec=True)
@mock.patch('os.path.exists', autospec=True) @mock.patch('os.path.exists', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True) @mock.patch.object(utils, 'execute', autospec=True)
@mock.patch.object(netutils, 'get_mac_addr', autospec=True) @mock.patch.object(netutils, 'get_mac_addr', autospec=True)
@mock.patch.object(netutils, 'interface_has_carrier', autospec=True) @mock.patch.object(netutils, 'interface_has_carrier', autospec=True)
@ -1067,7 +1066,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@mock.patch('netifaces.ifaddresses', autospec=True) @mock.patch('netifaces.ifaddresses', autospec=True)
@mock.patch('os.listdir', autospec=True) @mock.patch('os.listdir', autospec=True)
@mock.patch('os.path.exists', autospec=True) @mock.patch('os.path.exists', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True) @mock.patch.object(utils, 'execute', autospec=True)
@mock.patch.object(netutils, 'get_mac_addr', autospec=True) @mock.patch.object(netutils, 'get_mac_addr', autospec=True)
@mock.patch.object(netutils, 'interface_has_carrier', autospec=True) @mock.patch.object(netutils, 'interface_has_carrier', autospec=True)
@ -1125,7 +1124,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@mock.patch('netifaces.ifaddresses', autospec=True) @mock.patch('netifaces.ifaddresses', autospec=True)
@mock.patch('os.listdir', autospec=True) @mock.patch('os.listdir', autospec=True)
@mock.patch('os.path.exists', autospec=True) @mock.patch('os.path.exists', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True) @mock.patch.object(utils, 'execute', autospec=True)
def test_list_network_interfaces_with_lldp_error( def test_list_network_interfaces_with_lldp_error(
self, mocked_execute, mocked_open, mocked_exists, mocked_listdir, self, mocked_execute, mocked_open, mocked_exists, mocked_listdir,
@ -1161,7 +1160,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@mock.patch('netifaces.ifaddresses', autospec=True) @mock.patch('netifaces.ifaddresses', autospec=True)
@mock.patch('os.listdir', autospec=True) @mock.patch('os.listdir', autospec=True)
@mock.patch('os.path.exists', autospec=True) @mock.patch('os.path.exists', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True) @mock.patch.object(utils, 'execute', autospec=True)
@mock.patch.object(netutils, 'get_mac_addr', autospec=True) @mock.patch.object(netutils, 'get_mac_addr', autospec=True)
@mock.patch.object(netutils, 'interface_has_carrier', autospec=True) @mock.patch.object(netutils, 'interface_has_carrier', autospec=True)
@ -1203,7 +1202,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@mock.patch('netifaces.ifaddresses', autospec=True) @mock.patch('netifaces.ifaddresses', autospec=True)
@mock.patch('os.listdir', autospec=True) @mock.patch('os.listdir', autospec=True)
@mock.patch('os.path.exists', autospec=True) @mock.patch('os.path.exists', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True) @mock.patch.object(utils, 'execute', autospec=True)
@mock.patch.object(netutils, 'get_mac_addr', autospec=True) @mock.patch.object(netutils, 'get_mac_addr', autospec=True)
@mock.patch.object(netutils, 'interface_has_carrier', autospec=True) @mock.patch.object(netutils, 'interface_has_carrier', autospec=True)
@ -1414,7 +1413,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
def test__get_device_info(self): def test__get_device_info(self):
fileobj = mock.mock_open(read_data='fake-vendor') fileobj = mock.mock_open(read_data='fake-vendor')
with mock.patch( with mock.patch(
'six.moves.builtins.open', fileobj, create=True) as mock_open: 'builtins.open', fileobj, create=True) as mock_open:
vendor = hardware._get_device_info( vendor = hardware._get_device_info(
'/dev/sdfake', 'block', 'vendor') '/dev/sdfake', 'block', 'vendor')
mock_open.assert_called_once_with( mock_open.assert_called_once_with(
@ -1793,10 +1792,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
internal_info['disk_erasure_concurrency'] = 10 internal_info['disk_erasure_concurrency'] = 10
mocked_dispatch.return_value = 'erased device' mocked_dispatch.return_value = 'erased device'
if six.PY3: apply_result = multiprocessing.pool.ApplyResult({}, None, None)
apply_result = multiprocessing.pool.ApplyResult({}, None, None)
else:
apply_result = multiprocessing.pool.ApplyResult({}, None)
apply_result._success = True apply_result._success = True
apply_result._ready = True apply_result._ready = True
apply_result.get = lambda: 'erased device' apply_result.get = lambda: 'erased device'

View File

@ -341,7 +341,7 @@ class TestCollectPciDevicesInfo(base.IronicAgentTest):
{'vendor_id': '9876', 'product_id': '5432'}] {'vendor_id': '9876', 'product_id': '5432'}]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_read = mock_open.return_value.read mock_read = mock_open.return_value.read
mock_read.side_effect = reads mock_read.side_effect = reads
inspector.collect_pci_devices_info(self.data, self.failures) inspector.collect_pci_devices_info(self.data, self.failures)
@ -367,7 +367,7 @@ class TestCollectPciDevicesInfo(base.IronicAgentTest):
expected_pci_devices = [{'vendor_id': '1234', 'product_id': '5678'}] expected_pci_devices = [{'vendor_id': '1234', 'product_id': '5678'}]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_read = mock_open.return_value.read mock_read = mock_open.return_value.read
mock_read.side_effect = reads mock_read.side_effect = reads
inspector.collect_pci_devices_info(self.data, self.failures) inspector.collect_pci_devices_info(self.data, self.failures)

View File

@ -64,7 +64,7 @@ class TestCollectNumaTopologyInfo(base.IronicAgentTest):
"nics": [{'name': 'enp0s01', 'numa_node': 0}, "nics": [{'name': 'enp0s01', 'numa_node': 0},
{'name': 'enp0s02', 'numa_node': 1}]} {'name': 'enp0s02', 'numa_node': 1}]}
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
numa_insp.collect_numa_topology_info(self.data, self.failures) numa_insp.collect_numa_topology_info(self.data, self.failures)
self.assertEqual(expected_numa_info, self.data["numa_topology"]) self.assertEqual(expected_numa_info, self.data["numa_topology"])
@ -93,7 +93,7 @@ class TestCollectNumaTopologyInfo(base.IronicAgentTest):
'thread_siblings': [4, 5, 6]}] 'thread_siblings': [4, 5, 6]}]
mock_nics_info.side_effect = errors.IncompatibleNumaFormatError("") mock_nics_info.side_effect = errors.IncompatibleNumaFormatError("")
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
numa_insp.collect_numa_topology_info(self.data, self.failures) numa_insp.collect_numa_topology_info(self.data, self.failures)
self.assertNotIn("numa_topology", self.data) self.assertNotIn("numa_topology", self.data)
@ -150,7 +150,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
expected_meminfo = [{'numa_node': 0, 'size_kb': 1560000}, expected_meminfo = [{'numa_node': 0, 'size_kb': 1560000},
{'numa_node': 1, 'size_kb': 1200000}] {'numa_node': 1, 'size_kb': 1200000}]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_meminfo_file = mock.MagicMock() mock_meminfo_file = mock.MagicMock()
mock_meminfo_file.__enter__.side_effect = reads mock_meminfo_file.__enter__.side_effect = reads
mock_open.return_value = mock_meminfo_file mock_open.return_value = mock_meminfo_file
@ -164,7 +164,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
mock_node_id.side_effect = [0, 1] mock_node_id.side_effect = [0, 1]
reads = [['Node 0 MemTotal: 1560000 kB'], IOError] reads = [['Node 0 MemTotal: 1560000 kB'], IOError]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_meminfo_file = mock.MagicMock() mock_meminfo_file = mock.MagicMock()
mock_meminfo_file.__enter__.side_effect = reads mock_meminfo_file.__enter__.side_effect = reads
mock_open.return_value = mock_meminfo_file mock_open.return_value = mock_meminfo_file
@ -180,7 +180,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
reads = [['Node 0: MemTotal: 1560000 kB'], reads = [['Node 0: MemTotal: 1560000 kB'],
['Node 1 MemTotal: 1200000 kB']] ['Node 1 MemTotal: 1200000 kB']]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_meminfo_file = mock.MagicMock() mock_meminfo_file = mock.MagicMock()
mock_meminfo_file.__enter__.side_effect = reads mock_meminfo_file.__enter__.side_effect = reads
mock_open.return_value = mock_meminfo_file mock_open.return_value = mock_meminfo_file
@ -196,7 +196,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
reads = [['Node 0 MemTotal: 1560000 TB'], reads = [['Node 0 MemTotal: 1560000 TB'],
['Node 1 MemTotal: 1200000 kB']] ['Node 1 MemTotal: 1200000 kB']]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_meminfo_file = mock.MagicMock() mock_meminfo_file = mock.MagicMock()
mock_meminfo_file.__enter__.side_effect = reads mock_meminfo_file.__enter__.side_effect = reads
mock_open.return_value = mock_meminfo_file mock_open.return_value = mock_meminfo_file
@ -234,7 +234,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
{'cpu': 0, 'numa_node': 1, {'cpu': 0, 'numa_node': 1,
'thread_siblings': [5, 6, 7]}] 'thread_siblings': [5, 6, 7]}]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_core_id_file = mock_open.return_value.read mock_core_id_file = mock_open.return_value.read
mock_core_id_file.side_effect = reads mock_core_id_file.side_effect = reads
cpus = numa_insp.get_nodes_cores_info(numa_node_dirs) cpus = numa_insp.get_nodes_cores_info(numa_node_dirs)
@ -254,7 +254,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
mock_isdir.return_value = True mock_isdir.return_value = True
reads = ['0', '0', '1', '1', '1', IOError] reads = ['0', '0', '1', '1', '1', IOError]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_core_id_file = mock_open.return_value.read mock_core_id_file = mock_open.return_value.read
mock_core_id_file.side_effect = reads mock_core_id_file.side_effect = reads
self.assertRaises(errors.IncompatibleNumaFormatError, self.assertRaises(errors.IncompatibleNumaFormatError,
@ -283,7 +283,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
mock_isdir.return_value = True mock_isdir.return_value = True
reads = ['0', '0', '1', '1', '1', '2'] reads = ['0', '0', '1', '1', '1', '2']
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_core_id_file = mock_open.return_value.read mock_core_id_file = mock_open.return_value.read
mock_core_id_file.side_effect = reads mock_core_id_file.side_effect = reads
self.assertRaises(errors.IncompatibleNumaFormatError, self.assertRaises(errors.IncompatibleNumaFormatError,
@ -313,7 +313,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
expected_nicsinfo = [{'name': 'enp0s01', 'numa_node': 0}, expected_nicsinfo = [{'name': 'enp0s01', 'numa_node': 0},
{'name': 'enp0s02', 'numa_node': 1}] {'name': 'enp0s02', 'numa_node': 1}]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_nicsinfo_file = mock_open.return_value.read mock_nicsinfo_file = mock_open.return_value.read
mock_nicsinfo_file.side_effect = reads mock_nicsinfo_file.side_effect = reads
nics = numa_insp.get_nodes_nics_info('/sys/class/net/') nics = numa_insp.get_nodes_nics_info('/sys/class/net/')
@ -327,7 +327,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
mock_isdir.return_value = True mock_isdir.return_value = True
reads = ['0', IOError] reads = ['0', IOError]
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_nicsinfo_file = mock_open.return_value.read mock_nicsinfo_file = mock_open.return_value.read
mock_nicsinfo_file.side_effect = reads mock_nicsinfo_file.side_effect = reads
self.assertRaises(errors.IncompatibleNumaFormatError, self.assertRaises(errors.IncompatibleNumaFormatError,
@ -342,7 +342,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest):
mock_listdir.return_value = nic_dirs mock_listdir.return_value = nic_dirs
reads = ['0', '1'] reads = ['0', '1']
mock_open = mock.mock_open() mock_open = mock.mock_open()
with mock.patch('six.moves.builtins.open', mock_open): with mock.patch('builtins.open', mock_open):
mock_nicsinfo_file = mock_open.return_value.read mock_nicsinfo_file = mock_open.return_value.read
mock_nicsinfo_file.side_effect = reads mock_nicsinfo_file.side_effect = reads
self.assertRaises(errors.IncompatibleNumaFormatError, self.assertRaises(errors.IncompatibleNumaFormatError,

View File

@ -26,7 +26,6 @@ from ironic_lib import utils as ironic_utils
import mock import mock
from oslo_concurrency import processutils from oslo_concurrency import processutils
from oslo_serialization import base64 from oslo_serialization import base64
import six
import testtools import testtools
from ironic_python_agent import errors from ironic_python_agent import errors
@ -52,13 +51,13 @@ class ExecuteTestCase(ironic_agent_base.IronicAgentTest):
class GetAgentParamsTestCase(ironic_agent_base.IronicAgentTest): class GetAgentParamsTestCase(ironic_agent_base.IronicAgentTest):
@mock.patch('oslo_log.log.getLogger', autospec=True) @mock.patch('oslo_log.log.getLogger', autospec=True)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
def test__read_params_from_file_fail(self, logger_mock, open_mock): def test__read_params_from_file_fail(self, logger_mock, open_mock):
open_mock.side_effect = Exception open_mock.side_effect = Exception
params = utils._read_params_from_file('file-path') params = utils._read_params_from_file('file-path')
self.assertEqual({}, params) self.assertEqual({}, params)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
def test__read_params_from_file(self, open_mock): def test__read_params_from_file(self, open_mock):
kernel_line = 'api-url=http://localhost:9999 baz foo=bar\n' kernel_line = 'api-url=http://localhost:9999 baz foo=bar\n'
open_mock.return_value.__enter__ = lambda s: s open_mock.return_value.__enter__ = lambda s: s
@ -118,7 +117,7 @@ class GetAgentParamsTestCase(ironic_agent_base.IronicAgentTest):
self.assertEqual(expected_params, returned_params) self.assertEqual(expected_params, returned_params)
self.assertEqual(0, set_cache_mock.call_count) self.assertEqual(0, set_cache_mock.call_count)
@mock.patch('six.moves.builtins.open', autospec=True) @mock.patch('builtins.open', autospec=True)
@mock.patch.object(glob, 'glob', autospec=True) @mock.patch.object(glob, 'glob', autospec=True)
def test__get_vmedia_device(self, glob_mock, open_mock): def test__get_vmedia_device(self, glob_mock, open_mock):
@ -392,7 +391,7 @@ class TestUtils(testtools.TestCase):
contents = b'Squidward Tentacles' contents = b'Squidward Tentacles'
io_dict = {'fake-name': io.BytesIO(bytes(contents))} io_dict = {'fake-name': io.BytesIO(bytes(contents))}
data = utils.gzip_and_b64encode(io_dict=io_dict) data = utils.gzip_and_b64encode(io_dict=io_dict)
self.assertIsInstance(data, six.text_type) self.assertIsInstance(data, str)
res = io.BytesIO(base64.decode_as_bytes(data)) res = io.BytesIO(base64.decode_as_bytes(data))
with tarfile.open(fileobj=res) as tar: with tarfile.open(fileobj=res) as tar:

View File

@ -29,7 +29,6 @@ from oslo_concurrency import processutils
from oslo_log import log as logging from oslo_log import log as logging
from oslo_serialization import base64 from oslo_serialization import base64
from oslo_utils import units from oslo_utils import units
from six.moves.urllib import parse
from ironic_python_agent import errors from ironic_python_agent import errors
@ -231,17 +230,6 @@ def get_agent_params():
return copy.deepcopy(params) return copy.deepcopy(params)
def normalize(string):
"""Return a normalized string.
Take a urlencoded value from Ironic and urldecode it.
:param string: a urlencoded string
:returns: a normalized version of passed in string
"""
return parse.unquote(string).lower().strip()
class AccumulatedFailures(object): class AccumulatedFailures(object):
"""Object to accumulate failures without raising exception.""" """Object to accumulate failures without raising exception."""

View File

@ -80,7 +80,6 @@ rfc3986==1.1.0
Routes==2.4.1 Routes==2.4.1
rtslib-fb==2.1.65 rtslib-fb==2.1.65
simplegeneric==0.8.1 simplegeneric==0.8.1
six==1.10.0
snowballstemmer==1.2.1 snowballstemmer==1.2.1
Sphinx==1.6.2 Sphinx==1.6.2
sphinxcontrib-httpdomain==1.6.1 sphinxcontrib-httpdomain==1.6.1

View File

@ -18,7 +18,6 @@ psutil>=3.2.2 # BSD
pyudev>=0.18 # LGPLv2.1+ pyudev>=0.18 # LGPLv2.1+
requests>=2.14.2 # Apache-2.0 requests>=2.14.2 # Apache-2.0
rtslib-fb>=2.1.65 # Apache-2.0 rtslib-fb>=2.1.65 # Apache-2.0
six>=1.10.0 # MIT
stevedore>=1.20.0 # Apache-2.0 stevedore>=1.20.0 # Apache-2.0
WSME>=0.8.0 # MIT WSME>=0.8.0 # MIT
ironic-lib>=2.17.0 # Apache-2.0 ironic-lib>=2.17.0 # Apache-2.0