Implement depends_on to define an order for services in the v2 format.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-01-19 15:41:45 -05:00
commit 0bce467782
7 changed files with 70 additions and 8 deletions

View file

@ -894,9 +894,35 @@ class ConfigTest(unittest.TestCase):
'ext': {'external': True, 'driver': 'foo'}
}
})
with self.assertRaises(ConfigurationError):
with pytest.raises(ConfigurationError):
config.load(config_details)
def test_depends_on_orders_services(self):
config_details = build_config_details({
'version': 2,
'services': {
'one': {'image': 'busybox', 'depends_on': ['three', 'two']},
'two': {'image': 'busybox', 'depends_on': ['three']},
'three': {'image': 'busybox'},
},
})
actual = config.load(config_details)
assert (
[service['name'] for service in actual.services] ==
['three', 'two', 'one']
)
def test_depends_on_unknown_service_errors(self):
config_details = build_config_details({
'version': 2,
'services': {
'one': {'image': 'busybox', 'depends_on': ['three']},
},
})
with pytest.raises(ConfigurationError) as exc:
config.load(config_details)
assert "Service 'one' depends on service 'three'" in exc.exconly()
class PortsTest(unittest.TestCase):
INVALID_PORTS_TYPES = [

View file

@ -1,6 +1,8 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from compose.config.errors import DependencyError
from compose.config.sort_services import sort_service_dicts
from compose.config.types import VolumeFromSpec
@ -240,3 +242,15 @@ class SortServiceTest(unittest.TestCase):
self.assertIn('web', e.msg)
else:
self.fail('Should have thrown an DependencyError')
def test_sort_service_dicts_depends_on_self(self):
services = [
{
'depends_on': ['web'],
'name': 'web'
},
]
with pytest.raises(DependencyError) as exc:
sort_service_dicts(services)
assert 'A service can not depend on itself: web' in exc.exconly()