From: Narasimhan V Date: Tue, 25 Feb 2020 18:35:58 +0000 (+0530) Subject: Encoding for subprocess and typecast fixes X-Git-Tag: v1.11~30 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d882eea57bb798c20eb292e8d4f1d7916e0f3d27;p=users%2Fhch%2Fnvme-cli.git Encoding for subprocess and typecast fixes Encoding, string handling fixes for subprocess. Also some related typecast fixes. Signed-off-by: Narasimhan V --- diff --git a/tests/nvme_create_max_ns_test.py b/tests/nvme_create_max_ns_test.py index f853732..33a66b7 100644 --- a/tests/nvme_create_max_ns_test.py +++ b/tests/nvme_create_max_ns_test.py @@ -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() diff --git a/tests/nvme_format_test.py b/tests/nvme_format_test.py index ce93f5e..55092fa 100644 --- a/tests/nvme_format_test.py +++ b/tests/nvme_format_test.py @@ -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) diff --git a/tests/nvme_fw_log_test.py b/tests/nvme_fw_log_test.py index dc8a150..adb6386 100644 --- a/tests/nvme_fw_log_test.py +++ b/tests/nvme_fw_log_test.py @@ -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() diff --git a/tests/nvme_get_features_test.py b/tests/nvme_get_features_test.py index d84742e..cfca7a8 100644 --- a/tests/nvme_get_features_test.py +++ b/tests/nvme_get_features_test.py @@ -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) diff --git a/tests/nvme_id_ns_test.py b/tests/nvme_id_ns_test.py index cd30c31..cf56187 100644 --- a/tests/nvme_id_ns_test.py +++ b/tests/nvme_id_ns_test.py @@ -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): diff --git a/tests/nvme_test.py b/tests/nvme_test.py index f74ef3a..b49c12f 100644 --- a/tests/nvme_test.py +++ b/tests/nvme_test.py @@ -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)