On Thu, Nov 23, 2017 at 08:58:03AM +0100, Kamil Jerabek wrote:
This commit adds class TestRecipe that contains all setup and
methods, that
are in common for all our recipes.
It also contains simple_netperf test ported from recipes/regression_tests/phase1.
Signed-off-by: Kamil Jerabek <kjerabek(a)redhat.com>
---
* changes v2
* initial setup through physical interfaces
---
lnst/RecipeCommon/TestRecipe.py | 158 +++++++++++++++++++++++
recipes/examples/python_recipe_simple_netperf.py | 104 +++++++++++++++
2 files changed, 262 insertions(+)
create mode 100755 lnst/RecipeCommon/TestRecipe.py
create mode 100755 recipes/examples/python_recipe_simple_netperf.py
diff --git a/lnst/RecipeCommon/TestRecipe.py b/lnst/RecipeCommon/TestRecipe.py
new file mode 100755
index 0000000..05fc683
--- /dev/null
+++ b/lnst/RecipeCommon/TestRecipe.py
@@ -0,0 +1,158 @@
+#!/bin/python2
+
+import time
+import re
+
+from lnst.Common.Parameters import StrParam, IntParam, Param
+from lnst.Controller import BaseRecipe
+from lnst.Controller.Recipe import RecipeError
+
+from lnst.Tests.Netperf import Netperf
+
+from lnst.RecipeCommon.PerfRepo.PerfRepo import PerfRepoAPI
+from lnst.RecipeCommon.PerfRepo.PerfRepo import generate_perfrepo_comment
+from lnst.RecipeCommon.PerfRepo.PerfRepoUtils import netperf_baseline_template
+from lnst.RecipeCommon.PerfRepo.PerfRepoUtils import netperf_result_template
+
+from lnst.RecipeCommon.IRQ import pin_dev_irqs
+
+class TestRecipe(BaseRecipe):
+ ipv = StrParam(default="both")
+ mtu = IntParam(default=1500)
+
+ mapping_file = StrParam()
+ pr_user_comment = StrParam()
+
+ nperf_cpupin = IntParam()
+ nperf_reserve = IntParam(default=20)
+ nperf_mode = StrParam(default="default")
+
+ netperf_duration = IntParam(default=1)
+ netperf_confidence = StrParam(default="99,5")
+ netperf_runs = IntParam(default=5)
+ netperf_cpu_util = IntParam()
+ netperf_num_parallel = IntParam(default=2)
+ netperf_debug = IntParam(default=0)
+ netperf_max_deviation = Param(default={
+ 'type': 'percent',
+ 'value': 20})
+
+ test_if1 = Param()
+ test_if2 = Param()
+
+ def __init__(self, **kwargs):
+ super(TestRecipe, self).__init__(**kwargs)
+
+ if "mapping_file" in self.params:
+ self.perf_api = PerfRepoAPI(self.params.mapping_file)
+ self.perf_api.connect_PerfRepo()
+
+
+ def initial_setup(self):
+ machines = []
+
+ if "pr_user_comment" in self.params:
+ machines = [machines.append(m) for m in self.matched]
+
+ self.pr_comment = generate_perfrepo_comment(machines,
+ self.params.pr_user_comment)
+
+ if "nperf_cpupin" in self.params:
+ for m in self.matched:
+ m.run("service irqbalance stop")
+
+ for m in self.matched:
+ for d in m.devices:
+ if re.match(r'^eth[0-9]+$', d.name):
+ pin_dev_irqs(m, d, 0)
+
+
+ self.nperf_opts = ""
+
+ if "test_if2" in self.params:
+ self.nperf_opts = "-L %s" % (self.params.test_if2.ips[0])
+
+ if "nperf_cpupin" in self.params and self.params.netperf_mode !=
"multi":
+ self.nperf_opts += " -T%s,%s" % (self.params.netperf_cpupin,
+ self.params.netperf_cpupin)
+
+ self.nperf_opts6 = ""
+
+ if "test_if2" in self.params:
+ self.nperf_opts6 = "-L %s" % (self.params.test_if2.ips[1])
+
+ self.nperf_opts6 += " -6"
+
+ if "nperf_cpupin" in self.params and self.params.netperf_mode !=
"multi":
+ self.nperf_popts6 += " -T%s,%s" % (self.params.netperf_cpupin,
+ self.params.netperf_cpupin)
+
+ time.sleep(15)
+
+ def clean_setup(self):
+ if "nperf_cpupin" in self.params:
+ for m in self.matched:
+ m.run("service irqbalance start")
+
+ def generate_netperf_cli(self, dst_addr, testname):
+ kwargs = {}
+
+ for key, val in self.params:
+ param_name = re.split(r'netperf_', key)
+ if len(param_name) > 1:
+ kwargs[param_name[1]] = val
+
+ kwargs['server'] = dst_addr
+ kwargs['testname'] = testname
+
+ if str(dst_addr).find(":") is -1:
+ kwargs['opts'] = self.nperf_opts
+ else:
+ kwargs['opts'] = self.nperf_opts6
+
+ return Netperf(**kwargs)
+
+
+ def netperf_run(self, netserver, netperf, perfrepo_result=None):
+ srv_proc = self.matched.m1.run(netserver, bg=True)
+
+ if perfrepo_result:
+ if not hasattr(self, 'perf_api'):
+ raise RecipeError("no class variable called perf_api")
+
+
+ baseline = self.perf_api.get_baseline_of_result(perfrepo_result)
+ #TODO:
+ #netperf_baseline_template(netperf, baseline)
+
+ time.sleep(2)
+
+ res_data = self.matched.m2.run(netperf,
+ timeout = (
+ self.params.netperf_duration +
+ self.params.nperf_reserve) *
+ self.params.netperf_runs)
+
+ if perfrepo_result:
+ netperf_result_template(perfrepo_result, res_data)
+
+ if hasattr(self, 'pr_comment'):
+ perfrepo_result.set_comment(self.params.pr_comment)
+
+ self.perf_api.save_result(perfrepo_result)
+
+ srv_proc.kill(2)
+
+ return res_data, srv_proc
+
+ def network_setup(self):
+ pass
+
+ def core_test(self):
+ pass
+
+ def test(self):
+ self.network_setup()
+ self.initial_setup()
+ self.core_test()
+ self.clean_setup()
diff --git a/recipes/examples/python_recipe_simple_netperf.py
b/recipes/examples/python_recipe_simple_netperf.py
new file mode 100755
index 0000000..aab1c5b
--- /dev/null
+++ b/recipes/examples/python_recipe_simple_netperf.py
@@ -0,0 +1,104 @@
+#!/bin/python2
+
+import time
+
+from lnst.Common.Parameters import StrParam
+from lnst.Common.IpAddress import ipaddress
+from lnst.Controller import Controller
+from lnst.Controller import HostReq, DeviceReq
+
+from lnst.Tests.Netperf import Netserver
+from lnst.RecipeCommon.TestRecipe import TestRecipe
+
+class SimpleNetperfRecipe(TestRecipe):
+ offloads = ["gro", "gso", "tso", "tx"]
+ offload_settings = [[("gro", "on"), ("gso",
"on"), ("tso", "on"), ("tx", "on"),
("rx", "on")],
+ [("gro", "off"), ("gso",
"on"), ("tso", "on"), ("tx", "on"),
("rx", "on")],
+ [("gro", "on"), ("gso",
"off"), ("tso", "off"), ("tx", "on"),
("rx", "on")],
+ [("gro", "on"), ("gso",
"on"), ("tso", "off"), ("tx", "off"),
("rx", "on")],
+ [("gro", "on"), ("gso",
"on"), ("tso", "on"), ("tx", "on"),
("rx", "off")]]
+
+ mapping_file = StrParam(default="simple_netperf.mapping")
+ product_name = StrParam(default="RHEL7")
+
+ m1 = HostReq()
+ m1.eth0 = DeviceReq(label="net1")
+
+ m2 = HostReq()
+ m2.eth0 = DeviceReq(label="net1")
+
+ def network_setup(self):
+ self.matched.m1.eth0.ip_add(ipaddress("192.168.101.1/24"))
+ self.matched.m1.eth0.ip_add(ipaddress("fc00::1/64"))
+ self.matched.m1.eth0.up()
+
+ self.matched.m2.eth0.ip_add(ipaddress("192.168.101.2/24"))
+ self.matched.m2.eth0.ip_add(ipaddress("fc00::2/64"))
+ self.matched.m2.eth0.up()
+
+ def clean_setup(self):
+ super(SimpleNetperfRecipe, self).clean_setup()
+ #reset offload states
+ dev_features = ""
+ for offload in self.offloads:
+ dev_features += " %s %s" % (offload, "on")
+
+
+ self.matched.m1.run("ethtool -K %s %s" % (self.matched.m1.eth0.name,
+ dev_features))
+ self.matched.m2.run("ethtool -K %s %s" % (self.matched.m2.eth0.name,
+ dev_features))
+
+ def core_test(self):
+ ipv = ('ipv4', 'ipv6')
+ transport_type = [('tcp', 'TCP_STREAM'), ('udp',
'UDP_STREAM')]
+
+ for setting in self.offload_settings:
+ dev_features = ""
+
+ for offload in setting:
+ dev_features += " %s %s" % (offload[0], offload[1])
+
+ self.matched.m1.run("ethtool -K %s %s" %
(self.matched.m1.eth0.name,
+ dev_features))
+ self.matched.m2.run("ethtool -K %s %s" %
(self.matched.m2.eth0.name,
+ dev_features))
+
+ if ("rx", "off") in setting:
+ # when rx offload is turned off some of the cards might get reset
+ # and link goes down, so wait a few seconds until NIC is ready
+ time.sleep(15)
+
+
+ for ipver in ipv:
+ if self.params.ipv in [ipver, 'both']:
+ for ttype, ttype_name in transport_type:
+ result =
self.perf_api.new_result(ttype+"_"+ipver+"_id",
+
ttype+"_"+ipver+"_result",
+ hash_ignore=[
+ 'kernel_release',
+ 'redhat_release'])
+
+ for offload in setting:
+ result.set_parameter(offload[0], offload[1])
+
+ result.add_tag(self.params.product_name)
+ if self.params.nperf_mode == "multi":
+ result.add_tag("multithreaded")
+ result.set_parameter("num_parallel",
+ self.params.nperf_num_parallel)
+
+ ip_num = 0 if ipver is 'ipv4' else 1
+ netperf =
self.generate_netperf_cli(self.matched.m1.eth0.ips[ip_num],
+ ttype_name)
+
+
self.netperf_run(Netserver(bind=self.matched.m1.eth0.ips[ip_num]),
+ netperf,
+ result)
+ time.sleep(5)
+
+
+ctl = Controller(debug=1)
+
+r = SimpleNetperfRecipe()
+ctl.run(r, allow_virt=True)
--
2.5.5
_______________________________________________
LNST-developers mailing list -- lnst-developers(a)lists.fedorahosted.org
To unsubscribe send an email to lnst-developers-leave(a)lists.fedorahosted.org
pushed, thanks
-Ondrej