Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
'follow': stream and 1 or 0,
}
if utils.compare_version('1.13', self._version) >= 0:
if tail != 'all' and (not isinstance(tail, int) or tail <= 0):
if tail != 'all' and (not isinstance(tail, int) or tail < 0):
tail = 'all'
params['tail'] = tail
url = self._url("/containers/{0}/logs", container)
Expand Down
49 changes: 31 additions & 18 deletions tests/integration/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ def test_logs(self):
BUSYBOX, 'echo {0}'.format(snippet)
)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
self.client.start(id)
exitcode = self.client.wait(id)
self.assertEqual(exitcode, 0)
logs = self.client.logs(id)
Expand All @@ -627,43 +627,56 @@ def test_logs_tail_option(self):
BUSYBOX, 'echo "{0}"'.format(snippet)
)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
self.client.start(id)
exitcode = self.client.wait(id)
self.assertEqual(exitcode, 0)
logs = self.client.logs(id, tail=1)
self.assertEqual(logs, ('Line2\n').encode(encoding='ascii'))
self.assertEqual(logs, 'Line2\n'.encode(encoding='ascii'))

# def test_logs_streaming(self):
# snippet = 'Flowering Nights (Sakuya Iyazoi)'
# container = self.client.create_container(
# BUSYBOX, 'echo {0}'.format(snippet)
# )
# id = container['Id']
# self.client.start(id)
# self.tmp_containers.append(id)
# logs = bytes() if six.PY3 else str()
# for chunk in self.client.logs(id, stream=True):
# logs += chunk
def test_logs_streaming(self):
snippet = 'Flowering Nights (Sakuya Iyazoi)'
container = self.client.create_container(
BUSYBOX, 'echo {0}'.format(snippet)
)
id = container['Id']
self.tmp_containers.append(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think adding it to tmp_containers should happen before self.client.start(), otherwise start failures would leave a created container lying around

self.client.start(id)
logs = six.binary_type()
for chunk in self.client.logs(id, stream=True):
logs += chunk

# exitcode = self.client.wait(id)
# self.assertEqual(exitcode, 0)
exitcode = self.client.wait(id)
self.assertEqual(exitcode, 0)

# self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))
self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))

def test_logs_with_dict_instead_of_id(self):
snippet = 'Flowering Nights (Sakuya Iyazoi)'
container = self.client.create_container(
BUSYBOX, 'echo {0}'.format(snippet)
)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
self.client.start(id)
exitcode = self.client.wait(id)
self.assertEqual(exitcode, 0)
logs = self.client.logs(container)
self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))

def test_logs_with_tail_0(self):
snippet = 'Flowering Nights (Sakuya Iyazoi)'
container = self.client.create_container(
BUSYBOX, 'echo "{0}"'.format(snippet)
)
id = container['Id']
self.tmp_containers.append(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same minor ordering issue here

self.client.start(id)
exitcode = self.client.wait(id)
self.assertEqual(exitcode, 0)
logs = self.client.logs(id, tail=0)
self.assertEqual(logs, ''.encode(encoding='ascii'))


class DiffTest(api_test.BaseTestCase):
def test_diff(self):
Expand Down