summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStéphane Seguin <stephseguin93@gmail.com>2016-02-15 20:31:44 +0100
committerStéphane Seguin <stephseguin93@gmail.com>2016-02-16 18:51:55 +0100
commit71fafd3209342b136714cf2a4531793c50e3b0e1 (patch)
treeb63137ec00b1aaa8f3bf8772d16a5fcba6500f78
parentc3a66cc5999a5435b81769ac758d411d34c995c4 (diff)
downloaddocker-py-71fafd3209342b136714cf2a4531793c50e3b0e1.tar.gz
Separate params stream and follow for logs.
Closes #934 Signed-off-by: Stéphane Seguin <stephseguin93@gmail.com>
-rw-r--r--docker/api/container.py6
-rw-r--r--docs/api.md1
-rw-r--r--tests/integration/container_test.py4
-rw-r--r--tests/unit/container_test.py53
4 files changed, 56 insertions, 8 deletions
diff --git a/docker/api/container.py b/docker/api/container.py
index ceac173..8aa9aa2 100644
--- a/docker/api/container.py
+++ b/docker/api/container.py
@@ -193,12 +193,14 @@ class ContainerApiMixin(object):
@utils.check_resource
def logs(self, container, stdout=True, stderr=True, stream=False,
- timestamps=False, tail='all', since=None):
+ timestamps=False, tail='all', since=None, follow=None):
if utils.compare_version('1.11', self._version) >= 0:
+ if follow is None:
+ follow = stream
params = {'stderr': stderr and 1 or 0,
'stdout': stdout and 1 or 0,
'timestamps': timestamps and 1 or 0,
- 'follow': stream and 1 or 0,
+ 'follow': follow and 1 or 0,
}
if utils.compare_version('1.13', self._version) >= 0:
if tail != 'all' and (not isinstance(tail, int) or tail < 0):
diff --git a/docs/api.md b/docs/api.md
index 00ccabc..32952bf 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -677,6 +677,7 @@ output as it happens.
* timestamps (bool): Show timestamps
* tail (str or int): Output specified number of lines at the end of logs: `"all"` or `number`. Default `"all"`
* since (datetime or int): Show logs since a given datetime or integer epoch (in seconds)
+* follow (bool): Follow log output
**Returns** (generator or str):
diff --git a/tests/integration/container_test.py b/tests/integration/container_test.py
index 1714599..142299d 100644
--- a/tests/integration/container_test.py
+++ b/tests/integration/container_test.py
@@ -666,7 +666,7 @@ Line2'''
logs = self.client.logs(id, tail=1)
self.assertEqual(logs, 'Line2\n'.encode(encoding='ascii'))
- def test_logs_streaming(self):
+ def test_logs_streaming_and_follow(self):
snippet = 'Flowering Nights (Sakuya Iyazoi)'
container = self.client.create_container(
BUSYBOX, 'echo {0}'.format(snippet)
@@ -675,7 +675,7 @@ Line2'''
self.tmp_containers.append(id)
self.client.start(id)
logs = six.binary_type()
- for chunk in self.client.logs(id, stream=True):
+ for chunk in self.client.logs(id, stream=True, follow=True):
logs += chunk
exitcode = self.client.wait(id)
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py
index c2b2573..d66eeed 100644
--- a/tests/unit/container_test.py
+++ b/tests/unit/container_test.py
@@ -1121,6 +1121,36 @@ class ContainerTest(DockerClientTest):
def test_log_streaming(self):
with mock.patch('docker.Client.inspect_container',
fake_inspect_container):
+ self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=True,
+ follow=False)
+
+ fake_request.assert_called_with(
+ 'GET',
+ url_prefix + 'containers/3cc2351ab11b/logs',
+ params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
+ 'tail': 'all'},
+ timeout=DEFAULT_TIMEOUT_SECONDS,
+ stream=True
+ )
+
+ def test_log_following(self):
+ with mock.patch('docker.Client.inspect_container',
+ fake_inspect_container):
+ self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=False,
+ follow=True)
+
+ fake_request.assert_called_with(
+ 'GET',
+ url_prefix + 'containers/3cc2351ab11b/logs',
+ params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1,
+ 'tail': 'all'},
+ timeout=DEFAULT_TIMEOUT_SECONDS,
+ stream=False
+ )
+
+ def test_log_following_backwards(self):
+ with mock.patch('docker.Client.inspect_container',
+ fake_inspect_container):
self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=True)
fake_request.assert_called_with(
@@ -1132,12 +1162,27 @@ class ContainerTest(DockerClientTest):
stream=True
)
+ def test_log_streaming_and_following(self):
+ with mock.patch('docker.Client.inspect_container',
+ fake_inspect_container):
+ self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=True,
+ follow=True)
+
+ fake_request.assert_called_with(
+ 'GET',
+ url_prefix + 'containers/3cc2351ab11b/logs',
+ params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1,
+ 'tail': 'all'},
+ timeout=DEFAULT_TIMEOUT_SECONDS,
+ stream=True
+ )
+
def test_log_tail(self):
with mock.patch('docker.Client.inspect_container',
fake_inspect_container):
self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=False,
- tail=10)
+ follow=False, tail=10)
fake_request.assert_called_with(
'GET',
@@ -1153,7 +1198,7 @@ class ContainerTest(DockerClientTest):
with mock.patch('docker.Client.inspect_container',
fake_inspect_container):
self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=False,
- since=ts)
+ follow=False, since=ts)
fake_request.assert_called_with(
'GET',
@@ -1170,7 +1215,7 @@ class ContainerTest(DockerClientTest):
with mock.patch('docker.Client.inspect_container',
fake_inspect_container):
self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=False,
- since=time)
+ follow=False, since=time)
fake_request.assert_called_with(
'GET',
@@ -1188,7 +1233,7 @@ class ContainerTest(DockerClientTest):
with mock.patch('docker.Client._stream_raw_result',
m):
self.client.logs(fake_api.FAKE_CONTAINER_ID,
- stream=True)
+ follow=True, stream=True)
self.assertTrue(m.called)
fake_request.assert_called_with(