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
281b5558
Kaydet (Commit)
281b5558
authored
Ara 07, 2016
tarafından
Joffrey F
Kaydeden (comit)
GitHub
Ara 07, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #1340 from docker/dnephin-add-attachable
Add attachable option in create_network
üst
9050e1c6
738cfdcd
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
75 additions
and
24 deletions
+75
-24
Makefile
Makefile
+2
-2
network.py
docker/api/network.py
+12
-2
swarm.py
docker/api/swarm.py
+4
-0
errors.py
docker/errors.py
+3
-1
swarm.py
docker/models/swarm.py
+2
-1
helpers.py
tests/helpers.py
+1
-1
api_network_test.py
tests/integration/api_network_test.py
+22
-3
api_service_test.py
tests/integration/api_service_test.py
+13
-9
models_images_test.py
tests/integration/models_images_test.py
+4
-0
models_services_test.py
tests/integration/models_services_test.py
+6
-4
models_swarm_test.py
tests/integration/models_swarm_test.py
+6
-1
No files found.
Makefile
Dosyayı görüntüle @
281b5558
...
...
@@ -44,7 +44,7 @@ integration-test-py3: build-py3
.PHONY
:
integration-dind
integration-dind
:
build build-py3
docker
rm
-vf
dpy-dind
||
:
docker run
-d
--name
dpy-dind
--privileged
dockerswarm/dind:1.1
2.0
docker daemon
\
docker run
-d
--name
dpy-dind
--privileged
dockerswarm/dind:1.1
3.0-rc3
docker daemon
\
-H
tcp://0.0.0.0:2375
docker run
--rm
--env
=
"DOCKER_HOST=tcp://docker:2375"
--link
=
dpy-dind:docker docker-sdk-python
\
py.test tests/integration
...
...
@@ -57,7 +57,7 @@ integration-dind-ssl: build-dind-certs build build-py3
docker run
-d
--name
dpy-dind-certs dpy-dind-certs
docker run
-d
--env
=
"DOCKER_HOST=tcp://localhost:2375"
--env
=
"DOCKER_TLS_VERIFY=1"
\
--env
=
"DOCKER_CERT_PATH=/certs"
--volumes-from
dpy-dind-certs
--name
dpy-dind-ssl
\
-v
/tmp
--privileged
dockerswarm/dind:1.1
2.0
docker daemon
--tlsverify
\
-v
/tmp
--privileged
dockerswarm/dind:1.1
3.0-rc3
docker daemon
--tlsverify
\
--tlscacert
=
/certs/ca.pem
--tlscert
=
/certs/server-cert.pem
\
--tlskey
=
/certs/server-key.pem
-H
tcp://0.0.0.0:2375
docker run
--rm
--volumes-from
dpy-dind-ssl
--env
=
"DOCKER_HOST=tcp://docker:2375"
\
...
...
docker/api/network.py
Dosyayı görüntüle @
281b5558
...
...
@@ -38,7 +38,7 @@ class NetworkApiMixin(object):
@minimum_version
(
'1.21'
)
def
create_network
(
self
,
name
,
driver
=
None
,
options
=
None
,
ipam
=
None
,
check_duplicate
=
None
,
internal
=
False
,
labels
=
None
,
enable_ipv6
=
False
):
enable_ipv6
=
False
,
attachable
=
None
,
scope
=
None
):
"""
Create a network. Similar to the ``docker network create``.
...
...
@@ -54,6 +54,9 @@ class NetworkApiMixin(object):
labels (dict): Map of labels to set on the network. Default
``None``.
enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``.
attachable (bool): If enabled, and the network is in the global
scope, non-service containers on worker nodes will be able to
connect to the network.
Returns:
(dict): The created network reference object
...
...
@@ -91,7 +94,7 @@ class NetworkApiMixin(object):
'Driver'
:
driver
,
'Options'
:
options
,
'IPAM'
:
ipam
,
'CheckDuplicate'
:
check_duplicate
'CheckDuplicate'
:
check_duplicate
,
}
if
labels
is
not
None
:
...
...
@@ -116,6 +119,13 @@ class NetworkApiMixin(object):
'supported in API version < 1.22'
)
data
[
'Internal'
]
=
True
if
attachable
is
not
None
:
if
version_lt
(
self
.
_version
,
'1.24'
):
raise
InvalidVersion
(
'attachable is not supported in API version < 1.24'
)
data
[
'Attachable'
]
=
attachable
url
=
self
.
_url
(
"/networks/create"
)
res
=
self
.
_post_json
(
url
,
data
=
data
)
return
self
.
_result
(
res
,
json
=
True
)
...
...
docker/api/swarm.py
Dosyayı görüntüle @
281b5558
...
...
@@ -197,6 +197,10 @@ class SwarmApiMixin(object):
# Ignore "this node is not part of a swarm" error
if
force
and
response
.
status_code
==
http_client
.
NOT_ACCEPTABLE
:
return
True
# FIXME: Temporary workaround for 1.13.0-rc bug
# https://github.com/docker/docker/issues/29192
if
force
and
response
.
status_code
==
http_client
.
SERVICE_UNAVAILABLE
:
return
True
self
.
_raise_for_status
(
response
)
return
True
...
...
docker/errors.py
Dosyayı görüntüle @
281b5558
...
...
@@ -21,7 +21,9 @@ def create_api_error_from_http_exception(e):
explanation
=
response
.
content
.
strip
()
cls
=
APIError
if
response
.
status_code
==
404
:
if
explanation
and
'No such image'
in
str
(
explanation
):
if
explanation
and
(
'No such image'
in
str
(
explanation
)
or
'not found: does not exist or no read access'
in
str
(
explanation
)):
cls
=
ImageNotFound
else
:
cls
=
NotFound
...
...
docker/models/swarm.py
Dosyayı görüntüle @
281b5558
...
...
@@ -15,7 +15,8 @@ class Swarm(Model):
try
:
self
.
reload
()
except
APIError
as
e
:
if
e
.
response
.
status_code
!=
406
:
# FIXME: https://github.com/docker/docker/issues/29192
if
e
.
response
.
status_code
not
in
(
406
,
503
):
raise
@property
...
...
tests/helpers.py
Dosyayı görüntüle @
281b5558
...
...
@@ -73,4 +73,4 @@ def force_leave_swarm(client):
if
e
.
explanation
==
"context deadline exceeded"
:
continue
else
:
r
aise
r
eturn
tests/integration/api_network_test.py
Dosyayı görüntüle @
281b5558
...
...
@@ -7,6 +7,10 @@ from .base import BaseAPIIntegrationTest
class
TestNetworks
(
BaseAPIIntegrationTest
):
def
tearDown
(
self
):
super
(
TestNetworks
,
self
)
.
tearDown
()
self
.
client
.
leave_swarm
(
force
=
True
)
def
create_network
(
self
,
*
args
,
**
kwargs
):
net_name
=
random_name
()
net_id
=
self
.
client
.
create_network
(
net_name
,
*
args
,
**
kwargs
)[
'Id'
]
...
...
@@ -16,12 +20,10 @@ class TestNetworks(BaseAPIIntegrationTest):
@requires_api_version
(
'1.21'
)
def
test_list_networks
(
self
):
networks
=
self
.
client
.
networks
()
initial_size
=
len
(
networks
)
net_name
,
net_id
=
self
.
create_network
()
networks
=
self
.
client
.
networks
()
self
.
assertEqual
(
len
(
networks
),
initial_size
+
1
)
self
.
assertTrue
(
net_id
in
[
n
[
'Id'
]
for
n
in
networks
])
networks_by_name
=
self
.
client
.
networks
(
names
=
[
net_name
])
...
...
@@ -431,6 +433,23 @@ class TestNetworks(BaseAPIIntegrationTest):
@requires_api_version
(
'1.23'
)
def
test_create_network_ipv6_enabled
(
self
):
_
,
net_id
=
self
.
create_network
(
enable_ipv6
=
True
)
_
,
net_id
=
self
.
create_network
(
enable_ipv6
=
True
,
ipam
=
IPAMConfig
(
driver
=
'default'
,
pool_configs
=
[
IPAMPool
(
subnet
=
"2001:389::1/64"
,
iprange
=
"2001:389::0/96"
,
gateway
=
"2001:389::ffff"
)
]
)
)
net
=
self
.
client
.
inspect_network
(
net_id
)
assert
net
[
'EnableIPv6'
]
is
True
@requires_api_version
(
'1.25'
)
def
test_create_network_attachable
(
self
):
assert
self
.
client
.
init_swarm
(
'eth0'
)
_
,
net_id
=
self
.
create_network
(
driver
=
'overlay'
,
attachable
=
True
)
net
=
self
.
client
.
inspect_network
(
net_id
)
assert
net
[
'Attachable'
]
is
True
tests/integration/api_service_test.py
Dosyayı görüntüle @
281b5558
...
...
@@ -221,15 +221,19 @@ class ServiceTest(BaseAPIIntegrationTest):
svc_info
=
self
.
client
.
inspect_service
(
svc_id
)
print
(
svc_info
)
ports
=
svc_info
[
'Spec'
][
'EndpointSpec'
][
'Ports'
]
assert
{
'PublishedPort'
:
12562
,
'TargetPort'
:
678
,
'Protocol'
:
'tcp'
}
in
ports
assert
{
'PublishedPort'
:
53243
,
'TargetPort'
:
8080
,
'Protocol'
:
'tcp'
}
in
ports
assert
{
'PublishedPort'
:
12357
,
'TargetPort'
:
1990
,
'Protocol'
:
'udp'
}
in
ports
for
port
in
ports
:
if
port
[
'PublishedPort'
]
==
12562
:
assert
port
[
'TargetPort'
]
==
678
assert
port
[
'Protocol'
]
==
'tcp'
elif
port
[
'PublishedPort'
]
==
53243
:
assert
port
[
'TargetPort'
]
==
8080
assert
port
[
'Protocol'
]
==
'tcp'
elif
port
[
'PublishedPort'
]
==
12357
:
assert
port
[
'TargetPort'
]
==
1990
assert
port
[
'Protocol'
]
==
'udp'
else
:
self
.
fail
(
'Invalid port specification: {0}'
.
format
(
port
))
assert
len
(
ports
)
==
3
def
test_create_service_with_env
(
self
):
...
...
tests/integration/models_images_test.py
Dosyayı görüntüle @
281b5558
import
io
import
docker
import
pytest
from
.base
import
BaseIntegrationTest
...
...
@@ -14,6 +17,7 @@ class ImageCollectionTest(BaseIntegrationTest):
self
.
tmp_imgs
.
append
(
image
.
id
)
assert
client
.
containers
.
run
(
image
)
==
b
"hello world
\n
"
@pytest.mark.xfail
(
reason
=
'Engine 1.13 responds with status 500'
)
def
test_build_with_error
(
self
):
client
=
docker
.
from_env
()
with
self
.
assertRaises
(
docker
.
errors
.
BuildError
)
as
cm
:
...
...
tests/integration/models_services_test.py
Dosyayı görüntüle @
281b5558
import
unittest
import
docker
import
pytest
from
..
import
helpers
...
...
@@ -29,7 +32,7 @@ class ServiceTest(unittest.TestCase):
assert
service
.
name
==
name
assert
service
.
attrs
[
'Spec'
][
'Labels'
][
'foo'
]
==
'bar'
container_spec
=
service
.
attrs
[
'Spec'
][
'TaskTemplate'
][
'ContainerSpec'
]
assert
container_spec
[
'Image'
]
==
"alpine"
assert
"alpine"
in
container_spec
[
'Image'
]
assert
container_spec
[
'Labels'
]
==
{
'container'
:
'label'
}
def
test_get
(
self
):
...
...
@@ -78,6 +81,7 @@ class ServiceTest(unittest.TestCase):
assert
len
(
tasks
)
==
1
assert
tasks
[
0
][
'ServiceID'
]
==
service2
.
id
@pytest.mark.skip
(
reason
=
"Makes Swarm unstable?"
)
def
test_update
(
self
):
client
=
docker
.
from_env
()
service
=
client
.
services
.
create
(
...
...
@@ -87,14 +91,12 @@ class ServiceTest(unittest.TestCase):
image
=
"alpine"
,
command
=
"sleep 300"
)
new_name
=
helpers
.
random_name
()
service
.
update
(
# create argument
name
=
new_
name
,
name
=
service
.
name
,
# ContainerSpec argument
command
=
"sleep 600"
)
service
.
reload
()
assert
service
.
name
==
new_name
container_spec
=
service
.
attrs
[
'Spec'
][
'TaskTemplate'
][
'ContainerSpec'
]
assert
container_spec
[
'Command'
]
==
[
"sleep"
,
"600"
]
tests/integration/models_swarm_test.py
Dosyayı görüntüle @
281b5558
...
...
@@ -19,4 +19,9 @@ class SwarmTest(unittest.TestCase):
assert
client
.
swarm
.
leave
(
force
=
True
)
with
self
.
assertRaises
(
docker
.
errors
.
APIError
)
as
cm
:
client
.
swarm
.
reload
()
assert
cm
.
exception
.
response
.
status_code
==
406
assert
(
# FIXME: test for both until
# https://github.com/docker/docker/issues/29192 is resolved
cm
.
exception
.
response
.
status_code
==
406
or
cm
.
exception
.
response
.
status_code
==
503
)
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