is_named_volume also tests for home paths ~

Fix bug with VolumeSpec not being updated
Fix integration test

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2016-01-22 16:05:21 -08:00
parent 9e67eae311
commit 48377a354f
3 changed files with 10 additions and 8 deletions

View File

@ -166,6 +166,4 @@ class VolumeSpec(namedtuple('_VolumeSpec', 'external internal mode')):
@property
def is_named_volume(self):
return self.external and not (
self.external.startswith('.') or self.external.startswith('/')
)
return self.external and not self.external.startswith(('.', '/', '~'))

View File

@ -478,7 +478,8 @@ def get_networks(service_dict, network_definitions):
def match_named_volumes(service_dict, project_volumes):
for volume_spec in service_dict.get('volumes', []):
service_volumes = service_dict.get('volumes', [])
for volume_spec in service_volumes:
if volume_spec.is_named_volume:
declared_volume = next(
(v for v in project_volumes if v.name == volume_spec.external),
@ -491,7 +492,9 @@ def match_named_volumes(service_dict, project_volumes):
volume_spec.repr(), service_dict.get('name')
)
)
volume_spec._replace(external=declared_volume.full_name)
service_volumes[service_volumes.index(volume_spec)] = (
volume_spec._replace(external=declared_volume.full_name)
)
def get_volumes_from(project, service_dict):

View File

@ -846,6 +846,7 @@ class ProjectTest(DockerClientTestCase):
self.assertEqual(len(volumes), 1)
self.assertEqual(volumes[0].external, full_vol_name)
project.up()
engine_volumes = self.client.volumes()
self.assertIsNone(next(v for v in engine_volumes if v['Name'] == vol_name))
self.assertIsNotNone(next(v for v in engine_volumes if v['Name'] == full_vol_name))
engine_volumes = self.client.volumes()['Volumes']
container = service.get_container()
assert [mount['Name'] for mount in container.get('Mounts')] == [full_vol_name]
assert next((v for v in engine_volumes if v['Name'] == vol_name), None) is None