Example #1
0
 def test_get_checks_as_dict(self):
     foo = ServiceCheck(timestamp=42,
                        hostname='server1',
                        name='foo',
                        status=0,
                        output='foo out')
     bar = ServiceCheck(timestamp=42,
                        hostname='server1',
                        name='bar',
                        status=1,
                        output='bar out')
     with mock.patch.dict('sauna.check_results', foo=foo, bar=bar):
         self.assertDictEqual(
             base.AsyncConsumer.get_checks_as_dict(), {
                 'foo': {
                     'status': 'OK',
                     'code': 0,
                     'timestamp': 42,
                     'output': 'foo out'
                 },
                 'bar': {
                     'status': 'WARNING',
                     'code': 1,
                     'timestamp': 42,
                     'output': 'bar out'
                 }
             })
Example #2
0
 def test_get_current_status(self):
     foo = ServiceCheck(timestamp=42,
                        hostname='server1',
                        name='foo',
                        status=0,
                        output='foo out')
     bar = ServiceCheck(timestamp=42,
                        hostname='server1',
                        name='bar',
                        status=1,
                        output='bar out')
     with mock.patch.dict('sauna.check_results'):
         self.assertEquals(base.AsyncConsumer.get_current_status(),
                           ('OK', 0))
     with mock.patch.dict('sauna.check_results', foo=foo):
         self.assertEquals(base.AsyncConsumer.get_current_status(),
                           ('OK', 0))
     with mock.patch.dict('sauna.check_results', foo=foo, bar=bar):
         self.assertEquals(base.AsyncConsumer.get_current_status(),
                           ('WARNING', 1))
Example #3
0
 def test_consumer_send_success(self, time_mock):
     time_mock.time.return_value = 1461363313
     must_stop = threading.Event()
     s = ServiceCheck(timestamp=1461363313,
                      hostname='node-1.domain.tld',
                      name='dumb_check',
                      status=0,
                      output='Check okay')
     dumb_consumer = DumbConsumer({})
     dumb_consumer.try_send(s, must_stop)
     self.assertIs(s, dumb_consumer.last_service_check)