*Change the jenkins/hudson test scripts
[shinken.git] / test / test_module_pickle_retention.py
blob2ab684f586e376a4ecacd7cabbf2c96ae442201b
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 #It's ugly I know....
27 import os
29 from shinken_test import *
32 sys.path.append("../shinken/modules")
33 import pickle_retention_file_scheduler
34 from pickle_retention_file_scheduler import *
35 from module import Module
37 modconf = Module()
38 modconf.module_name = "PickleRetention"
39 modconf.module_type = pickle_retention_file_scheduler.properties['type']
40 modconf.properties = pickle_retention_file_scheduler.properties.copy()
43 class TestConfig(ShinkenTest):
44 #setUp is in shinken_test
46 #Change ME :)
47 def test_pickle_retention(self):
48 print self.conf.modules
49 #get our modules
50 mod = pickle_retention_file_scheduler.Pickle_retention_scheduler(modconf, 'tmp/retention-test.dat')
51 try :
52 os.unlink(mod.path)
53 except :
54 pass
56 sl = get_instance(mod)
57 print "Instance", sl
58 #Hack here :(
59 sl.properties = {}
60 sl.properties['to_queue'] = None
61 sl.init()
62 l = logger
64 #updte the hosts and service in the scheduler in the retentino-file
65 sl.update_retention_objects(self.sched, l)
67 #Now we change thing
68 svc = self.sched.hosts.find_by_name("test_host_0")
69 self.assert_(svc.state == 'PENDING')
70 print "State", svc.state
71 svc.state = 'UP' #was PENDING in the save time
73 r = sl.load_retention_objects(self.sched, l)
74 self.assert_(r == True)
76 #search if the host is not changed by the loading thing
77 svc2 = self.sched.hosts.find_by_name("test_host_0")
78 self.assert_(svc == svc2)
80 self.assert_(svc.state == 'PENDING')
82 #Ok, we can delete the retention file
83 os.unlink(mod.path)
86 # Now make real loops with notifications
87 self.scheduler_loop(10, [[svc, 2, 'CRITICAL | bibi=99%']])
88 #updte the hosts and service in the scheduler in the retentino-file
89 sl.update_retention_objects(self.sched, l)
91 r = sl.load_retention_objects(self.sched, l)
92 self.assert_(r == True)
96 if __name__ == '__main__':
97 unittest.main()