Add : service without host will be just droped, like Nagios.
[shinken.git] / test / test_realms.py
blob1342563a76a579bd2aaf7be8cbe24e81f84cf91a
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 #Uncomment this is you want to use a specific configuration
31 #for your test
32 def setUp(self):
33 self.setup_with_file('etc/nagios_realms.cfg')
36 # We check for each host, if they are in the good realm
37 def test_realm_assigntion(self):
39 # Config is not correct because of a wrong relative path
40 # in the main config file
42 print "Get the hosts and services"
43 now = time.time()
44 realm1 = self.conf.realms.find_by_name('realm1')
45 self.assert_(realm1 is not None)
46 realm2 = self.conf.realms.find_by_name('realm2')
47 self.assert_(realm2 is not None)
48 test_host_realm1 = self.sched.hosts.find_by_name("test_host_realm1")
49 self.assert_(test_host_realm1 is not None)
50 self.assert_(test_host_realm1.realm == realm1)
51 test_host_realm2 = self.sched.hosts.find_by_name("test_host_realm2")
52 self.assert_(test_host_realm2 is not None)
53 self.assert_(test_host_realm2.realm == realm2)
55 # We check for each host, if they are in the good realm
56 # but when they are apply in a hostgroup link
57 def test_realm_hostgroup_assigntion(self):
59 # Config is not correct because of a wrong relative path
60 # in the main config file
62 print "Get the hosts and services"
63 now = time.time()
64 in_realm2 = self.sched.hostgroups.find_by_name('in_realm2')
65 realm1 = self.conf.realms.find_by_name('realm1')
66 self.assert_(realm1 is not None)
67 realm2 = self.conf.realms.find_by_name('realm2')
68 self.assert_(realm2 is not None)
69 # 1 and 2 are link to realm2 because they are in the hostgroup in_realm2
70 test_host1_hg_realm2 = self.sched.hosts.find_by_name("test_host1_hg_realm2")
71 self.assert_(test_host1_hg_realm2 is not None)
72 self.assert_(test_host1_hg_realm2.realm == realm2)
73 self.assert_(in_realm2 in test_host1_hg_realm2.hostgroups)
75 test_host2_hg_realm2 = self.sched.hosts.find_by_name("test_host2_hg_realm2")
76 self.assert_(test_host2_hg_realm2 is not None)
77 self.assert_(test_host2_hg_realm2.realm == realm2)
78 self.assert_(in_realm2 in test_host2_hg_realm2.hostgroups)
80 test_host3_hg_realm2 = self.sched.hosts.find_by_name("test_host3_hg_realm2")
81 self.assert_(test_host3_hg_realm2 is not None)
82 self.assert_(test_host3_hg_realm2.realm == realm1)
83 self.assert_(in_realm2 in test_host3_hg_realm2.hostgroups)
86 if __name__ == '__main__':
87 unittest.main()