1 #!/usr/bin/env python2.6
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
8 #Shinken is free software: you can redistribute it and/or modify
9 #it under the terms of the GNU Affero General Public License as published by
10 #the Free Software Foundation, either version 3 of the License, or
11 #(at your option) any later version.
13 #Shinken is distributed in the hope that it will be useful,
14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #GNU Affero General Public License for more details.
18 #You should have received a copy of the GNU Affero General Public License
19 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
22 # This file is used to test reading and processing of config files
28 from shinken_test
import *
29 from shinken
.action
import Action
31 class TestConfig(ShinkenTest
):
32 #setUp is in shinken_test
34 def wait_finished(self
, a
):
35 for i
in xrange(1, 100000):
36 if a
.status
== 'launched':
37 a
.check_finished(8012)
41 def test_action(self
):
47 a
.command
= r
'libexec\\dummy_command.cmd'
49 a
.command
= "libexec/dummy_command.sh"
50 self
.assert_(a
.got_shell_characters() == False)
52 self
.assert_(a
.status
== 'launched')
53 #Give also the max output we want for the command
55 self
.assert_(a
.exit_status
== 0)
56 self
.assert_(a
.status
== 'done')
57 self
.assert_(a
.output
== "Hi, I'm for testing only. Please do not use me directly, really")
58 self
.assert_(a
.perf_data
== "Hip=99% Bob=34mm")
61 def test_environnement_variables(self
):
67 a
.command
= "/usr/bin/env"
68 a
.env
= {'TITI' : 'est en vacance'}
70 self
.assert_(a
.got_shell_characters() == False)
74 self
.assert_(a
.status
== 'launched')
75 #Give also the max output we want for the command
77 print "Output", a
.long_output
, a
.output
79 for l
in a
.long_output
.splitlines():
80 if l
== 'TITI=est en vacance':
83 self
.assert_(titi_found
== True)
86 #Some commands are shell without bangs! (like in Centreon...)
87 #We can show it in the launch, and it should be managed
88 def test_noshell_bang_command(self
):
91 a
.command
= "libexec/dummy_command_nobang.sh"
95 self
.assert_(a
.got_shell_characters() == False)
98 self
.assert_(a
.status
== 'launched')
100 print "FUck", a
.status
, a
.output
101 self
.assert_(a
.exit_status
== 0)
102 self
.assert_(a
.status
== 'done')
105 def test_got_shell_characters(self
):
108 a
.command
= "libexec/dummy_command_nobang.sh && echo finished ok"
112 self
.assert_(a
.got_shell_characters() == True)
115 self
.assert_(a
.status
== 'launched')
116 self
.wait_finished(a
)
117 print "FUck", a
.status
, a
.output
118 self
.assert_(a
.exit_status
== 0)
119 self
.assert_(a
.status
== 'done')
121 if __name__
== '__main__':
124 os
.chdir(os
.path
.dirname(sys
.argv
[0]))