Пример #1
0
    def setUp(self):
        config = get_collector_config('PingCollector', {
            'interval': 10,
            'target_a': 'localhost'
        })

        self.collector = PingCollector(config, None)
Пример #2
0
    def test_should_work_with_real_data_host_gentoo(self, publish_mock):
        config = get_collector_config(
            'PingCollector', {
                'interval': 10,
                'target_a': 'localhost',
                'target_b': 'www.example.org',
                'target_c': '192.168.0.1',
                'bin': 'true'
            })

        collector = PingCollector(config, None)

        def popen_se(command, **kwargs):
            popen_mock = Mock()
            if command[-1] == 'localhost':
                popen_mock.communicate = Mock(
                    return_value=(self.getFixture('host_gentoo').getvalue(),
                                  ''))
            elif command[-1] == 'www.example.org':
                popen_mock.communicate = Mock(
                    return_value=(self.getFixture('host_gentoo2').getvalue(),
                                  ''))
            elif command[-1] == '192.168.0.1':
                popen_mock.communicate = Mock(
                    return_value=(self.getFixture('host_gentoo3').getvalue(),
                                  ''))
            return popen_mock

        patch_popen = patch('subprocess.Popen', Mock(side_effect=popen_se))

        patch_popen.start()
        collector.collect()
        patch_popen.stop()

        metrics = {'localhost': 11, 'www_example_org': 23, '192_168_0_1': 16}

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