Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
cdf6dc8c
Kaydet (Commit)
cdf6dc8c
authored
Şub 25, 2016
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #942 from seguins/934-separate-stream-follow-logs
Separate params stream and follow for logs.
üst
44555f32
71fafd32
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
8 deletions
+56
-8
container.py
docker/api/container.py
+4
-2
api.md
docs/api.md
+1
-0
container_test.py
tests/integration/container_test.py
+2
-2
container_test.py
tests/unit/container_test.py
+49
-4
No files found.
docker/api/container.py
Dosyayı görüntüle @
cdf6dc8c
...
@@ -193,12 +193,14 @@ class ContainerApiMixin(object):
...
@@ -193,12 +193,14 @@ class ContainerApiMixin(object):
@utils.check_resource
@utils.check_resource
def
logs
(
self
,
container
,
stdout
=
True
,
stderr
=
True
,
stream
=
False
,
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
utils
.
compare_version
(
'1.11'
,
self
.
_version
)
>=
0
:
if
follow
is
None
:
follow
=
stream
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'
:
follow
and
1
or
0
,
}
}
if
utils
.
compare_version
(
'1.13'
,
self
.
_version
)
>=
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
):
...
...
docs/api.md
Dosyayı görüntüle @
cdf6dc8c
...
@@ -677,6 +677,7 @@ output as it happens.
...
@@ -677,6 +677,7 @@ output as it happens.
*
timestamps (bool): Show timestamps
*
timestamps (bool): Show timestamps
*
tail (str or int): Output specified number of lines at the end of logs:
`"all"`
or
`number`
. Default
`"all"`
*
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)
*
since (datetime or int): Show logs since a given datetime or integer epoch (in seconds)
*
follow (bool): Follow log output
**Returns**
(generator or str):
**Returns**
(generator or str):
...
...
tests/integration/container_test.py
Dosyayı görüntüle @
cdf6dc8c
...
@@ -679,7 +679,7 @@ Line2'''
...
@@ -679,7 +679,7 @@ Line2'''
logs
=
self
.
client
.
logs
(
id
,
tail
=
1
)
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
):
def
test_logs_streaming
_and_follow
(
self
):
snippet
=
'Flowering Nights (Sakuya Iyazoi)'
snippet
=
'Flowering Nights (Sakuya Iyazoi)'
container
=
self
.
client
.
create_container
(
container
=
self
.
client
.
create_container
(
BUSYBOX
,
'echo {0}'
.
format
(
snippet
)
BUSYBOX
,
'echo {0}'
.
format
(
snippet
)
...
@@ -688,7 +688,7 @@ Line2'''
...
@@ -688,7 +688,7 @@ Line2'''
self
.
tmp_containers
.
append
(
id
)
self
.
tmp_containers
.
append
(
id
)
self
.
client
.
start
(
id
)
self
.
client
.
start
(
id
)
logs
=
six
.
binary_type
()
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
logs
+=
chunk
exitcode
=
self
.
client
.
wait
(
id
)
exitcode
=
self
.
client
.
wait
(
id
)
...
...
tests/unit/container_test.py
Dosyayı görüntüle @
cdf6dc8c
...
@@ -1119,6 +1119,36 @@ class ContainerTest(DockerClientTest):
...
@@ -1119,6 +1119,36 @@ class ContainerTest(DockerClientTest):
)
)
def
test_log_streaming
(
self
):
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'
,
with
mock
.
patch
(
'docker.Client.inspect_container'
,
fake_inspect_container
):
fake_inspect_container
):
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
True
)
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
True
)
...
@@ -1132,12 +1162,27 @@ class ContainerTest(DockerClientTest):
...
@@ -1132,12 +1162,27 @@ class ContainerTest(DockerClientTest):
stream
=
True
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
):
def
test_log_tail
(
self
):
with
mock
.
patch
(
'docker.Client.inspect_container'
,
with
mock
.
patch
(
'docker.Client.inspect_container'
,
fake_inspect_container
):
fake_inspect_container
):
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
False
,
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
False
,
tail
=
10
)
follow
=
False
,
tail
=
10
)
fake_request
.
assert_called_with
(
fake_request
.
assert_called_with
(
'GET'
,
'GET'
,
...
@@ -1153,7 +1198,7 @@ class ContainerTest(DockerClientTest):
...
@@ -1153,7 +1198,7 @@ class ContainerTest(DockerClientTest):
with
mock
.
patch
(
'docker.Client.inspect_container'
,
with
mock
.
patch
(
'docker.Client.inspect_container'
,
fake_inspect_container
):
fake_inspect_container
):
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
False
,
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
False
,
since
=
ts
)
follow
=
False
,
since
=
ts
)
fake_request
.
assert_called_with
(
fake_request
.
assert_called_with
(
'GET'
,
'GET'
,
...
@@ -1170,7 +1215,7 @@ class ContainerTest(DockerClientTest):
...
@@ -1170,7 +1215,7 @@ class ContainerTest(DockerClientTest):
with
mock
.
patch
(
'docker.Client.inspect_container'
,
with
mock
.
patch
(
'docker.Client.inspect_container'
,
fake_inspect_container
):
fake_inspect_container
):
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
False
,
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
False
,
since
=
time
)
follow
=
False
,
since
=
time
)
fake_request
.
assert_called_with
(
fake_request
.
assert_called_with
(
'GET'
,
'GET'
,
...
@@ -1188,7 +1233,7 @@ class ContainerTest(DockerClientTest):
...
@@ -1188,7 +1233,7 @@ class ContainerTest(DockerClientTest):
with
mock
.
patch
(
'docker.Client._stream_raw_result'
,
with
mock
.
patch
(
'docker.Client._stream_raw_result'
,
m
):
m
):
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
self
.
client
.
logs
(
fake_api
.
FAKE_CONTAINER_ID
,
stream
=
True
)
follow
=
True
,
stream
=
True
)
self
.
assertTrue
(
m
.
called
)
self
.
assertTrue
(
m
.
called
)
fake_request
.
assert_called_with
(
fake_request
.
assert_called_with
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment