5
5
6
6
import docker
7
7
8
- from ..helpers import force_leave_swarm , requires_api_version
8
+ from ..helpers import (
9
+ force_leave_swarm , requires_api_version , requires_experimental
10
+ )
9
11
from .base import BaseAPIIntegrationTest , BUSYBOX
10
12
11
13
@@ -27,13 +29,15 @@ def tearDown(self):
27
29
def get_service_name (self ):
28
30
return 'dockerpytest_{0:x}' .format (random .getrandbits (64 ))
29
31
30
- def get_service_container (self , service_name , attempts = 20 , interval = 0.5 ):
32
+ def get_service_container (self , service_name , attempts = 20 , interval = 0.5 ,
33
+ include_stopped = False ):
31
34
# There is some delay between the service's creation and the creation
32
35
# of the service's containers. This method deals with the uncertainty
33
36
# when trying to retrieve the container associated with a service.
34
37
while True :
35
38
containers = self .client .containers (
36
- filters = {'name' : [service_name ]}, quiet = True
39
+ filters = {'name' : [service_name ]}, quiet = True ,
40
+ all = include_stopped
37
41
)
38
42
if len (containers ) > 0 :
39
43
return containers [0 ]
@@ -97,6 +101,18 @@ def test_create_service_simple(self):
97
101
assert len (services ) == 1
98
102
assert services [0 ]['ID' ] == svc_id ['ID' ]
99
103
104
+ @requires_api_version ('1.25' )
105
+ @requires_experimental
106
+ def test_service_logs (self ):
107
+ name , svc_id = self .create_simple_service ()
108
+ assert self .get_service_container (name , include_stopped = True )
109
+ logs = self .client .service_logs (svc_id , stdout = True , is_tty = False )
110
+ log_line = next (logs )
111
+ assert 'hello\n ' in log_line
112
+ assert 'com.docker.swarm.service.id={}' .format (
113
+ svc_id ['ID' ]
114
+ ) in log_line
115
+
100
116
def test_create_service_custom_log_driver (self ):
101
117
container_spec = docker .types .ContainerSpec (
102
118
BUSYBOX , ['echo' , 'hello' ]
0 commit comments