Esempio n. 1
0
class TestCollectdDriver(base.BaseTest):
    OPTS = []

    # noinspection PyPep8Naming
    @classmethod
    def setUpClass(cls):
        cls.conf = cfg.ConfigOpts()
        cls.conf.register_opts(cls.OPTS, group='collectd')

    # noinspection PyAttributeOutsideInit
    def setUp(self):
        super(TestCollectdDriver, self).setUp()
        self.driver = CollectdDriver(self.conf)

    def test_enrich_event_with_alarm_up(self):
        now = datetime.now().isoformat()

        event = self._enrich_event(now, HOST,
                                   WARN_SEVERITY,
                                   WARNING_EVENT_TYPE)

        self._assert_event_equal(event, WARNING_EVENT_TYPE,
                                 HOST, WARN_SEVERITY, now)

    def _enrich_event(self, time_now, hostname, severity, event_type):
        event = self._generate_event(time_now, hostname, severity)
        event = self.driver.enrich_event(event, event_type)
        return event

    @staticmethod
    def _generate_event(time, hostname, severity):
        update_vals = {}
        if hostname:
            update_vals[CProps.HOST] = hostname
        if severity:
            update_vals[CProps.SEVERITY] = severity

        if time:
            update_vals[CProps.TIME] = time

        generators = mock_driver.simple_doctor_alarm_generators(
            update_vals=update_vals)

        return mock_driver.generate_sequential_events_list(generators)[0]

    def _assert_event_equal(self,
                            event,
                            expected_event_type,
                            expected_hostname,
                            expected_severity,
                            expected_sample_date):
        self.assertIsNotNone(event, 'No event returned')
        self.assertEqual(expected_hostname, event[CProps.HOST])
        self.assertEqual(expected_severity, event[CProps.SEVERITY])
        self.assertEqual(expected_sample_date, event[CProps.TIME])
        self.assertEqual(expected_event_type, event[DSProps.EVENT_TYPE])
Esempio n. 2
0
 def setUp(self):
     super(TestCollectdDriver, self).setUp()
     self.driver = CollectdDriver(self.conf)