当前位置: 首页>>代码示例>>Python>>正文


Python DockerUtil.wait方法代码示例

本文整理汇总了Python中utils.dockerutil.DockerUtil.wait方法的典型用法代码示例。如果您正苦于以下问题:Python DockerUtil.wait方法的具体用法?Python DockerUtil.wait怎么用?Python DockerUtil.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.dockerutil.DockerUtil的用法示例。


在下文中一共展示了DockerUtil.wait方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCheckDockerDaemonNoSetUp

# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import wait [as 别名]
class TestCheckDockerDaemonNoSetUp(AgentCheckTest):
    """Tests for docker_daemon integration that don't need the setUp."""
    CHECK_NAME = 'docker_daemon'

    def test_event_attributes_tag(self):
        self.docker_client = DockerUtil().client
        config = {
            "init_config": {},
            "instances": [{
                "url": "unix://var/run/docker.sock",
                "event_attributes_as_tags": ["exitCode", "name"],
            },
            ],
        }

        DockerUtil().set_docker_settings(config['init_config'], config['instances'][0])

        container_fail = self.docker_client.create_container(
            "nginx:latest", detach=True, name='event-tags-test', entrypoint='/bin/false')
        log.debug('start nginx:latest with entrypoint /bin/false')
        self.docker_client.start(container_fail)
        log.debug('container exited with %s' % self.docker_client.wait(container_fail, 1))
        # Wait 1 second after exit so the event will be picked up
        from time import sleep
        sleep(1)
        self.run_check(config, force_reload=True)
        self.docker_client.remove_container(container_fail)

        # Previous tests might have left unprocessed events, to be ignored
        filtered_events = []
        for event in self.events:
            if 'container_name:event-tags-test' in event.get('tags', []):
                filtered_events.append(event)

        self.assertEqual(len(filtered_events), 1)
        self.assertIn("exitCode:1", filtered_events[0]["tags"])
        self.assertNotIn("name:test-exit-fail", filtered_events[0]["tags"])
开发者ID:dblackdblack,项目名称:integrations-core,代码行数:39,代码来源:test_docker_daemon.py

示例2: TestCheckDockerDaemon

# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import wait [as 别名]

#.........这里部分代码省略.........
    def test_container_name_extraction(self):
        containers = [
            ({'Id': 'deadbeef'}, ['deadbeef']),
            ({'Names': ['/redis'], 'Id': 'deadbeef'}, ['redis']),
            ({'Names': ['/mongo', '/redis/mongo'], 'Id': 'deadbeef'}, ['mongo']),
            ({'Names': ['/redis/mongo', '/mongo'], 'Id': 'deadbeef'}, ['mongo']),
        ]
        for co in containers:
            self.assertEqual(DockerUtil.container_name_extractor(co[0]), co[1])

    def test_collect_exit_code(self):
        config = {
            "init_config": {},
            "instances": [{
                "url": "unix://var/run/docker.sock",
                "collect_exit_codes": True
            }]
        }
        DockerUtil().set_docker_settings(config['init_config'], config['instances'][0])

        expected_service_checks = [
            (AgentCheck.OK, ['docker_image:nginx:latest', 'image_name:nginx', 'image_tag:latest', 'container_name:test-exit-ok']),
            (AgentCheck.CRITICAL, ['docker_image:nginx:latest', 'image_name:nginx', 'image_tag:latest', 'container_name:test-exit-fail']),
        ]

        container_ok = self.docker_client.create_container(
            "nginx:latest", detach=True, name='test-exit-ok', entrypoint='/bin/true')
        log.debug('start nginx:latest with entrypoint /bin/true')
        container_fail = self.docker_client.create_container(
            "nginx:latest", detach=True, name='test-exit-fail', entrypoint='/bin/false')
        log.debug('start nginx:latest with entrypoint /bin/false')
        self.docker_client.start(container_ok)
        self.docker_client.start(container_fail)
        log.debug('container exited with %s' % self.docker_client.wait(container_ok, 1))
        log.debug('container exited with %s' % self.docker_client.wait(container_fail, 1))
        # After the container exits, we need to wait a second so the event isn't too recent
        # when the check runs, otherwise the event is not picked up
        from time import sleep
        sleep(1)

        self.run_check(config)
        self.docker_client.remove_container(container_ok)
        self.docker_client.remove_container(container_fail)

        for status, tags in expected_service_checks:
            self.assertServiceCheck('docker.exit', status=status, tags=tags, count=1)

    def test_network_tagging(self):
        expected_metrics = [
            ('docker.net.bytes_rcvd',
             ['container_name:test-new-nginx-latest', 'docker_image:nginx:latest', 'image_name:nginx',
              'image_tag:latest', 'docker_network:bridge']),
            ('docker.net.bytes_rcvd',
             ['container_name:test-new-nginx-latest', 'docker_image:nginx:latest', 'image_name:nginx',
              'image_tag:latest', 'docker_network:second']),
            ('docker.net.bytes_sent',
             ['container_name:test-new-nginx-latest', 'docker_image:nginx:latest', 'image_name:nginx',
              'image_tag:latest', 'docker_network:bridge']),
            ('docker.net.bytes_sent',
             ['container_name:test-new-nginx-latest', 'docker_image:nginx:latest', 'image_name:nginx',
              'image_tag:latest', 'docker_network:second'])
        ]

        custom_tags = ["extra_tag", "env:testing"]
        config = {
            "init_config": {},
开发者ID:dblackdblack,项目名称:integrations-core,代码行数:70,代码来源:test_docker_daemon.py


注:本文中的utils.dockerutil.DockerUtil.wait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。