[PATCH] osmo-gsm-tester[master]: Use tmpdir to create bts pcu-socket

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/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Fri Sep 8 12:09:58 UTC 2017


Review at  https://gerrit.osmocom.org/3894

Use tmpdir to create bts pcu-socket

In commit 329b6f4 pcu-socket path was moved to run inside the test run
dir to avoid issues between different tests creating a socket in the
same place.

However, it seems unix sockets paths are limited to 108 bytes (with Null
char included). In some cases, the run dir for a test can be quite long,
as it contains suite name, test name, etc. and the path can be longer
that the limit defined above.

In order to fix this issue, create a tmp dir using mkdtemp to ensure the
path to be used for the pcu-socket doesn't collide between different
instances of osmo-bts-trx.

Clean up of tmp dir and pcu socket is done inside the cleanup() method
called by suite.py.

method pcu_socket_path() is added to help with new implementation, and
it will be used as well as a public API later soon to be used by OsmoPcu
classes.

Related: OS#2507

Change-Id: I0c53a0a3ccc5eb2823265fe14c0f7b8f4adb1038
---
M src/osmo_gsm_tester/bts_osmotrx.py
M src/osmo_gsm_tester/bts_sysmo.py
M src/osmo_gsm_tester/suite.py
3 files changed, 27 insertions(+), 3 deletions(-)


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

diff --git a/src/osmo_gsm_tester/bts_osmotrx.py b/src/osmo_gsm_tester/bts_osmotrx.py
index b5262a2..3077b0f 100644
--- a/src/osmo_gsm_tester/bts_osmotrx.py
+++ b/src/osmo_gsm_tester/bts_osmotrx.py
@@ -19,6 +19,7 @@
 
 import os
 import pprint
+import tempfile
 from . import log, config, util, template, process, event_loop
 
 class OsmoBtsTrx(log.Origin):
@@ -28,6 +29,7 @@
     inst = None
     env = None
     trx = None
+    pcu_sk_tmp_dir = None
 
     BIN_BTS_TRX = 'osmo-bts-trx'
     BIN_PCU = 'osmo-pcu'
@@ -39,6 +41,20 @@
         self.suite_run = suite_run
         self.conf = conf
         self.env = {}
+        self.pcu_sk_tmp_dir = tempfile.mkdtemp(None, 'ogtpcusk', None)
+        if len(self.pcu_socket_path().encode()) > 107:
+            raise log.Error('Path for pcu socket is longer than max allowed len for unix socket path (107):', self.pcu_socket_path())
+
+    def cleanup(self):
+        if self.pcu_sk_tmp_dir:
+            try:
+                os.remove(self.pcu_socket_path())
+            except OSError:
+                pass
+            os.rmdir(self.pcu_sk_tmp_dir)
+
+    def pcu_socket_path(self):
+        return os.path.join(self.pcu_sk_tmp_dir, 'pcu_bts')
 
     def remote_addr(self):
         return self.conf.get('addr')
@@ -105,7 +121,7 @@
                             'oml_remote_ip': self.bsc.addr(),
                             'trx_local_ip': self.remote_addr(),
                             'trx_remote_ip': self.trx_remote_ip(),
-                            'pcu_socket_path': os.path.join(str(self.run_dir), 'pcu_bts')
+                            'pcu_socket_path': self.pcu_socket_path(),
                         }
         })
         config.overlay(values, { 'osmo_bts_trx': self.conf })
diff --git a/src/osmo_gsm_tester/bts_sysmo.py b/src/osmo_gsm_tester/bts_sysmo.py
index f37f88b..e8ac7c2 100644
--- a/src/osmo_gsm_tester/bts_sysmo.py
+++ b/src/osmo_gsm_tester/bts_sysmo.py
@@ -80,6 +80,12 @@
              '-i', self.bsc.addr()),
             remote_cwd=remote_run_dir)
 
+    def cleanup(self):
+        pass
+
+    def pcu_socket_path(self):
+        return os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts')
+
     def _process_remote(self, name, popen_args, remote_cwd=None):
         run_dir = self.run_dir.new_dir(name)
         return process.RemoteProcess(name, run_dir, self.remote_user, self.remote_addr(), remote_cwd,
@@ -122,7 +128,7 @@
         config.overlay(values, {
                         'osmo_bts_sysmo': {
                             'oml_remote_ip': self.bsc.addr(),
-                            'pcu_socket_path': os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts')
+                            'pcu_socket_path': self.pcu_socket_path(),
                         }
         })
         config.overlay(values, { 'osmo_bts_sysmo': self.conf })
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index 2ac2062..9b975fd 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -351,7 +351,9 @@
         return osmo_stp.OsmoStp(self, ip_address)
 
     def bts(self, specifics=None):
-        return bts_obj(self, self.reserved_resources.get(resource.R_BTS, specifics=specifics))
+        bts = bts_obj(self, self.reserved_resources.get(resource.R_BTS, specifics=specifics))
+        self.register_for_cleanup(bts)
+        return bts
 
     def modem(self, specifics=None):
         conf = self.reserved_resources.get(resource.R_MODEM, specifics=specifics)

-- 
To view, visit https://gerrit.osmocom.org/3894
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c53a0a3ccc5eb2823265fe14c0f7b8f4adb1038
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list