[MERGED] python/osmo-python-tests[master]: cosmetic: put socket connection code in separate function

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
Mon Mar 6 14:31:52 UTC 2017


Neels Hofmeyr has submitted this change and it was merged.

Change subject: cosmetic: put socket connection code in separate function
......................................................................


cosmetic: put socket connection code in separate function

Prepare for upcoming patch that adds connection retries to speed up tests.

Change-Id: I2dddf8794b4241898373178c8a1aa2e98b01095c
---
M osmopy/obscvty.py
1 file changed, 15 insertions(+), 10 deletions(-)

Approvals:
  Holger Freyther: Looks good to me, approved



diff --git a/osmopy/obscvty.py b/osmopy/obscvty.py
index f5c85fb..857d75b 100755
--- a/osmopy/obscvty.py
+++ b/osmopy/obscvty.py
@@ -68,6 +68,19 @@
         self.priv_end = re.compile('\r\n%s(?:\(([\w-]*)\))?# $' % self.name)
         self.last_node = ''
 
+    def _connect_socket(self):
+        if self.socket is not None:
+            return
+        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)
+
     def _close_socket(self):
         global debug_tcp_sockets
         if self.socket is None:
@@ -141,16 +154,8 @@
         global debug_tcp_sockets
         if not ends:
             ends = [self.norm_end, self.priv_end]
-        if not self.socket:
-            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)
+
+        self._connect_socket()
 
         # Now send the command
         self.socket.send("%s\r" % request)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2dddf8794b4241898373178c8a1aa2e98b01095c
Gerrit-PatchSet: 2
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list