Merge pull request #23975 from terminalmage/fix-docker-volumes

Check for VOLUME lines in image
This commit is contained in:
Nicole Thomas 2015-05-20 13:59:04 -06:00
commit b39e2d950d
2 changed files with 16 additions and 6 deletions

View File

@ -1389,11 +1389,18 @@ def running(name,
# Add any needed container creation arguments based on the validated
# runtime arguments.
if runtime_kwargs.get('binds') is not None:
# Using bind mounts requries mountpoints to be specified at the
# time the container is created, so we need to add them to the
# create_kwargs.
create_kwargs['volumes'] = [bind_conf['bind'] for bind_conf in
runtime_kwargs['binds'].values()]
if 'volumes' not in create_kwargs:
# Check if there are preconfigured volumes in the image
for step in __salt__['dockerng.history'](image, quiet=True):
if step.lstrip().startswith('VOLUME'):
break
else:
# No preconfigured volumes, we need to make our own. Use
# the ones from the "binds" configuration.
create_kwargs['volumes'] = [
x['bind']
for x in six.itervalues(runtime_kwargs['binds'])
]
if runtime_kwargs.get('port_bindings') is not None \
and create_kwargs.get('ports') is None:
create_kwargs['ports'] = ','.join(

View File

@ -39,14 +39,17 @@ class DockerngTestCase(TestCase):
'''
Test dockerng.running function
'''
mock_volume = '/container-0'
dockerng_create = Mock()
dockerng_start = Mock()
dockerng_history = MagicMock(return_value=mock_volume)
__salt__ = {'dockerng.list_containers': MagicMock(),
'dockerng.list_tags': MagicMock(),
'dockerng.pull': MagicMock(),
'dockerng.state': MagicMock(),
'dockerng.create': dockerng_create,
'dockerng.start': dockerng_start,
'dockerng.history': dockerng_history,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
@ -58,7 +61,7 @@ class DockerngTestCase(TestCase):
'image:latest',
validate_input=False,
name='cont',
volumes=['/container-0'],
volumes=[mock_volume],
client_timeout=60)
dockerng_start.assert_called_with(
'cont',