Skip to content

Commit 05741a1

Browse files
committed
Merge branch 'Niboo-issue1567'
2 parents a453aef + f27ecf3 commit 05741a1

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

docker/types/services.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ def __init__(self, image, command=None, args=None, hostname=None, env=None,
107107
if labels is not None:
108108
self['Labels'] = labels
109109
if mounts is not None:
110+
parsed_mounts = []
110111
for mount in mounts:
111112
if isinstance(mount, six.string_types):
112-
mounts.append(Mount.parse_mount_string(mount))
113-
mounts.remove(mount)
114-
self['Mounts'] = mounts
113+
parsed_mounts.append(Mount.parse_mount_string(mount))
114+
else:
115+
# If mount already parsed
116+
parsed_mounts.append(mount)
117+
self['Mounts'] = parsed_mounts
115118
if stop_grace_period is not None:
116119
self['StopGracePeriod'] = stop_grace_period
117120

tests/unit/dockertypes_test.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from docker.constants import DEFAULT_DOCKER_API_VERSION
99
from docker.errors import InvalidArgument, InvalidVersion
1010
from docker.types import (
11-
ContainerConfig, EndpointConfig, HostConfig, IPAMConfig, IPAMPool,
12-
LogConfig, Mount, ServiceMode, Ulimit,
11+
ContainerConfig, ContainerSpec, EndpointConfig, HostConfig, IPAMConfig,
12+
IPAMPool, LogConfig, Mount, ServiceMode, Ulimit,
1313
)
1414

1515
try:
@@ -220,6 +220,22 @@ def test_create_container_config_volume_driver_warning(self):
220220
assert 'The volume_driver option has been moved' in str(w[0].message)
221221

222222

223+
class ContainerSpecTest(unittest.TestCase):
224+
def test_parse_mounts(self):
225+
spec = ContainerSpec(
226+
image='scratch', mounts=[
227+
'/local:/container',
228+
'/local2:/container2:ro',
229+
Mount(target='/target', source='/source')
230+
]
231+
)
232+
233+
assert 'Mounts' in spec
234+
assert len(spec['Mounts']) == 3
235+
for mount in spec['Mounts']:
236+
assert isinstance(mount, Mount)
237+
238+
223239
class UlimitTest(unittest.TestCase):
224240
def test_create_host_config_dict_ulimit(self):
225241
ulimit_dct = {'name': 'nofile', 'soft': 8096}

0 commit comments

Comments
 (0)