Merge branch 'master' of ssh://naparuba@shinken.git.sourceforge.net/gitroot/shinken...
[shinken.git] / test / test_action.py
blob273f2b0604845cea96e2a8ad6afa2e8a010507b6
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
25 import os
27 #It's ugly I know....
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, 10000):
36 if a.status == 'launched':
37 a.check_finished(8012)
39 #Change ME :)
40 def test_action(self):
41 a = Action()
42 a.timeout = 10
43 a.env = {}
45 if os.name == 'nt':
46 a.command = "./dummy_command.cmd"
47 else:
48 a.command = "./dummy_command.sh"
49 self.assert_(a.got_shell_caracters() == False)
50 a.execute()
51 self.assert_(a.status == 'launched')
52 #Give also the max output we want for the command
53 self.wait_finished(a)
54 self.assert_(a.exit_status == 0)
55 self.assert_(a.status == 'done')
56 self.assert_(a.output == "Hi, I'm for testing only. Please do not use me directly, really")
57 self.assert_(a.perf_data == "Hip=99% Bob=34mm")
60 def test_environnement_variables(self):
61 a = Action()
62 a.timeout = 10
63 if os.name == 'nt':
64 return
65 else:
66 a.command = "/usr/bin/env"
67 a.env = {'TITI' : 'est en vacance'}
69 self.assert_(a.got_shell_caracters() == False)
71 a.execute()
73 self.assert_(a.status == 'launched')
74 #Give also the max output we want for the command
75 self.wait_finished(a)
76 print "Output", a.long_output, a.output
77 titi_found = False
78 for l in a.long_output.splitlines():
79 if l == 'TITI=est en vacance':
80 titi_found = True
82 self.assert_(titi_found == True)
85 #Some commands are shell without bangs! (like in Centreon...)
86 #We can show it in the launch, and it should be managed
87 def test_noshell_bang_command(self):
88 a = Action()
89 a.timeout = 10
90 a.command = "./dummy_command_nobang.sh"
91 a.env = {}
92 if os.name == 'nt':
93 return
94 self.assert_(a.got_shell_caracters() == False)
95 a.execute()
97 self.assert_(a.status == 'launched')
98 self.wait_finished(a)
99 print "FUck", a.status, a.output
100 self.assert_(a.exit_status == 0)
101 self.assert_(a.status == 'done')
105 if __name__ == '__main__':
106 unittest.main()