Exemplo n.º 1
0
class TestDockerCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('DockerCollector', {
            'interval': 10,
        })

        self.collector = DockerCollector(config, None)

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

    def test_docker_stats_method_exists(self):
        self.assertTrue("stats" in dir(Client))

    def test_docker_stats_output_parse(self):
        f = open(os.path.join(fixtures_path, "example.stat")).read()
        stat = json.loads(f)
        for path in self.collector.METRICS:
            val = self.collector.get_value(path, stat)
            self.assertTrue(val is not None)

    def test_docker_stats_output_parse_fail(self):
        f = open(os.path.join(fixtures_path, "example_empty.stat")).read()
        stat = json.loads(f)
        for path in self.collector.METRICS:
            val = self.collector.get_value(path, stat)
            self.assertTrue(val is None)
Exemplo n.º 2
0
    def setUp(self):
        config = get_collector_config(
            'DockerCollector', {
                'interval': 10,
                'byte_unit': 'megabyte',
                'memory_path': fixtures_path,
            })

        self.collector = DockerCollector(config, None)
class TestDockerCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('DockerCollector', {
            'interval': 10,
            'byte_unit': 'megabyte',
            'memory_path': fixtures_path,
        })

        self.collector = DockerCollector(config, None)

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

    def test_finds_linux_v2_memory_stat_path(self):
        tid = 'c3341726a9b4235a35b390c5f6f28e5a6869879a48da1d609db8f6bf4275bdc5'
        path = self.collector._memory_stat_path(tid)
        self.assertTrue(path is not None)
        self.assertTrue(os.path.exists(path))

    def test_finds_linux_v3_memory_stat_path(self):
        tid = '0aec7f643ca1cb45f54d41dcabd8fcbcfcbc57170c3e6dd439af1a52761c2bed'
        path = self.collector._memory_stat_path(tid)
        self.assertTrue(path is not None)
        self.assertTrue(os.path.exists(path))

    def test_doesnt_find_bogus_memory_stat_path(self):
        tid = 'testcontainer'
        path = self.collector._memory_stat_path(tid)
        self.assertTrue(path is None)

    @patch('os.path.exists', Mock(return_value=True))
    def test_default_memory_path(self):
        read_data = "\n".join([
            'none /selinux selinuxfs rw,relatime 0 0',
            'cgroup /goofy/memory cgroup'
            ' rw,nosuid,nodev,noexec,relatime,devices 0 0',
            'cgroup /mickeymouse/memory cgroup'
            ' rw,nosuid,nodev,noexec,relatime,memory 0 0',
            'tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0',
            '',
        ])

        m = mock_open(read_data=read_data)
        with patch('__builtin__.open', m, create=True):
            self.assertEqual(self.collector._default_memory_path(),
                             '/mickeymouse/memory')

        m.assert_called_once_with('/proc/mounts')
Exemplo n.º 4
0
class TestDockerCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config(
            'DockerCollector', {
                'interval': 10,
                'byte_unit': 'megabyte',
                'memory_path': fixtures_path,
            })

        self.collector = DockerCollector(config, None)

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

    def test_finds_linux_v2_memory_stat_path(self):
        tid = 'c3341726a9b4235a35b390c5f6f28e5a6869879a48da1d609db8f6bf4275bdc5'
        path = self.collector._memory_stat_path(tid)
        self.assertTrue(path is not None)
        self.assertTrue(os.path.exists(path))

    def test_finds_linux_v3_memory_stat_path(self):
        tid = '0aec7f643ca1cb45f54d41dcabd8fcbcfcbc57170c3e6dd439af1a52761c2bed'
        path = self.collector._memory_stat_path(tid)
        self.assertTrue(path is not None)
        self.assertTrue(os.path.exists(path))

    def test_doesnt_find_bogus_memory_stat_path(self):
        tid = 'testcontainer'
        path = self.collector._memory_stat_path(tid)
        self.assertTrue(path is None)

    @patch('os.path.exists', Mock(return_value=True))
    def test_default_memory_path(self):
        read_data = "\n".join([
            'none /selinux selinuxfs rw,relatime 0 0',
            'cgroup /goofy/memory cgroup'
            ' rw,nosuid,nodev,noexec,relatime,devices 0 0',
            'cgroup /mickeymouse/memory cgroup'
            ' rw,nosuid,nodev,noexec,relatime,memory 0 0',
            'tmpfs /dev/shm tmpfs rw,seclabel,nosuid,nodev 0 0',
            '',
        ])

        m = mock_open(read_data=read_data)
        with patch('__builtin__.open', m, create=True):
            self.assertEqual(self.collector._default_memory_path(),
                             '/mickeymouse/memory')

        m.assert_called_once_with('/proc/mounts')
    def setUp(self):
        config = get_collector_config('DockerCollector', {
            'interval': 10,
            'byte_unit': 'megabyte',
            'memory_path': fixtures_path,
        })

        self.collector = DockerCollector(config, None)
Exemplo n.º 6
0
    def setUp(self):
        config = get_collector_config('DockerCollector', {
            'interval': 10,
        })

        self.collector = DockerCollector(config, None)