]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Encoding for subprocess and typecast fixes
authorNarasimhan V <sim@linux.vnet.ibm.com>
Tue, 25 Feb 2020 18:35:58 +0000 (00:05 +0530)
committerKeith Busch <kbusch@kernel.org>
Tue, 25 Feb 2020 19:10:10 +0000 (12:10 -0700)
Encoding, string handling fixes for subprocess.
Also some related typecast fixes.

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

index f853732157eedc48e74f9c76ebbe08705f1966f4..33a66b7493a774f009cd27ac0c2b3f62626a89f4 100644 (file)
@@ -50,7 +50,7 @@ class TestNVMeCreateMaxNS(TestNVMe):
         TestNVMe.__init__(self)
         self.dps = 0
         self.flbas = 0
-        self.nsze = self.get_ncap() / self.get_format() / self.get_max_ns()
+        self.nsze = int(self.get_ncap() / self.get_format() / self.get_max_ns())
         self.ncap = self.nsze
         self.setup_log_dir(self.__class__.__name__)
         self.max_ns = self.get_max_ns()
index ce93f5ec2d89d0d28c2c9a46162d354677780fa8..55092fa6b7e385a9ebac4191a71b1fc5f1605284 100644 (file)
@@ -101,20 +101,23 @@ class TestNVMeFormatCmd(TestNVMe):
         # read lbaf information
         id_ns = "nvme id-ns " + self.ctrl + \
                 " -n1 | grep ^lbaf | awk '{print $2}' | tr -s \"\\n\" \" \""
-        proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE)
+        proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
+                                encoding='utf-8')
         self.lba_format_list = proc.stdout.read().strip().split(" ")
         if proc.wait() == 0:
             # read lbads information
             id_ns = "nvme id-ns " + self.ctrl + \
                     " -n1 | grep ^lbaf | awk '{print $5}'" + \
                     " | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
-            proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE)
+            proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
+                                    encoding='utf-8')
             self.lbads_list = proc.stdout.read().strip().split(" ")
             # read metadata information
             id_ns = "nvme id-ns " + self.ctrl + \
                     " -n1 | grep ^lbaf | awk '{print $4}'" + \
                     " | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
-            proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE)
+            proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
+                                    encoding='utf-8')
             self.ms_list = proc.stdout.read().strip().split(" ")
             assert_equal(self.detach_ns(self.ctrl_id, self.default_nsid), 0)
             assert_equal(self.delete_and_validate_ns(self.default_nsid), 0)
index dc8a150620bff8f81182c7cf01c7f230673acccf..adb638634b5c1403ab2f12ab81046fb8c11ad3bf 100644 (file)
@@ -59,7 +59,8 @@ class TestNVMeFwLogCmd(TestNVMe):
         fw_log_cmd = "nvme fw-log " + self.ctrl
         proc = subprocess.Popen(fw_log_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         fw_log_output = proc.communicate()[0]
         print(fw_log_output + "\n")
         err = proc.wait()
index d84742e232c49fc6d7a3d5cdb28fa3ed1a6dd2c5..cfca7a8cf6c1e4210d15d48673cca129f787871f 100644 (file)
@@ -58,7 +58,8 @@ class TestNVMeGetMandatoryFeatures(TestNVMe):
                               " cut -d : -f 1 | tr -d ' ' | tr '\n' ' '"
         proc = subprocess.Popen(get_vector_list_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         self.vector_list = []
         self.vector_list = proc.stdout.read().strip().split(" ")
 
@@ -93,7 +94,8 @@ class TestNVMeGetMandatoryFeatures(TestNVMe):
                            " --feature-id=" + str(feature_id)
             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 cd30c31e816e4e68453f6fae8e21b64ad1b8d15c..cf56187a1a386902765bd018393a33da0f34fa8f 100644 (file)
@@ -62,7 +62,8 @@ class TestNVMeIdentifyNamespace(TestNVMe):
         id_ns_cmd = "nvme id-ns " + self.ctrl + "n" + str(nsid)
         proc = subprocess.Popen(id_ns_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         id_ns_output = proc.communicate()[0]
         print(id_ns_output + "\n")
         err = proc.wait()
@@ -78,7 +79,7 @@ class TestNVMeIdentifyNamespace(TestNVMe):
         """
         err = 0
         for namespace  in self.ns_list:
-            err = self.get_id_ns(str(namespace).split("x", 1)[1])
+            err = self.get_id_ns(str(namespace))
         return err
 
     def test_id_ns(self):
index f74ef3af90d7df582b26252b376361659028b6f9..b49c12f0b420a4bcfb6a8b1b67d5bae1cde96db5 100644 (file)
@@ -118,7 +118,8 @@ class TestNVMe(object):
     @tools.nottest
     def exec_cmd(self, cmd):
         """ Wrapper for executing a shell command and return the result. """
-        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
+                                encoding='utf-8')
         return proc.wait()
 
     @tools.nottest
@@ -132,14 +133,16 @@ class TestNVMe(object):
         nvme_reset_cmd = "nvme reset " + self.ctrl
         err = subprocess.call(nvme_reset_cmd,
                               shell=True,
-                              stdout=subprocess.PIPE)
+                              stdout=subprocess.PIPE,
+                              encoding='utf-8')
         assert_equal(err, 0, "ERROR : nvme reset failed")
         time.sleep(5)
         rescan_cmd = "echo 1 > /sys/bus/pci/rescan"
         proc = subprocess.Popen(rescan_cmd,
                                 shell=True,
                                 stdout=subprocess.PIPE,
-                                stderr=subprocess.PIPE)
+                                stderr=subprocess.PIPE,
+                                encoding='utf-8')
         time.sleep(5)
         assert_equal(proc.wait(), 0, "ERROR : pci rescan failed")
 
@@ -154,7 +157,8 @@ class TestNVMe(object):
         get_ctrl_id = "nvme list-ctrl " + self.ctrl
         proc = subprocess.Popen(get_ctrl_id,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         err = proc.wait()
         assert_equal(err, 0, "ERROR : nvme list-ctrl failed")
         line = proc.stdout.readline()
@@ -177,7 +181,7 @@ class TestNVMe(object):
                                 encoding='utf-8')
         assert_equal(proc.wait(), 0, "ERROR : nvme list namespace failed")
         for line in proc.stdout:
-            ns_list.append(line.replace('\n', '', 1))
+            ns_list.append(line.split('x')[-1])
 
         return ns_list
 
@@ -194,7 +198,8 @@ class TestNVMe(object):
         max_ns_cmd = "nvme id-ctrl " + self.ctrl
         proc = subprocess.Popen(max_ns_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         err = proc.wait()
         assert_equal(err, 0, "ERROR : reading maximum namespace count failed")
 
@@ -218,7 +223,8 @@ class TestNVMe(object):
         ncap_cmd = "nvme id-ctrl " + self.ctrl
         proc = subprocess.Popen(ncap_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         err = proc.wait()
         assert_equal(err, 0, "ERROR : reading nvm capacity failed")
 
@@ -242,7 +248,8 @@ class TestNVMe(object):
         nvm_format_cmd = "nvme id-ns " + self.ctrl + " -n1"
         proc = subprocess.Popen(nvm_format_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         err = proc.wait()
         assert_equal(err, 0, "ERROR : reading nvm capacity failed")
 
@@ -265,7 +272,8 @@ class TestNVMe(object):
         list_ns_cmd = "nvme list-ns " + self.ctrl + " --all | wc -l"
         proc = subprocess.Popen(list_ns_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         output = proc.stdout.read().strip()
         assert_equal(output, '0', "ERROR : deleting all namespace failed")
 
@@ -303,7 +311,8 @@ class TestNVMe(object):
             id_ns_cmd = "nvme id-ns " + self.ctrl + " -n " + str(nsid)
             err = subprocess.call(id_ns_cmd,
                                   shell=True,
-                                  stdout=subprocess.PIPE)
+                                  stdout=subprocess.PIPE,
+                                  encoding='utf-8')
         return err
 
     @tools.nottest
@@ -320,7 +329,8 @@ class TestNVMe(object):
                         " --controllers=" + ctrl_id
         err = subprocess.call(attach_ns_cmd,
                               shell=True,
-                              stdout=subprocess.PIPE)
+                              stdout=subprocess.PIPE,
+                              encoding='utf-8')
         time.sleep(5)
         if err == 0:
             # enumerate new namespace block device
@@ -344,7 +354,8 @@ class TestNVMe(object):
                         " --controllers=" + ctrl_id
         return subprocess.call(detach_ns_cmd,
                                shell=True,
-                               stdout=subprocess.PIPE)
+                               stdout=subprocess.PIPE,
+                               encoding='utf-8')
 
     @tools.nottest
     def delete_and_validate_ns(self, nsid):
@@ -358,7 +369,8 @@ class TestNVMe(object):
         delete_ns_cmd = "nvme delete-ns " + self.ctrl + " -n " + str(nsid)
         err = subprocess.call(delete_ns_cmd,
                               shell=True,
-                              stdout=subprocess.PIPE)
+                              stdout=subprocess.PIPE,
+                              encoding='utf-8')
         assert_equal(err, 0, "ERROR : delete namespace failed")
         return err
 
@@ -412,7 +424,8 @@ class TestNVMe(object):
         print(id_ctrl_cmd)
         proc = subprocess.Popen(id_ctrl_cmd,
                                 shell=True,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                encoding='utf-8')
         err = proc.wait()
         assert_equal(err, 0, "ERROR : nvme id controller failed")
         return err
@@ -448,17 +461,19 @@ class TestNVMe(object):
             - Returns:
                 - None
         """
-        block_size = mmap.PAGESIZE if lbads < 9 else 2 ** int(lbads)
+        block_size = mmap.PAGESIZE if int(lbads) < 9 else 2 ** int(lbads)
         ns_path = self.ctrl + "n" + str(nsid)
         io_cmd = "dd if=" + ns_path + " of=/dev/null" + " bs=" + \
                  str(block_size) + " count=10 > /dev/null 2>&1"
         print(io_cmd)
-        run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE)
+        run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE,
+                                  encoding='utf-8')
         run_io_result = run_io.communicate()[1]
         assert_equal(run_io_result, None)
         io_cmd = "dd if=/dev/zero of=" + ns_path + " bs=" + \
                  str(block_size) + " count=10 > /dev/null 2>&1"
         print(io_cmd)
-        run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE)
+        run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE,
+                                  encoding='utf-8')
         run_io_result = run_io.communicate()[1]
         assert_equal(run_io_result, None)