Mark Bergsma has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/172215

Change subject: Add error logging for ipvsadm invocations
......................................................................

Add error logging for ipvsadm invocations

Rewrites the existing (synchronous) invocation of ipvsadm using
os.popen using Twisted's (asynchronous) spawnProcess.

UNTESTED MOCKUP

Change-Id: I2f58010d2e19004b2524e0858254f5b846478f6b
---
M pybal/ipvs.py
1 file changed, 29 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal 
refs/changes/15/172215/1

diff --git a/pybal/ipvs.py b/pybal/ipvs.py
index 2387b38..1e7f6b0 100644
--- a/pybal/ipvs.py
+++ b/pybal/ipvs.py
@@ -5,7 +5,28 @@
 LVS state/configuration classes for PyBal
 """
 
-import os
+from twisted.internet import reactor, defer, protocol, error
+
+class IPVSProcessProtocol(protocol.ProcessProtocol):
+    def __init__(self, cmdList):
+        super(IPVSProcessProtocol, self).__init__()
+
+        self.stderr = ""
+        self.cmdList = cmdList
+
+    def connectionMade(self):
+        # Send the ipvsadm commands
+        self.transport.writeSequence(self.cmdList)
+        self.transport.closeStdin()
+
+    def errReceived(self, data):
+        self.stderr += data
+
+    def processExited(self, reason):
+        if reason.check(error.ProcessTerminated):
+            print "ipvsadm exited with status %d when executing cmdlist %s" % 
(reason.value.exitCode, self.cmdList)
+            print "ipvsadm stderr output:"
+            print self.stderr
 
 class IPVSManager:
     """
@@ -23,16 +44,13 @@
         """
         
         print cmdList
-        if cls.DryRun: return
-        
-        command = [cls.ipvsPath, '-R']
-        stdin = os.popen(" ".join(command), 'w')
-        for line in cmdList:
-            stdin.write(line + '\n')
-        stdin.close()
-        
-        # FIXME: Check return code and act on failure
-        
+        if cls.DryRun: return defer.succeed(0)
+
+        ipvsProcessProtocol = IPVSProcessProtocol(cmdList)
+        return reactor.spawnProcess(ipvsProcessProtocol, cls.ipvsPath, 
[cls.ipvsPath, '-R'])
+
+        # FIXME: Do something with this deferred
+
     modifyState = classmethod(modifyState)
     
     def subCommandService(service):

-- 
To view, visit https://gerrit.wikimedia.org/r/172215
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f58010d2e19004b2524e0858254f5b846478f6b
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Mark Bergsma <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to