2014-01-06 03:26:32 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
2015-01-12 15:59:05 +01:00
|
|
|
from compose.service import Service
|
2015-07-03 16:06:53 +02:00
|
|
|
from compose.config import ServiceLoader
|
2015-05-30 20:52:10 +02:00
|
|
|
from compose.const import LABEL_PROJECT
|
2015-01-12 15:59:05 +01:00
|
|
|
from compose.cli.docker_client import docker_client
|
|
|
|
from compose.progress_stream import stream_output
|
2014-04-25 23:58:21 +02:00
|
|
|
from .. import unittest
|
2013-12-09 18:36:44 +01:00
|
|
|
|
|
|
|
|
2014-01-06 12:22:46 +01:00
|
|
|
class DockerClientTestCase(unittest.TestCase):
|
2013-12-09 18:36:44 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2014-10-13 20:14:46 +02:00
|
|
|
cls.client = docker_client()
|
2013-12-09 18:36:44 +01:00
|
|
|
|
2015-05-30 22:17:21 +02:00
|
|
|
def tearDown(self):
|
2015-05-30 20:52:10 +02:00
|
|
|
for c in self.client.containers(
|
|
|
|
all=True,
|
|
|
|
filters={'label': '%s=composetest' % LABEL_PROJECT}):
|
|
|
|
self.client.kill(c['Id'])
|
|
|
|
self.client.remove_container(c['Id'])
|
2015-05-30 22:17:21 +02:00
|
|
|
for i in self.client.images(
|
|
|
|
filters={'label': 'com.docker.compose.test_image'}):
|
|
|
|
self.client.remove_image(i)
|
2013-12-09 18:36:44 +01:00
|
|
|
|
2013-12-09 22:39:11 +01:00
|
|
|
def create_service(self, name, **kwargs):
|
2015-04-30 12:57:46 +02:00
|
|
|
if 'image' not in kwargs and 'build' not in kwargs:
|
|
|
|
kwargs['image'] = 'busybox:latest'
|
2015-02-27 12:54:57 +01:00
|
|
|
|
2014-02-21 19:12:51 +01:00
|
|
|
if 'command' not in kwargs:
|
2015-05-21 17:19:15 +02:00
|
|
|
kwargs['command'] = ["top"]
|
2015-02-27 12:54:57 +01:00
|
|
|
|
2015-07-03 16:06:53 +02:00
|
|
|
options = ServiceLoader(working_dir='.').make_service_dict(name, kwargs)
|
|
|
|
|
2013-12-09 18:36:44 +01:00
|
|
|
return Service(
|
2015-01-12 15:59:05 +01:00
|
|
|
project='composetest',
|
2013-12-09 18:36:44 +01:00
|
|
|
client=self.client,
|
2015-07-03 16:06:53 +02:00
|
|
|
**options
|
2013-12-09 18:36:44 +01:00
|
|
|
)
|
|
|
|
|
2014-09-26 19:58:52 +02:00
|
|
|
def check_build(self, *args, **kwargs):
|
2015-05-30 22:17:21 +02:00
|
|
|
kwargs.setdefault('rm', True)
|
2014-09-26 19:58:52 +02:00
|
|
|
build_output = self.client.build(*args, **kwargs)
|
|
|
|
stream_output(build_output, open('/dev/null', 'w'))
|