Add : service without host will be just droped, like Nagios.
[shinken.git] / test / test_action.py
blob16cc4d2f86bad12842978fe9eb0720cec8fa0e61
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, 100000):
36 if a.status == 'launched':
37 a.check_finished(8012)
38 time.sleep(0.01)
40 #Change ME :)
41 def test_action(self):
42 a = Action()
43 a.timeout = 10
44 a.env = {}
46 if os.name == 'nt':
47 a.command = r'libexec\\dummy_command.cmd'
48 else:
49 a.command = "libexec/dummy_command.sh"
50 self.assert_(a.got_shell_characters() == False)
51 a.execute()
52 self.assert_(a.status == 'launched')
53 #Give also the max output we want for the command
54 self.wait_finished(a)
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):
62 a = Action()
63 a.timeout = 10
64 if os.name == 'nt':
65 return
66 else:
67 a.command = "/usr/bin/env"
68 a.env = {'TITI' : 'est en vacance'}
70 self.assert_(a.got_shell_characters() == False)
72 a.execute()
74 self.assert_(a.status == 'launched')
75 #Give also the max output we want for the command
76 self.wait_finished(a)
77 print "Output", a.long_output, a.output
78 titi_found = False
79 for l in a.long_output.splitlines():
80 if l == 'TITI=est en vacance':
81 titi_found = True
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):
89 a = Action()
90 a.timeout = 10
91 a.command = "libexec/dummy_command_nobang.sh"
92 a.env = {}
93 if os.name == 'nt':
94 return
95 self.assert_(a.got_shell_characters() == False)
96 a.execute()
98 self.assert_(a.status == 'launched')
99 self.wait_finished(a)
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):
106 a = Action()
107 a.timeout = 10
108 a.command = "libexec/dummy_command_nobang.sh && echo finished ok"
109 a.env = {}
110 if os.name == 'nt':
111 return
112 self.assert_(a.got_shell_characters() == True)
113 a.execute()
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__':
122 import sys
124 os.chdir(os.path.dirname(sys.argv[0]))
125 unittest.main()