Fix : error message with unknown host for a service.
[shinken.git] / test / test_module_pickle_retention_broker.py
blob1b350fdc1eb7a1fc3fc9934be2a838d1bb099ff6
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
26 import os
27 import copy
29 from shinken_test import *
30 from shinken.log import logger
31 from shinken.objects.module import Module
32 from shinken.modules import pickle_retention_file_generic
33 from shinken.modules.pickle_retention_file_generic import get_instance
36 modconf = Module()
37 modconf.module_name = "PickleRetentionGeneric"
38 modconf.module_type = pickle_retention_file_generic.properties['type']
39 modconf.properties = pickle_retention_file_generic.properties.copy()
42 class TestPickleRetentionBroker(ShinkenTest):
43 #setUp is in shinken_test
45 #Change ME :)
46 def test_pickle_retention(self):
47 print self.conf.modules
48 #get our modules
49 mod = pickle_retention_file_generic.Pickle_retention_generic(modconf, 'tmp/retention-test.dat')
50 try :
51 os.unlink(mod.path)
52 except :
53 pass
55 sl = get_instance(mod)
56 print "Instance", sl
57 #Hack here :(
58 sl.properties = {}
59 sl.properties['to_queue'] = None
60 sl.init()
61 l = logger
63 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
64 self.scheduler_loop(1, [[svc, 2, 'BAD | value1=0 value2=0']])
66 self.sched.get_new_broks()
68 # Saving the broks we got
69 old_broks = copy.copy(self.sched.broks)
71 # Now get a real broker object
72 broker = Broker('', False, False, False, None)
74 broker.broks = self.sched.broks.values()
75 #updte the hosts and service in the scheduler in the retentino-file
76 sl.hook_save_retention(broker)#, l)
78 # Now we clean the source, like if we restart
79 broker.broks = []
81 self.assert_(len(broker.broks)==0)
83 r = sl.hook_load_retention(broker)
84 print len(old_broks), len(broker.broks)
86 #We check we load them :)
87 for b in old_broks.values():
88 print "Look for good", b
89 finded = False
90 for b2 in broker.broks:
91 if b2.id == b.id:
92 finded = True
93 self.assert_(finded)
95 #Ok, we can delete the retention file
96 os.unlink(mod.path)
101 if __name__ == '__main__':
102 unittest.main()