Fri, Mar 20, 2020 at 04:12:10PM CET, olichtne(a)redhat.com wrote:
On Mon, Mar 16, 2020 at 07:03:19PM +0100, Jan Tluka wrote:
> This patch adds ZeroPassPingEvaluator and RatePingEvaluator
> evaluators that can be used to evaluate results of Ping test
> module.
>
> ZeroPassPingEvaluator passes when no packets could be sent.
> RatePingEvaluator uses the rate reported by the Ping test module
> and compares with the configured min_rate, max_rate and rate
> parameters.
>
> Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
> ---
> .../Ping/Evaluators/RatePingEvaluator.py | 59 +++++++++++++++++++
> .../Ping/Evaluators/ZeroPassPingEvaluator.py | 22 +++++++
> lnst/RecipeCommon/Ping/Evaluators/__init__.py | 2 +
> 3 files changed, 83 insertions(+)
> create mode 100644 lnst/RecipeCommon/Ping/Evaluators/RatePingEvaluator.py
> create mode 100644 lnst/RecipeCommon/Ping/Evaluators/ZeroPassPingEvaluator.py
> create mode 100644 lnst/RecipeCommon/Ping/Evaluators/__init__.py
>
> diff --git a/lnst/RecipeCommon/Ping/Evaluators/RatePingEvaluator.py
b/lnst/RecipeCommon/Ping/Evaluators/RatePingEvaluator.py
> new file mode 100644
> index 00000000..7e0ca715
> --- /dev/null
> +++ b/lnst/RecipeCommon/Ping/Evaluators/RatePingEvaluator.py
> @@ -0,0 +1,59 @@
> +from lnst.RecipeCommon.Perf.Evaluators.BaseEvaluator import BaseEvaluator
The BaseEvaluator should probably be moved to just the RecipeCommon
package, I don't like it being imported in Ping package from the Perf
package.
Should also probably be renamed to something like BaseResultEvaluator.
Yes, makes sense.
> +
> +class RatePingEvaluator(BaseEvaluator):
> + def __init__(self, min_rate=None, max_rate=None, rate=None):
> + self.min_rate = min_rate
> + self.max_rate = max_rate
> + self.rate = rate
> +
> + if min_rate is None and max_rate is None and rate is None:
> + raise Exception('{} requires at least one of min_rate, '
> + 'max_rate and rate parameters specified'.format(
> + self.__class__.__name__)
> + )
> +
> + def evaluate_results(self, recipe, result):
> + result_status = True
> + ping_rate = int(result['rate'])
> +
> + result_text = []
> +
> + if self.min_rate is not None:
> + rate_text = 'measured rate {} is {} than min_rate({})'
> + if ping_rate < int(self.min_rate):
> + result_status = False
> + result_text.append(
> + rate_text.format(ping_rate, 'less', self.min_rate)
> + )
> + else:
> + result_text.append(
> + rate_text.format(ping_rate, 'more', self.min_rate)
> + )
> +
> + if self.max_rate is not None:
> + rate_text = 'measured rate {} is {} than max_rate({})'
> + if ping_rate > int(self.max_rate):
> + result_status = False
> + result_text.append(
> + rate_text.format(ping_rate, 'more', self.max_rate)
> + )
> + else:
> + result_text.append(
> + rate_text.format(ping_rate, 'less', self.max_rate)
> + )
> +
> + if self.rate is not None:
> + rate_text = 'measured rate {} is {} rate({})'.format(
> + ping_rate, self.rate)
> +
> + if ping_rate != int(self.rate):
> + result_status = False
> + result_text.append(
> + rate_text.format(ping_rate, 'different than',
self.rate)
> + )
> + else:
> + result_text.append(
> + rate_text.format(ping_rate, 'equal to', self.rate)
> + )
> +
> + recipe.add_result(result_status, "\n".join(result_text))
> diff --git a/lnst/RecipeCommon/Ping/Evaluators/ZeroPassPingEvaluator.py
b/lnst/RecipeCommon/Ping/Evaluators/ZeroPassPingEvaluator.py
> new file mode 100644
> index 00000000..13f5087a
> --- /dev/null
> +++ b/lnst/RecipeCommon/Ping/Evaluators/ZeroPassPingEvaluator.py
> @@ -0,0 +1,22 @@
> +from lnst.RecipeCommon.Perf.Evaluators.BaseEvaluator import BaseEvaluator
> +
> +class ZeroPassPingEvaluator(BaseEvaluator):
> + def evaluate_results(self, recipe, result):
> + result_status = True
> + trans_packets = int(result['trans_pkts'])
> + recv_packets = int(result['recv_pkts'])
> +
> + if recv_packets > 0:
> + result_status = False
> + result_text = [
> + 'expected zero packets but {} of {} packets '
> + 'were received'.format(
> + recv_packets, trans_packets)
> + ]
> + else:
> + result_text = ['received {} of {} packets as expected'.format(
> + recv_packets, trans_packets)
> + ]
> +
> + recipe.add_result(result_status, "\n".join(result_text))
> +
> diff --git a/lnst/RecipeCommon/Ping/Evaluators/__init__.py
b/lnst/RecipeCommon/Ping/Evaluators/__init__.py
> new file mode 100644
> index 00000000..2270cce7
> --- /dev/null
> +++ b/lnst/RecipeCommon/Ping/Evaluators/__init__.py
> @@ -0,0 +1,2 @@
> +from lnst.RecipeCommon.Ping.Evaluators.ZeroPassPingEvaluator import
ZeroPassPingEvaluator
> +from lnst.RecipeCommon.Ping.Evaluators.RatePingEvaluator import RatePingEvaluator
> --
> 2.21.1
> _______________________________________________
> LNST-developers mailing list -- lnst-developers(a)lists.fedorahosted.org
> To unsubscribe send an email to lnst-developers-leave(a)lists.fedorahosted.org
> Fedora Code of Conduct:
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives:
https://lists.fedorahosted.org/archives/list/lnst-developers@lists.fedora...