Fix extra warnings on masked volumes.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-11-13 10:49:17 -05:00
parent 9f6a5a964a
commit e1308a8329
2 changed files with 39 additions and 1 deletions

View File

@ -963,7 +963,10 @@ def warn_on_masked_volume(volumes_option, container_volumes, service):
for volume in container_volumes) for volume in container_volumes)
for volume in volumes_option: for volume in volumes_option:
if container_volumes.get(volume.internal) != volume.external: if (
volume.internal in container_volumes and
container_volumes.get(volume.internal) != volume.external
):
log.warn(( log.warn((
"Service \"{service}\" is using volume \"{volume}\" from the " "Service \"{service}\" is using volume \"{volume}\" from the "
"previous container. Host mapping \"{host_path}\" has no effect. " "previous container. Host mapping \"{host_path}\" has no effect. "

View File

@ -26,6 +26,8 @@ from compose.service import parse_volume_spec
from compose.service import Service from compose.service import Service
from compose.service import ServiceNet from compose.service import ServiceNet
from compose.service import VolumeFromSpec from compose.service import VolumeFromSpec
from compose.service import VolumeSpec
from compose.service import warn_on_masked_volume
class ServiceTest(unittest.TestCase): class ServiceTest(unittest.TestCase):
@ -750,6 +752,39 @@ class ServiceVolumesTest(unittest.TestCase):
['/mnt/sda1/host/path:/data:rw'], ['/mnt/sda1/host/path:/data:rw'],
) )
def test_warn_on_masked_volume_no_warning_when_no_container_volumes(self):
volumes_option = [VolumeSpec('/home/user', '/path', 'rw')]
container_volumes = []
service = 'service_name'
with mock.patch('compose.service.log') as mock_log:
warn_on_masked_volume(volumes_option, container_volumes, service)
assert not mock_log.warn.called
def test_warn_on_masked_volume_when_masked(self):
volumes_option = [VolumeSpec('/home/user', '/path', 'rw')]
container_volumes = [
VolumeSpec('/var/lib/docker/path', '/path', 'rw'),
VolumeSpec('/var/lib/docker/path', '/other', 'rw'),
]
service = 'service_name'
with mock.patch('compose.service.log') as mock_log:
warn_on_masked_volume(volumes_option, container_volumes, service)
mock_log.warn.called_once_with(mock.ANY)
def test_warn_on_masked_no_warning_with_same_path(self):
volumes_option = [VolumeSpec('/home/user', '/path', 'rw')]
container_volumes = [VolumeSpec('/home/user', '/path', 'rw')]
service = 'service_name'
with mock.patch('compose.service.log') as mock_log:
warn_on_masked_volume(volumes_option, container_volumes, service)
assert not mock_log.warn.called
def test_create_with_special_volume_mode(self): def test_create_with_special_volume_mode(self):
self.mock_client.inspect_image.return_value = {'Id': 'imageid'} self.mock_client.inspect_image.return_value = {'Id': 'imageid'}