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
96bf4e07
Kaydet (Commit)
96bf4e07
authored
Ock 09, 2017
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Detect mount type in parse_mount_string
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
26ff2482
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
13 deletions
+48
-13
services.py
docker/types/services.py
+11
-1
dockertypes_test.py
tests/unit/dockertypes_test.py
+37
-12
No files found.
docker/types/services.py
Dosyayı görüntüle @
96bf4e07
import
six
from
..
import
errors
from
..constants
import
IS_WINDOWS_PLATFORM
from
..utils
import
format_environment
,
split_command
...
...
@@ -175,8 +176,17 @@ class Mount(dict):
else
:
target
=
parts
[
1
]
source
=
parts
[
0
]
mount_type
=
'volume'
if
source
.
startswith
(
'/'
)
or
(
IS_WINDOWS_PLATFORM
and
source
[
0
]
.
isalpha
()
and
source
[
1
]
==
':'
):
# FIXME: That windows condition will fail earlier since we
# split on ':'. We should look into doing a smarter split
# if we detect we are on Windows.
mount_type
=
'bind'
read_only
=
not
(
len
(
parts
)
==
2
or
parts
[
2
]
==
'rw'
)
return
cls
(
target
,
source
,
read_only
=
read_only
)
return
cls
(
target
,
source
,
read_only
=
read_only
,
type
=
mount_type
)
class
Resources
(
dict
):
...
...
tests/unit/dockertypes_test.py
Dosyayı görüntüle @
96bf4e07
...
...
@@ -10,6 +10,11 @@ from docker.types import (
EndpointConfig
,
HostConfig
,
IPAMConfig
,
IPAMPool
,
LogConfig
,
Mount
,
Ulimit
,
)
try
:
from
unittest
import
mock
except
:
import
mock
def
create_host_config
(
*
args
,
**
kwargs
):
return
HostConfig
(
*
args
,
**
kwargs
)
...
...
@@ -258,28 +263,48 @@ class IPAMConfigTest(unittest.TestCase):
class
TestMounts
(
unittest
.
TestCase
):
def
test_parse_mount_string_ro
(
self
):
mount
=
Mount
.
parse_mount_string
(
"/foo/bar:/baz:ro"
)
self
.
assertEqual
(
mount
[
'Source'
],
"/foo/bar"
)
self
.
assertEqual
(
mount
[
'Target'
],
"/baz"
)
self
.
assertEqual
(
mount
[
'ReadOnly'
],
True
)
assert
mount
[
'Source'
]
==
"/foo/bar"
assert
mount
[
'Target'
]
==
"/baz"
assert
mount
[
'ReadOnly'
]
is
True
def
test_parse_mount_string_rw
(
self
):
mount
=
Mount
.
parse_mount_string
(
"/foo/bar:/baz:rw"
)
self
.
assertEqual
(
mount
[
'Source'
],
"/foo/bar"
)
self
.
assertEqual
(
mount
[
'Target'
],
"/baz"
)
self
.
assertEqual
(
mount
[
'ReadOnly'
],
False
)
assert
mount
[
'Source'
]
==
"/foo/bar"
assert
mount
[
'Target'
]
==
"/baz"
assert
not
mount
[
'ReadOnly'
]
def
test_parse_mount_string_short_form
(
self
):
mount
=
Mount
.
parse_mount_string
(
"/foo/bar:/baz"
)
self
.
assertEqual
(
mount
[
'Source'
],
"/foo/bar"
)
self
.
assertEqual
(
mount
[
'Target'
],
"/baz"
)
self
.
assertEqual
(
mount
[
'ReadOnly'
],
False
)
assert
mount
[
'Source'
]
==
"/foo/bar"
assert
mount
[
'Target'
]
==
"/baz"
assert
not
mount
[
'ReadOnly'
]
def
test_parse_mount_string_no_source
(
self
):
mount
=
Mount
.
parse_mount_string
(
"foo/bar"
)
self
.
assertEqual
(
mount
[
'Source'
],
None
)
self
.
assertEqual
(
mount
[
'Target'
],
"foo/bar"
)
self
.
assertEqual
(
mount
[
'ReadOnly'
],
False
)
assert
mount
[
'Source'
]
is
None
assert
mount
[
'Target'
]
==
"foo/bar"
assert
not
mount
[
'ReadOnly'
]
def
test_parse_mount_string_invalid
(
self
):
with
pytest
.
raises
(
InvalidArgument
):
Mount
.
parse_mount_string
(
"foo:bar:baz:rw"
)
def
test_parse_mount_named_volume
(
self
):
mount
=
Mount
.
parse_mount_string
(
"foobar:/baz"
)
assert
mount
[
'Source'
]
==
'foobar'
assert
mount
[
'Target'
]
==
'/baz'
assert
mount
[
'Type'
]
==
'volume'
def
test_parse_mount_bind
(
self
):
mount
=
Mount
.
parse_mount_string
(
'/foo/bar:/baz'
)
assert
mount
[
'Source'
]
==
"/foo/bar"
assert
mount
[
'Target'
]
==
"/baz"
assert
mount
[
'Type'
]
==
'bind'
@pytest.mark.xfail
def
test_parse_mount_bind_windows
(
self
):
with
mock
.
patch
(
'docker.types.services.IS_WINDOWS_PLATFORM'
,
True
):
mount
=
Mount
.
parse_mount_string
(
'C:/foo/bar:/baz'
)
assert
mount
[
'Source'
]
==
"C:/foo/bar"
assert
mount
[
'Target'
]
==
"/baz"
assert
mount
[
'Type'
]
==
'bind'
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