Kaydet (Commit) 54244d0a authored tarafından Joffrey F's avatar Joffrey F

Add service_logs integration test

Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst 672a9ee6
......@@ -167,6 +167,7 @@ class ServiceApiMixin(object):
return self._result(self._get(url, params=params), True)
@utils.minimum_version('1.25')
@utils.check_resource
def service_logs(self, service, details=False, follow=False, stdout=False,
stderr=False, since=0, timestamps=False, tail='all',
is_tty=None):
......@@ -176,7 +177,7 @@ class ServiceApiMixin(object):
or ``journald`` logging drivers.
Args:
service (str): ID or name of the container
service (str): ID or name of the service
details (bool): Show extra details provided to logs.
Default: ``False``
follow (bool): Keep connection open to read logs as they are
......
import functools
import os
import os.path
import random
......@@ -53,6 +54,15 @@ def requires_api_version(version):
)
def requires_experimental(f):
@functools.wraps(f)
def wrapped(self, *args, **kwargs):
if not self.client.info()['ExperimentalBuild']:
pytest.skip('Feature requires Docker Engine experimental mode')
return f(self, *args, **kwargs)
return wrapped
def wait_on_condition(condition, delay=0.1, timeout=40):
start_time = time.time()
while not condition():
......
......@@ -5,7 +5,9 @@ import time
import docker
from ..helpers import force_leave_swarm, requires_api_version
from ..helpers import (
force_leave_swarm, requires_api_version, requires_experimental
)
from .base import BaseAPIIntegrationTest, BUSYBOX
......@@ -27,13 +29,15 @@ class ServiceTest(BaseAPIIntegrationTest):
def get_service_name(self):
return 'dockerpytest_{0:x}'.format(random.getrandbits(64))
def get_service_container(self, service_name, attempts=20, interval=0.5):
def get_service_container(self, service_name, attempts=20, interval=0.5,
include_stopped=False):
# There is some delay between the service's creation and the creation
# of the service's containers. This method deals with the uncertainty
# when trying to retrieve the container associated with a service.
while True:
containers = self.client.containers(
filters={'name': [service_name]}, quiet=True
filters={'name': [service_name]}, quiet=True,
all=include_stopped
)
if len(containers) > 0:
return containers[0]
......@@ -97,6 +101,18 @@ class ServiceTest(BaseAPIIntegrationTest):
assert len(services) == 1
assert services[0]['ID'] == svc_id['ID']
@requires_api_version('1.25')
@requires_experimental
def test_service_logs(self):
name, svc_id = self.create_simple_service()
assert self.get_service_container(name, include_stopped=True)
logs = self.client.service_logs(svc_id, stdout=True, is_tty=False)
log_line = next(logs)
assert 'hello\n' in log_line
assert 'com.docker.swarm.service.id={}'.format(
svc_id['ID']
) in log_line
def test_create_service_custom_log_driver(self):
container_spec = docker.types.ContainerSpec(
BUSYBOX, ['echo', 'hello']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment