本文整理汇总了Python中utils.dockerutil.DockerUtil.start方法的典型用法代码示例。如果您正苦于以下问题:Python DockerUtil.start方法的具体用法?Python DockerUtil.start怎么用?Python DockerUtil.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.dockerutil.DockerUtil
的用法示例。
在下文中一共展示了DockerUtil.start方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestProxy
# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import start [as 别名]
class TestProxy(AsyncTestCase):
@attr(requires='core_integration')
def test_proxy(self):
config = {
"endpoints": {"https://app.datadoghq.com": ["foo"]},
"proxy_settings": {
"host": "localhost",
"port": PROXY_PORT,
"user": None,
"password": None
}
}
app = Application()
app.skip_ssl_validation = True
app._agentConfig = config
trManager = TransactionManager(MAX_WAIT_FOR_REPLAY, MAX_QUEUE_SIZE, THROTTLING_DELAY)
trManager._flush_without_ioloop = True # Use blocking API to emulate tornado ioloop
CustomAgentTransaction.set_tr_manager(trManager)
app.use_simple_http_client = False # We need proxy capabilities
app.agent_dns_caching = False
# _test is the instance of this class. It is needed to call the method stop() and deal with the asynchronous
# calls as described here : http://www.tornadoweb.org/en/stable/testing.html
CustomAgentTransaction._test = self
CustomAgentTransaction.set_application(app)
CustomAgentTransaction.set_endpoints(config['endpoints'])
CustomAgentTransaction('body', {}, "") # Create and flush the transaction
self.wait()
del CustomAgentTransaction._test
access_log = self.docker_client.exec_start(
self.docker_client.exec_create(CONTAINER_NAME, 'cat /var/log/squid/access.log')['Id'])
self.assertTrue("CONNECT" in access_log) # There should be an entry in the proxy access log
self.assertEquals(len(trManager._endpoints_errors), 1) # There should be an error since we gave a bogus api_key
def setUp(self):
super(TestProxy, self).setUp()
self.docker_client = DockerUtil().client
self.docker_client.pull(CONTAINER_TO_RUN)
self.container = self.docker_client.create_container(CONTAINER_TO_RUN, detach=True, name=CONTAINER_NAME,
ports=[PROXY_PORT], host_config=self.docker_client.create_host_config(port_bindings={3128: PROXY_PORT}))
log.info("Starting container: {0}".format(CONTAINER_TO_RUN))
self.docker_client.start(CONTAINER_NAME)
for line in self.docker_client.logs(CONTAINER_NAME, stdout=True, stream=True):
if "Accepting HTTP Socket connections" in line:
break # Wait for the container to properly start, otherwise we get 'Proxy CONNECT aborted'
def tearDown(self):
log.info("Stopping container: {0}".format(CONTAINER_TO_RUN))
self.docker_client.remove_container(CONTAINER_NAME, force=True)
super(TestProxy, self).tearDown()
示例2: TestCheckDockerDaemonNoSetUp
# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import start [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"])
示例3: TestCheckDockerDaemon
# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import start [as 别名]
class TestCheckDockerDaemon(AgentCheckTest):
CHECK_NAME = 'docker_daemon'
def setUp(self):
self.docker_client = DockerUtil().client
for c in CONTAINERS_TO_RUN:
images = [i["RepoTags"][0] for i in self.docker_client.images(c.split(":")[0]) if i["RepoTags"][0].startswith(c)]
if len(images) == 0:
for line in self.docker_client.pull(c, stream=True):
print line
self.containers = []
for c in CONTAINERS_TO_RUN:
name = "test-new-{0}".format(c.replace(":", "-"))
host_config = None
labels = None
if c == "nginx":
host_config = {"Memory": 137438953472}
labels = {"label1": "nginx", "foo": "bar"}
cont = self.docker_client.create_container(
c, detach=True, name=name, host_config=host_config, labels=labels)
self.containers.append(cont)
for c in self.containers:
log.info("Starting container: {0}".format(c))
self.docker_client.start(c)
def tearDown(self):
for c in self.containers:
log.info("Stopping container: {0}".format(c))
self.docker_client.remove_container(c, force=True)
def test_basic_config_single(self):
expected_metrics = [
('docker.containers.running', ['docker_image:nginx', 'image_name:nginx']),
('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx']),
('docker.image.size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),
('docker.image.size', ['image_name:nginx', 'image_tag:1.9.1']),
('docker.image.size', ['image_name:redis', 'image_tag:latest']),
('docker.image.size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.6', 'image_tag:latest']),
('docker.image.size', ['image_name:nginx', 'image_tag:1.9.0']),
('docker.image.size', ['image_name:nginx', 'image_tag:1.7.11']),
('docker.image.size', ['image_name:nginx', 'image_tag:1.9.2']),
('docker.image.size', ['image_name:nginx', 'image_tag:1.9.3']),
('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.1']),
('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),
('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.0']),
('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7.11']),
('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.6', 'image_tag:latest']),
('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.2']),
('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.3']),
('docker.image.virtual_size', ['image_name:redis', 'image_tag:latest']),
('docker.images.available', None),
('docker.images.intermediate', None),
('docker.mem.cache', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.mem.cache', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.mem.rss', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.mem.rss', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.mem.limit', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.mem.in_use', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.disk.used', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.disk.free', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.disk.total', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx'])
]
config = {
"init_config": {},
"instances": [{
"url": "unix://var/run/docker.sock",
"collect_image_size": True,
"collect_images_stats": True,
"collect_disk_stats": True,
},
],
}
DockerUtil().set_docker_settings(config['init_config'], config['instances'][0])
self.run_check(config, force_reload=True)
for mname, tags in expected_metrics:
self.assertMetric(mname, tags=tags, count=1, at_least=1)
def test_basic_config_twice(self):
expected_metrics = [
('docker.containers.running', ['docker_image:nginx', 'image_name:nginx']),
('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx']),
('docker.images.available', None),
('docker.images.intermediate', None),
('docker.cpu.system', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.cpu.system', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.cpu.user', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.cpu.user', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.io.read_bytes', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.io.read_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.io.write_bytes', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),
('docker.io.write_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
#.........这里部分代码省略.........
示例4: TestCheckDockerDaemon
# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import start [as 别名]
#.........这里部分代码省略.........
self.run_check(MOCK_CONFIG, force_reload=True)
self.assertMetric('docker.metadata.free', value=9e6)
self.assertMetric('docker.metadata.total', value=10e6)
self.assertMetric('docker.metadata.percent', value=10.0)
@mock.patch('docker.Client.info')
def test_devicemapper_invalid_values(self, mock_info):
"""Invalid values are detected in _calc_percent_disk_stats and 'percent' use 'free'+'used' instead of 'total' """
mock_info.return_value = self.mock_get_info_invalid_values()
self.run_check(MOCK_CONFIG, force_reload=True)
self.assertMetric('docker.metadata.free', value=9e6)
self.assertMetric('docker.metadata.used', value=11e6)
self.assertMetric('docker.metadata.total', value=10e6)
self.assertMetric('docker.metadata.percent', value=55)
@mock.patch('docker.Client.info')
def test_devicemapper_all_zeros(self, mock_info):
"""Percentage should not be calculated, other metrics should be collected correctly"""
mock_info.return_value = self.mock_get_info_all_zeros()
self.run_check(MOCK_CONFIG, force_reload=True)
metric_names = [metric[0] for metric in self.metrics]
self.assertMetric('docker.data.free', value=0)
self.assertMetric('docker.data.used', value=0)
self.assertMetric('docker.data.total', value=0)
self.assertNotIn('docker.data.percent', metric_names)
# integration tests #
def setUp(self):
self.docker_client = DockerUtil().client
for c in CONTAINERS_TO_RUN:
images = [i["RepoTags"][0] for i in self.docker_client.images(c.split(":")[0]) if i["RepoTags"][0].startswith(c)]
if len(images) == 0:
for line in self.docker_client.pull(c, stream=True):
print line
self.containers = []
for c in CONTAINERS_TO_RUN:
name = "test-new-{0}".format(c.replace(":", "-"))
host_config = None
labels = None
if c == "nginx:latest":
host_config = {"Memory": 137438953472}
labels = {"label1": "nginx", "foo": "bar"}
cont = self.docker_client.create_container(
c, detach=True, name=name, host_config=host_config, labels=labels)
self.containers.append(cont)
for c in self.containers:
log.info("Starting container: {0}".format(c))
self.docker_client.start(c)
def tearDown(self):
for c in self.containers:
log.info("Stopping container: {0}".format(c))
self.docker_client.remove_container(c, force=True)
def test_basic_config_single(self):
expected_metrics = [
('docker.containers.running', ['docker_image:nginx:latest', 'image_name:nginx', 'image_tag:latest']),
('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),
('docker.containers.stopped', ['docker_image:nginx:latest', 'image_name:nginx', 'image_tag:latest']),