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
2ff7371a
Kaydet (Commit)
2ff7371a
authored
Kas 16, 2016
tarafından
Aanand Prasad
Kaydeden (comit)
GitHub
Kas 16, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #1294 from aanand/add-healthcheck
Add support for passing healthcheck to create_container
üst
f262dd6d
e4b6d0dc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
5 deletions
+130
-5
container.py
docker/api/container.py
+4
-3
__init__.py
docker/types/__init__.py
+1
-0
healthcheck.py
docker/types/healthcheck.py
+53
-0
utils.py
docker/utils/utils.py
+12
-2
helpers.py
tests/helpers.py
+9
-0
healthcheck_test.py
tests/integration/healthcheck_test.py
+51
-0
No files found.
docker/api/container.py
Dosyayı görüntüle @
2ff7371a
...
...
@@ -115,7 +115,8 @@ class ContainerApiMixin(object):
cpu_shares
=
None
,
working_dir
=
None
,
domainname
=
None
,
memswap_limit
=
None
,
cpuset
=
None
,
host_config
=
None
,
mac_address
=
None
,
labels
=
None
,
volume_driver
=
None
,
stop_signal
=
None
,
networking_config
=
None
):
stop_signal
=
None
,
networking_config
=
None
,
healthcheck
=
None
):
if
isinstance
(
volumes
,
six
.
string_types
):
volumes
=
[
volumes
,
]
...
...
@@ -130,7 +131,7 @@ class ContainerApiMixin(object):
tty
,
mem_limit
,
ports
,
environment
,
dns
,
volumes
,
volumes_from
,
network_disabled
,
entrypoint
,
cpu_shares
,
working_dir
,
domainname
,
memswap_limit
,
cpuset
,
host_config
,
mac_address
,
labels
,
volume_driver
,
stop_signal
,
networking_config
,
volume_driver
,
stop_signal
,
networking_config
,
healthcheck
,
)
return
self
.
create_container_from_config
(
config
,
name
)
...
...
@@ -365,7 +366,7 @@ class ContainerApiMixin(object):
cap_drop
=
cap_drop
,
volumes_from
=
volumes_from
,
devices
=
devices
,
network_mode
=
network_mode
,
restart_policy
=
restart_policy
,
extra_hosts
=
extra_hosts
,
read_only
=
read_only
,
pid_mode
=
pid_mode
,
ipc_mode
=
ipc_mode
,
security_opt
=
security_opt
,
ulimits
=
ulimits
ipc_mode
=
ipc_mode
,
security_opt
=
security_opt
,
ulimits
=
ulimits
,
)
start_config
=
None
...
...
docker/types/__init__.py
Dosyayı görüntüle @
2ff7371a
...
...
@@ -4,4 +4,5 @@ from .services import (
ContainerSpec
,
DriverConfig
,
EndpointSpec
,
Mount
,
Resources
,
RestartPolicy
,
TaskTemplate
,
UpdateConfig
)
from
.healthcheck
import
Healthcheck
from
.swarm
import
SwarmSpec
,
SwarmExternalCA
docker/types/healthcheck.py
0 → 100644
Dosyayı görüntüle @
2ff7371a
from
.base
import
DictType
import
six
class
Healthcheck
(
DictType
):
def
__init__
(
self
,
**
kwargs
):
test
=
kwargs
.
get
(
'test'
,
kwargs
.
get
(
'Test'
))
if
isinstance
(
test
,
six
.
string_types
):
test
=
[
"CMD-SHELL"
,
test
]
interval
=
kwargs
.
get
(
'interval'
,
kwargs
.
get
(
'Interval'
))
timeout
=
kwargs
.
get
(
'timeout'
,
kwargs
.
get
(
'Timeout'
))
retries
=
kwargs
.
get
(
'retries'
,
kwargs
.
get
(
'Retries'
))
super
(
Healthcheck
,
self
)
.
__init__
({
'Test'
:
test
,
'Interval'
:
interval
,
'Timeout'
:
timeout
,
'Retries'
:
retries
})
@property
def
test
(
self
):
return
self
[
'Test'
]
@test.setter
def
test
(
self
,
value
):
self
[
'Test'
]
=
value
@property
def
interval
(
self
):
return
self
[
'Interval'
]
@interval.setter
def
interval
(
self
,
value
):
self
[
'Interval'
]
=
value
@property
def
timeout
(
self
):
return
self
[
'Timeout'
]
@timeout.setter
def
timeout
(
self
,
value
):
self
[
'Timeout'
]
=
value
@property
def
retries
(
self
):
return
self
[
'Retries'
]
@retries.setter
def
retries
(
self
,
value
):
self
[
'Retries'
]
=
value
docker/utils/utils.py
Dosyayı görüntüle @
2ff7371a
...
...
@@ -18,7 +18,7 @@ import six
from
..
import
constants
from
..
import
errors
from
..
import
tls
from
..types
import
Ulimit
,
LogConfig
from
..types
import
Ulimit
,
LogConfig
,
Healthcheck
if
six
.
PY2
:
from
urllib
import
splitnport
...
...
@@ -1029,6 +1029,7 @@ def create_container_config(
entrypoint
=
None
,
cpu_shares
=
None
,
working_dir
=
None
,
domainname
=
None
,
memswap_limit
=
None
,
cpuset
=
None
,
host_config
=
None
,
mac_address
=
None
,
labels
=
None
,
volume_driver
=
None
,
stop_signal
=
None
,
networking_config
=
None
,
healthcheck
=
None
,
):
if
isinstance
(
command
,
six
.
string_types
):
command
=
split_command
(
command
)
...
...
@@ -1057,6 +1058,11 @@ def create_container_config(
'stop_signal was only introduced in API version 1.21'
)
if
healthcheck
is
not
None
and
version_lt
(
version
,
'1.24'
):
raise
errors
.
InvalidVersion
(
'Health options were only introduced in API version 1.24'
)
if
compare_version
(
'1.19'
,
version
)
<
0
:
if
volume_driver
is
not
None
:
raise
errors
.
InvalidVersion
(
...
...
@@ -1113,6 +1119,9 @@ def create_container_config(
# Force None, an empty list or dict causes client.start to fail
volumes_from
=
None
if
healthcheck
and
isinstance
(
healthcheck
,
dict
):
healthcheck
=
Healthcheck
(
**
healthcheck
)
attach_stdin
=
False
attach_stdout
=
False
attach_stderr
=
False
...
...
@@ -1164,5 +1173,6 @@ def create_container_config(
'MacAddress'
:
mac_address
,
'Labels'
:
labels
,
'VolumeDriver'
:
volume_driver
,
'StopSignal'
:
stop_signal
'StopSignal'
:
stop_signal
,
'Healthcheck'
:
healthcheck
,
}
tests/helpers.py
Dosyayı görüntüle @
2ff7371a
...
...
@@ -2,6 +2,7 @@ import os
import
os.path
import
tarfile
import
tempfile
import
time
import
docker
import
pytest
...
...
@@ -47,3 +48,11 @@ def requires_api_version(version):
),
reason
=
"API version is too low (< {0})"
.
format
(
version
)
)
def
wait_on_condition
(
condition
,
delay
=
0.1
,
timeout
=
40
):
start_time
=
time
.
time
()
while
not
condition
():
if
time
.
time
()
-
start_time
>
timeout
:
raise
AssertionError
(
"Timeout:
%
s"
%
condition
)
time
.
sleep
(
delay
)
tests/integration/healthcheck_test.py
0 → 100644
Dosyayı görüntüle @
2ff7371a
from
.base
import
BaseIntegrationTest
from
.base
import
BUSYBOX
from
..
import
helpers
SECOND
=
1000000000
def
wait_on_health_status
(
client
,
container
,
status
):
def
condition
():
res
=
client
.
inspect_container
(
container
)
return
res
[
'State'
][
'Health'
][
'Status'
]
==
status
return
helpers
.
wait_on_condition
(
condition
)
class
HealthcheckTest
(
BaseIntegrationTest
):
@helpers.requires_api_version
(
'1.24'
)
def
test_healthcheck_shell_command
(
self
):
container
=
self
.
client
.
create_container
(
BUSYBOX
,
'top'
,
healthcheck
=
dict
(
test
=
'echo "hello world"'
))
self
.
tmp_containers
.
append
(
container
)
res
=
self
.
client
.
inspect_container
(
container
)
assert
res
[
'Config'
][
'Healthcheck'
][
'Test'
]
==
\
[
'CMD-SHELL'
,
'echo "hello world"'
]
@helpers.requires_api_version
(
'1.24'
)
def
test_healthcheck_passes
(
self
):
container
=
self
.
client
.
create_container
(
BUSYBOX
,
'top'
,
healthcheck
=
dict
(
test
=
"true"
,
interval
=
1
*
SECOND
,
timeout
=
1
*
SECOND
,
retries
=
1
,
))
self
.
tmp_containers
.
append
(
container
)
self
.
client
.
start
(
container
)
wait_on_health_status
(
self
.
client
,
container
,
"healthy"
)
@helpers.requires_api_version
(
'1.24'
)
def
test_healthcheck_fails
(
self
):
container
=
self
.
client
.
create_container
(
BUSYBOX
,
'top'
,
healthcheck
=
dict
(
test
=
"false"
,
interval
=
1
*
SECOND
,
timeout
=
1
*
SECOND
,
retries
=
1
,
))
self
.
tmp_containers
.
append
(
container
)
self
.
client
.
start
(
container
)
wait_on_health_status
(
self
.
client
,
container
,
"unhealthy"
)
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