Skip to content

Commit b3ca1b4

Browse files
authored
Merge pull request #123 from elfosardo/goodbye-six
Stop using six library
2 parents cb4c25b + 1d53aee commit b3ca1b4

File tree

11 files changed

+15
-94
lines changed

11 files changed

+15
-94
lines changed

hardware/benchmark/cpu.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import subprocess
2222
import sys
2323

24-
import six
25-
2624
from hardware.benchmark import utils
2725

2826

@@ -51,8 +49,7 @@ def run_sysbench_cpu(hw_lst, max_time, cpu_count, processor_num=None):
5149
sysbench_cmd = subprocess.Popen(cmds, shell=True, stdout=subprocess.PIPE)
5250

5351
for line in sysbench_cmd.stdout:
54-
if isinstance(line, six.binary_type):
55-
line = line.decode()
52+
line = line.decode()
5653
if "total number of events" in line:
5754
line_ = line.rstrip('\n').replace(' ', '')
5855
_, perf = line_.split(':')

hardware/benchmark/disk.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import subprocess
2424
import sys
2525

26-
import six
27-
2826

2927
# NOTE(lucasagomes): The amount of time a specified workload will run before
3028
# logging any performance numbers. Useful for letting performance settle
@@ -44,8 +42,7 @@ def is_booted_storage_device(disk):
4442
grep_cmd = subprocess.Popen(cmdline,
4543
shell=True, stdout=subprocess.PIPE)
4644
for booted_disk in grep_cmd.stdout:
47-
if isinstance(booted_disk, six.binary_type):
48-
booted_disk = booted_disk.decode(errors='ignore')
45+
booted_disk = booted_disk.decode(errors='ignore')
4946
booted_disk = booted_disk.rstrip('\n').strip()
5047
if booted_disk == disk:
5148
return True
@@ -94,8 +91,7 @@ def run_fio(hw_lst, disks_list, mode, io_size, time, rampup_time):
9491
shell=True, stdout=subprocess.PIPE)
9592
current_disk = ''
9693
for line in fio_cmd.stdout:
97-
if isinstance(line, six.binary_type):
98-
line = line.decode(errors='ignore')
94+
line = line.decode(errors='ignore')
9995
if ('MYJOB-' in line) and ('pid=' in line):
10096
# MYJOB-sda: (groupid=0, jobs=1): err= 0: pid=23652: Mon Sep 9
10197
# 16:21:42 2013

hardware/benchmark/mem.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import subprocess
2323
import sys
2424

25-
import six
26-
2725
from hardware.benchmark import utils
2826

2927

@@ -90,8 +88,7 @@ def run_sysbench_memory_threaded(hw_lst, max_time, block_size, cpu_count,
9088
shell=True, stdout=subprocess.PIPE)
9189

9290
for line in sysbench_cmd.stdout:
93-
if isinstance(line, six.binary_type):
94-
line = line.decode()
91+
line = line.decode()
9592
if "transferred" in line:
9693
_, right = line.rstrip('\n').replace(' ', '').split('(')
9794
perf, _ = right.split('.')
@@ -129,8 +126,7 @@ def run_sysbench_memory_forked(hw_lst, max_time, block_size, cpu_count):
129126
process = subprocess.Popen(
130127
sysbench_cmd, shell=True, stdout=subprocess.PIPE)
131128
for line in process.stdout:
132-
if isinstance(line, six.binary_type):
133-
line = line.decode()
129+
line = line.decode()
134130
if "transferred" in line:
135131
_, right = line.rstrip('\n').replace(' ', '').split('(')
136132
perf, _ = right.split('.')

hardware/generate.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@
1818
"""Generate range of values according to a model."""
1919

2020
import re
21-
import sys
2221
import types
2322

24-
from six.moves import range
25-
2623

2724
_PREFIX = None
2825

2926

30-
if sys.version_info.major:
31-
xrange = range
32-
33-
3427
def _generate_range(num_range):
3528
"""Generate number for range specified like 10-12:20-30."""
3629

hardware/smart_utils.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
import subprocess
1515
import sys
1616

17-
import six
18-
1917
from hardware import smart_utils_info
2018

2119

2220
def _parse_line(line):
23-
line = line.strip()
24-
if isinstance(line, six.binary_type):
25-
line = line.decode(errors='ignore')
21+
line = line.strip().decode(errors='ignore')
2622
return line
2723

2824

@@ -280,11 +276,8 @@ def read_smart_nvme(hwlst, device_name):
280276
shell=True, stdout=subprocess.PIPE)
281277

282278
for line in sdparm_cmd.stdout:
283-
line = line.strip()
284-
if isinstance(line, six.binary_type):
285-
line = line.decode(errors='ignore')
286-
for disk_info, info_tag in six.iteritems(
287-
smart_utils_info.NVME_INFOS):
279+
line = line.strip().decode(errors='ignore')
280+
for disk_info, info_tag in smart_utils_info.NVME_INFOS.items():
288281
read_smart_field(hwlst, line, device_name, disk_info, info_tag)
289282
return hwlst
290283

hardware/tests/test_benchmark_cpu.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,3 @@ def test_run_sysbench_cpu_bytes(self, mock_popen, mock_cpu_socket,
9999
'--cpu-max-prime=15000 run',
100100
shell=True, stdout=subprocess.PIPE)
101101
self.assertEqual([('cpu', 'logical', 'loops_per_sec', '123')], hw_data)
102-
103-
def test_run_sysbench_cpu_text(self, mock_popen, mock_cpu_socket,
104-
mock_search_info):
105-
mock_popen.return_value = mock.Mock(
106-
stdout=SYSBENCH_OUTPUT.splitlines())
107-
hw_data = []
108-
cpu.run_sysbench_cpu(hw_data, 10, 1)
109-
mock_popen.assert_called_once_with(' sysbench --max-time=10 '
110-
'--max-requests=10000000 '
111-
'--num-threads=1 --test=cpu '
112-
'--cpu-max-prime=15000 run',
113-
shell=True, stdout=subprocess.PIPE)
114-
self.assertEqual([('cpu', 'logical', 'loops_per_sec', '123')], hw_data)

hardware/tests/test_benchmark_disk.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ def setUp(self):
5252
self.hw_data = [('disk', 'fake-disk', 'size', '10'),
5353
('disk', 'fake-disk2', 'size', '15')]
5454

55-
def test_disk_perf_text(self, mock_popen):
56-
mock_popen.return_value = mock.Mock(
57-
stdout=FIO_OUTPUT_READ.splitlines())
58-
disk.disk_perf(self.hw_data)
59-
self.assertEqual(sorted(DISK_PERF_EXPECTED), sorted(self.hw_data))
60-
6155
def test_disk_perf_bytes(self, mock_popen):
6256
mock_popen.return_value = mock.Mock(
6357
stdout=FIO_OUTPUT_READ.encode().splitlines())
@@ -70,7 +64,7 @@ def test_get_disks_name(self, mock_popen):
7064

7165
def test_run_fio(self, mock_popen):
7266
mock_popen.return_value = mock.Mock(
73-
stdout=FIO_OUTPUT_READ.splitlines())
67+
stdout=FIO_OUTPUT_READ.encode().splitlines())
7468
hw_data = []
7569
disks_list = ['fake-disk', 'fake-disk2']
7670
disk.run_fio(hw_data, disks_list, "read", 123, 10, 5)

hardware/tests/test_benchmark_mem.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ def test_mem_perf_bytes(self, mock_popen, mock_cpu_socket,
9898
expected = EXPECTED_RESULT
9999
self.assertEqual(sorted(expected), sorted(self.hw_data))
100100

101-
def test_mem_perf_text(self, mock_popen, mock_cpu_socket,
102-
mock_get_memory):
103-
mock_get_memory.return_value = 123456789012
104-
mock_popen.return_value = mock.Mock(
105-
stdout=SYSBENCH_OUTPUT.splitlines())
106-
mock_cpu_socket.return_value = range(2)
107-
mem.mem_perf(self.hw_data)
108-
109-
expected = EXPECTED_RESULT
110-
self.assertEqual(sorted(expected), sorted(self.hw_data))
111-
112101
def test_check_mem_size(self, mock_popen, mock_cpu_socket,
113102
mock_get_memory):
114103
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,
122111
for block_size in block_size_list:
123112
self.assertFalse(mem.check_mem_size(block_size, 2))
124113

125-
def test_run_sysbench_memory_forked_text(self, mock_popen, mock_cpu_socket,
126-
mock_get_memory):
127-
mock_get_memory.return_value = 123456789012
128-
mock_popen.return_value = mock.Mock(
129-
stdout=SYSBENCH_OUTPUT.splitlines())
130-
131-
hw_data = []
132-
mem.run_sysbench_memory_forked(hw_data, 10, '1K', 2)
133-
self.assertEqual([('cpu', 'logical', 'forked_bandwidth_1K', '382')],
134-
hw_data)
135-
136114
def test_run_sysbench_memory_forked_bytes(self, mock_popen,
137115
mock_cpu_socket,
138116
mock_get_memory):
@@ -145,18 +123,6 @@ def test_run_sysbench_memory_forked_bytes(self, mock_popen,
145123
self.assertEqual([('cpu', 'logical', 'forked_bandwidth_1K', '382')],
146124
hw_data)
147125

148-
def test_run_sysbench_memory_threaded_text(self, mock_popen,
149-
mock_cpu_socket,
150-
mock_get_memory):
151-
mock_get_memory.return_value = 123456789012
152-
mock_popen.return_value = mock.Mock(
153-
stdout=SYSBENCH_OUTPUT.splitlines())
154-
155-
hw_data = []
156-
mem.run_sysbench_memory_threaded(hw_data, 10, '1K', 2)
157-
self.assertEqual([('cpu', 'logical', 'threaded_bandwidth_1K', '382')],
158-
hw_data)
159-
160126
def test_run_sysbench_memory_threaded_bytes(self, mock_popen,
161127
mock_cpu_socket,
162128
mock_get_memory):

hardware/tests/test_detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def test_get_uuid_x86_64(self, mock_uname, mock_popen):
303303
def test_get_uuid_ppc64le_ok_generate(self, mock_access, mock_uname):
304304
expected_uuid = 'a2724b67-c27e-5e5f-aa2b-3089a2bd8f41'
305305
fileobj = mock.mock_open(read_data=expected_uuid)
306-
with mock.patch('six.moves.builtins.open', fileobj, create=True):
306+
with mock.patch('builtins.open', fileobj, create=True):
307307
uuid = detect.get_uuid([])
308308
self.assertEqual(expected_uuid, uuid)
309309

hardware/tests/test_smart_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_read_smart_scsi_error_log(self):
8282
@mock.patch.object(subprocess, 'Popen')
8383
def test_read_smart_scsi(self, mock_popen):
8484
hwlst = []
85-
fake_output = sample('smartctl_scsi').splitlines()
85+
fake_output = sample('smartctl_scsi', mode='rb').splitlines()
8686
mock_popen.return_value = mock.Mock(stdout=fake_output)
8787
smart_utils.read_smart_scsi(hwlst, 'fake')
8888

@@ -91,7 +91,7 @@ def test_read_smart_scsi(self, mock_popen):
9191
@mock.patch.object(subprocess, 'Popen')
9292
def test_read_smart_ata(self, mock_popen):
9393
hwlst = []
94-
fake_output = sample('smartctl_ata').splitlines()
94+
fake_output = sample('smartctl_ata', mode='rb').splitlines()
9595
mock_popen.return_value = mock.Mock(stdout=fake_output)
9696
smart_utils.read_smart_ata(hwlst, 'fake')
9797

@@ -113,7 +113,7 @@ def test_read_smart_ata_decode_ignore(self, mock_popen):
113113
def test_read_smart_call_smart_ata(self, mock_popen, mock_os_path_exists,
114114
mock_ata):
115115
hwlst = []
116-
fake_output = sample('smartctl_ata').splitlines()
116+
fake_output = sample('smartctl_ata', mode='rb').splitlines()
117117
mock_popen.return_value = mock.Mock(stdout=fake_output)
118118
smart_utils.read_smart(hwlst, 'fake')
119119

@@ -125,7 +125,7 @@ def test_read_smart_call_smart_ata(self, mock_popen, mock_os_path_exists,
125125
def test_read_smart_call_smart_scsi(self, mock_popen, mock_os_path_exists,
126126
mock_scsi):
127127
hwlst = []
128-
fake_output = sample('smartctl_scsi').splitlines()
128+
fake_output = sample('smartctl_scsi', mode='rb').splitlines()
129129
mock_popen.return_value = mock.Mock(stdout=fake_output)
130130
smart_utils.read_smart(hwlst, 'fake')
131131

@@ -135,7 +135,7 @@ def test_read_smart_call_smart_scsi(self, mock_popen, mock_os_path_exists,
135135
@mock.patch.object(subprocess, 'Popen')
136136
def test_read_smart_nvme(self, mock_popen, mock_os_path_exists):
137137
hwlst = []
138-
fake_output = sample('smartctl_nvme').splitlines()
138+
fake_output = sample('smartctl_nvme', mode='rb').splitlines()
139139
mock_popen.return_value = mock.Mock(stdout=fake_output)
140140
smart_utils.read_smart_nvme(hwlst, 'fake_nvme')
141141

0 commit comments

Comments
 (0)