Merge pull request #6406 from collin5/b5948

Error on duplicate mount points.
This commit is contained in:
Joffrey F 2019-01-02 10:11:50 -08:00 committed by GitHub
commit 4bd93b95a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import os
import string
import sys
from collections import namedtuple
from operator import attrgetter
import six
import yaml
@ -835,6 +836,17 @@ def finalize_service_volumes(service_dict, environment):
finalized_volumes.append(MountSpec.parse(v, normalize, win_host))
else:
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
return service_dict

View File

@ -3106,6 +3106,41 @@ class ConfigTest(unittest.TestCase):
)
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):