mirror of https://github.com/docker/compose.git
Merge pull request #6406 from collin5/b5948
Error on duplicate mount points.
This commit is contained in:
commit
4bd93b95a9
|
@ -8,6 +8,7 @@ import os
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from operator import attrgetter
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -835,6 +836,17 @@ def finalize_service_volumes(service_dict, environment):
|
||||||
finalized_volumes.append(MountSpec.parse(v, normalize, win_host))
|
finalized_volumes.append(MountSpec.parse(v, normalize, win_host))
|
||||||
else:
|
else:
|
||||||
finalized_volumes.append(VolumeSpec.parse(v, normalize, win_host))
|
finalized_volumes.append(VolumeSpec.parse(v, normalize, win_host))
|
||||||
|
|
||||||
|
duplicate_mounts = []
|
||||||
|
mounts = [v.as_volume_spec() if isinstance(v, MountSpec) else v for v in finalized_volumes]
|
||||||
|
for mount in mounts:
|
||||||
|
if list(map(attrgetter('internal'), mounts)).count(mount.internal) > 1:
|
||||||
|
duplicate_mounts.append(mount.repr())
|
||||||
|
|
||||||
|
if duplicate_mounts:
|
||||||
|
raise ConfigurationError("Duplicate mount points: [%s]" % (
|
||||||
|
', '.join(duplicate_mounts)))
|
||||||
|
|
||||||
service_dict['volumes'] = finalized_volumes
|
service_dict['volumes'] = finalized_volumes
|
||||||
|
|
||||||
return service_dict
|
return service_dict
|
||||||
|
|
|
@ -3106,6 +3106,41 @@ class ConfigTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
config.load(config_details)
|
config.load(config_details)
|
||||||
|
|
||||||
|
def test_config_duplicate_mount_points(self):
|
||||||
|
config1 = build_config_details(
|
||||||
|
{
|
||||||
|
'version': '3.5',
|
||||||
|
'services': {
|
||||||
|
'web': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'volumes': ['/tmp/foo:/tmp/foo', '/tmp/foo:/tmp/foo:rw']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
config2 = build_config_details(
|
||||||
|
{
|
||||||
|
'version': '3.5',
|
||||||
|
'services': {
|
||||||
|
'web': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'volumes': ['/x:/y', '/z:/y']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(ConfigurationError) as e:
|
||||||
|
config.load(config1)
|
||||||
|
self.assertEquals(str(e.exception), 'Duplicate mount points: [%s]' % (
|
||||||
|
', '.join(['/tmp/foo:/tmp/foo:rw']*2)))
|
||||||
|
|
||||||
|
with self.assertRaises(ConfigurationError) as e:
|
||||||
|
config.load(config2)
|
||||||
|
self.assertEquals(str(e.exception), 'Duplicate mount points: [%s]' % (
|
||||||
|
', '.join(['/x:/y:rw', '/z:/y:rw'])))
|
||||||
|
|
||||||
|
|
||||||
class NetworkModeTest(unittest.TestCase):
|
class NetworkModeTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue