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/>.
23 # This file is used to test reading and processing of config files
28 from shinken_test
import unittest
, ShinkenTest
30 from shinken
.modules
.status_dat_broker
import get_instance
33 class TestConfig(ShinkenTest
):
34 #setUp is in shinken_test
36 def nb_of_string(self
, buf
, s
):
38 for line
in buf
.splitlines():
46 def test_simplelog(self
):
47 print self
.conf
.modules
50 for m
in self
.conf
.modules
:
51 if m
.module_type
== 'status_dat':
53 self
.assert_(mod
is not None)
54 self
.assert_(mod
.status_file
== '/usr/local/shinken/var/status.data')
55 self
.assert_(mod
.module_name
== 'Status-Dat')
56 self
.assert_(mod
.object_cache_file
== '/usr/local/shinken/var/objects.cache')
59 os
.unlink(mod
.status_file
)
60 os
.unlink(mod
.module_name
)
64 sl
= get_instance(mod
)
68 sl
.properties
['to_queue'] = None
69 self
.sched
.fill_initial_broks()
70 print self
.sched
.broks
72 for b
in self
.sched
.broks
.values():
76 #Now verify the objects.dat file
77 sl
.objects_cache
.create_or_update()
78 obj
= open(mod
.object_cache_file
)
81 #Check for 1 service and only one
82 nb_services
= self
.nb_of_string(buf
, "define service {")
83 self
.assert_(nb_services
== 1)
84 #2 hosts : host and a router
85 nb_hosts
= self
.nb_of_string(buf
, "define host {")
86 self
.assert_(nb_hosts
== 2)
89 sl
.status
.create_or_update()
90 status
= open(mod
.status_file
)
94 nb_prog
= self
.nb_of_string(buf
, "programstatus {")
95 self
.assert_(nb_prog
== 1)
97 nb_hosts
= self
.nb_of_string(buf
, "hoststatus {")
98 self
.assert_(nb_hosts
== 2)
100 nb_services
= self
.nb_of_string(buf
, "servicestatus {")
101 self
.assert_(nb_services
== 1)
104 #now check if after a resend we still got the good number
105 self
.sched
.broks
.clear()
106 self
.sched
.fill_initial_broks()
107 for b
in self
.sched
.broks
.values():
111 #Now verify the objects.dat file
112 sl
.objects_cache
.create_or_update()
113 obj
= open(mod
.object_cache_file
)
116 #Check for 1 service and only one
117 nb_services
= self
.nb_of_string(buf
, "define service {")
118 self
.assert_(nb_services
== 1)
119 #2 hosts : host and a router
120 nb_hosts
= self
.nb_of_string(buf
, "define host {")
121 self
.assert_(nb_hosts
== 2)
123 #Same for status.dat.
124 sl
.status
.create_or_update()
125 status
= open(mod
.status_file
)
129 nb_prog
= self
.nb_of_string(buf
, "programstatus {")
130 self
.assert_(nb_prog
== 1)
132 nb_hosts
= self
.nb_of_string(buf
, "hoststatus {")
133 self
.assert_(nb_hosts
== 2)
135 nb_services
= self
.nb_of_string(buf
, "servicestatus {")
136 self
.assert_(nb_services
== 1)
139 os
.unlink(mod
.status_file
)
140 os
.unlink(mod
.object_cache_file
)
143 if __name__
== '__main__':