[PATCH] python/osmo-python-tests[master]: debug: monitor used TCP sockets and running osmo processes

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

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri Feb 24 19:41:51 UTC 2017


Hello Harald Welte,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1904

to look at the new patch set (#2).

debug: monitor used TCP sockets and running osmo processes

Add global flag debug_tcp_sockets; if true, monitors all open TCP sockets of
the system and running processes by regular 'ss' and 'ps' output, and logs
which VTY sockets are opened and closed.

Change-Id: I0cc7dc049c66f29fe58fee204e74aa9e82c21989
---
M osmopy/obscvty.py
1 file changed, 33 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/04/1904/2

diff --git a/osmopy/obscvty.py b/osmopy/obscvty.py
index 3c9edb1..4c0803a 100755
--- a/osmopy/obscvty.py
+++ b/osmopy/obscvty.py
@@ -18,6 +18,7 @@
 #
 import re
 import socket
+import sys, subprocess
 
 """VTYInteract: interact with an osmocom vty
 
@@ -25,6 +26,23 @@
 Connections will be reestablished as necessary.
 Methods: __init__, command, enabled_command, verify, w_verify"""
 
+debug_tcp_sockets = True
+
+def cmd(what):
+    print '\n> %s' % what
+    sys.stdout.flush()
+    subprocess.call(what, shell=True)
+    sys.stdout.flush()
+    sys.stderr.flush()
+    print ''
+    sys.stdout.flush()
+
+def print_used_tcp_sockets():
+    if not debug_tcp_sockets:
+        return
+    cmd('ss -tn');
+    cmd('ss -tln');
+    cmd('ps xua | grep osmo');
 
 class VTYInteract(object):
     """__init__(self, name, host, port):
@@ -32,7 +50,12 @@
     name is the name the vty prints for commands, ie OpenBSC
     host is the hostname to connect to
     port is the port to connect on"""
+
+    all_sockets = []
+
     def __init__(self, name, host, port):
+        print_used_tcp_sockets()
+
         self.name = name
         self.host = host
         self.port = port
@@ -44,6 +67,11 @@
 
     def _close_socket(self):
         if self.socket:
+            if debug_tcp_sockets:
+                VTYInteract.all_sockets.remove(self.socket)
+                print "Socket: closing %s:%d %r (%d sockets open)" % (
+                        self.host, self.port, self.socket,
+                        len(VTYInteract.all_sockets))
             self.socket.close()
             self.socket = None
 
@@ -107,6 +135,11 @@
             self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self.socket.setblocking(1)
             self.socket.connect((self.host, self.port))
+            if debug_tcp_sockets:
+                VTYInteract.all_sockets.append(self.socket)
+                print "Socket: connected to %s:%d %r (%d sockets open)" % (
+                        self.host, self.port, self.socket,
+                        len(VTYInteract.all_sockets))
             self.socket.recv(4096)
 
         # Now send the command

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0cc7dc049c66f29fe58fee204e74aa9e82c21989
Gerrit-PatchSet: 2
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list