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

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Feb 27 01:13:32 UTC 2017


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

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(-)


  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/23/1923/1

diff --git a/osmopy/obscvty.py b/osmopy/obscvty.py
index cb2d06f..1f9db09 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: newchange
Gerrit-Change-Id: I2dddf8794b4241898373178c8a1aa2e98b01095c
Gerrit-PatchSet: 1
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list