Skip to content

Commit d882eea

Browse files
narasimhan-vkeithbusch
authored andcommitted
Encoding for subprocess and typecast fixes
Encoding, string handling fixes for subprocess. Also some related typecast fixes. Signed-off-by: Narasimhan V <[email protected]>
1 parent 4d3b2b5 commit d882eea

6 files changed

Lines changed: 48 additions & 26 deletions

File tree

tests/nvme_create_max_ns_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self):
5050
TestNVMe.__init__(self)
5151
self.dps = 0
5252
self.flbas = 0
53-
self.nsze = self.get_ncap() / self.get_format() / self.get_max_ns()
53+
self.nsze = int(self.get_ncap() / self.get_format() / self.get_max_ns())
5454
self.ncap = self.nsze
5555
self.setup_log_dir(self.__class__.__name__)
5656
self.max_ns = self.get_max_ns()

tests/nvme_format_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,23 @@ def attach_detach_primary_ns(self):
101101
# read lbaf information
102102
id_ns = "nvme id-ns " + self.ctrl + \
103103
" -n1 | grep ^lbaf | awk '{print $2}' | tr -s \"\\n\" \" \""
104-
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE)
104+
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
105+
encoding='utf-8')
105106
self.lba_format_list = proc.stdout.read().strip().split(" ")
106107
if proc.wait() == 0:
107108
# read lbads information
108109
id_ns = "nvme id-ns " + self.ctrl + \
109110
" -n1 | grep ^lbaf | awk '{print $5}'" + \
110111
" | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
111-
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE)
112+
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
113+
encoding='utf-8')
112114
self.lbads_list = proc.stdout.read().strip().split(" ")
113115
# read metadata information
114116
id_ns = "nvme id-ns " + self.ctrl + \
115117
" -n1 | grep ^lbaf | awk '{print $4}'" + \
116118
" | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
117-
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE)
119+
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
120+
encoding='utf-8')
118121
self.ms_list = proc.stdout.read().strip().split(" ")
119122
assert_equal(self.detach_ns(self.ctrl_id, self.default_nsid), 0)
120123
assert_equal(self.delete_and_validate_ns(self.default_nsid), 0)

tests/nvme_fw_log_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def get_fw_log(self):
5959
fw_log_cmd = "nvme fw-log " + self.ctrl
6060
proc = subprocess.Popen(fw_log_cmd,
6161
shell=True,
62-
stdout=subprocess.PIPE)
62+
stdout=subprocess.PIPE,
63+
encoding='utf-8')
6364
fw_log_output = proc.communicate()[0]
6465
print(fw_log_output + "\n")
6566
err = proc.wait()

tests/nvme_get_features_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def __init__(self):
5858
" cut -d : -f 1 | tr -d ' ' | tr '\n' ' '"
5959
proc = subprocess.Popen(get_vector_list_cmd,
6060
shell=True,
61-
stdout=subprocess.PIPE)
61+
stdout=subprocess.PIPE,
62+
encoding='utf-8')
6263
self.vector_list = []
6364
self.vector_list = proc.stdout.read().strip().split(" ")
6465

@@ -93,7 +94,8 @@ def get_mandatory_features(self, feature_id):
9394
" --feature-id=" + str(feature_id)
9495
proc = subprocess.Popen(get_feat_cmd,
9596
shell=True,
96-
stdout=subprocess.PIPE)
97+
stdout=subprocess.PIPE,
98+
encoding='utf-8')
9799
feature_output = proc.communicate()[0]
98100
print(feature_output)
99101
assert_equal(proc.wait(), 0)

tests/nvme_id_ns_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def get_id_ns(self, nsid):
6262
id_ns_cmd = "nvme id-ns " + self.ctrl + "n" + str(nsid)
6363
proc = subprocess.Popen(id_ns_cmd,
6464
shell=True,
65-
stdout=subprocess.PIPE)
65+
stdout=subprocess.PIPE,
66+
encoding='utf-8')
6667
id_ns_output = proc.communicate()[0]
6768
print(id_ns_output + "\n")
6869
err = proc.wait()
@@ -78,7 +79,7 @@ def get_id_ns_all(self):
7879
"""
7980
err = 0
8081
for namespace in self.ns_list:
81-
err = self.get_id_ns(str(namespace).split("x", 1)[1])
82+
err = self.get_id_ns(str(namespace))
8283
return err
8384

8485
def test_id_ns(self):

tests/nvme_test.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def setup_log_dir(self, test_name):
118118
@tools.nottest
119119
def exec_cmd(self, cmd):
120120
""" Wrapper for executing a shell command and return the result. """
121-
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
121+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
122+
encoding='utf-8')
122123
return proc.wait()
123124

124125
@tools.nottest
@@ -132,14 +133,16 @@ def nvme_reset_ctrl(self):
132133
nvme_reset_cmd = "nvme reset " + self.ctrl
133134
err = subprocess.call(nvme_reset_cmd,
134135
shell=True,
135-
stdout=subprocess.PIPE)
136+
stdout=subprocess.PIPE,
137+
encoding='utf-8')
136138
assert_equal(err, 0, "ERROR : nvme reset failed")
137139
time.sleep(5)
138140
rescan_cmd = "echo 1 > /sys/bus/pci/rescan"
139141
proc = subprocess.Popen(rescan_cmd,
140142
shell=True,
141143
stdout=subprocess.PIPE,
142-
stderr=subprocess.PIPE)
144+
stderr=subprocess.PIPE,
145+
encoding='utf-8')
143146
time.sleep(5)
144147
assert_equal(proc.wait(), 0, "ERROR : pci rescan failed")
145148

@@ -154,7 +157,8 @@ def get_ctrl_id(self):
154157
get_ctrl_id = "nvme list-ctrl " + self.ctrl
155158
proc = subprocess.Popen(get_ctrl_id,
156159
shell=True,
157-
stdout=subprocess.PIPE)
160+
stdout=subprocess.PIPE,
161+
encoding='utf-8')
158162
err = proc.wait()
159163
assert_equal(err, 0, "ERROR : nvme list-ctrl failed")
160164
line = proc.stdout.readline()
@@ -177,7 +181,7 @@ def get_ns_list(self):
177181
encoding='utf-8')
178182
assert_equal(proc.wait(), 0, "ERROR : nvme list namespace failed")
179183
for line in proc.stdout:
180-
ns_list.append(line.replace('\n', '', 1))
184+
ns_list.append(line.split('x')[-1])
181185

182186
return ns_list
183187

@@ -194,7 +198,8 @@ def get_max_ns(self):
194198
max_ns_cmd = "nvme id-ctrl " + self.ctrl
195199
proc = subprocess.Popen(max_ns_cmd,
196200
shell=True,
197-
stdout=subprocess.PIPE)
201+
stdout=subprocess.PIPE,
202+
encoding='utf-8')
198203
err = proc.wait()
199204
assert_equal(err, 0, "ERROR : reading maximum namespace count failed")
200205

@@ -218,7 +223,8 @@ def get_ncap(self):
218223
ncap_cmd = "nvme id-ctrl " + self.ctrl
219224
proc = subprocess.Popen(ncap_cmd,
220225
shell=True,
221-
stdout=subprocess.PIPE)
226+
stdout=subprocess.PIPE,
227+
encoding='utf-8')
222228
err = proc.wait()
223229
assert_equal(err, 0, "ERROR : reading nvm capacity failed")
224230

@@ -242,7 +248,8 @@ def get_format(self):
242248
nvm_format_cmd = "nvme id-ns " + self.ctrl + " -n1"
243249
proc = subprocess.Popen(nvm_format_cmd,
244250
shell=True,
245-
stdout=subprocess.PIPE)
251+
stdout=subprocess.PIPE,
252+
encoding='utf-8')
246253
err = proc.wait()
247254
assert_equal(err, 0, "ERROR : reading nvm capacity failed")
248255

@@ -265,7 +272,8 @@ def delete_all_ns(self):
265272
list_ns_cmd = "nvme list-ns " + self.ctrl + " --all | wc -l"
266273
proc = subprocess.Popen(list_ns_cmd,
267274
shell=True,
268-
stdout=subprocess.PIPE)
275+
stdout=subprocess.PIPE,
276+
encoding='utf-8')
269277
output = proc.stdout.read().strip()
270278
assert_equal(output, '0', "ERROR : deleting all namespace failed")
271279

@@ -303,7 +311,8 @@ def create_and_validate_ns(self, nsid, nsze, ncap, flbas, dps):
303311
id_ns_cmd = "nvme id-ns " + self.ctrl + " -n " + str(nsid)
304312
err = subprocess.call(id_ns_cmd,
305313
shell=True,
306-
stdout=subprocess.PIPE)
314+
stdout=subprocess.PIPE,
315+
encoding='utf-8')
307316
return err
308317

309318
@tools.nottest
@@ -320,7 +329,8 @@ def attach_ns(self, ctrl_id, ns_id):
320329
" --controllers=" + ctrl_id
321330
err = subprocess.call(attach_ns_cmd,
322331
shell=True,
323-
stdout=subprocess.PIPE)
332+
stdout=subprocess.PIPE,
333+
encoding='utf-8')
324334
time.sleep(5)
325335
if err == 0:
326336
# enumerate new namespace block device
@@ -344,7 +354,8 @@ def detach_ns(self, ctrl_id, nsid):
344354
" --controllers=" + ctrl_id
345355
return subprocess.call(detach_ns_cmd,
346356
shell=True,
347-
stdout=subprocess.PIPE)
357+
stdout=subprocess.PIPE,
358+
encoding='utf-8')
348359

349360
@tools.nottest
350361
def delete_and_validate_ns(self, nsid):
@@ -358,7 +369,8 @@ def delete_and_validate_ns(self, nsid):
358369
delete_ns_cmd = "nvme delete-ns " + self.ctrl + " -n " + str(nsid)
359370
err = subprocess.call(delete_ns_cmd,
360371
shell=True,
361-
stdout=subprocess.PIPE)
372+
stdout=subprocess.PIPE,
373+
encoding='utf-8')
362374
assert_equal(err, 0, "ERROR : delete namespace failed")
363375
return err
364376

@@ -412,7 +424,8 @@ def get_id_ctrl(self, vendor=False):
412424
print(id_ctrl_cmd)
413425
proc = subprocess.Popen(id_ctrl_cmd,
414426
shell=True,
415-
stdout=subprocess.PIPE)
427+
stdout=subprocess.PIPE,
428+
encoding='utf-8')
416429
err = proc.wait()
417430
assert_equal(err, 0, "ERROR : nvme id controller failed")
418431
return err
@@ -448,17 +461,19 @@ def run_ns_io(self, nsid, lbads):
448461
- Returns:
449462
- None
450463
"""
451-
block_size = mmap.PAGESIZE if lbads < 9 else 2 ** int(lbads)
464+
block_size = mmap.PAGESIZE if int(lbads) < 9 else 2 ** int(lbads)
452465
ns_path = self.ctrl + "n" + str(nsid)
453466
io_cmd = "dd if=" + ns_path + " of=/dev/null" + " bs=" + \
454467
str(block_size) + " count=10 > /dev/null 2>&1"
455468
print(io_cmd)
456-
run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE)
469+
run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE,
470+
encoding='utf-8')
457471
run_io_result = run_io.communicate()[1]
458472
assert_equal(run_io_result, None)
459473
io_cmd = "dd if=/dev/zero of=" + ns_path + " bs=" + \
460474
str(block_size) + " count=10 > /dev/null 2>&1"
461475
print(io_cmd)
462-
run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE)
476+
run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE,
477+
encoding='utf-8')
463478
run_io_result = run_io.communicate()[1]
464479
assert_equal(run_io_result, None)

0 commit comments

Comments
 (0)