From ca7a46b113c64edd87bfa7b9f56fdb97a0c96dd6 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Thu, 28 Nov 2019 17:10:40 +0100 Subject: [PATCH] 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 --- ironic_python_agent/agent.py | 2 +- .../api/controllers/v1/base.py | 3 +- ironic_python_agent/extensions/base.py | 10 +++--- ironic_python_agent/extensions/standby.py | 13 ++++--- ironic_python_agent/hardware.py | 11 ++---- .../tests/unit/extensions/test_standby.py | 34 +++++++++---------- .../tests/unit/hardware_managers/test_cna.py | 4 +-- .../tests/unit/test_hardware.py | 20 +++++------ .../tests/unit/test_inspector.py | 4 +-- .../tests/unit/test_numa_inspector.py | 24 ++++++------- ironic_python_agent/tests/unit/test_utils.py | 9 +++-- ironic_python_agent/utils.py | 12 ------- lower-constraints.txt | 1 - requirements.txt | 1 - 14 files changed, 60 insertions(+), 88 deletions(-) diff --git a/ironic_python_agent/agent.py b/ironic_python_agent/agent.py index c9fe2acc1..b8f3c44d3 100644 --- a/ironic_python_agent/agent.py +++ b/ironic_python_agent/agent.py @@ -19,6 +19,7 @@ import select import socket import threading import time +from urllib import parse as urlparse from wsgiref import simple_server from ironic_lib import exception as lib_exc @@ -29,7 +30,6 @@ from oslo_config import cfg from oslo_log import log from oslo_utils import netutils import pkg_resources -from six.moves.urllib import parse as urlparse from stevedore import extension from ironic_python_agent.api import app diff --git a/ironic_python_agent/api/controllers/v1/base.py b/ironic_python_agent/api/controllers/v1/base.py index b221124d0..c3644efaf 100644 --- a/ironic_python_agent/api/controllers/v1/base.py +++ b/ironic_python_agent/api/controllers/v1/base.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six from wsme import types as wtypes @@ -67,7 +66,7 @@ class MultiType(wtypes.UserType): 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): diff --git a/ironic_python_agent/extensions/base.py b/ironic_python_agent/extensions/base.py index a23e2f315..69f113517 100644 --- a/ironic_python_agent/extensions/base.py +++ b/ironic_python_agent/extensions/base.py @@ -19,7 +19,6 @@ import threading from oslo_log import log from oslo_utils import uuidutils -import six from ironic_python_agent import encoding from ironic_python_agent import errors @@ -90,8 +89,7 @@ class SyncCommandResult(BaseCommandResult): super(SyncCommandResult, self).__init__(command_name, command_params) - - if isinstance(result_or_error, (bytes, six.text_type)): + if isinstance(result_or_error, (bytes, str)): result_key = 'result' if success else 'error' result_or_error = {result_key: result_or_error} @@ -159,7 +157,7 @@ class AsyncCommandResult(BaseCommandResult): try: 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)} LOG.info('Command: %(name)s, result: %(result)s', {'name': self.command_name, 'result': result}) @@ -282,7 +280,7 @@ def async_command(command_name, validator=None): def async_decorator(func): func.command_name = command_name - @six.wraps(func) + @functools.wraps(func) def wrapper(self, **command_params): # Run a validator before passing everything off to async. # validators should raise exceptions or return silently. @@ -311,7 +309,7 @@ def sync_command(command_name, validator=None): def sync_decorator(func): func.command_name = command_name - @six.wraps(func) + @functools.wraps(func) def wrapper(self, **command_params): # Run a validator before invoking the function. # validators should raise exceptions or return silently. diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py index dd19c2005..7b911ead0 100644 --- a/ironic_python_agent/extensions/standby.py +++ b/ironic_python_agent/extensions/standby.py @@ -16,6 +16,7 @@ import hashlib import os import tempfile import time +from urllib import parse as urlparse from ironic_lib import disk_utils from ironic_lib import exception @@ -23,8 +24,6 @@ from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log import requests -import six -from six.moves.urllib import parse as urlparse from ironic_python_agent import errors from ironic_python_agent.extensions import base @@ -97,8 +96,8 @@ def _fetch_checksum(checksum, image_info): return lines[0] # FIXME(dtantsur): can we assume the same name for all images? - expected_fname = os.path.basename( - urlparse.urlparse(image_info['urls'][0]).path) + expected_fname = os.path.basename(urlparse.urlparse( + image_info['urls'][0]).path) for line in lines: checksum, fname = line.strip().split(None, 1) # 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.') 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']): raise errors.InvalidCommandParamsError( '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_value = image_info.get('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): raise errors.InvalidCommandParamsError( '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): raise errors.InvalidCommandParamsError( 'Image \'os_hash_value\' must be a non-empty string.') diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index 79f7ac8f6..c7911f398 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -31,7 +31,6 @@ from oslo_log import log import pint import psutil import pyudev -import six import stevedore import yaml @@ -510,8 +509,7 @@ class BootInfo(encoding.SerializableComparable): self.pxe_interface = pxe_interface -@six.add_metaclass(abc.ABCMeta) -class HardwareManager(object): +class HardwareManager(object, metaclass=abc.ABCMeta): @abc.abstractmethod def evaluate_hardware_support(self): pass @@ -1865,11 +1863,8 @@ def _get_managers(): # There will always be at least one extension available (the # GenericHardwareManager). - if six.PY2: - extensions = sorted(extension_manager, _compare_extensions) - else: - extensions = sorted(extension_manager, - key=functools.cmp_to_key(_compare_extensions)) + extensions = sorted(extension_manager, + key=functools.cmp_to_key(_compare_extensions)) preferred_managers = [] diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py index 9682aef5d..6a2fa4408 100644 --- a/ironic_python_agent/tests/unit/extensions/test_standby.py +++ b/ironic_python_agent/tests/unit/extensions/test_standby.py @@ -150,7 +150,7 @@ class TestStandbyExtension(base.IronicAgentTest): expected_loc = os.path.join(tempfile.gettempdir(), 'fake_id') 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) def test_write_image(self, execute_mock, open_mock): 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]) @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_lib.disk_utils.get_image_mb', 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) @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_lib.disk_utils.get_image_mb', 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) @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_lib.disk_utils.get_image_mb', 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) @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_lib.disk_utils.work_on_disk', 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) @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) def test_download_image(self, requests_mock, open_mock, md5_mock): image_info = _build_fake_image_info() @@ -363,7 +363,7 @@ class TestStandbyExtension(base.IronicAgentTest): self.assertEqual(2, write.call_count) @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.dict(os.environ, {}) def test_download_image_proxy( @@ -403,7 +403,7 @@ class TestStandbyExtension(base.IronicAgentTest): image_info) @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) def test_download_image_verify_fails(self, requests_mock, open_mock, md5_mock): @@ -417,7 +417,7 @@ class TestStandbyExtension(base.IronicAgentTest): image_info) @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) def test_verify_image_success(self, requests_mock, open_mock, md5_mock): image_info = _build_fake_image_info() @@ -430,7 +430,7 @@ class TestStandbyExtension(base.IronicAgentTest): image_download.verify_image(image_location) @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) def test_verify_image_success_with_new_hash_fields(self, requests_mock, open_mock, @@ -448,7 +448,7 @@ class TestStandbyExtension(base.IronicAgentTest): hashlib_mock.assert_called_with('sha512') @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) def test_verify_image_success_without_md5(self, requests_mock, open_mock, hashlib_mock): @@ -466,7 +466,7 @@ class TestStandbyExtension(base.IronicAgentTest): hashlib_mock.assert_called_with('sha512') @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) def test_verify_image_success_with_md5_fallback(self, requests_mock, open_mock, md5_mock): @@ -482,7 +482,7 @@ class TestStandbyExtension(base.IronicAgentTest): image_download.verify_image(image_location) @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) def test_verify_image_failure_with_new_hash_fields(self, requests_mock, open_mock, @@ -502,7 +502,7 @@ class TestStandbyExtension(base.IronicAgentTest): hashlib_mock.assert_called_with('sha512') @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) def test_verify_image_failure(self, requests_mock, open_mock, md5_mock): image_info = _build_fake_image_info() @@ -517,7 +517,7 @@ class TestStandbyExtension(base.IronicAgentTest): image_location) @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) def test_verify_image_failure_without_fallback(self, requests_mock, open_mock, hashlib_mock): @@ -1047,7 +1047,7 @@ class TestStandbyExtension(base.IronicAgentTest): write_mock.assert_called_once_with(image_info, device) @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) def test_stream_raw_image_onto_device(self, requests_mock, open_mock, md5_mock): @@ -1070,7 +1070,7 @@ class TestStandbyExtension(base.IronicAgentTest): file_mock.write.assert_has_calls(expected_calls) @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) def test_stream_raw_image_onto_device_write_error(self, requests_mock, open_mock, md5_mock): diff --git a/ironic_python_agent/tests/unit/hardware_managers/test_cna.py b/ironic_python_agent/tests/unit/hardware_managers/test_cna.py index 3253ad4cf..0f3af3a2f 100644 --- a/ironic_python_agent/tests/unit/hardware_managers/test_cna.py +++ b/ironic_python_agent/tests/unit/hardware_managers/test_cna.py @@ -84,7 +84,7 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest): mock_exists.return_value = True mock_listdir.return_value = ['foo', 'bar'] 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() write_mock().write.assert_called_with('lldp stop') self.assertFalse(mock_log.warning.called) @@ -107,7 +107,7 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest): listdir_dict = ['foo', 'bar'] mock_listdir.return_value = listdir_dict 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') cna._disable_embedded_lldp_agent_in_cna_card() expected_log_message = ('Failed to disable the embedded LLDP on ' diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index 1caa0d935..e1ae2cc58 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -24,7 +24,6 @@ from oslo_concurrency import processutils from oslo_config import cfg from oslo_utils import units import pyudev -import six from stevedore import extension from ironic_python_agent import errors @@ -933,7 +932,7 @@ class TestGenericHardwareManager(base.IronicAgentTest): @mock.patch('netifaces.ifaddresses', autospec=True) @mock.patch('os.listdir', 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(netutils, 'get_mac_addr', 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('os.listdir', 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(netutils, 'get_mac_addr', 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('os.listdir', 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(netutils, 'get_mac_addr', 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('os.listdir', 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) def test_list_network_interfaces_with_lldp_error( 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('os.listdir', 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(netutils, 'get_mac_addr', 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('os.listdir', 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(netutils, 'get_mac_addr', 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): fileobj = mock.mock_open(read_data='fake-vendor') 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( '/dev/sdfake', 'block', 'vendor') mock_open.assert_called_once_with( @@ -1793,10 +1792,7 @@ class TestGenericHardwareManager(base.IronicAgentTest): internal_info['disk_erasure_concurrency'] = 10 mocked_dispatch.return_value = 'erased device' - if six.PY3: - apply_result = multiprocessing.pool.ApplyResult({}, None, None) - else: - apply_result = multiprocessing.pool.ApplyResult({}, None) + apply_result = multiprocessing.pool.ApplyResult({}, None, None) apply_result._success = True apply_result._ready = True apply_result.get = lambda: 'erased device' diff --git a/ironic_python_agent/tests/unit/test_inspector.py b/ironic_python_agent/tests/unit/test_inspector.py index 10f9f9e41..978ce971b 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -341,7 +341,7 @@ class TestCollectPciDevicesInfo(base.IronicAgentTest): {'vendor_id': '9876', 'product_id': '5432'}] 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.side_effect = reads 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'}] 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.side_effect = reads inspector.collect_pci_devices_info(self.data, self.failures) diff --git a/ironic_python_agent/tests/unit/test_numa_inspector.py b/ironic_python_agent/tests/unit/test_numa_inspector.py index 0d3163403..1bd8df45c 100644 --- a/ironic_python_agent/tests/unit/test_numa_inspector.py +++ b/ironic_python_agent/tests/unit/test_numa_inspector.py @@ -64,7 +64,7 @@ class TestCollectNumaTopologyInfo(base.IronicAgentTest): "nics": [{'name': 'enp0s01', 'numa_node': 0}, {'name': 'enp0s02', 'numa_node': 1}]} 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) self.assertEqual(expected_numa_info, self.data["numa_topology"]) @@ -93,7 +93,7 @@ class TestCollectNumaTopologyInfo(base.IronicAgentTest): 'thread_siblings': [4, 5, 6]}] mock_nics_info.side_effect = errors.IncompatibleNumaFormatError("") 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) self.assertNotIn("numa_topology", self.data) @@ -150,7 +150,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): expected_meminfo = [{'numa_node': 0, 'size_kb': 1560000}, {'numa_node': 1, 'size_kb': 1200000}] 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.__enter__.side_effect = reads mock_open.return_value = mock_meminfo_file @@ -164,7 +164,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): mock_node_id.side_effect = [0, 1] reads = [['Node 0 MemTotal: 1560000 kB'], IOError] 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.__enter__.side_effect = reads mock_open.return_value = mock_meminfo_file @@ -180,7 +180,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): reads = [['Node 0: MemTotal: 1560000 kB'], ['Node 1 MemTotal: 1200000 kB']] 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.__enter__.side_effect = reads mock_open.return_value = mock_meminfo_file @@ -196,7 +196,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): reads = [['Node 0 MemTotal: 1560000 TB'], ['Node 1 MemTotal: 1200000 kB']] 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.__enter__.side_effect = reads mock_open.return_value = mock_meminfo_file @@ -234,7 +234,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): {'cpu': 0, 'numa_node': 1, 'thread_siblings': [5, 6, 7]}] 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.side_effect = reads cpus = numa_insp.get_nodes_cores_info(numa_node_dirs) @@ -254,7 +254,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): mock_isdir.return_value = True reads = ['0', '0', '1', '1', '1', IOError] 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.side_effect = reads self.assertRaises(errors.IncompatibleNumaFormatError, @@ -283,7 +283,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): mock_isdir.return_value = True reads = ['0', '0', '1', '1', '1', '2'] 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.side_effect = reads self.assertRaises(errors.IncompatibleNumaFormatError, @@ -313,7 +313,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): expected_nicsinfo = [{'name': 'enp0s01', 'numa_node': 0}, {'name': 'enp0s02', 'numa_node': 1}] 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.side_effect = reads nics = numa_insp.get_nodes_nics_info('/sys/class/net/') @@ -327,7 +327,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): mock_isdir.return_value = True reads = ['0', IOError] 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.side_effect = reads self.assertRaises(errors.IncompatibleNumaFormatError, @@ -342,7 +342,7 @@ class TestGetNumaTopologyInfo(base.IronicAgentTest): mock_listdir.return_value = nic_dirs reads = ['0', '1'] 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.side_effect = reads self.assertRaises(errors.IncompatibleNumaFormatError, diff --git a/ironic_python_agent/tests/unit/test_utils.py b/ironic_python_agent/tests/unit/test_utils.py index 4ee0ebd39..5b3138462 100644 --- a/ironic_python_agent/tests/unit/test_utils.py +++ b/ironic_python_agent/tests/unit/test_utils.py @@ -26,7 +26,6 @@ from ironic_lib import utils as ironic_utils import mock from oslo_concurrency import processutils from oslo_serialization import base64 -import six import testtools from ironic_python_agent import errors @@ -52,13 +51,13 @@ class ExecuteTestCase(ironic_agent_base.IronicAgentTest): class GetAgentParamsTestCase(ironic_agent_base.IronicAgentTest): @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): open_mock.side_effect = Exception params = utils._read_params_from_file('file-path') 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): kernel_line = 'api-url=http://localhost:9999 baz foo=bar\n' 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(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) def test__get_vmedia_device(self, glob_mock, open_mock): @@ -392,7 +391,7 @@ class TestUtils(testtools.TestCase): contents = b'Squidward Tentacles' io_dict = {'fake-name': io.BytesIO(bytes(contents))} 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)) with tarfile.open(fileobj=res) as tar: diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py index 0257cfb1a..639b6f215 100644 --- a/ironic_python_agent/utils.py +++ b/ironic_python_agent/utils.py @@ -29,7 +29,6 @@ from oslo_concurrency import processutils from oslo_log import log as logging from oslo_serialization import base64 from oslo_utils import units -from six.moves.urllib import parse from ironic_python_agent import errors @@ -231,17 +230,6 @@ def get_agent_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): """Object to accumulate failures without raising exception.""" diff --git a/lower-constraints.txt b/lower-constraints.txt index a87dcc8ff..8c0f260b2 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -80,7 +80,6 @@ rfc3986==1.1.0 Routes==2.4.1 rtslib-fb==2.1.65 simplegeneric==0.8.1 -six==1.10.0 snowballstemmer==1.2.1 Sphinx==1.6.2 sphinxcontrib-httpdomain==1.6.1 diff --git a/requirements.txt b/requirements.txt index f8c4bb80b..e64620659 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,6 @@ psutil>=3.2.2 # BSD pyudev>=0.18 # LGPLv2.1+ requests>=2.14.2 # Apache-2.0 rtslib-fb>=2.1.65 # Apache-2.0 -six>=1.10.0 # MIT stevedore>=1.20.0 # Apache-2.0 WSME>=0.8.0 # MIT ironic-lib>=2.17.0 # Apache-2.0