t/fiotestlib: add ability to ingest iops logs
authorVincent Fu <vincent.fu@samsung.com>
Wed, 7 Jun 2023 21:21:50 +0000 (21:21 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 8 Jun 2023 18:39:07 +0000 (14:39 -0400)
Enhance the FioJobCmdTest class with the ability to read in an IOPS log
if one was generated during the course of the test run.

This reads in only the first IOPS log written as a result of
--write_iops_log.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
t/fiotestlib.py

index 69f630a08b5067313d23c77b1ffbe70a5159bb30..0fe17b74bae3a0ef12bbac0a29387cf5c441ef85 100755 (executable)
@@ -279,17 +279,17 @@ class FioJobCmdTest(FioExeTest):
         self.basename = basename if basename else os.path.basename(fio_path)
         self.fio_opts = fio_opts
         self.json_data = None
+        self.iops_log_lines = None
 
         super().__init__(fio_path, success, testnum, artifact_root)
 
-        filename_stub = f"{self.basename}{self.testnum:03d}"
-        self.filenames['cmd'] = os.path.join(self.paths['test_dir'], f"{filename_stub}.command")
-        self.filenames['stdout'] = os.path.join(self.paths['test_dir'], f"{filename_stub}.stdout")
-        self.filenames['stderr'] = os.path.join(self.paths['test_dir'], f"{filename_stub}.stderr")
-        self.filenames['output'] = os.path.abspath(os.path.join(self.paths['test_dir'],
-                                     f"{filename_stub}.output"))
-        self.filenames['exitcode'] = os.path.join(self.paths['test_dir'],
-                                                  f"{filename_stub}.exitcode")
+        filename_stub = os.path.join(self.paths['test_dir'], f"{self.basename}{self.testnum:03d}")
+        self.filenames['cmd'] = f"{filename_stub}.command"
+        self.filenames['stdout'] = f"{filename_stub}.stdout"
+        self.filenames['stderr'] = f"{filename_stub}.stderr"
+        self.filenames['output'] = os.path.abspath(f"{filename_stub}.output")
+        self.filenames['exitcode'] = f"{filename_stub}.exitcode"
+        self.filenames['iopslog'] = os.path.abspath(f"{filename_stub}")
 
     def run(self):
         super().run()
@@ -300,6 +300,16 @@ class FioJobCmdTest(FioExeTest):
                 print('Unable to decode JSON data')
                 self.passed = False
 
+        if any('--write_iops_log=' in param for param in self.parameters):
+            self.get_iops_log()
+
+    def get_iops_log(self):
+        """Read IOPS log from the first job."""
+
+        log_filename = self.filenames['iopslog'] + "_iops.1.log"
+        with open(log_filename, 'r', encoding=locale.getpreferredencoding()) as iops_file:
+            self.iops_log_lines = iops_file.read()
+
     def get_json(self):
         """Convert fio JSON output into a python JSON object"""