4444from vsc .utils .nagios import NAGIOS_EXIT_WARNING , NagiosStatusMixin
4545from vsc .utils .script_tools import (
4646 ExtendedSimpleOption , DEFAULT_OPTIONS , NrpeCLI , CLI , OldCLI ,
47- CLIBase , LockMixin , HAMixin , TimestampMixin )
48-
49- from lib .vsc .utils .script_tools import LogMixin
47+ CLIBase , LockMixin , HAMixin , TimestampMixin , LogMixin )
5048
5149
5250class TestExtendedSimpleOption (TestCase ):
@@ -120,7 +118,7 @@ def do(self, _):
120118 return magic .go ()
121119
122120class TestOldCLI (TestCase ):
123- """Tests for the CLI base class"""
121+ """Tests for the OldCLI base class"""
124122
125123 @mock .patch ('vsc.utils.script_tools.ExtendedSimpleOption.prologue' )
126124 def test_opts (self , _ ):
@@ -178,7 +176,7 @@ def test_exit(self, locklock, releaselock):
178176
179177
180178class TestNrpeCLI (TestCase ):
181- """Tests for the CLI base class"""
179+ """Tests for the NrpeCLI base class"""
182180
183181 def setUp (self ):
184182 super ().setUp ()
@@ -190,7 +188,7 @@ class MyNrpeCLI(NrpeCLI):
190188 'magic' : ('some magic' , None , 'store' , 'magicdef' ),
191189 }
192190
193- def do (self ,dryrun ):
191+ def do (self , dry_run ):
194192 return magic .go ()
195193
196194 self .cli = MyNrpeCLI (name = "abc" )
@@ -263,16 +261,15 @@ def do(self, dry_run):
263261
264262 self .ms = MyCLI (name = "abc" )
265263
266- class SomeCLI (HAMixin , LockMixin , LogMixin , NagiosStatusMixin , CLIBase ):
267- CLI_OPTIONS = {
268- 'magic' : ('magicdef' , None , 'store' , 'magicdef' ),
269- }
270-
271- self .some_ms = SomeCLI (name = "abc" )
272-
273264 @mock .patch ('vsc.utils.script_tools.ExtendedSimpleOption.prologue' )
274265 def test_opts (self , _ ):
275266
267+ self .assertTrue (isinstance (self .ms , LogMixin ))
268+ self .assertTrue (isinstance (self .ms , HAMixin ))
269+ self .assertTrue (isinstance (self .ms , LockMixin ))
270+ self .assertTrue (isinstance (self .ms , NagiosStatusMixin ))
271+ self .assertTrue (isinstance (self .ms , TimestampMixin ))
272+
276273 logging .debug ("options %s %s %s" , self .ms .options , dir (self .ms .options ), vars (self .ms .options ))
277274
278275 extsimpopts = {
@@ -301,32 +298,74 @@ def test_opts(self, _):
301298 myopts .update (extsimpopts )
302299 self .assertEqual (self .ms .options .__dict__ , myopts )
303300
301+ @mock .patch ('vsc.utils.script_tools.lock_or_bork' )
302+ @mock .patch ('vsc.utils.script_tools.release_or_bork' )
303+ def test_exit (self , locklock , releaselock ):
304+
305+ fake_exit = mock .MagicMock ()
306+ with mock .patch ('vsc.utils.script_tools.sys.exit' , fake_exit ):
307+ self .ms .warning ("be warned" )
308+ fake_exit .assert_called_with (1 )
309+
310+
311+ class TestBaseNoTimestamp (TestCase ):
312+
313+ def setUp (self ):
314+ super ().setUp ()
315+
316+ sys .argv = ["abc" ]
317+
318+ class NoTimeStampCLI (HAMixin , LockMixin , LogMixin , NagiosStatusMixin , CLIBase ):
319+ CLI_OPTIONS = {
320+ 'magic' : ('magicdef' , None , 'store' , 'magicdef' ),
321+ }
322+ def do (self , dry_run ):
323+ return magic .go ()
324+
325+ self .ms = NoTimeStampCLI (name = "abc" )
326+
327+ if isinstance (self .ms , LogMixin ):
328+ logging .warning ("LogMixin is part of this instance" )
329+ else :
330+ logging .warning ("LogMixin is not part of this instance" )
331+
332+
333+ if isinstance (self .ms , TimestampMixin ):
334+ logging .warning ("TimestampMixin is part of this instance" )
335+ else :
336+ logging .warning ("TimestampMixin is not part of this instance" )
337+
304338 def test_without_timestamp_mixin (self ):
305339
340+ self .assertTrue (isinstance (self .ms , LogMixin ))
341+ self .assertTrue (isinstance (self .ms , HAMixin ))
342+ self .assertTrue (isinstance (self .ms , LockMixin ))
343+ self .assertTrue (isinstance (self .ms , NagiosStatusMixin ))
344+
306345 extsimpopts = {
307346 'configfiles' : None ,
308- # 'debug': False,
347+ 'debug' : False ,
309348 'disable_locking' : False ,
310349 'dry_run' : False ,
311350 'ha' : None ,
312351 'help' : None ,
313352 'ignoreconfigfiles' : None ,
314- # 'info': False,
353+ 'info' : False ,
315354 'locking_filename' : '/var/lock/setup.lock' ,
316355 'nagios_check_filename' : '/var/cache/setup.nagios.json.gz' ,
317356 'nagios_check_interval_threshold' : 0 ,
318357 'nagios_report' : False ,
319358 'nagios_user' : 'nrpe' ,
320359 'nagios_world_readable_check' : False ,
321- # 'quiet': False,
360+ 'quiet' : False ,
322361 }
323362
324363 myopts = {
325364 'magic' : 'magicdef' ,
326365 }
327366 myopts .update (extsimpopts )
328- logging .debug ("options wo default sync options %s" , self .some_ms .options )
329- self .assertEqual (self .some_ms .options .__dict__ , myopts )
367+ logging .warning ("options wo default sync options %s" , self .ms .options )
368+ self .assertEqual (self .ms .options .__dict__ , myopts )
330369
331370 @mock .patch ('vsc.utils.script_tools.lock_or_bork' )
332371 @mock .patch ('vsc.utils.script_tools.release_or_bork' )
0 commit comments