From: Ondrej Lichtner <olichtne(a)redhat.com>
We can now use the DeviceParam class instead of the generic Param class
and skip additional parameter check implementation by the __init__
method.
This also modifies the example python recipe to show usage of this
parameter.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Tests/IcmpPing.py | 20 +++-----------------
recipes/examples/python_recipe.py | 3 ++-
2 files changed, 5 insertions(+), 18 deletions(-)
diff --git a/lnst/Tests/IcmpPing.py b/lnst/Tests/IcmpPing.py
index 8b07a2c..f28d2cf 100644
--- a/lnst/Tests/IcmpPing.py
+++ b/lnst/Tests/IcmpPing.py
@@ -1,7 +1,6 @@
import re
import logging
-from lnst.Devices import Device
-from lnst.Common.Parameters import IntParam, Param, FloatParam, IpParam
+from lnst.Common.Parameters import IntParam, FloatParam, IpParam, DeviceParam
from lnst.Common.TestModule import BaseTestModule, TestModuleError
from lnst.Common.ExecCmd import exec_cmd
@@ -10,29 +9,16 @@ class IcmpPing(BaseTestModule):
dst = IpParam(mandatory=True)
count = IntParam(default=10)
interval = FloatParam(default=1.0)
- iface = Param()
+ iface = DeviceParam()
size = IntParam()
-
limit_rate = IntParam(default=80)
- def __init__(self, **kwargs):
- super(IcmpPing, self).__init__(**kwargs)
-
- if self.iface.set:
- if not isinstance(self.iface.val, Device) and\
- not isinstance(self.iface.val, str):
- raise TestModuleError("Invalid 'iface' parameter.")
-
def _compose_cmd(self):
cmd = "ping %s" % self.params.dst.val
cmd += " -c %d" % self.params.count
cmd += " -i %f" % self.params.interval
if self.params.iface.set:
- if isinstance(self.params.iface.val, str):
- cmd += " -I %s" % self.params.iface
- elif isinstance(self.params.iface.val, Device):
- pass
- # cmd += " -I %s" % iface.val.devname
+ cmd += " -I %s" % self.params.iface.val.name
if self.params.size.set:
cmd += " -s %d" % self.params.size
return cmd
diff --git a/recipes/examples/python_recipe.py b/recipes/examples/python_recipe.py
index b15bc60..09b65c4 100755
--- a/recipes/examples/python_recipe.py
+++ b/recipes/examples/python_recipe.py
@@ -23,7 +23,8 @@ class MyRecipe(BaseRecipe):
self.matched.m1.eth0.ip_add(IpAddress("192.168.1.1/24"))
self.matched.m2.eth0.ip_add(IpAddress("192.168.1.2/24"))
ping_job = self.matched.m1.run(IcmpPing(dst=self.matched.m2.eth0,
- interval=0))
+ interval=0,
+ iface=self.matched.m1.eth0))
ctl = Controller(debug=1)
--
2.13.0