From 367de7fa38c07541b6472e48ec73ec907a4a2467 Mon Sep 17 00:00:00 2001 From: Dennis Maisenbacher Date: Tue, 15 Oct 2024 12:08:37 +0000 Subject: [PATCH] tests: Fix nvme_copy_test python traceback fails Reworking the `get_ocfs` function to correctly parse the ocfs field. At the same time refactor `nvme id-ctrl` that extracts the ocfs field into separate functions. This is in preparation for following commits that reuse the same functionality. Furthermore nvme_copy_test fails on devices that do not support any copy formats. For this to pass we need to declare `self.host_behavior_data` in any case. Signed-off-by: Dennis Maisenbacher --- tests/nvme_copy_test.py | 1 + tests/nvme_test.py | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/nvme_copy_test.py b/tests/nvme_copy_test.py index a5472312..5d16b00d 100644 --- a/tests/nvme_copy_test.py +++ b/tests/nvme_copy_test.py @@ -36,6 +36,7 @@ class TestNVMeCopy(TestNVMe): super().setUp() print("\nSetting up test...") self.ocfs = self.get_ocfs() + self.host_behavior_data = None cross_namespace_copy = self.ocfs & 0xc if cross_namespace_copy: # get host behavior support data diff --git a/tests/nvme_test.py b/tests/nvme_test.py index 5292ed13..235c855a 100644 --- a/tests/nvme_test.py +++ b/tests/nvme_test.py @@ -260,6 +260,25 @@ class TestNVMe(unittest.TestCase): print(ncap) return int(ncap) + def get_id_ctrl_field_value(self, field): + """ Wrapper for extracting id-ctrl field values + - Args: + - None + - Returns: + - Filed value of the given field + """ + id_ctrl_cmd = f"nvme id-ctrl {self.ctrl} --output-format=json" + proc = subprocess.Popen(id_ctrl_cmd, + shell=True, + stdout=subprocess.PIPE, + encoding='utf-8') + err = proc.wait() + self.assertEqual(err, 0, "ERROR : reading id-ctrl failed") + json_output = json.loads(proc.stdout.read()) + self.assertTrue(field in json_output, + f"ERROR : reading field '{field}' failed") + return str(json_output[field]) + def get_ocfs(self): """ Wrapper for extracting optional copy formats supported - Args: @@ -267,11 +286,7 @@ class TestNVMe(unittest.TestCase): - Returns: - Optional Copy Formats Supported """ - pattern = re.compile(r'^ocfs\s*: 0x[0-9a-fA-F]+$') - output = subprocess.check_output(["nvme", "id-ctrl", self.ctrl], encoding='utf-8') - ocfs_line = next(line for line in output.splitlines() if pattern.match(line)) - ocfs = ocfs_line.split(":")[1].strip() - return int(ocfs, 16) + return int(self.get_id_ctrl_field_value("ocfs"), 16) def get_format(self): """ Wrapper for extracting format. -- 2.50.1