mirror of https://github.com/docker/compose.git
Make down idempotent, continue to remove resources if one is missing.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
e5cd869c61
commit
e5529a89e1
|
@ -149,7 +149,10 @@ class ProjectNetworks(object):
|
||||||
if not self.use_networking:
|
if not self.use_networking:
|
||||||
return
|
return
|
||||||
for network in self.networks.values():
|
for network in self.networks.values():
|
||||||
|
try:
|
||||||
network.remove()
|
network.remove()
|
||||||
|
except NotFound:
|
||||||
|
log.warn("Network %s not found.", network.full_name)
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
if not self.use_networking:
|
if not self.use_networking:
|
||||||
|
|
|
@ -76,7 +76,10 @@ class ProjectVolumes(object):
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
for volume in self.volumes.values():
|
for volume in self.volumes.values():
|
||||||
|
try:
|
||||||
volume.remove()
|
volume.remove()
|
||||||
|
except NotFound:
|
||||||
|
log.warn("Volume %s not found.", volume.full_name)
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
|
from docker.errors import NotFound
|
||||||
|
|
||||||
from .. import mock
|
from .. import mock
|
||||||
from .. import unittest
|
from .. import unittest
|
||||||
|
@ -12,6 +13,7 @@ from compose.config.types import VolumeFromSpec
|
||||||
from compose.const import LABEL_SERVICE
|
from compose.const import LABEL_SERVICE
|
||||||
from compose.container import Container
|
from compose.container import Container
|
||||||
from compose.project import Project
|
from compose.project import Project
|
||||||
|
from compose.service import ImageType
|
||||||
from compose.service import Service
|
from compose.service import Service
|
||||||
|
|
||||||
|
|
||||||
|
@ -476,3 +478,23 @@ class ProjectTest(unittest.TestCase):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.assertEqual([c.id for c in project.containers()], ['1'])
|
self.assertEqual([c.id for c in project.containers()], ['1'])
|
||||||
|
|
||||||
|
def test_down_with_no_resources(self):
|
||||||
|
project = Project.from_config(
|
||||||
|
name='test',
|
||||||
|
client=self.mock_client,
|
||||||
|
config_data=Config(
|
||||||
|
version='2',
|
||||||
|
services=[{
|
||||||
|
'name': 'web',
|
||||||
|
'image': 'busybox:latest',
|
||||||
|
}],
|
||||||
|
networks={'default': {}},
|
||||||
|
volumes={'data': {}},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.mock_client.remove_network.side_effect = NotFound(None, None, 'oops')
|
||||||
|
self.mock_client.remove_volume.side_effect = NotFound(None, None, 'oops')
|
||||||
|
|
||||||
|
project.down(ImageType.all, True)
|
||||||
|
self.mock_client.remove_image.assert_called_once_with("busybox:latest")
|
||||||
|
|
Loading…
Reference in New Issue