def test_verify_proc_diskstats_parsing_kernel_post_4_18(self): file_path = os.path.join(FIXTURES_DIR, "kernel_post_4.18.txt") output_file_sucess = io.StringIO() output_file_error = io.StringIO() f_diskstats = None try: f_diskstats = open(file_path, "r") parse_and_print_metrics(f_diskstats, output_file_sucess, output_file_error) finally: if f_diskstats: f_diskstats.close() output_success = output_file_sucess.getvalue() output_error = output_file_error.getvalue() output_success_lines = output_success.strip().split("\n") self.assertEqual(output_error, "") self.assertOutputContainsAllFields(output_success) self.assertEqual(output_success_lines[0], "iostat.disk.read_requests 104 446216 dev=hda") self.assertEqual( output_success_lines[-1], "iostat.disk.msec_weighted_total 104 23705160 dev=hda", )
def test_verify_proc_diskstats_parsing_kernel_5_5(self): file_path = os.path.join(FIXTURES_DIR, "kernel_5.5.7.txt") output_file_sucess = io.StringIO() output_file_error = io.StringIO() f_diskstats = None try: f_diskstats = open(file_path, "r") parse_and_print_metrics(f_diskstats, output_file_sucess, output_file_error) finally: if f_diskstats: f_diskstats.close() output_success = output_file_sucess.getvalue() output_error = output_file_error.getvalue() output_success_lines = output_success.strip().split("\n") self.assertEqual(output_error, "") self.assertOutputContainsAllFields(output_success) self.assertEqual(output_success_lines[0], "iostat.disk.read_requests 102 475618 dev=nvme0n1") self.assertEqual( output_success_lines[-1], "iostat.part.msec_weighted_total 102 343377888 dev=dm-3", )
def test_verify_proc_diskstats_parsing_invalid_content(self): file_path = os.path.join(FIXTURES_DIR, "invalid.txt") output_file_sucess = io.StringIO() output_file_error = io.StringIO() f_diskstats = None try: f_diskstats = open(file_path, "r") parse_and_print_metrics(f_diskstats, output_file_sucess, output_file_error) finally: if f_diskstats: f_diskstats.close() output_success = output_file_sucess.getvalue() output_error = output_file_error.getvalue().strip() self.assertEqual( output_error, "Cannot parse /proc/diskstats line: 3 0 hda 446216") self.assertEqual(output_success, "")