2015-06-09 18:54:59 +02:00
|
|
|
from __future__ import absolute_import
|
2015-08-24 21:25:25 +02:00
|
|
|
from __future__ import unicode_literals
|
2015-06-09 18:54:59 +02:00
|
|
|
|
2015-07-03 04:35:20 +02:00
|
|
|
from .. import mock
|
2015-06-09 18:54:59 +02:00
|
|
|
from .testcases import DockerClientTestCase
|
2015-11-14 01:40:10 +01:00
|
|
|
from compose.config.types import VolumeSpec
|
2015-08-24 21:25:25 +02:00
|
|
|
from compose.project import Project
|
2015-09-02 17:07:59 +02:00
|
|
|
from compose.service import ConvergenceStrategy
|
2015-06-09 18:54:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ResilienceTest(DockerClientTestCase):
|
2015-07-03 11:28:39 +02:00
|
|
|
def setUp(self):
|
2015-11-14 01:40:10 +01:00
|
|
|
self.db = self.create_service(
|
|
|
|
'db',
|
|
|
|
volumes=[VolumeSpec.parse('/var/db')],
|
|
|
|
command='top')
|
2015-07-03 11:28:39 +02:00
|
|
|
self.project = Project('composetest', [self.db], self.client)
|
2015-06-09 18:54:59 +02:00
|
|
|
|
2015-07-03 11:28:39 +02:00
|
|
|
container = self.db.create_container()
|
2015-11-02 19:33:13 +01:00
|
|
|
container.start()
|
2015-07-03 11:28:39 +02:00
|
|
|
self.host_path = container.get('Volumes')['/var/db']
|
2015-06-09 18:54:59 +02:00
|
|
|
|
2015-07-03 11:28:39 +02:00
|
|
|
def test_successful_recreate(self):
|
2015-09-02 17:07:59 +02:00
|
|
|
self.project.up(strategy=ConvergenceStrategy.always)
|
2015-07-03 11:28:39 +02:00
|
|
|
container = self.db.containers()[0]
|
|
|
|
self.assertEqual(container.get('Volumes')['/var/db'], self.host_path)
|
2015-06-09 18:54:59 +02:00
|
|
|
|
2015-07-03 11:28:39 +02:00
|
|
|
def test_create_failure(self):
|
2015-06-09 18:54:59 +02:00
|
|
|
with mock.patch('compose.service.Service.create_container', crash):
|
|
|
|
with self.assertRaises(Crash):
|
2015-09-02 17:07:59 +02:00
|
|
|
self.project.up(strategy=ConvergenceStrategy.always)
|
2015-06-09 18:54:59 +02:00
|
|
|
|
2015-07-03 11:28:39 +02:00
|
|
|
self.project.up()
|
|
|
|
container = self.db.containers()[0]
|
|
|
|
self.assertEqual(container.get('Volumes')['/var/db'], self.host_path)
|
|
|
|
|
|
|
|
def test_start_failure(self):
|
2015-11-02 19:33:13 +01:00
|
|
|
with mock.patch('compose.container.Container.start', crash):
|
2015-07-03 11:28:39 +02:00
|
|
|
with self.assertRaises(Crash):
|
2015-09-02 17:07:59 +02:00
|
|
|
self.project.up(strategy=ConvergenceStrategy.always)
|
2015-07-03 11:28:39 +02:00
|
|
|
|
|
|
|
self.project.up()
|
|
|
|
container = self.db.containers()[0]
|
|
|
|
self.assertEqual(container.get('Volumes')['/var/db'], self.host_path)
|
2015-06-09 18:54:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Crash(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def crash(*args, **kwargs):
|
|
|
|
raise Crash()
|