Example #1
0
class TestCpuAcctCgroupCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('CpuAcctCgroupCollector', {
            'interval': 10
        })

        self.collector = CpuAcctCgroupCollector(config, None)

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

    @patch('__builtin__.open')
    @patch('os.walk', Mock(return_value=iter(fixtures)))
    @patch.object(Collector, 'publish')
    def test_should_open_all_cpuacct_stat(self, publish_mock, open_mock):
        open_mock.side_effect = lambda x: StringIO('')
        self.collector.collect()
        open_mock.assert_any_call(
            fixtures_path + 'lxc/testcontainer/cpuacct.stat')
        open_mock.assert_any_call(fixtures_path + 'lxc/cpuacct.stat')
        open_mock.assert_any_call(fixtures_path + 'cpuacct.stat')

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        CpuAcctCgroupCollector.CPUACCT_PATH = fixtures_path
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {
            'lxc.testcontainer.user': 1318,
            'lxc.testcontainer.system': 332,
            'lxc.user': 36891,
            'lxc.system': 88927,
            'system.user': 3781253,
            'system.system': 4784004,
        })
class TestCpuAcctCgroupCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('CpuAcctCgroupCollector',
                                      {'interval': 10})

        self.collector = CpuAcctCgroupCollector(config, None)

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

    @patch('__builtin__.open')
    @patch('os.walk', Mock(return_value=iter(fixtures)))
    @patch.object(Collector, 'publish')
    def test_should_open_all_cpuacct_stat(self, publish_mock, open_mock):
        open_mock.side_effect = lambda x: StringIO('')
        self.collector.collect()
        open_mock.assert_any_call(fixtures_path +
                                  'lxc/testcontainer/cpuacct.stat')
        open_mock.assert_any_call(fixtures_path + 'lxc/cpuacct.stat')
        open_mock.assert_any_call(fixtures_path + 'cpuacct.stat')

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        CpuAcctCgroupCollector.CPUACCT_PATH = fixtures_path
        self.collector.collect()

        self.assertPublishedMany(
            publish_mock, {
                'lxc.testcontainer.user': 1318,
                'lxc.testcontainer.system': 332,
                'lxc.user': 36891,
                'lxc.system': 88927,
                'system.user': 3781253,
                'system.system': 4784004,
            })
Example #3
0
class TestCpuAcctCgroupCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('CpuAcctCgroupCollector',
                                      {'interval': 10})

        self.collector = CpuAcctCgroupCollector(config, None)

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

    @patch('__builtin__.open')
    @patch.object(Collector, 'publish')
    def test_should_open_all_cpuacct_stat(self, publish_mock, open_mock):
        return
        self.collector.config['path'] = self.getFixtureDirPath()
        open_mock.side_effect = lambda x: StringIO('')
        self.collector.collect()

        # All the fixtures we should be opening
        paths = [
            'lxc/testcontainer/cpuacct.stat',
            'lxc/cpuacct.stat',
            'cpuacct.stat',
        ]

        for path in paths:
            open_mock.assert_any_call(
                os.path.join(self.getFixtureDirPath(), path))

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        self.collector.config['path'] = self.getFixtureDirPath()
        self.collector.collect()

        self.assertPublishedMany(
            publish_mock, {
                'lxc.testcontainer.user': 1318,
                'lxc.testcontainer.system': 332,
                'lxc.user': 36891,
                'lxc.system': 88927,
                'system.user': 3781253,
                'system.system': 4784004,
            })
Example #4
0
class TestCpuAcctCgroupCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('CpuAcctCgroupCollector', {
            'interval': 10
        })

        self.collector = CpuAcctCgroupCollector(config, None)

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

    @patch('__builtin__.open')
    @patch.object(Collector, 'publish')
    def test_should_open_all_cpuacct_stat(self, publish_mock, open_mock):
        return
        self.collector.config['path'] = self.getFixtureDirPath()
        open_mock.side_effect = lambda x: StringIO('')
        self.collector.collect()

        # All the fixtures we should be opening
        paths = [
            'lxc/testcontainer/cpuacct.stat',
            'lxc/cpuacct.stat',
            'cpuacct.stat',
        ]

        for path in paths:
            open_mock.assert_any_call(os.path.join(
                self.getFixtureDirPath(), path))

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        self.collector.config['path'] = self.getFixtureDirPath()
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {
            'lxc.testcontainer.user': 1318,
            'lxc.testcontainer.system': 332,
            'lxc.user': 36891,
            'lxc.system': 88927,
            'system.user': 3781253,
            'system.system': 4784004,
        })
Example #5
0
class TestCpuAcctCgroupCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config("CpuAcctCgroupCollector", {"interval": 10})

        self.collector = CpuAcctCgroupCollector(config, None)

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

    @patch("__builtin__.open")
    @patch.object(Collector, "publish")
    def test_should_open_all_cpuacct_stat(self, publish_mock, open_mock):
        return
        self.collector.config["path"] = self.getFixtureDirPath()
        open_mock.side_effect = lambda x: StringIO("")
        self.collector.collect()

        # All the fixtures we should be opening
        paths = ["lxc/testcontainer/cpuacct.stat", "lxc/cpuacct.stat", "cpuacct.stat"]

        for path in paths:
            open_mock.assert_any_call(os.path.join(self.getFixtureDirPath(), path))

    @patch.object(Collector, "publish")
    def test_should_work_with_real_data(self, publish_mock):
        self.collector.config["path"] = self.getFixtureDirPath()
        self.collector.collect()

        self.assertPublishedMany(
            publish_mock,
            {
                "lxc.testcontainer.user": 1318,
                "lxc.testcontainer.system": 332,
                "lxc.user": 36891,
                "lxc.system": 88927,
                "system.user": 3781253,
                "system.system": 4784004,
            },
        )
Example #6
0
    def setUp(self):
        config = get_collector_config('CpuAcctCgroupCollector',
                                      {'interval': 10})

        self.collector = CpuAcctCgroupCollector(config, None)
Example #7
0
    def setUp(self):
        config = get_collector_config('CpuAcctCgroupCollector', {
            'interval': 10
        })

        self.collector = CpuAcctCgroupCollector(config, None)
Example #8
0
    def setUp(self):
        config = get_collector_config("CpuAcctCgroupCollector", {"interval": 10})

        self.collector = CpuAcctCgroupCollector(config, None)