From b3665481de6a563e97286d5897d74222b571f650 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Tue, 14 Jan 2020 15:44:38 +0100 Subject: [PATCH] Stop using six library Since we've dropped support for Python 2.7 and we're going for Python 3.x only, we don't need the six library anymore. --- hardware/benchmark/cpu.py | 5 +--- hardware/benchmark/disk.py | 8 ++----- hardware/benchmark/mem.py | 8 ++----- hardware/generate.py | 7 ------ hardware/smart_utils.py | 13 +++------- hardware/tests/test_benchmark_cpu.py | 13 ---------- hardware/tests/test_benchmark_disk.py | 8 +------ hardware/tests/test_benchmark_mem.py | 34 --------------------------- hardware/tests/test_detect.py | 2 +- hardware/tests/test_smart_utils.py | 10 ++++---- requirements.txt | 1 - 11 files changed, 15 insertions(+), 94 deletions(-) diff --git a/hardware/benchmark/cpu.py b/hardware/benchmark/cpu.py index edb12830..99ef816a 100644 --- a/hardware/benchmark/cpu.py +++ b/hardware/benchmark/cpu.py @@ -21,8 +21,6 @@ import subprocess import sys -import six - from hardware.benchmark import utils @@ -51,8 +49,7 @@ def run_sysbench_cpu(hw_lst, max_time, cpu_count, processor_num=None): sysbench_cmd = subprocess.Popen(cmds, shell=True, stdout=subprocess.PIPE) for line in sysbench_cmd.stdout: - if isinstance(line, six.binary_type): - line = line.decode() + line = line.decode() if "total number of events" in line: line_ = line.rstrip('\n').replace(' ', '') _, perf = line_.split(':') diff --git a/hardware/benchmark/disk.py b/hardware/benchmark/disk.py index 92f779db..b8ae336b 100644 --- a/hardware/benchmark/disk.py +++ b/hardware/benchmark/disk.py @@ -23,8 +23,6 @@ import subprocess import sys -import six - # NOTE(lucasagomes): The amount of time a specified workload will run before # logging any performance numbers. Useful for letting performance settle @@ -44,8 +42,7 @@ def is_booted_storage_device(disk): grep_cmd = subprocess.Popen(cmdline, shell=True, stdout=subprocess.PIPE) for booted_disk in grep_cmd.stdout: - if isinstance(booted_disk, six.binary_type): - booted_disk = booted_disk.decode(errors='ignore') + booted_disk = booted_disk.decode(errors='ignore') booted_disk = booted_disk.rstrip('\n').strip() if booted_disk == disk: return True @@ -94,8 +91,7 @@ def run_fio(hw_lst, disks_list, mode, io_size, time, rampup_time): shell=True, stdout=subprocess.PIPE) current_disk = '' for line in fio_cmd.stdout: - if isinstance(line, six.binary_type): - line = line.decode(errors='ignore') + line = line.decode(errors='ignore') if ('MYJOB-' in line) and ('pid=' in line): # MYJOB-sda: (groupid=0, jobs=1): err= 0: pid=23652: Mon Sep 9 # 16:21:42 2013 diff --git a/hardware/benchmark/mem.py b/hardware/benchmark/mem.py index 1a30ba36..d94c4cd7 100644 --- a/hardware/benchmark/mem.py +++ b/hardware/benchmark/mem.py @@ -22,8 +22,6 @@ import subprocess import sys -import six - from hardware.benchmark import utils @@ -90,8 +88,7 @@ def run_sysbench_memory_threaded(hw_lst, max_time, block_size, cpu_count, shell=True, stdout=subprocess.PIPE) for line in sysbench_cmd.stdout: - if isinstance(line, six.binary_type): - line = line.decode() + line = line.decode() if "transferred" in line: _, right = line.rstrip('\n').replace(' ', '').split('(') perf, _ = right.split('.') @@ -129,8 +126,7 @@ def run_sysbench_memory_forked(hw_lst, max_time, block_size, cpu_count): process = subprocess.Popen( sysbench_cmd, shell=True, stdout=subprocess.PIPE) for line in process.stdout: - if isinstance(line, six.binary_type): - line = line.decode() + line = line.decode() if "transferred" in line: _, right = line.rstrip('\n').replace(' ', '').split('(') perf, _ = right.split('.') diff --git a/hardware/generate.py b/hardware/generate.py index 69a1bcee..5b4155f6 100644 --- a/hardware/generate.py +++ b/hardware/generate.py @@ -18,19 +18,12 @@ """Generate range of values according to a model.""" import re -import sys import types -from six.moves import range - _PREFIX = None -if sys.version_info.major: - xrange = range - - def _generate_range(num_range): """Generate number for range specified like 10-12:20-30.""" diff --git a/hardware/smart_utils.py b/hardware/smart_utils.py index 1f6cdd44..d9f05044 100644 --- a/hardware/smart_utils.py +++ b/hardware/smart_utils.py @@ -14,15 +14,11 @@ import subprocess import sys -import six - from hardware import smart_utils_info def _parse_line(line): - line = line.strip() - if isinstance(line, six.binary_type): - line = line.decode(errors='ignore') + line = line.strip().decode(errors='ignore') return line @@ -280,11 +276,8 @@ def read_smart_nvme(hwlst, device_name): shell=True, stdout=subprocess.PIPE) for line in sdparm_cmd.stdout: - line = line.strip() - if isinstance(line, six.binary_type): - line = line.decode(errors='ignore') - for disk_info, info_tag in six.iteritems( - smart_utils_info.NVME_INFOS): + line = line.strip().decode(errors='ignore') + for disk_info, info_tag in smart_utils_info.NVME_INFOS.items(): read_smart_field(hwlst, line, device_name, disk_info, info_tag) return hwlst diff --git a/hardware/tests/test_benchmark_cpu.py b/hardware/tests/test_benchmark_cpu.py index aad52a3d..a8a8a48e 100644 --- a/hardware/tests/test_benchmark_cpu.py +++ b/hardware/tests/test_benchmark_cpu.py @@ -99,16 +99,3 @@ def test_run_sysbench_cpu_bytes(self, mock_popen, mock_cpu_socket, '--cpu-max-prime=15000 run', shell=True, stdout=subprocess.PIPE) self.assertEqual([('cpu', 'logical', 'loops_per_sec', '123')], hw_data) - - def test_run_sysbench_cpu_text(self, mock_popen, mock_cpu_socket, - mock_search_info): - mock_popen.return_value = mock.Mock( - stdout=SYSBENCH_OUTPUT.splitlines()) - hw_data = [] - cpu.run_sysbench_cpu(hw_data, 10, 1) - mock_popen.assert_called_once_with(' sysbench --max-time=10 ' - '--max-requests=10000000 ' - '--num-threads=1 --test=cpu ' - '--cpu-max-prime=15000 run', - shell=True, stdout=subprocess.PIPE) - self.assertEqual([('cpu', 'logical', 'loops_per_sec', '123')], hw_data) diff --git a/hardware/tests/test_benchmark_disk.py b/hardware/tests/test_benchmark_disk.py index 3c1f6eb0..ab3b6083 100644 --- a/hardware/tests/test_benchmark_disk.py +++ b/hardware/tests/test_benchmark_disk.py @@ -52,12 +52,6 @@ def setUp(self): self.hw_data = [('disk', 'fake-disk', 'size', '10'), ('disk', 'fake-disk2', 'size', '15')] - def test_disk_perf_text(self, mock_popen): - mock_popen.return_value = mock.Mock( - stdout=FIO_OUTPUT_READ.splitlines()) - disk.disk_perf(self.hw_data) - self.assertEqual(sorted(DISK_PERF_EXPECTED), sorted(self.hw_data)) - def test_disk_perf_bytes(self, mock_popen): mock_popen.return_value = mock.Mock( stdout=FIO_OUTPUT_READ.encode().splitlines()) @@ -70,7 +64,7 @@ def test_get_disks_name(self, mock_popen): def test_run_fio(self, mock_popen): mock_popen.return_value = mock.Mock( - stdout=FIO_OUTPUT_READ.splitlines()) + stdout=FIO_OUTPUT_READ.encode().splitlines()) hw_data = [] disks_list = ['fake-disk', 'fake-disk2'] disk.run_fio(hw_data, disks_list, "read", 123, 10, 5) diff --git a/hardware/tests/test_benchmark_mem.py b/hardware/tests/test_benchmark_mem.py index 445a4c50..a3223868 100644 --- a/hardware/tests/test_benchmark_mem.py +++ b/hardware/tests/test_benchmark_mem.py @@ -98,17 +98,6 @@ def test_mem_perf_bytes(self, mock_popen, mock_cpu_socket, expected = EXPECTED_RESULT self.assertEqual(sorted(expected), sorted(self.hw_data)) - def test_mem_perf_text(self, mock_popen, mock_cpu_socket, - mock_get_memory): - mock_get_memory.return_value = 123456789012 - mock_popen.return_value = mock.Mock( - stdout=SYSBENCH_OUTPUT.splitlines()) - mock_cpu_socket.return_value = range(2) - mem.mem_perf(self.hw_data) - - expected = EXPECTED_RESULT - self.assertEqual(sorted(expected), sorted(self.hw_data)) - def test_check_mem_size(self, mock_popen, mock_cpu_socket, mock_get_memory): block_size_list = ('1K', '4K', '1M', '16M', '128M', '1G', '2G') @@ -122,17 +111,6 @@ def test_check_mem_size(self, mock_popen, mock_cpu_socket, for block_size in block_size_list: self.assertFalse(mem.check_mem_size(block_size, 2)) - def test_run_sysbench_memory_forked_text(self, mock_popen, mock_cpu_socket, - mock_get_memory): - mock_get_memory.return_value = 123456789012 - mock_popen.return_value = mock.Mock( - stdout=SYSBENCH_OUTPUT.splitlines()) - - hw_data = [] - mem.run_sysbench_memory_forked(hw_data, 10, '1K', 2) - self.assertEqual([('cpu', 'logical', 'forked_bandwidth_1K', '382')], - hw_data) - def test_run_sysbench_memory_forked_bytes(self, mock_popen, mock_cpu_socket, mock_get_memory): @@ -145,18 +123,6 @@ def test_run_sysbench_memory_forked_bytes(self, mock_popen, self.assertEqual([('cpu', 'logical', 'forked_bandwidth_1K', '382')], hw_data) - def test_run_sysbench_memory_threaded_text(self, mock_popen, - mock_cpu_socket, - mock_get_memory): - mock_get_memory.return_value = 123456789012 - mock_popen.return_value = mock.Mock( - stdout=SYSBENCH_OUTPUT.splitlines()) - - hw_data = [] - mem.run_sysbench_memory_threaded(hw_data, 10, '1K', 2) - self.assertEqual([('cpu', 'logical', 'threaded_bandwidth_1K', '382')], - hw_data) - def test_run_sysbench_memory_threaded_bytes(self, mock_popen, mock_cpu_socket, mock_get_memory): diff --git a/hardware/tests/test_detect.py b/hardware/tests/test_detect.py index 8ddbf39f..bb641595 100644 --- a/hardware/tests/test_detect.py +++ b/hardware/tests/test_detect.py @@ -303,7 +303,7 @@ def test_get_uuid_x86_64(self, mock_uname, mock_popen): def test_get_uuid_ppc64le_ok_generate(self, mock_access, mock_uname): expected_uuid = 'a2724b67-c27e-5e5f-aa2b-3089a2bd8f41' fileobj = mock.mock_open(read_data=expected_uuid) - with mock.patch('six.moves.builtins.open', fileobj, create=True): + with mock.patch('builtins.open', fileobj, create=True): uuid = detect.get_uuid([]) self.assertEqual(expected_uuid, uuid) diff --git a/hardware/tests/test_smart_utils.py b/hardware/tests/test_smart_utils.py index 3db59b91..e3990f17 100644 --- a/hardware/tests/test_smart_utils.py +++ b/hardware/tests/test_smart_utils.py @@ -82,7 +82,7 @@ def test_read_smart_scsi_error_log(self): @mock.patch.object(subprocess, 'Popen') def test_read_smart_scsi(self, mock_popen): hwlst = [] - fake_output = sample('smartctl_scsi').splitlines() + fake_output = sample('smartctl_scsi', mode='rb').splitlines() mock_popen.return_value = mock.Mock(stdout=fake_output) smart_utils.read_smart_scsi(hwlst, 'fake') @@ -91,7 +91,7 @@ def test_read_smart_scsi(self, mock_popen): @mock.patch.object(subprocess, 'Popen') def test_read_smart_ata(self, mock_popen): hwlst = [] - fake_output = sample('smartctl_ata').splitlines() + fake_output = sample('smartctl_ata', mode='rb').splitlines() mock_popen.return_value = mock.Mock(stdout=fake_output) smart_utils.read_smart_ata(hwlst, 'fake') @@ -113,7 +113,7 @@ def test_read_smart_ata_decode_ignore(self, mock_popen): def test_read_smart_call_smart_ata(self, mock_popen, mock_os_path_exists, mock_ata): hwlst = [] - fake_output = sample('smartctl_ata').splitlines() + fake_output = sample('smartctl_ata', mode='rb').splitlines() mock_popen.return_value = mock.Mock(stdout=fake_output) smart_utils.read_smart(hwlst, 'fake') @@ -125,7 +125,7 @@ def test_read_smart_call_smart_ata(self, mock_popen, mock_os_path_exists, def test_read_smart_call_smart_scsi(self, mock_popen, mock_os_path_exists, mock_scsi): hwlst = [] - fake_output = sample('smartctl_scsi').splitlines() + fake_output = sample('smartctl_scsi', mode='rb').splitlines() mock_popen.return_value = mock.Mock(stdout=fake_output) smart_utils.read_smart(hwlst, 'fake') @@ -135,7 +135,7 @@ def test_read_smart_call_smart_scsi(self, mock_popen, mock_os_path_exists, @mock.patch.object(subprocess, 'Popen') def test_read_smart_nvme(self, mock_popen, mock_os_path_exists): hwlst = [] - fake_output = sample('smartctl_nvme').splitlines() + fake_output = sample('smartctl_nvme', mode='rb').splitlines() mock_popen.return_value = mock.Mock(stdout=fake_output) smart_utils.read_smart_nvme(hwlst, 'fake_nvme') diff --git a/requirements.txt b/requirements.txt index f3c27add..93f1c4f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ # process, which may cause wedges in the gate later. pbr>=1.0 # Apache-2.0 -six # MIT ipaddress # PSF netaddr # BSD pexpect # ISC