On Thu, Jun 13, 2019 at 12:03:33PM +0200, Jan Tluka wrote:
Tue, Jun 11, 2019 at 11:33:21AM CEST, olichtne(a)redhat.com wrote:
>From: Ondrej Lichtner <olichtne(a)redhat.com>
>
>The BaseHWConfigMixin class hierarchy implements various device
>configuration scripts related to hw devices that we almost always do in
>the same order and on the same set of devices. It includes:
>* mtu configuration
>* device interrupt cpu pinning
>* coalescing configuration
>* QDisc configuration in case parallel stream tests are requested
>
>Each configuration is implemented in its own mixin class inheriting from
>the BaseHWConfigMixin class that defines the interface. Additionally the
>CommonHWConfigMixin class inherits from all 4 config mixins and
>implements a collaborative inheritance version of the
>test_wide_configuration, deconfiguration and description methods to be
>added to the BaseEnrtRecipe derived classes.
>
>Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
>---
> lnst/Recipes/ENRT/BaseEnrtRecipe.py | 5 -
> .../ENRT/ConfigMixins/BaseHWConfigMixin.py | 42 ++++++++
> .../ConfigMixins/CoalescingHWConfigMixin.py | 32 ++++++
> .../ENRT/ConfigMixins/CommonHWConfigMixin.py | 31 ++++++
> .../ConfigMixins/DevInterruptHWConfigMixin.py | 102 ++++++++++++++++++
> .../ENRT/ConfigMixins/MTUHWConfigMixin.py | 18 ++++
> .../ParallelStreamQDiscHWConfigMixin.py | 32 ++++++
> 7 files changed, 257 insertions(+), 5 deletions(-)
> create mode 100644 lnst/Recipes/ENRT/ConfigMixins/BaseHWConfigMixin.py
> create mode 100644 lnst/Recipes/ENRT/ConfigMixins/CoalescingHWConfigMixin.py
> create mode 100644 lnst/Recipes/ENRT/ConfigMixins/CommonHWConfigMixin.py
> create mode 100644 lnst/Recipes/ENRT/ConfigMixins/DevInterruptHWConfigMixin.py
> create mode 100644 lnst/Recipes/ENRT/ConfigMixins/MTUHWConfigMixin.py
> create mode 100644
lnst/Recipes/ENRT/ConfigMixins/ParallelStreamQDiscHWConfigMixin.py
>
>diff --git a/lnst/Recipes/ENRT/BaseEnrtRecipe.py
b/lnst/Recipes/ENRT/BaseEnrtRecipe.py
>index d89ad03..4c941c9 100644
>--- a/lnst/Recipes/ENRT/BaseEnrtRecipe.py
>+++ b/lnst/Recipes/ENRT/BaseEnrtRecipe.py
>@@ -22,11 +22,6 @@ class BaseEnrtRecipe(BaseSubConfigMixin, PingTestAndEvaluate,
PerfRecipe):
> #common requirements parameters
> driver = StrParam(default="ixgbe")
>
>- #common configuration parameters
>- mtu = IntParam(mandatory=False)
>- adaptive_rx_coalescing = BoolParam(mandatory=False)
>- adaptive_tx_coalescing = BoolParam(mandatory=False)
>-
> #common test parameters
> ip_versions = Param(default=("ipv4", "ipv6"))
>
>diff --git a/lnst/Recipes/ENRT/ConfigMixins/BaseHWConfigMixin.py
b/lnst/Recipes/ENRT/ConfigMixins/BaseHWConfigMixin.py
>new file mode 100644
>index 0000000..1550691
>--- /dev/null
>+++ b/lnst/Recipes/ENRT/ConfigMixins/BaseHWConfigMixin.py
>@@ -0,0 +1,42 @@
>+class BaseHWConfigMixin(object):
>+ @property
>+ def hw_config_dev_list(self):
>+ return []
>+
>+ def hw_config(self, config):
>+ config.hw_config = {}
>+
>+ def hw_deconfig(self, config):
>+ del config.hw_config
>+
>+ def describe_hw_config(self, config):
>+ return []
>+
>+ def _configure_dev_attribute(self, config, attr_name, value):
>+ hw_config = config.hw_config
>+ if value:
>+ attr_cfg = hw_config[attr_name + "_configuration"] = {}
>+ for dev in self.hw_config_dev_list:
>+ attr_cfg[dev] = {}
>+ attr_cfg[dev]["original"] = getattr(dev, attr_name)
>+ setattr(dev, attr_name, value)
>+ attr_cfg[dev]["configured"] = getattr(dev, attr_name)
>+
>+ def _describe_dev_attribute(self, config, attr_name):
>+ hw_config = config.hw_config
>+ res = []
>+ attr = hw_config.get(attr_name + "_configuration", None)
>+ if attr:
>+ for dev, info in attr.items():
>+ res.append(
>+ "{}.{}.{} configured to {}, original value
{}".format(
>+ dev.host.hostid,
>+ dev.name,
>+ attr_name,
>+ info["configured"],
>+ info["original"],
>+ )
>+ )
>+ else:
>+ res.append("{} configuration skipped.".format(attr_name))
>+ return res
>diff --git a/lnst/Recipes/ENRT/ConfigMixins/CoalescingHWConfigMixin.py
b/lnst/Recipes/ENRT/ConfigMixins/CoalescingHWConfigMixin.py
>new file mode 100644
>index 0000000..c4e926e
>--- /dev/null
>+++ b/lnst/Recipes/ENRT/ConfigMixins/CoalescingHWConfigMixin.py
>@@ -0,0 +1,32 @@
>+from lnst.Common.Parameters import BoolParam
>+
>+from lnst.Recipes.ENRT.ConfigMixins.BaseHWConfigMixin import BaseHWConfigMixin
>+
>+
>+class CoalescingHWConfigMixin(BaseHWConfigMixin):
>+ adaptive_rx_coalescing = BoolParam(mandatory=False)
>+ adaptive_tx_coalescing = BoolParam(mandatory=False)
>+
>+ def hw_config(self, config):
>+ super().hw_config(config)
>+
>+ self._configure_dev_attribute(
>+ config,
>+ "adaptive_rx_coalescing",
>+ getattr(self.params, "adaptive_rx_coalescing", None),
>+ )
>+ self._configure_dev_attribute(
>+ config,
>+ "adaptive_tx_coalescing",
>+ getattr(self.params, "adaptive_tx_coalescing", None),
>+ )
>+
>+ def describe_hw_config(self, config):
>+ parent = super().describe_hw_config(config)
I'd rename 'parent' to 'desc' or similar. This applies to all other
occurrences in this patch. Not a big deal, I can live with it as it is,
but makes it a bit readable.
>+ parent.extend(
>+ self._describe_dev_attribute(config,
"adaptive_rx_coalescing")
>+ )
>+ parent.extend(
>+ self._describe_dev_attribute(config,
"adaptive_tx_coalescing")
>+ )
>+ return parent
>diff --git a/lnst/Recipes/ENRT/ConfigMixins/CommonHWConfigMixin.py
b/lnst/Recipes/ENRT/ConfigMixins/CommonHWConfigMixin.py
>new file mode 100644
>index 0000000..73958f9
>--- /dev/null
>+++ b/lnst/Recipes/ENRT/ConfigMixins/CommonHWConfigMixin.py
>@@ -0,0 +1,31 @@
>+from lnst.Recipes.ENRT.ConfigMixins.ParallelStreamQDiscHWConfigMixin import (
>+ ParallelStreamQDiscHWConfigMixin,
>+)
>+from lnst.Recipes.ENRT.ConfigMixins.DevInterruptHWConfigMixin import (
>+ DevInterruptHWConfigMixin,
>+)
>+from lnst.Recipes.ENRT.ConfigMixins.CoalescingHWConfigMixin import (
>+ CoalescingHWConfigMixin,
>+)
>+from lnst.Recipes.ENRT.ConfigMixins.MTUHWConfigMixin import MTUHWConfigMixin
>+
>+
>+class CommonHWConfigMixin(
>+ ParallelStreamQDiscHWConfigMixin,
>+ DevInterruptHWConfigMixin,
>+ CoalescingHWConfigMixin,
>+ MTUHWConfigMixin,
>+):
>+ def test_wide_configuration(self):
>+ configuration = super().test_wide_configuration()
>+ self.hw_config(configuration)
>+ return configuration
>+
>+ def test_wide_deconfiguration(self, configuration):
>+ self.hw_deconfig(configuration)
>+ return super().test_wide_deconfiguration(configuration)
>+
>+ def generate_test_wide_description(self, config):
>+ parent = super().generate_test_wide_description(config)
>+ parent.extend(self.describe_hw_config(config))
>+ return parent
So at the moment it is not possible to use individual HWConfigMixin
classes, correct?
J.
It is, you can inherit them as mixins and then call their hw_config
method directly.
This wrapper class includes it into the test_wide_configuration call by
default, but if you want more control over which configuration happens
when, you might want to do this manually.
-Ondrej