Fix : fix hot module under windows test. (at leat I hope...)
[shinken.git] / test / test_complex_hostgroups.py
blob82f340dee69fa131c331aa8c539557b8a2afd5ce
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 #It's ugly I know....
26 from shinken_test import *
29 class TestConfig(ShinkenTest):
30 #setUp is in shinken_test
31 def setUp(self):
32 self.setup_with_file('etc/nagios_complex_hostgroups.cfg')
35 def get_svc(self):
36 return self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
38 def find_service(self, name, desc):
39 return self.sched.services.find_srv_by_name_and_hostname(name, desc)
41 def find_host(self, name):
42 return self.sched.hosts.find_by_name(name)
44 def find_hostgroup(self, name):
45 return self.sched.hostgroups.find_by_name(name)
47 def dump_hosts(self, svc):
48 for h in svc.host_name:
49 print h
51 #check if service exist in hst, but NOT in others
52 def srv_define_only_on(self, desc, hsts):
53 r = True
54 #first hsts
55 for h in hsts:
56 svc = self.find_service(h.host_name, desc)
57 if svc is None:
58 print "Error : the host %s is missing service %s!!" % (h.host_name, desc)
59 r = False
61 for h in self.sched.hosts:
62 if h not in hsts:
63 svc = self.find_service(h.host_name, desc)
64 if svc is not None:
65 print "Error : the host %s got the service %s!!" % (h.host_name, desc)
66 r = False
67 return r
70 #Change ME :)
71 def test_dummy(self):
72 print self.sched.services.items
73 svc = self.get_svc()
74 print "Service", svc
75 #print self.conf.hostgroups
77 #All our hosts
78 test_linux_web_prod_0 = self.find_host('test_linux_web_prod_0')
79 test_linux_web_qual_0 = self.find_host('test_linux_web_qual_0')
80 test_win_web_prod_0 = self.find_host('test_win_web_prod_0')
81 test_win_web_qual_0 = self.find_host('test_win_web_qual_0')
82 test_linux_file_prod_0 = self.find_host('test_linux_file_prod_0')
86 hg_linux = self.find_hostgroup('linux')
87 hg_web = self.find_hostgroup('web')
88 hg_win = self.find_hostgroup('win')
89 hg_file = self.find_hostgroup('file')
90 print "HG Linux", hg_linux
91 for h in hg_linux:
92 print "H", h.get_name()
94 self.assert_(test_linux_web_prod_0 in hg_linux.members)
95 self.assert_(test_linux_web_prod_0 not in hg_file.members)
97 #First the service define for linux only
98 svc = self.find_service('test_linux_web_prod_0', 'linux_0')
99 print "Service Linux only", svc.get_dbg_name()
100 r = self.srv_define_only_on('linux_0', [test_linux_web_prod_0, test_linux_web_qual_0, test_linux_file_prod_0])
101 self.assert_(r == True)
103 print "Service Linux,web"
104 r = self.srv_define_only_on('linux_web_0', [test_linux_web_prod_0, test_linux_web_qual_0, test_linux_file_prod_0,test_win_web_prod_0,test_win_web_qual_0])
105 self.assert_(r == True)
107 ###Now the real complex things :)
108 print "Service Linux&web"
109 r = self.srv_define_only_on('linux_AND_web_0', [test_linux_web_prod_0, test_linux_web_qual_0])
110 self.assert_(r == True)
112 print "Service Linux|web"
113 r = self.srv_define_only_on('linux_OR_web_0', [test_linux_web_prod_0, test_linux_web_qual_0, test_win_web_prod_0, test_win_web_qual_0, test_linux_file_prod_0])
114 self.assert_(r == True)
116 print "(linux|web),file"
117 r = self.srv_define_only_on('linux_OR_web_PAR_file0', [test_linux_web_prod_0, test_linux_web_qual_0, test_win_web_prod_0, test_win_web_qual_0, test_linux_file_prod_0, test_linux_file_prod_0])
118 self.assert_(r == True)
120 print "(linux|web)&prod"
121 r = self.srv_define_only_on('linux_OR_web_PAR_AND_prod0', [test_linux_web_prod_0, test_win_web_prod_0, test_linux_file_prod_0])
122 self.assert_(r == True)
124 print "(linux|web)&!prod"
125 r = self.srv_define_only_on('linux_OR_web_PAR_AND_NOT_prod0', [test_linux_web_qual_0, test_win_web_qual_0])
126 self.assert_(r == True)
128 print "Special minus problem"
129 r = self.srv_define_only_on('name-with-minus-in-it', [test_linux_web_prod_0])
130 self.assert_(r == True)
132 if __name__ == '__main__':
133 unittest.main()