Change in osmo-gsm-tester[master]: ms_driver: Switch to process.Process from subprocess

Holger Freyther gerrit-no-reply at lists.osmocom.org
Wed Nov 14 21:16:54 UTC 2018


Holger Freyther has submitted this change and it was merged. ( https://gerrit.osmocom.org/11597 )

Change subject: ms_driver: Switch to process.Process from subprocess
......................................................................

ms_driver: Switch to process.Process from subprocess

Use a single tmp/rundir for all these instances. In the next step
we can create separate directories.

Change-Id: Icf4d4e161ac4283a63ed4e0745b375e7e6a25004
---
M src/osmo_gsm_tester/ms_driver.py
M src/osmo_ms_driver/__main__.py
M src/osmo_ms_driver/location_update_test.py
M src/osmo_ms_driver/starter.py
4 files changed, 27 insertions(+), 28 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Pau Espin Pedrol: Looks good to me, approved



diff --git a/src/osmo_gsm_tester/ms_driver.py b/src/osmo_gsm_tester/ms_driver.py
index 86186b7..36da921 100644
--- a/src/osmo_gsm_tester/ms_driver.py
+++ b/src/osmo_gsm_tester/ms_driver.py
@@ -63,7 +63,6 @@
         self._test_duration = timedelta(seconds=120)
         self._cdf = cdfs["ease_in_out"](self._time_start, self._time_step)
         self._loop = SimpleLoop()
-        self._suite_run.remember_to_stop(self)
         self._test_case = None
         self.event_server_sk_tmp_dir = None
 
@@ -86,7 +85,8 @@
         self._ev_server.listen(self._loop)
         options = BinaryOptions("virtphy", "mobile", None)
         self._test_case = MassUpdateLocationTest("mass", options, self._num_ms, self._cdf,
-                                                 self._ev_server, self.event_server_sk_tmp_dir)
+                                                 self._ev_server, self.event_server_sk_tmp_dir,
+                                                 suite_run=self._suite_run)
 
         # TODO: We should pass subscribers down to the test and not get it from
         # there.
@@ -120,16 +120,11 @@
 
     def cleanup(self):
         """
-        Stops the testcase and all launched processes. Called by the
-        suite.
+        Cleans up the driver (e.g. AF_UNIX files).
         """
 
         # Clean-up the temporary directory.
         if self.event_server_sk_tmp_dir:
             shutil.rmtree(path=self.event_server_sk_tmp_dir)
 
-        if not self._test_case:
-            return
-        self._test_case.stop_all()
-
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_ms_driver/__main__.py b/src/osmo_ms_driver/__main__.py
index 265ce47..0e3611b 100644
--- a/src/osmo_ms_driver/__main__.py
+++ b/src/osmo_ms_driver/__main__.py
@@ -83,7 +83,7 @@
     ev_server.listen(loop)
 
     # Just a single test for now.
-    options = BinaryOptions("virtphy", "mobile", None)
+    options = BinaryOptions("virtphy", "mobile", os.environ)
     test = MassUpdateLocationTest("lu_test", options, args.num_ms, cdf, ev_server, tmp_dir)
     atexit.register(test.stop_all)
 
diff --git a/src/osmo_ms_driver/location_update_test.py b/src/osmo_ms_driver/location_update_test.py
index dee99fe..90e405e 100644
--- a/src/osmo_ms_driver/location_update_test.py
+++ b/src/osmo_ms_driver/location_update_test.py
@@ -56,12 +56,14 @@
     TEMPLATE_LUA = "osmo-mobile-lu.lua"
     TEMPLATE_CFG = "osmo-mobile.cfg"
 
-    def __init__(self, name, options, number_of_ms, cdf_function, event_server, tmp_dir):
+    def __init__(self, name, options, number_of_ms, cdf_function,
+                 event_server, tmp_dir, suite_run=None):
         super().__init__(log.C_RUN, name)
         self._binary_options = options
         self._number_of_ms = number_of_ms
         self._cdf = cdf_function
         self._cdf.set_target(number_of_ms)
+        self._suite_run = suite_run
         self._unstarted = []
         self._mobiles = []
         self._phys = []
@@ -100,7 +102,7 @@
         """
         self.log("Pre-launching all virtphy's")
         for phy in self._phys:
-            phy.start(loop)
+            phy.start(loop, self._suite_run)
 
         self.log("Checking if sockets are in the filesystem")
         for phy in self._phys:
@@ -132,7 +134,7 @@
         # start pending MS
         while len(self._started) < self._cdf.current_scaled_value() and len(self._unstarted) > 0:
             ms = self._unstarted.pop(0)
-            ms.start(loop)
+            ms.start(loop, self._suite_run)
             launch_time = time.clock_gettime(time.CLOCK_MONOTONIC)
             self._results[ms.name_number()].set_launch_time(launch_time)
             self._started.append(ms)
@@ -170,7 +172,7 @@
 
     def stop_all(self):
         for launcher in self._started:
-            launcher.kill()
+            launcher.terminate()
 
     def handle_msg(self, _data, addr, time):
         import json
diff --git a/src/osmo_ms_driver/starter.py b/src/osmo_ms_driver/starter.py
index 2ffb33a..66027c6 100644
--- a/src/osmo_ms_driver/starter.py
+++ b/src/osmo_ms_driver/starter.py
@@ -16,17 +16,13 @@
 # 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 osmo_gsm_tester import log, template
+from osmo_gsm_tester import log, process, template
 
 import collections
 import os
 import os.path
-import subprocess
 import time
 
-_devnull = open(os.devnull, 'w')
-#_devnull = open('/dev/stdout', 'w')
-
 BinaryOptions = collections.namedtuple("BinaryOptions", ["virtphy", "mobile", "env"])
 
 class Launcher(log.Origin):
@@ -49,14 +45,17 @@
     def phy_filename(self):
         return self._phy_filename
 
-    def start(self, loop):
+    def start(self, loop, suite_run=None):
         if len(self._phy_filename.encode()) > 107:
             raise log.Error('Path for unix socket is longer than max allowed len for unix socket path (107):', self._phy_filename)
 
-        self.log("Starting virtphy process")
+        self.log("Starting virtphy")
         args = [self._binary, "--l1ctl-sock=" + self._phy_filename]
-        self.log(' '.join(args))
-        self._vphy_proc = subprocess.Popen(args, stderr=_devnull, stdout=_devnull, env=self._env)
+        self._vphy_proc = process.Process(self.name(), self._tmp_dir,
+                                          args, env=self._env)
+        if suite_run:
+            suite_run.remember_to_stop(self._vphy_proc)
+        self._vphy_proc.launch()
 
     def verify_ready(self):
         while True:
@@ -64,7 +63,7 @@
                 return
             time.sleep(0.2)
 
-    def kill(self):
+    def terminate(self):
         """Clean up things."""
         if self._vphy_proc:
             self._vphy_proc.terminate()
@@ -116,17 +115,20 @@
             w.write(mob_vty)
         return mob_cfg_file
 
-    def start(self, loop):
+    def start(self, loop, suite_run=None):
         lua_filename = self.write_lua_cfg()
         mob_filename = self.write_mob_cfg(lua_filename, self._phy_filename)
 
-        self.log("Starting process")
+        self.log("Starting mobile")
         # Let the kernel pick an unused port for the VTY.
         args = [self._binary, "-c", mob_filename, "--vty-port=0"]
-        self.log(' '.join(args))
-        self._omob_proc = subprocess.Popen(args, stderr=_devnull, stdout=_devnull, env=self._env)
+        self._omob_proc = process.Process(self.name(), self._tmp_dir,
+                                          args, env=self._env)
+        if suite_run:
+            suite_run.remember_to_stop(self._omob_proc)
+        self._omob_proc.launch()
 
-    def kill(self):
+    def terminate(self):
         """Clean up things."""
         if self._omob_proc:
             self._omob_proc.terminate()

-- 
To view, visit https://gerrit.osmocom.org/11597
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Icf4d4e161ac4283a63ed4e0745b375e7e6a25004
Gerrit-Change-Number: 11597
Gerrit-PatchSet: 4
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181114/bc95ce20/attachment.html>


More information about the gerrit-log mailing list