Properly validate volume definition
Test valid empty volume definitions Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
153185eadb
commit
e41e6c1241
3 changed files with 44 additions and 23 deletions
|
|
@ -272,9 +272,21 @@ def load_volumes(config_files):
|
|||
volumes = {}
|
||||
for config_file in config_files:
|
||||
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})
|
||||
external = volume_config.get('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):
|
||||
volume_config['external_name'] = external.get('name')
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -32,32 +32,24 @@
|
|||
"definitions": {
|
||||
"volume": {
|
||||
"id": "#/definitions/volume",
|
||||
"oneOf": [{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"driver": {"type": "string"},
|
||||
"driver_opts": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^.+$": {"type": ["string", "number"]}
|
||||
},
|
||||
"additionalProperties": false
|
||||
"type": ["object", "null"],
|
||||
"properties": {
|
||||
"driver": {"type": "string"},
|
||||
"driver_opts": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^.+$": {"type": ["string", "number"]}
|
||||
}
|
||||
},
|
||||
"external": {
|
||||
"type": ["boolean", "object"],
|
||||
"properties": {
|
||||
"name": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}, {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"external": {
|
||||
"type": ["boolean", "object"],
|
||||
"properties": {
|
||||
"name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}]
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue