Beispiel #1
0
    def test_should_work_wtih_real_data_and_custom_config(self, publish_mock):
        config = get_collector_config('NtpCollector', {
            'time_scale': 'seconds',
            'precision': 3,
        })

        self.collector = NtpCollector(config, None)

        ntpdate_data = Mock(
            return_value=(self.getFixture('ntpdate').getvalue(), None))
        collector_mock = patch.object(NtpCollector,
                                      'run_command',
                                      ntpdate_data)
        collector_mock.start()
        self.collector.collect()
        collector_mock.stop()

        metrics = {
            'server.count': 4,
            'offset.seconds': -0.000128
        }

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)
Beispiel #2
0
    def test_should_work_wtih_real_data_and_custom_config(self, publish_mock):
        config = get_collector_config('NtpCollector', {
            'time_scale': 'seconds',
            'precision': 3,
        })

        self.collector = NtpCollector(config, None)

        ntpdate_data = Mock(
            return_value=(self.getFixture('ntpdate').getvalue(), None))
        collector_mock = patch.object(NtpCollector, 'run_command',
                                      ntpdate_data)
        collector_mock.start()
        self.collector.collect()
        collector_mock.stop()

        metrics = {'server.count': 4, 'offset.seconds': -0.000128}

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)
Beispiel #3
0
    def setUp(self):
        config = get_collector_config('NtpCollector', {})

        self.collector = NtpCollector(config, None)
Beispiel #4
0
class TestNtpCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('NtpCollector', {})

        self.collector = NtpCollector(config, None)

    def test_import(self):
        self.assertTrue(NtpCollector)

    @patch.object(Collector, 'publish')
    def test_should_work_wtih_real_data(self, publish_mock):
        ntpdate_data = Mock(
            return_value=(self.getFixture('ntpdate').getvalue(), None))
        collector_mock = patch.object(NtpCollector,
                                      'run_command',
                                      ntpdate_data)
        collector_mock.start()
        self.collector.collect()
        collector_mock.stop()

        metrics = {
            'server.count': 4,
            'offset.milliseconds': 0
        }

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)


    # XXX: Diamond collector custom configs are broken in Yelp/fullerite
    # @patch.object(Collector, 'publish')
    # def test_should_work_wtih_real_data_and_custom_config(self, publish_mock):
    #     config = get_collector_config('NtpCollector', {
    #         'time_scale': 'seconds',
    #         'precision': 3,
    #     })

    #     self.collector = NtpCollector(config, None)

    #     ntpdate_data = Mock(
    #         return_value=(self.getFixture('ntpdate').getvalue(), None))
    #     collector_mock = patch.object(NtpCollector,
    #                                   'run_command',
    #                                   ntpdate_data)
    #     collector_mock.start()
    #     self.collector.collect()
    #     collector_mock.stop()

    #     metrics = {
    #         'server.count': 4,
    #         'offset.seconds': -0.000128
    #     }

    #     self.setDocExample(collector=self.collector.__class__.__name__,
    #                        metrics=metrics,
    #                        defaultpath=self.collector.config['path'])
    #     self.assertPublishedMany(publish_mock, metrics)

    @patch.object(Collector, 'publish')
    def test_should_fail_gracefully(self, publish_mock):
        ntpdate_data = Mock(return_value=('', None))
        collector_mock = patch.object(NtpCollector,
                                      'run_command',
                                      ntpdate_data)

        collector_mock.start()
        self.collector.collect()
        collector_mock.stop()

        self.assertPublishedMany(publish_mock, {})
Beispiel #5
0
    def setUp(self):
        config = get_collector_config('NtpCollector', {})

        self.collector = NtpCollector(config, None)