Ema has submitted this change and it was merged. (
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, 39 insertions(+), 1 deletion(-)
Approvals:
Ema: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pybal/monitors/runcommand.py b/pybal/monitors/runcommand.py
index b10afce..d1a3cc7 100644
--- a/pybal/monitors/runcommand.py
+++ b/pybal/monitors/runcommand.py
@@ -117,7 +117,13 @@
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, ValueError):
+ # Default to empty stringlist if runcommand.arguments has not been
+ # specified or if it is an empty list
+ 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..ff6935f 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,34 @@
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, [""])
+
+ def testInitArgumentsNotStringList(self):
+ self.config['runcommand.arguments'] = "[]"
+ 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: merged
Gerrit-Change-Id: Ie4233179e2cda0661b673fb6eeec4e13eed803e9
Gerrit-PatchSet: 2
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Ema <[email protected]>
Gerrit-Reviewer: BBlack <[email protected]>
Gerrit-Reviewer: Elukey <[email protected]>
Gerrit-Reviewer: Ema <[email protected]>
Gerrit-Reviewer: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits