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 | 21 +++++++
lnst/RecipeCommon/Ping/Evaluators/__init__.py | 2 +
3 files changed, 82 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..6760d32a
--- /dev/null
+++ b/lnst/RecipeCommon/Ping/Evaluators/RatePingEvaluator.py
@@ -0,0 +1,59 @@
+from lnst.RecipeCommon.BaseResultEvaluator import BaseResultEvaluator
+
+class RatePingEvaluator(BaseResultEvaluator):
+ 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..350e157e
--- /dev/null
+++ b/lnst/RecipeCommon/Ping/Evaluators/ZeroPassPingEvaluator.py
@@ -0,0 +1,21 @@
+from lnst.RecipeCommon.BaseResultEvaluator import BaseResultEvaluator
+
+class ZeroPassPingEvaluator(BaseResultEvaluator):
+ 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