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
369168e2
Kaydet (Commit)
369168e2
authored
Agu 07, 2017
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge branch 'bolshakov-bugfix/run-container-with-syslog-driver'
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
1a923c56
8bcf2f27
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
4 deletions
+77
-4
errors.py
docker/errors.py
+5
-2
containers.py
docker/models/containers.py
+15
-1
models_containers_test.py
tests/integration/models_containers_test.py
+18
-0
errors_test.py
tests/unit/errors_test.py
+33
-1
fake_api.py
tests/unit/fake_api.py
+6
-0
No files found.
docker/errors.py
Dosyayı görüntüle @
369168e2
...
...
@@ -127,8 +127,11 @@ class ContainerError(DockerException):
self
.
command
=
command
self
.
image
=
image
self
.
stderr
=
stderr
msg
=
(
"Command '{}' in image '{}' returned non-zero exit status {}: "
"{}"
)
.
format
(
command
,
image
,
exit_status
,
stderr
)
err
=
": {}"
.
format
(
stderr
)
if
stderr
is
not
None
else
""
msg
=
(
"Command '{}' in image '{}' returned non-zero exit "
"status {}{}"
)
.
format
(
command
,
image
,
exit_status
,
err
)
super
(
ContainerError
,
self
)
.
__init__
(
msg
)
...
...
docker/models/containers.py
Dosyayı görüntüle @
369168e2
...
...
@@ -667,6 +667,13 @@ class ContainerCollection(Collection):
The container logs, either ``STDOUT``, ``STDERR``, or both,
depending on the value of the ``stdout`` and ``stderr`` arguments.
``STDOUT`` and ``STDERR`` may be read only if either ``json-file``
or ``journald`` logging driver used. Thus, if you are using none of
these drivers, a ``None`` object is returned instead. See the
`Engine API documentation
<https://docs.docker.com/engine/api/v1.30/#operation/ContainerLogs/>`_
for full details.
If ``detach`` is ``True``, a :py:class:`Container` object is
returned instead.
...
...
@@ -709,7 +716,14 @@ class ContainerCollection(Collection):
if
exit_status
!=
0
:
stdout
=
False
stderr
=
True
out
=
container
.
logs
(
stdout
=
stdout
,
stderr
=
stderr
)
logging_driver
=
container
.
attrs
[
'HostConfig'
][
'LogConfig'
][
'Type'
]
if
logging_driver
==
'json-file'
or
logging_driver
==
'journald'
:
out
=
container
.
logs
(
stdout
=
stdout
,
stderr
=
stderr
)
else
:
out
=
None
if
remove
:
container
.
remove
()
if
exit_status
!=
0
:
...
...
tests/integration/models_containers_test.py
Dosyayı görüntüle @
369168e2
...
...
@@ -88,6 +88,24 @@ class ContainerCollectionTest(BaseIntegrationTest):
assert
'Networks'
in
attrs
[
'NetworkSettings'
]
assert
list
(
attrs
[
'NetworkSettings'
][
'Networks'
]
.
keys
())
==
[
net_name
]
def
test_run_with_none_driver
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
out
=
client
.
containers
.
run
(
"alpine"
,
"echo hello"
,
log_config
=
dict
(
type
=
'none'
)
)
self
.
assertEqual
(
out
,
None
)
def
test_run_with_json_file_driver
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
out
=
client
.
containers
.
run
(
"alpine"
,
"echo hello"
,
log_config
=
dict
(
type
=
'json-file'
)
)
self
.
assertEqual
(
out
,
b
'hello
\n
'
)
def
test_get
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
container
=
client
.
containers
.
run
(
"alpine"
,
"sleep 300"
,
detach
=
True
)
...
...
tests/unit/errors_test.py
Dosyayı görüntüle @
369168e2
...
...
@@ -2,8 +2,10 @@ import unittest
import
requests
from
docker.errors
import
(
APIError
,
DockerException
,
from
docker.errors
import
(
APIError
,
ContainerError
,
DockerException
,
create_unexpected_kwargs_error
)
from
.fake_api
import
FAKE_CONTAINER_ID
,
FAKE_IMAGE_ID
from
.fake_api_client
import
make_fake_client
class
APIErrorTest
(
unittest
.
TestCase
):
...
...
@@ -77,6 +79,36 @@ class APIErrorTest(unittest.TestCase):
assert
err
.
is_client_error
()
is
True
class
ContainerErrorTest
(
unittest
.
TestCase
):
def
test_container_without_stderr
(
self
):
"""The massage does not contain stderr"""
client
=
make_fake_client
()
container
=
client
.
containers
.
get
(
FAKE_CONTAINER_ID
)
command
=
"echo Hello World"
exit_status
=
42
image
=
FAKE_IMAGE_ID
stderr
=
None
err
=
ContainerError
(
container
,
exit_status
,
command
,
image
,
stderr
)
msg
=
(
"Command '{}' in image '{}' returned non-zero exit status {}"
)
.
format
(
command
,
image
,
exit_status
,
stderr
)
assert
str
(
err
)
==
msg
def
test_container_with_stderr
(
self
):
"""The massage contains stderr"""
client
=
make_fake_client
()
container
=
client
.
containers
.
get
(
FAKE_CONTAINER_ID
)
command
=
"echo Hello World"
exit_status
=
42
image
=
FAKE_IMAGE_ID
stderr
=
"Something went wrong"
err
=
ContainerError
(
container
,
exit_status
,
command
,
image
,
stderr
)
msg
=
(
"Command '{}' in image '{}' returned non-zero exit status {}: "
"{}"
)
.
format
(
command
,
image
,
exit_status
,
stderr
)
assert
str
(
err
)
==
msg
class
CreateUnexpectedKwargsErrorTest
(
unittest
.
TestCase
):
def
test_create_unexpected_kwargs_error_single
(
self
):
e
=
create_unexpected_kwargs_error
(
'f'
,
{
'foo'
:
'bar'
})
...
...
tests/unit/fake_api.py
Dosyayı görüntüle @
369168e2
...
...
@@ -146,6 +146,12 @@ def get_fake_inspect_container(tty=False):
"StartedAt"
:
"2013-09-25T14:01:18.869545111+02:00"
,
"Ghost"
:
False
},
"HostConfig"
:
{
"LogConfig"
:
{
"Type"
:
"json-file"
,
"Config"
:
{}
},
},
"MacAddress"
:
"02:42:ac:11:00:0a"
}
return
status_code
,
response
...
...
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