Ema has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/384000 )

Change subject: runcommand: do not crash on empty runcommand.arguments
......................................................................

runcommand: do not crash on empty runcommand.arguments

Bug: T178149
Change-Id: Ie4233179e2cda0661b673fb6eeec4e13eed803e9
---
M pybal/monitors/runcommand.py
M pybal/test/test_monitors.py
2 files changed, 31 insertions(+), 1 deletion(-)


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

diff --git a/pybal/monitors/runcommand.py b/pybal/monitors/runcommand.py
index b10afce..d0bb5a8 100644
--- a/pybal/monitors/runcommand.py
+++ b/pybal/monitors/runcommand.py
@@ -117,7 +117,11 @@
         self.intvCheck = self._getConfigInt('interval', self.INTV_CHECK)
         self.timeout = self._getConfigInt('timeout', self.TIMEOUT_RUN)
         self.command = self._getConfigString('command')
-        self.arguments = self._getConfigStringList('arguments', locals=locals)
+        try:
+            self.arguments = self._getConfigStringList('arguments', 
locals=locals)
+        except KeyError:
+            self.arguments = [""]
+
         self.logOutput = self._getConfigBool('log-output', True)
 
         self.checkCall = None
diff --git a/pybal/test/test_monitors.py b/pybal/test/test_monitors.py
index ed5d05f..09daba8 100644
--- a/pybal/test/test_monitors.py
+++ b/pybal/test/test_monitors.py
@@ -10,6 +10,7 @@
 import pybal.util
 from pybal.monitors.idleconnection import IdleConnectionMonitoringProtocol
 from pybal.monitors.dnsquery import DNSQueryMonitoringProtocol
+from pybal.monitors.runcommand import RunCommandMonitoringProtocol
 
 from twisted.internet import defer
 from twisted.internet.reactor import getDelayedCalls
@@ -188,3 +189,28 @@
     def testQueryFailedUnknownError(self):
         self.__testQuery(expectSuccess=False,
                          fakeResolver=FakeResolverUnknownError)
+
+
+class RunCommandMonitoringProtocolTestCase(PyBalTestCase):
+    """Test case for `pybal.monitors.RunCommandMonitoringProtocol`."""
+
+    def setUp(self):
+        super(RunCommandMonitoringProtocolTestCase, self).setUp()
+        self.config = pybal.util.ConfigDict()
+        self.config['runcommand.command'] = '/bin/true'
+
+    def testInit(self):
+        self.config['runcommand.arguments'] = '[ "--help" ]'
+        self.monitor = RunCommandMonitoringProtocol(
+            self.coordinator, self.server, self.config)
+
+        self.assertEquals(self.monitor.intvCheck,
+                          RunCommandMonitoringProtocol.INTV_CHECK)
+        self.assertEquals(self.monitor.timeout,
+                          RunCommandMonitoringProtocol.TIMEOUT_RUN)
+        self.assertEquals(self.monitor.arguments, ["--help",])
+
+    def testInitNoArguments(self):
+        self.monitor = RunCommandMonitoringProtocol(
+            self.coordinator, self.server, self.config)
+        self.assertEquals(self.monitor.arguments, [""])

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

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

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

Reply via email to