Exemplo n.º 1
0
    def test_pickle_retention(self):
        # get our modules
        mod = pickle_retention_file_generic.Pickle_retention_generic(
            modconf, 'tmp/retention-test.dat')
        try:
            os.unlink(mod.path)
        except:
            pass

        sl = get_instance(mod)
        # Hack here :(
        sl.properties = {}
        sl.properties['to_queue'] = None
        sl.init()

        svc = self.sched.services.find_srv_by_name_and_hostname(
            "test_host_0", "test_ok_0")
        self.scheduler_loop(1, [[svc, 2, 'BAD | value1=0 value2=0']])

        self.sched.get_new_broks()

        # Saving the broks we got
        old_broks = copy.copy(self.sched.broks)

        # Now get a real broker object
        arbiter = Arbiter([''], False, False, False, None, None, None)

        arbiter.broks = self.sched.broks
        sl.hook_save_retention(arbiter)  #, l)
        # update the hosts and service in the scheduler in the retention-file

        # Now we clean the source, like if we restart
        arbiter.broks.clear()

        self.assertEqual(len(arbiter.broks), 0)

        r = sl.hook_load_retention(arbiter)

        # We check we load them :)
        for b in old_broks.values():
            found = False
            for b2 in arbiter.broks.values():
                if b2.id == b.id:
                    found = True
                    break
            self.assertTrue(found)

        # Ok, we can delete the retention file
        os.unlink(mod.path)
    def test_pickle_retention(self):
        # get our modules
        mod = pickle_retention_file_generic.Pickle_retention_generic(
            modconf, 'tmp/retention-test.dat')
        try:
            os.unlink(mod.path)
        except:
            pass

        sl = get_instance(mod)
        # Hack here :(
        sl.properties = {}
        sl.properties['to_queue'] = None
        sl.init()

        svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
        self.scheduler_loop(1, [[svc, 2, 'BAD | value1=0 value2=0']])

        self.sched.get_new_broks()

        # Saving the broks we got
        old_broks = copy.copy(self.sched.broks)

        # Now get a real broker object
        arbiter = Arbiter([''], False, False, False, None, None, None)

        arbiter.broks = self.sched.broks
        sl.hook_save_retention(arbiter) #, l)
        # update the hosts and service in the scheduler in the retention-file

        # Now we clean the source, like if we restart
        arbiter.broks.clear()

        self.assertEqual(len(arbiter.broks), 0)

        r = sl.hook_load_retention(arbiter)

        # We check we load them :)
        for b in old_broks.values():
            found = False
            for b2 in arbiter.broks.values():
                if b2.id == b.id:
                    found = True
                    break
            self.assertTrue(found)

        # Ok, we can delete the retention file
        os.unlink(mod.path)