mirror of https://github.com/docker/compose.git
Merge pull request #2655 from shin-/updated_volume_definition
Properly validate volume definition
This commit is contained in:
commit
dbe04a70f0
|
@ -273,9 +273,21 @@ def load_volumes(config_files):
|
||||||
volumes = {}
|
volumes = {}
|
||||||
for config_file in config_files:
|
for config_file in config_files:
|
||||||
for name, volume_config in config_file.config.get('volumes', {}).items():
|
for name, volume_config in config_file.config.get('volumes', {}).items():
|
||||||
|
if volume_config is None:
|
||||||
|
volumes.update({name: {}})
|
||||||
|
continue
|
||||||
|
|
||||||
volumes.update({name: volume_config})
|
volumes.update({name: volume_config})
|
||||||
external = volume_config.get('external')
|
external = volume_config.get('external')
|
||||||
if external:
|
if external:
|
||||||
|
if len(volume_config.keys()) > 1:
|
||||||
|
raise ConfigurationError(
|
||||||
|
'Volume {0} declared as external but specifies'
|
||||||
|
' additional attributes ({1}). '.format(
|
||||||
|
name,
|
||||||
|
', '.join([k for k in volume_config.keys() if k != 'external'])
|
||||||
|
)
|
||||||
|
)
|
||||||
if isinstance(external, dict):
|
if isinstance(external, dict):
|
||||||
volume_config['external_name'] = external.get('name')
|
volume_config['external_name'] = external.get('name')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -32,32 +32,24 @@
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"volume": {
|
"volume": {
|
||||||
"id": "#/definitions/volume",
|
"id": "#/definitions/volume",
|
||||||
"oneOf": [{
|
"type": ["object", "null"],
|
||||||
"type": "object",
|
"properties": {
|
||||||
"properties": {
|
"driver": {"type": "string"},
|
||||||
"driver": {"type": "string"},
|
"driver_opts": {
|
||||||
"driver_opts": {
|
"type": "object",
|
||||||
"type": "object",
|
"patternProperties": {
|
||||||
"patternProperties": {
|
"^.+$": {"type": ["string", "number"]}
|
||||||
"^.+$": {"type": ["string", "number"]}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"external": {
|
||||||
|
"type": ["boolean", "object"],
|
||||||
|
"properties": {
|
||||||
|
"name": {"type": "string"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
}, {
|
},
|
||||||
"type": "object",
|
"additionalProperties": false
|
||||||
"properties": {
|
|
||||||
"external": {
|
|
||||||
"type": ["boolean", "object"],
|
|
||||||
"properties": {
|
|
||||||
"name": {"type": "string"}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
|
@ -112,6 +112,23 @@ class ConfigTest(unittest.TestCase):
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def test_named_volume_config_empty(self):
|
||||||
|
config_details = build_config_details({
|
||||||
|
'version': 2,
|
||||||
|
'services': {
|
||||||
|
'simple': {'image': 'busybox'}
|
||||||
|
},
|
||||||
|
'volumes': {
|
||||||
|
'simple': None,
|
||||||
|
'other': {},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
config_result = config.load(config_details)
|
||||||
|
volumes = config_result.volumes
|
||||||
|
assert 'simple' in volumes
|
||||||
|
assert volumes['simple'] == {}
|
||||||
|
assert volumes['other'] == {}
|
||||||
|
|
||||||
def test_load_service_with_name_version(self):
|
def test_load_service_with_name_version(self):
|
||||||
config_data = config.load(
|
config_data = config.load(
|
||||||
build_config_details({
|
build_config_details({
|
||||||
|
|
Loading…
Reference in New Issue