Skip to content

Commit

Permalink
Merge pull request #123 from elfosardo/goodbye-six
Browse files Browse the repository at this point in the history
Stop using six library
  • Loading branch information
tbreeds authored Jan 15, 2020
2 parents cb4c25b + 1d53aee commit b3ca1b4
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 94 deletions.
5 changes: 1 addition & 4 deletions hardware/benchmark/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import subprocess
import sys

import six

from hardware.benchmark import utils


Expand Down Expand Up @@ -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(':')
Expand Down
8 changes: 2 additions & 6 deletions hardware/benchmark/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions hardware/benchmark/mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import subprocess
import sys

import six

from hardware.benchmark import utils


Expand Down Expand Up @@ -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('.')
Expand Down Expand Up @@ -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('.')
Expand Down
7 changes: 0 additions & 7 deletions hardware/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
13 changes: 3 additions & 10 deletions hardware/smart_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down
13 changes: 0 additions & 13 deletions hardware/tests/test_benchmark_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 1 addition & 7 deletions hardware/tests/test_benchmark_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down
34 changes: 0 additions & 34 deletions hardware/tests/test_benchmark_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion hardware/tests/test_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions hardware/tests/test_smart_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# process, which may cause wedges in the gate later.

pbr>=1.0 # Apache-2.0
six # MIT
pexpect # ISC
numpy # BSD
pandas # BSD

0 comments on commit b3ca1b4

Please sign in to comment.