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')
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')