Use VolumeSpec instead of re-parsing the volume string.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-11-04 16:46:19 -05:00
parent 0e19c92e82
commit ec22d98377
2 changed files with 13 additions and 10 deletions

View File

@ -911,14 +911,15 @@ def merge_volume_bindings(volumes_option, previous_container):
"""Return a list of volume bindings for a container. Container data volumes
are replaced by those from the previous container.
"""
volumes = [parse_volume_spec(volume) for volume in volumes_option or []]
volume_bindings = dict(
build_volume_binding(parse_volume_spec(volume))
for volume in volumes_option or []
if ':' in volume)
build_volume_binding(volume)
for volume in volumes
if volume.external)
if previous_container:
volume_bindings.update(
get_container_data_volumes(previous_container, volumes_option))
get_container_data_volumes(previous_container, volumes))
return list(volume_bindings.values())
@ -929,12 +930,14 @@ def get_container_data_volumes(container, volumes_option):
"""
volumes = []
volumes_option = volumes_option or []
container_volumes = container.get('Volumes') or {}
image_volumes = container.image_config['ContainerConfig'].get('Volumes') or {}
image_volumes = [
parse_volume_spec(volume)
for volume in
container.image_config['ContainerConfig'].get('Volumes') or {}
]
for volume in set(volumes_option + list(image_volumes)):
volume = parse_volume_spec(volume)
for volume in set(volumes_option + image_volumes):
# No need to preserve host volumes
if volume.external:
continue

View File

@ -593,11 +593,11 @@ class ServiceVolumesTest(unittest.TestCase):
self.assertEqual(binding, ('/inside', '/outside:/inside:rw'))
def test_get_container_data_volumes(self):
options = [
options = [parse_volume_spec(v) for v in [
'/host/volume:/host/volume:ro',
'/new/volume',
'/existing/volume',
]
]]
self.mock_client.inspect_image.return_value = {
'ContainerConfig': {