mirror of https://github.com/docker/docker-py.git
Merge branch 'totem-feature_logs-tail'
This commit is contained in:
commit
e7f5766f30
|
|
@ -574,7 +574,7 @@ class Client(requests.Session):
|
||||||
'AttachStderr': stderr,
|
'AttachStderr': stderr,
|
||||||
'Detach': detach,
|
'Detach': detach,
|
||||||
'Cmd': cmd
|
'Cmd': cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
# create the command
|
# create the command
|
||||||
url = self._url('/containers/{0}/exec'.format(container))
|
url = self._url('/containers/{0}/exec'.format(container))
|
||||||
|
|
@ -738,13 +738,15 @@ class Client(requests.Session):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
if utils.compare_version('1.11', self._version) >= 0:
|
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,
|
params = {'stderr': stderr and 1 or 0,
|
||||||
'stdout': stdout and 1 or 0,
|
'stdout': stdout and 1 or 0,
|
||||||
'timestamps': timestamps and 1 or 0,
|
'timestamps': timestamps and 1 or 0,
|
||||||
'follow': stream 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))
|
url = self._url("/containers/{0}/logs".format(container))
|
||||||
res = self._get(url, params=params, stream=stream)
|
res = self._get(url, params=params, stream=stream)
|
||||||
if stream:
|
if stream:
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,22 @@ class TestLogs(BaseTestCase):
|
||||||
self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))
|
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):
|
# class TestLogsStreaming(BaseTestCase):
|
||||||
# def runTest(self):
|
# def runTest(self):
|
||||||
# snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
# snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
||||||
|
|
|
||||||
|
|
@ -1069,6 +1069,20 @@ class DockerClientTest(Cleanup, unittest.TestCase):
|
||||||
stream=True
|
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):
|
def test_diff(self):
|
||||||
try:
|
try:
|
||||||
self.client.diff(fake_api.FAKE_CONTAINER_ID)
|
self.client.diff(fake_api.FAKE_CONTAINER_ID)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue