Pau Espin Pedrol | 969a4ee | 2020-07-02 13:21:08 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running stress(-ng), a tool to load and stress a computer system |
| 2 | # |
| 3 | # Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH |
| 4 | # |
| 5 | # Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as |
| 9 | # published by the Free Software Foundation, either version 3 of the |
| 10 | # License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | from ..core import log |
| 21 | from ..core import util |
| 22 | from ..core import process |
| 23 | from ..core import remote |
| 24 | |
| 25 | class StressTool(log.Origin): |
| 26 | |
| 27 | STRESS_BIN = 'stress' |
| 28 | |
| 29 | ############## |
| 30 | # PROTECTED |
| 31 | ############## |
| 32 | def __init__(self, testenv, run_node): |
| 33 | super().__init__(log.C_RUN, StressTool.STRESS_BIN) |
| 34 | self.testenv = testenv |
| 35 | self._run_node = run_node |
| 36 | self.proc = None |
| 37 | self.rem_host = None |
| 38 | |
| 39 | def runs_locally(self): |
| 40 | locally = not self._run_node or self._run_node.is_local() |
| 41 | return locally |
| 42 | |
| 43 | ################### |
| 44 | # PUBLIC (test API included) |
| 45 | ################### |
| 46 | def start(self, cpu_workers=0, mem_workers=0, io_workers=0, timeout=0): |
| 47 | self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name())) |
| 48 | |
| 49 | popen_args = (StressTool.STRESS_BIN,) |
| 50 | if cpu_workers > 0: |
| 51 | popen_args += ('-c', str(cpu_workers)) |
| 52 | if mem_workers > 0: |
| 53 | popen_args += ('-m', str(mem_workers)) |
| 54 | if io_workers > 0: |
| 55 | popen_args += ('-i', str(io_workers)) |
| 56 | if timeout > 0: |
| 57 | popen_args += ('-t', str(timeout)) |
| 58 | |
| 59 | if self.runs_locally(): |
| 60 | self.proc = process.Process(self.name(), self.run_dir, popen_args, env={}) |
| 61 | else: |
| 62 | self.rem_host = remote.RemoteHost(self.run_dir, self._run_node.ssh_user(), self._run_node.ssh_addr()) |
| 63 | self.proc = self.rem_host.RemoteProcess(self.name(), popen_args, env={}) |
| 64 | # Warning: Be aware that if process ends before test is finished due to |
| 65 | # "-t timeout" param being set, the test will most probably fail as |
| 66 | # detected 'early exit' by the testenv. |
| 67 | self.testenv.remember_to_stop(self.proc) |
| 68 | self.proc.launch() |
| 69 | |
| 70 | def stop(self): |
| 71 | self.testenv.stop_process(self.proc) |
| 72 | |
| 73 | # vim: expandtab tabstop=4 shiftwidth=4 |