Ejemplo n.º 1
0
    def setUp(self):
        config = get_collector_config('NetfilterAccountingCollector', {
            'interval': 10,
            'bin': 'true',
        })

        self.collector = NetfilterAccountingCollector(config, None)
Ejemplo n.º 2
0
    def setUp(self):
        config = get_collector_config('NetfilterAccountingCollector', {
            'interval': 10,
            'bin': 'true',
        })

        self.collector = NetfilterAccountingCollector(config, None)
Ejemplo n.º 3
0
class TestNetfilterAccountingCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('NetfilterAccountingCollector', {
            'interval': 10,
            'bin': 'true',
        })

        self.collector = NetfilterAccountingCollector(config, None)

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

    @patch.object(Collector, 'publish')
    def test_no_counters(self, publish_mock):
        patch_communicate = patch(
            'subprocess.Popen.communicate',
            Mock(return_value=('', '')))
        patch_communicate.start()
        self.collector.collect()
        patch_communicate.stop()

        self.assertPublishedMany(publish_mock, {})

    @patch.object(Collector, 'publish')
    def test_counters(self, publish_mock):
        patch_communicate = patch(
            'subprocess.Popen.communicate',
            Mock(return_value=(self.getFixture('nfacct').getvalue(), '')))
        patch_communicate.start()
        self.collector.collect()
        patch_communicate.stop()

        self.assertPublishedMany(publish_mock, {
            'Tcp.pkts': 3,
            'Tcp.bytes': 300,
            'Udp.pkts': 0,
            'Udp.bytes': 0,
            'Tcp.Incoming.pkts': 1,
            'Tcp.Incoming.bytes': 100,
            'Tcp.Outgoing.pkts': 2,
            'Tcp.Outgoing.bytes': 200,
        })
Ejemplo n.º 4
0
class TestNetfilterAccountingCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('NetfilterAccountingCollector', {
            'interval': 10,
            'bin': 'true',
        })

        self.collector = NetfilterAccountingCollector(config, None)

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

    @patch.object(Collector, 'publish')
    def test_no_counters(self, publish_mock):
        patch_communicate = patch('subprocess.Popen.communicate',
                                  Mock(return_value=('', '')))
        patch_communicate.start()
        self.collector.collect()
        patch_communicate.stop()

        self.assertPublishedMany(publish_mock, {})

    @patch.object(Collector, 'publish')
    def test_counters(self, publish_mock):
        patch_communicate = patch(
            'subprocess.Popen.communicate',
            Mock(return_value=(self.getFixture('nfacct').getvalue(), '')))
        patch_communicate.start()
        self.collector.collect()
        patch_communicate.stop()

        self.assertPublishedMany(
            publish_mock, {
                'Tcp.pkts': 3,
                'Tcp.bytes': 300,
                'Udp.pkts': 0,
                'Udp.bytes': 0,
                'Tcp.Incoming.pkts': 1,
                'Tcp.Incoming.bytes': 100,
                'Tcp.Outgoing.pkts': 2,
                'Tcp.Outgoing.bytes': 200,
            })