From: Jozef Urbanovsky <jurbanov(a)redhat.com>
Signed-off-by: Jozef Urbanovsky <jurbanov(a)redhat.com>
---
lnst/RecipeCommon/PacketAssert.py | 42 +++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/lnst/RecipeCommon/PacketAssert.py b/lnst/RecipeCommon/PacketAssert.py
index 689250e..872cfbb 100644
--- a/lnst/RecipeCommon/PacketAssert.py
+++ b/lnst/RecipeCommon/PacketAssert.py
@@ -4,6 +4,18 @@ from lnst.Tests import PacketAssert
from lnst.Common.LnstError import LnstError
class PacketAssertConf(object):
+ """
+ Class for the configuration of the :py:mod:`lnst.RecipeCommon.PacketAssert`.
+
+ :param host: client in :any:`PingConf` object used to specify host for the ping test
+ :param iface: interface to be used by the tcpdump
+ :param p_filter: tcpdump's pcap filter expression to be matched
+ :param grep_for: regex to be matched in the string representation of a
+ packet in the tcpdump output
+ :param p_min: minimum count of the packets to be found in the dump
+ :param p_max: maximum count of the packets to be found in the dump
+ :param promiscuous: toggle of promiscuous mode
+ """
def __init__(self, host, iface, **kwargs):
self._host = host
self._iface = iface
@@ -42,9 +54,25 @@ class PacketAssertConf(object):
return self._promiscuous
class PacketAssertTestAndEvaluate(BaseRecipe):
+ """
+ This class provides an extension to BaseRecipe class to perform an
+ evaluation of the captured packets on an interface. The class uses
+ :py:mod:`lnst.Tests.PacketAssert` test module to capture the packets
+ based on the filters defined in :any:`PacketAssertConf` configuration.
+ The pass or fail decision is made upon whether the number of the
+ captured packets matching the criteria fits the min/max interval
+ defined through :any:`PacketAssertConf`.
+ """
started_job = None
def packet_assert_test_start(self, packet_assert_config):
+ """
+ Method starts a :py:mod:`lnst.RecipeCommon.PacketAssert` job
+ and stores ***started_job*** attribute containing LNST :any:`Job`: object.
+
+ :param packet_assert_config: configuration in a form of
+ :any:`PacketAssertConf` class
+ """
if self.started_job:
raise LnstError("Only 1 packet_assert job is allowed to run at a
time.")
@@ -54,6 +82,12 @@ class PacketAssertTestAndEvaluate(BaseRecipe):
self.started_job = host.prepare_job(packet_assert).start(bg=True)
def packet_assert_test_stop(self):
+ """
+ Method kills a process executing :py:mod:`lnst.RecipeCommon.PacketAssert`
+ job and resets the value of the ***started_job*** attribute.
+
+ :return: result of the packet assert job
+ """
if not self.started_job:
raise LnstError("No packet_assert job is running.")
@@ -64,6 +98,14 @@ class PacketAssertTestAndEvaluate(BaseRecipe):
return result
def packet_assert_evaluate_and_report(self, packet_assert_config, results):
+ """
+ Method evaluates the result of the packet assert job based on the
+ received packets.
+
+ :param packet_assert_config: configuration containing values crucial to
+ the evaluation process
+ :param results: object where results are stored
+ """
if results["p_recv"] >= packet_assert_config.p_min and \
(results["p_recv"] <= packet_assert_config.p_max or
not packet_assert_config.p_max):
--
2.25.4