mirror of
https://github.com/docker/compose.git
synced 2025-07-26 15:14:04 +02:00
Merge pull request #3340 from johnharris85/2922-config-does-not-catch-missing-links
Fix #2922: Config does not catch missing links
This commit is contained in:
commit
d4bebbb1ba
@ -37,6 +37,7 @@ from .validation import validate_against_config_schema
|
|||||||
from .validation import validate_config_section
|
from .validation import validate_config_section
|
||||||
from .validation import validate_depends_on
|
from .validation import validate_depends_on
|
||||||
from .validation import validate_extends_file_path
|
from .validation import validate_extends_file_path
|
||||||
|
from .validation import validate_links
|
||||||
from .validation import validate_network_mode
|
from .validation import validate_network_mode
|
||||||
from .validation import validate_service_constraints
|
from .validation import validate_service_constraints
|
||||||
from .validation import validate_top_level_object
|
from .validation import validate_top_level_object
|
||||||
@ -580,6 +581,7 @@ def validate_service(service_config, service_names, version):
|
|||||||
validate_ulimits(service_config)
|
validate_ulimits(service_config)
|
||||||
validate_network_mode(service_config, service_names)
|
validate_network_mode(service_config, service_names)
|
||||||
validate_depends_on(service_config, service_names)
|
validate_depends_on(service_config, service_names)
|
||||||
|
validate_links(service_config, service_names)
|
||||||
|
|
||||||
if not service_dict.get('image') and has_uppercase(service_name):
|
if not service_dict.get('image') and has_uppercase(service_name):
|
||||||
raise ConfigurationError(
|
raise ConfigurationError(
|
||||||
|
@ -171,6 +171,14 @@ def validate_network_mode(service_config, service_names):
|
|||||||
"is undefined.".format(s=service_config, dep=dependency))
|
"is undefined.".format(s=service_config, dep=dependency))
|
||||||
|
|
||||||
|
|
||||||
|
def validate_links(service_config, service_names):
|
||||||
|
for link in service_config.config.get('links', []):
|
||||||
|
if link.split(':')[0] not in service_names:
|
||||||
|
raise ConfigurationError(
|
||||||
|
"Service '{s.name}' has a link to service '{link}' which is "
|
||||||
|
"undefined.".format(s=service_config, link=link))
|
||||||
|
|
||||||
|
|
||||||
def validate_depends_on(service_config, service_names):
|
def validate_depends_on(service_config, service_names):
|
||||||
for dependency in service_config.config.get('depends_on', []):
|
for dependency in service_config.config.get('depends_on', []):
|
||||||
if dependency not in service_names:
|
if dependency not in service_names:
|
||||||
|
2
tests/fixtures/extends/invalid-links.yml
vendored
2
tests/fixtures/extends/invalid-links.yml
vendored
@ -1,3 +1,5 @@
|
|||||||
|
mydb:
|
||||||
|
build: '.'
|
||||||
myweb:
|
myweb:
|
||||||
build: '.'
|
build: '.'
|
||||||
extends:
|
extends:
|
||||||
|
@ -1360,6 +1360,17 @@ class ConfigTest(unittest.TestCase):
|
|||||||
config.load(config_details)
|
config.load(config_details)
|
||||||
assert "Service 'one' depends on service 'three'" in exc.exconly()
|
assert "Service 'one' depends on service 'three'" in exc.exconly()
|
||||||
|
|
||||||
|
def test_linked_service_is_undefined(self):
|
||||||
|
with self.assertRaises(ConfigurationError):
|
||||||
|
config.load(
|
||||||
|
build_config_details({
|
||||||
|
'version': '2',
|
||||||
|
'services': {
|
||||||
|
'web': {'image': 'busybox', 'links': ['db:db']},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
def test_load_dockerfile_without_context(self):
|
def test_load_dockerfile_without_context(self):
|
||||||
config_details = build_config_details({
|
config_details = build_config_details({
|
||||||
'version': '2',
|
'version': '2',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user