]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Tests: Hande string encoding and handling failures
authorNarasimhan V <sim@linux.vnet.ibm.com>
Mon, 20 Jan 2020 10:34:37 +0000 (16:04 +0530)
committerKeith Busch <kbusch@kernel.org>
Tue, 21 Jan 2020 16:23:39 +0000 (09:23 -0700)
Handling string encoding to utf-8 and also string handling in
tests.

Signed-off-by: Narasimhan V <sim@linux.vnet.ibm.com>
tests/nvme_get_features_test.py
tests/nvme_test.py

index 8888e4a930d7c7b3101fb6c0a5dbb1cfaa1528b7..d84742e232c49fc6d7a3d5cdb28fa3ed1a6dd2c5 100644 (file)
@@ -83,7 +83,8 @@ class TestNVMeGetMandatoryFeatures(TestNVMe):
                                " --cdw11=" + str(vector)
                 proc = subprocess.Popen(get_feat_cmd,
                                         shell=True,
-                                        stdout=subprocess.PIPE)
+                                        stdout=subprocess.PIPE,
+                                        encoding='utf-8')
                 feature_output = proc.communicate()[0]
                 print(feature_output)
                 assert_equal(proc.wait(), 0)
index 80939dc78d42de8ba7839f9a708a883f5f26da57..f74ef3af90d7df582b26252b376361659028b6f9 100644 (file)
@@ -28,7 +28,6 @@ import mmap
 import stat
 import time
 import shutil
-import string
 import subprocess
 from nose import tools
 from nose.tools import assert_equal
@@ -174,10 +173,11 @@ class TestNVMe(object):
         ns_list_cmd = "nvme list-ns " + self.ctrl
         proc = subprocess.Popen(ns_list_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         assert_equal(proc.wait(), 0, "ERROR : nvme list namespace failed")
         for line in proc.stdout:
-            ns_list.append(string.replace(line.split(":")[1], '\n', ''))
+            ns_list.append(line.replace('\n', '', 1))
 
         return ns_list
 
@@ -373,23 +373,24 @@ class TestNVMe(object):
         print(smart_log_cmd)
         proc = subprocess.Popen(smart_log_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         err = proc.wait()
         assert_equal(err, 0, "ERROR : nvme smart log failed")
 
         for line in proc.stdout:
             if "data_units_read" in line:
                 data_units_read = \
-                    string.replace(line.split(":")[1].strip(), ",", "")
+                    line.replace(",", "", 1)
             if "data_units_written" in line:
                 data_units_written = \
-                    string.replace(line.split(":")[1].strip(), ",", "")
+                    line.replace(",", "", 1)
             if "host_read_commands" in line:
                 host_read_commands = \
-                    string.replace(line.split(":")[1].strip(), ",", "")
+                    line.replace(",", "", 1)
             if "host_write_commands" in line:
                 host_write_commands = \
-                    string.replace(line.split(":")[1].strip(), ",", "")
+                    line.replace(",", "", 1)
 
         print("data_units_read " + data_units_read)
         print("data_units_written " + data_units_written)
@@ -427,7 +428,8 @@ class TestNVMe(object):
         error_log_cmd = "nvme error-log " + self.ctrl
         proc = subprocess.Popen(error_log_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         err = proc.wait()
         assert_equal(err, 0, "ERROR : nvme error log failed")
         line = proc.stdout.readline()