Don't copy over volumes that were previously host volumes, and are now container volumes.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-01-19 14:41:21 -05:00 committed by Aanand Prasad
parent fbe8484377
commit 24e71db345
2 changed files with 29 additions and 0 deletions

View File

@ -917,6 +917,10 @@ def get_container_data_volumes(container, volumes_option):
if not mount:
continue
# Volume was previously a host volume, now it's a container volume
if not mount.get('Name'):
continue
# Copy existing volume from old container
volume = volume._replace(external=mount['Source'])
volumes.append(volume)

View File

@ -343,6 +343,31 @@ class ServiceTest(DockerClientTestCase):
)
self.assertEqual(new_container.get_mount('/data')['Source'], volume_path)
def test_execute_convergence_plan_when_host_volume_is_removed(self):
host_path = '/tmp/host-path'
service = self.create_service(
'db',
build={'context': 'tests/fixtures/dockerfile-with-volume'},
volumes=[VolumeSpec(host_path, '/data', 'rw')])
old_container = create_and_start_container(service)
assert (
[mount['Destination'] for mount in old_container.get('Mounts')] ==
['/data']
)
service.options['volumes'] = []
with mock.patch('compose.service.log', autospec=True) as mock_log:
new_container, = service.execute_convergence_plan(
ConvergencePlan('recreate', [old_container]))
assert not mock_log.warn.called
assert (
[mount['Destination'] for mount in new_container.get('Mounts')],
['/data']
)
assert new_container.get_mount('/data')['Source'] != host_path
def test_execute_convergence_plan_without_start(self):
service = self.create_service(
'db',