From 969a4eebaefdeb62a80b9f6b746ba69574a14c0a Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Thu, 2 Jul 2020 13:21:08 +0200 Subject: Introduce stress tool object This object allows to run the "stress" cmdline program in the background on the specifies run_node, to simulate system load. To run stress, a test can simply do: stress = tenv.stress(epc.run_node()) stress.start(cpu_workers=2, mem_workers=1, io_workers=1) And the test environment will remember to stop it when the test finishes. Change-Id: I21023e6c64c48109f294291bfe3d8d8f4e1de038 --- src/osmo_gsm_tester/obj/stress.py | 73 +++++++++++++++++++++++++++++++++++++++ src/osmo_gsm_tester/testenv.py | 5 +++ 2 files changed, 78 insertions(+) create mode 100644 src/osmo_gsm_tester/obj/stress.py (limited to 'src/osmo_gsm_tester') diff --git a/src/osmo_gsm_tester/obj/stress.py b/src/osmo_gsm_tester/obj/stress.py new file mode 100644 index 0000000..f0e417a --- /dev/null +++ b/src/osmo_gsm_tester/obj/stress.py @@ -0,0 +1,73 @@ +# osmo_gsm_tester: specifics for running stress(-ng), a tool to load and stress a computer system +# +# Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH +# +# Author: Pau Espin Pedrol +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from ..core import log +from ..core import util +from ..core import process +from ..core import remote + +class StressTool(log.Origin): + + STRESS_BIN = 'stress' + +############## +# PROTECTED +############## + def __init__(self, testenv, run_node): + super().__init__(log.C_RUN, StressTool.STRESS_BIN) + self.testenv = testenv + self._run_node = run_node + self.proc = None + self.rem_host = None + + def runs_locally(self): + locally = not self._run_node or self._run_node.is_local() + return locally + +################### +# PUBLIC (test API included) +################### + def start(self, cpu_workers=0, mem_workers=0, io_workers=0, timeout=0): + self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name())) + + popen_args = (StressTool.STRESS_BIN,) + if cpu_workers > 0: + popen_args += ('-c', str(cpu_workers)) + if mem_workers > 0: + popen_args += ('-m', str(mem_workers)) + if io_workers > 0: + popen_args += ('-i', str(io_workers)) + if timeout > 0: + popen_args += ('-t', str(timeout)) + + if self.runs_locally(): + self.proc = process.Process(self.name(), self.run_dir, popen_args, env={}) + else: + self.rem_host = remote.RemoteHost(self.run_dir, self._run_node.ssh_user(), self._run_node.ssh_addr()) + self.proc = self.rem_host.RemoteProcess(self.name(), popen_args, env={}) + # Warning: Be aware that if process ends before test is finished due to + # "-t timeout" param being set, the test will most probably fail as + # detected 'early exit' by the testenv. + self.testenv.remember_to_stop(self.proc) + self.proc.launch() + + def stop(self): + self.testenv.stop_process(self.proc) + +# vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/osmo_gsm_tester/testenv.py b/src/osmo_gsm_tester/testenv.py index ea71df9..1790059 100644 --- a/src/osmo_gsm_tester/testenv.py +++ b/src/osmo_gsm_tester/testenv.py @@ -318,6 +318,11 @@ class TestEnv(log_module.Origin): iperf3srv_obj = IPerf3Server(self, ip_address) return iperf3srv_obj + def stress(self, run_node=None): + from .obj.stress import StressTool + stress_obj = StressTool(self, run_node) + return stress_obj + def msisdn(self): msisdn = self.suite_run.resource_pool().next_msisdn(self) self.log('using MSISDN', msisdn) -- cgit v1.2.3