Example #1
0
    def test_sighup(self):
        m = SimpleMonitor("tests/monitor-empty.ini")
        m._load_monitors(Path("tests/monitors-prehup.ini"))
        self.assertEqual(m._need_hup, False, "need_hup did not start False")
        m._handle_sighup(None, None)
        self.assertEqual(m._need_hup, True, "need_hup did not get set to True")

        self.assertEqual(
            m.monitors["monitor1"].monitor_type,
            "null",
            "monitor1 did not load correctly",
        )
        self.assertEqual(
            m.monitors["monitor2"].monitor_type,
            "host",
            "monitor2 did not load correctly",
        )
        self.assertEqual(m.monitors["monitor2"].host, "127.0.0.1",
                         "monitor2 did not load correctly")

        m._load_monitors(Path("tests/monitors-posthup.ini"))
        self.assertEqual(m.monitors["monitor1"].monitor_type, "null",
                         "monitor1 changed type")
        self.assertEqual(m.monitors["monitor2"].monitor_type, "host",
                         "monitor2 changed type")
        self.assertEqual(m.monitors["monitor2"].host, "127.0.0.2",
                         "monitor2 did not update config")
Example #2
0
    def test_sighup(self):
        monitor.setup_signals()

        self.assertEqual(monitor.need_hup, False,
                         "need_hup did not start False")
        monitor.handle_sighup(None, None)
        self.assertEqual(monitor.need_hup, True,
                         "need_hup did not get set to True")

        m = SimpleMonitor()
        m = monitor.load_monitors(m, "tests/monitors-prehup.ini")
        self.assertEqual(m.monitors["monitor1"].type, "null",
                         "monitor1 did not load correctly")
        self.assertEqual(m.monitors["monitor2"].type, "host",
                         "monitor2 did not load correctly")
        self.assertEqual(m.monitors["monitor2"].host, "127.0.0.1",
                         "monitor2 did not load correctly")

        m = monitor.load_monitors(m, "tests/monitors-posthup.ini")
        self.assertEqual(m.monitors["monitor1"].type, "null",
                         "monitor1 changed type")
        self.assertEqual(m.monitors["monitor2"].type, "host",
                         "monitor2 changed type")
        self.assertEqual(m.monitors["monitor2"].host, "127.0.0.2",
                         "monitor2 did not update config")
Example #3
0
 def test_groups_all_match(self):
     with patch.object(logger.Logger, "save_result2") as mock_method:
         this_logger = logger.Logger({"groups": "_all"})
         s = SimpleMonitor(Path("tests/monitor-empty.ini"))
         s.add_monitor("test", MonitorNull("unnamed", {"group": "test1"}))
         s.log_result(this_logger)
     mock_method.assert_called_once()