From: Ondrej Lichtner olichtne@redhat.com
The level attribute specifies the importance of the Result object that is used either for filtering or formatting purposes when processing the recipe results.
The data_level attribute is an extension of that by specifying the importance of the data provided with the result. It is used by the RunSummaryFormatter to filter out the data provided with the result.
The default for the Base class is ResultLevel.DEBUG same as the level attribute.
For the JobResult class it's always level+1, for ease of use when formatting results: * choose filter level -> show results * choose filter level + 1 -> show results and their data
For the Result class used by user, the default is ResultLevel.IMPORTANT+1 (so level+1 same as the JobResult), but the user has the ability to change this when calling Recipe.add_result
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- lnst/Controller/Recipe.py | 6 ++++-- lnst/Controller/RecipeResults.py | 21 +++++++++++++++++++-- lnst/Controller/RunSummaryFormatter.py | 3 ++- 3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/lnst/Controller/Recipe.py b/lnst/Controller/Recipe.py index 080dd46..5a0a347 100644 --- a/lnst/Controller/Recipe.py +++ b/lnst/Controller/Recipe.py @@ -139,8 +139,10 @@ class BaseRecipe(object): else: return None
- def add_result(self, success, description="", data=None): - self.current_run.add_result(Result(success, description, data)) + def add_result(self, success, description="", data=None, + level=None, data_level=None): + self.current_run.add_result(Result(success, description, data, + level, data_level))
class RecipeRun(object): def __init__(self, match, desc=None): diff --git a/lnst/Controller/RecipeResults.py b/lnst/Controller/RecipeResults.py index 6b42a83..05ce5fb 100644 --- a/lnst/Controller/RecipeResults.py +++ b/lnst/Controller/RecipeResults.py @@ -49,6 +49,10 @@ class BaseResult(object): def level(self): return ResultLevel.DEBUG
+ @property + def data_level(self): + return ResultLevel.DEBUG + class JobResult(BaseResult): """Base class for storing result data of Jobs
@@ -66,6 +70,10 @@ class JobResult(BaseResult): def level(self): return self.job.level
+ @BaseResult.data_level.getter + def data_level(self): + return self.job.level+1 + class JobStartResult(JobResult): """Generated automatically when a Job is succesfully started on a slave""" @BaseResult.short_desc.getter @@ -98,12 +106,17 @@ class Result(BaseResult): Will be created when the tester calls the Recipe interface for adding results.""" def __init__(self, success, short_desc="", data=None, - level=ResultLevel.IMPORTANT): + level=None, data_level=None): super(Result, self).__init__(success)
self._short_desc = short_desc self._data = data - self._level = level + self._level = (level + if isinstance(level, ResultLevel) + else ResultLevel.IMPORTANT) + self._data_level = (data_level + if isinstance(data_level, ResultLevel) + else ResultLevel.IMPORTANT+1)
@BaseResult.short_desc.getter def short_desc(self): @@ -116,3 +129,7 @@ class Result(BaseResult): @BaseResult.level.getter def level(self): return self._level + + @BaseResult.data_level.getter + def data_level(self): + return self._data_level diff --git a/lnst/Controller/RunSummaryFormatter.py b/lnst/Controller/RunSummaryFormatter.py index 888b897..a5d505e 100644 --- a/lnst/Controller/RunSummaryFormatter.py +++ b/lnst/Controller/RunSummaryFormatter.py @@ -107,7 +107,8 @@ class RunSummaryFormatter(object): src = self._format_source(res), desc = res.short_desc))
- output_lines.extend(self._format_data(res.data)) + if res.data_level <= self._level: + output_lines.extend(self._format_data(res.data))
output_lines.append("Overall result of this Run: {}". format(self._format_success(overall_result)))