Fix : fix hot module under windows test. (at leat I hope...)
[shinken.git] / test / test_module_memcache_retention.py
bloba5813ebc7c66ae6324b9a348dc5345d2c29b8ada
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 memcachetribute 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
28 from shinken_test import unittest, ShinkenTest
30 from shinken.log import logger
31 from shinken.objects.module import Module
32 from shinken.modules import memcache_retention_scheduler
33 from shinken.modules.memcache_retention_scheduler import get_instance
36 modconf = Module()
37 modconf.module_name = "MemcacheRetention"
38 modconf.module_type = memcache_retention_scheduler.properties['type']
39 modconf.properties = memcache_retention_scheduler.properties.copy()
42 class TestConfig(ShinkenTest):
43 #setUp is in shinken_test
45 #Change ME :)
46 def test_memcache_retention(self):
47 print self.conf.modules
48 #get our modules
49 modconf.server = 'localhost'
50 modconf.port = '11211'
51 mod = memcache_retention_scheduler.Memcache_retention_scheduler(modconf)
53 sl = get_instance(mod)
54 print "Instance", sl
55 #Hack here :(
56 sl.properties = {}
57 sl.properties['to_queue'] = None
58 sl.init()
59 l = logger
61 #updte the hosts and service in the scheduler in the retentino-file
62 sl.hook_save_retention(self.sched)
64 #Now we change thing
65 svc = self.sched.hosts.find_by_name("test_host_0")
66 self.assert_(svc.state == 'PENDING')
67 print "State", svc.state
68 svc.state = 'UP' #was PENDING in the save time
70 r = sl.hook_load_retention(self.sched)
71 self.assert_(r == True)
73 #search if the host is not changed by the loading thing
74 svc2 = self.sched.hosts.find_by_name("test_host_0")
75 self.assert_(svc == svc2)
77 self.assert_(svc.state == 'PENDING')
79 # Now make real loops with notifications
80 self.scheduler_loop(10, [[svc, 2, 'CRITICAL | bibi=99%']])
81 #updte the hosts and service in the scheduler in the retentino-file
82 sl.hook_save_retention(self.sched)
84 r = sl.hook_load_retention(self.sched)
85 self.assert_(r == True)
89 if __name__ == '__main__':
90 unittest.main()