Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
docs/source/base_enrt_tunnel_class.rst | 6 ++
docs/source/enrt_recipes.rst | 1 +
lnst/Recipes/ENRT/BaseTunnelRecipe.py | 140 +++++++++++++++++++++++++
lnst/Recipes/ENRT/__init__.py | 1 +
4 files changed, 148 insertions(+)
create mode 100644 docs/source/base_enrt_tunnel_class.rst
create mode 100644 lnst/Recipes/ENRT/BaseTunnelRecipe.py
diff --git a/docs/source/base_enrt_tunnel_class.rst
b/docs/source/base_enrt_tunnel_class.rst
new file mode 100644
index 00000000..b3acddfd
--- /dev/null
+++ b/docs/source/base_enrt_tunnel_class.rst
@@ -0,0 +1,6 @@
+BaseTunnelRecipe class
+====================
+
+.. autoclass:: lnst.Recipes.ENRT.BaseTunnelRecipe.BaseTunnelRecipe
+ :members:
+ :show-inheritance:
diff --git a/docs/source/enrt_recipes.rst b/docs/source/enrt_recipes.rst
index af8935ab..da6a330e 100644
--- a/docs/source/enrt_recipes.rst
+++ b/docs/source/enrt_recipes.rst
@@ -8,5 +8,6 @@ Early Network Regression Testing (ENRT)
:caption: ENRT Components
base_enrt_class
+ base_enrt_tunnel_class
config_mixins
specific_scenarios
diff --git a/lnst/Recipes/ENRT/BaseTunnelRecipe.py
b/lnst/Recipes/ENRT/BaseTunnelRecipe.py
new file mode 100644
index 00000000..4a354a9d
--- /dev/null
+++ b/lnst/Recipes/ENRT/BaseTunnelRecipe.py
@@ -0,0 +1,140 @@
+from lnst.Common.IpAddress import ipaddress
+from lnst.Recipes.ENRT.BaremetalEnrtRecipe import BaremetalEnrtRecipe
+from lnst.RecipeCommon.PacketAssert import PacketAssertConf, PacketAssertTestAndEvaluate
+
+
+class BaseTunnelRecipe(
+ PacketAssertTestAndEvaluate,
+ BaremetalEnrtRecipe,
+):
+ """
+ This base class extends the :any:`BaseEnrtRecipe` class and defines
+ a common API for implementation of baremetal tunnel recipes.
+
+ The :meth:`ping_test` method is overridden to include a test
+ that the ping packets are properly tunnelled. This is implemented with
+ :any:`PacketAssert` test module. Each child class needs to implement
+ :meth:`get_packet_assert_config` so that the correct filters are passed
+ to the module.
+
+ The class inheriting from this base class need to implement following
+ methods:
+
+ * :meth:`configure_underlying_network`
+ * :meth:`create_tunnel`
+ * :meth:`get_packet_assert_config`
+ """
+
+ def test_wide_configuration(self):
+ """
+ The base class defines common steps to create the test wide
+ configuration of a tunnel recipe.
+
+ First, an underlying network that will be the transport layer for
+ the tunnel is configured in :meth:`configure_underlying_network`,
+ then the tunnel is created between the specified endpoints in
+ :meth:`create_tunnel`.
+ """
+
+ configuration = super().test_wide_configuration()
+ configuration.test_wide_devices = []
+ configuration.tunnel_endpoints = None
+ configuration.tunnel_devices = []
+
+ self.configure_underlying_network(configuration)
+ self.create_tunnel(configuration)
+
+ return configuration
+
+ def configure_underlying_network(self, configuration):
+ """
+ This method must be implemented by the child class.
+
+ The child class should configure the network stack that will be
+ the transport layer for the tunnel configured in :meth:`create_tunnel`.
+
+ That usually includes configuring the IP addresses, creating additional
+ network devices such as bonding or vlans, creating network namespaces,
+ etc.
+
+ The method must also update the ``tunnel_endpoints`` attribute of the
+ ``configuration`` object with a tuple of two Device objects that will
+ be used as tunnel endpoints in :meth:`create_tunnel`
+
+ :param configuration:
+ An EnrtConfiguration instance that will be populated with the
+ configured network devices and tunnel endpoints.
+ :type configuration: :any:`EnrtConfiguration`
+ """
+ raise NotImplementedError
+
+ def create_tunnel(self, configuration):
+ """
+ This method must be implemented by the child class.
+
+ The child class should create a network tunnel between endpoints
+ provided in the ``configuration``. That usually includes creating
+ tunnel devices such as :any:`GreDevice`, :any:`VxlanDevice`, etc.
+ and configuring the IP addresses.
+
+ :param configuration:
+ An EnrtConfiguration instance that should have ``tunnel_endpoints``
+ attribute populated with the tunnel endpoints.
+ :type configuration: :any:`EnrtConfiguration`
+ """
+ raise NotImplementedError
+
+ def generate_test_wide_description(self, config):
+ """
+ Test wide description is extended with the configured addresses
+ of the underlying network devices and the configured tunnel devices
+ """
+ desc = super().generate_test_wide_description(config)
+ desc += [
+ "Configured {}.{}.ips = {}".format(dev.host.hostid, dev.name,
dev.ips)
+ for dev in config.test_wide_devices
+ ]
+ desc += [
+ "Configured tunnel endpoint {}.{}.ips = {}".format(
+ dev.host.hostid, dev.name, dev.ips
+ )
+ for dev in config.tunnel_devices
+ ]
+ return desc
+
+ def test_wide_deconfiguration(self, config):
+ "" # overriding the parent docstring
+ del config.tunnel_devices
+ del config.test_wide_devices
+
+ super().test_wide_deconfiguration(config)
+
+ def ping_test(self, ping_configs):
+ pa_config = self.get_packet_assert_config(ping_configs[0])
+ self.packet_assert_test_start(pa_config)
+ self.ctl.wait(2)
+ ping_result = super().ping_test(ping_configs)
+ self.ctl.wait(2)
+ pa_result = self.packet_assert_test_stop()
+
+ result = ((ping_result, pa_config, pa_result),)
+
+ return result
+
+ def ping_report_and_evaluate(self, results):
+ for res in results:
+ super().ping_report_and_evaluate(res[0])
+ self.packet_assert_evaluate_and_report(res[1], res[2])
+
+ def get_packet_assert_config(self, ping_config):
+ """
+ This method must be implemented by the child class.
+
+ :param ping_config:
+ Ping configuration generated by
:meth:`BaseEnrtRecipe.generate_ping_configurations`
+ :type ping_config: :any:`PingConfig`
+
+ :return: returns a PacketAssert configuration
+ :rtype: :any:`PacketAssertConf`
+ """
+ raise NotImplementedError
diff --git a/lnst/Recipes/ENRT/__init__.py b/lnst/Recipes/ENRT/__init__.py
index e3c7d1e6..f08c6375 100644
--- a/lnst/Recipes/ENRT/__init__.py
+++ b/lnst/Recipes/ENRT/__init__.py
@@ -82,3 +82,4 @@ from lnst.Recipes.ENRT.VxlanMulticastRecipe import VxlanMulticastRecipe
from lnst.Recipes.ENRT.VxlanRemoteRecipe import VxlanRemoteRecipe
from lnst.Recipes.ENRT.BaseEnrtRecipe import BaseEnrtRecipe
+from lnst.Recipes.ENRT.BaseTunnelRecipe import BaseTunnelRecipe
--
2.26.3