From f124611e107b472c30d31c1282ad24355547aa86 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 19 Apr 2022 11:20:15 +0200 Subject: [PATCH] test api: utility to extract info about CAS md Signed-off-by: Michal Mielewczyk --- test/functional/api/cas/dmesg.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/functional/api/cas/dmesg.py diff --git a/test/functional/api/cas/dmesg.py b/test/functional/api/cas/dmesg.py new file mode 100644 index 0000000..344c129 --- /dev/null +++ b/test/functional/api/cas/dmesg.py @@ -0,0 +1,39 @@ +# +# Copyright(c) 2019-2022 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause +# + +import re + +from test_utils.size import Size, Unit + + +def get_metadata_size(dmesg): + for s in dmesg.split("\n"): + if "Metadata capacity:" in s: + size = re.search("[0-9]* MiB", s).group() + return Size(int(re.search("[0-9]*", size).group()), Unit.MebiByte) + + raise ValueError("Can't find the metadata size in the privded dmesg output") + + +def _get_metadata_info(dmesg, section_name): + for s in dmesg.split("\n"): + if section_name in s: + size, unit = re.search("[0-9]* (B|kiB)", s).group().split() + unit = Unit.KibiByte if unit == "kiB" else Unit.Byte + return Size(int(re.search("[0-9]*", size).group()), unit) + + raise ValueError(f'"{section_name}" entry doesn\'t exist in the given dmesg output') + + +def get_md_section_size(section_name, dmesg): + section_name = section_name.strip() + section_name += " size" + return _get_metadata_info(dmesg, section_name) + + +def get_md_section_offset(section_name, dmesg): + section_name = section_name.strip() + section_name += " offset" + return _get_metadata_info(dmesg, section_name)