コード例 #1
0
ファイル: test_timeout.py プロジェクト: popomomi/shinken-1
    def test_notification_timeout(self):
        if os.name == 'nt':
            return

        svc = self.sched.services.find_srv_by_name_and_hostname(
            "test_host_0", "test_ok_0")

        # These queues connect a poller/reactionner with a worker
        to_queue = Queue()
        #manager = Manager()
        from_queue = Queue()  #manager.list()
        control_queue = Queue()

        # This testscript plays the role of the reactionner
        # Now "fork" a worker
        w = Worker(1, to_queue, from_queue, 1)
        w.id = 1
        w.i_am_dying = False

        # We prepare a notification in the to_queue
        c = Contact()
        c.contact_name = "mr.schinken"
        n = Notification('PROBLEM',
                         'scheduled',
                         'libexec/sleep_command.sh 7',
                         '',
                         svc,
                         '',
                         '',
                         id=1)
        n.status = "queue"
        #n.command = "libexec/sleep_command.sh 7"
        n.t_to_go = time.time()
        n.contact = c
        n.timeout = 2
        n.env = {}
        n.exit_status = 0
        n.module_type = "fork"
        nn = n.copy_shell()

        # Send the job to the worker
        msg = Message(id=0, type='Do', data=nn)
        to_queue.put(msg)

        w.checks = []
        w.returns_queue = from_queue
        w.s = to_queue
        w.c = control_queue
        # Now we simulate the Worker's work() routine. We can't call it
        # as w.work() because it is an endless loop
        for i in xrange(1, 10):
            w.get_new_checks()
            # During the first loop the sleeping command is launched
            w.launch_new_checks()
            w.manage_finished_checks()
            time.sleep(1)

        # The worker should have finished it's job now, either correctly or
        # with a timeout
        o = from_queue.get()

        self.assert_(o.status == 'timeout')
        self.assert_(o.exit_status == 3)
        self.assert_(o.execution_time < n.timeout + 1)

        # Be a good poller and clean up.
        to_queue.close()
        control_queue.close()

        # Now look what the scheduler says to all this
        self.sched.actions[n.id] = n
        self.sched.put_results(o)
        self.show_logs()
        self.assert_(
            self.any_log_match(
                "Contact mr.schinken service notification command 'libexec/sleep_command.sh 7 ' timed out after 2 seconds"
            ))
コード例 #2
0
 def setUp(self):
     from shinken.objects.contact import Contact
     self.item = Contact()
コード例 #3
0
ファイル: test_timeout.py プロジェクト: 0pc0deFR/shinken
    def test_notification_timeout(self):
        if os.name == 'nt':
            return

        svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")

        # These queues connect a poller/reactionner with a worker
        to_queue = Queue()
        #manager = Manager()
        from_queue = Queue() #manager.list()
        control_queue = Queue()

        # This testscript plays the role of the reactionner
        # Now "fork" a worker
        w = Worker(1, to_queue, from_queue, 1)
        w.id = 1
        w.i_am_dying = False

        # We prepare a notification in the to_queue
        c = Contact()
        c.contact_name = "mr.schinken"
        n = Notification('PROBLEM', 'scheduled', 'libexec/sleep_command.sh 7', '', svc, '', '', id=1)
        n.status = "queue"
        #n.command = "libexec/sleep_command.sh 7"
        n.t_to_go = time.time()
        n.contact = c
        n.timeout = 2
        n.env = {}
        n.exit_status = 0
        n.module_type = "fork"
        nn = n.copy_shell()

        # Send the job to the worker
        msg = Message(id=0, type='Do', data=nn)
        to_queue.put(msg)

        w.checks = []
        w.returns_queue = from_queue
        w.s = to_queue
        w.c = control_queue
        # Now we simulate the Worker's work() routine. We can't call it
        # as w.work() because it is an endless loop
        for i in xrange(1, 10):
            w.get_new_checks()
            # During the first loop the sleeping command is launched
            w.launch_new_checks()
            w.manage_finished_checks()
            time.sleep(1)

        # The worker should have finished it's job now, either correctly or
        # with a timeout
        o = from_queue.get()

        self.assertEqual('timeout', o.status)
        self.assertEqual(3, o.exit_status)
        self.assertLess(o.execution_time, n.timeout+1)

        # Be a good poller and clean up.
        to_queue.close()
        control_queue.close()

        # Now look what the scheduler says to all this
        self.sched.actions[n.id] = n
        self.sched.put_results(o)
        self.show_logs()
        self.assert_any_log_match("Contact mr.schinken service notification command 'libexec/sleep_command.sh 7 ' timed out after 2 seconds")