Skip to content

Commit 6c1862d

Browse files
authored
Merge pull request hpcugent#69 from itkovian/fix-exit-cli
Fix the argument order and add a test
2 parents 3486a2d + 93cda80 commit 6c1862d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

lib/vsc/utils/script_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,20 @@ def warning(self, msg):
285285
"""
286286
Convenience method that calls ExtendedSimpleOptions warning and exists with nagios warning exitcode
287287
"""
288-
exit_from_errorcode(msg, 1)
288+
exit_from_errorcode(1, msg)
289289

290290
def critical(self, msg):
291291
"""
292292
Convenience method that calls ExtendedSimpleOptions critical and exists with nagios critical exitcode
293293
"""
294-
exit_from_errorcode(msg, 2)
294+
exit_from_errorcode(2, msg)
295295

296296
def critical_exception(self, msg, exception):
297297
"""
298298
Convenience method: report exception and critical method
299299
"""
300300
logging.exception("%s: %s", msg, exception)
301-
exit_from_errorcode(msg, 2)
301+
exit_from_errorcode(2, msg)
302302

303303
def do(self, dry_run): #pylint: disable=unused-argument
304304
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656

5757
PACKAGE = {
58-
'version': '2.1.1',
58+
'version': '2.1.2',
5959
'author': [ag, sdw],
6060
'maintainer': [ag, sdw],
6161
'excluded_pkgs_rpm': ['vsc', 'vsc.utils'], # vsc is default, vsc.utils is provided by vsc-base

test/script_tools.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
import sys
3535

3636
from vsc.install.testing import TestCase
37+
from vsc.utils.nagios import NAGIOS_EXIT_WARNING
3738
from vsc.utils.script_tools import ExtendedSimpleOption, DEFAULT_OPTIONS, CLI
3839

39-
4040
class TestExtendedSimpleOption(TestCase):
4141
"""
4242
Tests for the ExtendedSimpleOption class.
@@ -146,3 +146,14 @@ def test_opts(self, prol):
146146
logging.debug("options wo default sync options %s", ms.options)
147147
self.assertEqual(ms.options.__dict__, myopts)
148148

149+
@mock.patch('vsc.utils.script_tools.ExtendedSimpleOption.prologue')
150+
def test_exit(self, mock_prologue):
151+
152+
cli = MyCLI()
153+
154+
fake_exit = mock.MagicMock()
155+
with mock.patch('vsc.utils.nagios._real_exit', fake_exit):
156+
cli.warning("be warned")
157+
fake_exit.assert_called_with("be warned", NAGIOS_EXIT_WARNING)
158+
159+

0 commit comments

Comments
 (0)