Merge pull request #6434 from docker/and800-master

Lower severity to "warning" if `down` tries to remove nonexisting image
This commit is contained in:
Joffrey F 2018-12-28 14:25:33 -08:00 committed by GitHub
commit f9061720b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -1148,6 +1148,9 @@ class Service(object):
try: try:
self.client.remove_image(self.image_name) self.client.remove_image(self.image_name)
return True return True
except ImageNotFound:
log.warning("Image %s not found.", self.image_name)
return False
except APIError as e: except APIError as e:
log.error("Failed to remove image for service %s: %s", self.name, e) log.error("Failed to remove image for service %s: %s", self.name, e)
return False return False

View File

@ -5,6 +5,7 @@ import docker
import pytest import pytest
from docker.constants import DEFAULT_DOCKER_API_VERSION from docker.constants import DEFAULT_DOCKER_API_VERSION
from docker.errors import APIError from docker.errors import APIError
from docker.errors import ImageNotFound
from docker.errors import NotFound from docker.errors import NotFound
from .. import mock from .. import mock
@ -755,6 +756,13 @@ class ServiceTest(unittest.TestCase):
mock_log.error.assert_called_once_with( mock_log.error.assert_called_once_with(
"Failed to remove image for service %s: %s", web.name, error) "Failed to remove image for service %s: %s", web.name, error)
def test_remove_non_existing_image(self):
self.mock_client.remove_image.side_effect = ImageNotFound('image not found')
web = Service('web', image='example', client=self.mock_client)
with mock.patch('compose.service.log', autospec=True) as mock_log:
assert not web.remove_image(ImageType.all)
mock_log.warning.assert_called_once_with("Image %s not found.", web.image_name)
def test_specifies_host_port_with_no_ports(self): def test_specifies_host_port_with_no_ports(self):
service = Service( service = Service(
'foo', 'foo',