Merge branch 'feature_logs-tail' of github.com:totem/docker-py into totem-feature_logs-tail

Conflicts:
	docker/client.py
	tests/fake_api.py
This commit is contained in:
Joffrey F 2014-10-30 15:07:58 +01:00
commit 213ca7d71d
3 changed files with 36 additions and 4 deletions

View File

@ -574,7 +574,7 @@ class Client(requests.Session):
'AttachStderr': stderr,
'Detach': detach,
'Cmd': cmd
}
}
# create the command
url = self._url('/containers/{0}/exec'.format(container))
@ -738,13 +738,15 @@ class Client(requests.Session):
if isinstance(container, dict):
container = container.get('Id')
if utils.compare_version('1.11', self._version) >= 0:
if tail != 'all' and (not isinstance(tail, int) or tail <= 0):
tail = 'all'
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,
'tail': tail}
}
if utils.compare_version('1.13', self._version) >= 0:
if tail != 'all' and (not isinstance(tail, int) or tail <= 0):
tail = 'all'
params['tail'] = tail
url = self._url("/containers/{0}/logs".format(container))
res = self._get(url, params=params, stream=stream)
if stream:

View File

@ -292,6 +292,22 @@ class TestLogs(BaseTestCase):
self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))
class TestLogsWithTailOption(BaseTestCase):
def runTest(self):
snippet = '''Line1
Line2'''
container = self.client.create_container(
'busybox', 'echo "{0}"'.format(snippet)
)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(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'))
# class TestLogsStreaming(BaseTestCase):
# def runTest(self):
# snippet = 'Flowering Nights (Sakuya Iyazoi)'

View File

@ -1069,6 +1069,20 @@ class DockerClientTest(Cleanup, unittest.TestCase):
stream=True
)
def test_log_tail(self):
try:
self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=False, tail=10)
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))
fake_request.assert_called_with(
url_prefix + 'containers/3cc2351ab11b/logs',
params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
'tail': 10},
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS,
stream=False
)
def test_diff(self):
try:
self.client.diff(fake_api.FAKE_CONTAINER_ID)