Change in osmo-gsm-tester[master]: Introduce stress tool object

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Thu Jul 2 11:35:07 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-gsm-tester/+/19105 )


Change subject: Introduce stress tool object
......................................................................

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
---
A src/osmo_gsm_tester/obj/stress.py
M src/osmo_gsm_tester/testenv.py
2 files changed, 78 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/05/19105/1

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 <pespin at sysmocom.de>
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+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 @@
         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)

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/19105
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Change-Id: I21023e6c64c48109f294291bfe3d8d8f4e1de038
Gerrit-Change-Number: 19105
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200702/ff6b678f/attachment.htm>


More information about the gerrit-log mailing list