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:
Daniel Nephin 2016-04-18 10:13:47 -04:00
commit d4bebbb1ba
4 changed files with 23 additions and 0 deletions

View File

@ -37,6 +37,7 @@ from .validation import validate_against_config_schema
from .validation import validate_config_section
from .validation import validate_depends_on
from .validation import validate_extends_file_path
from .validation import validate_links
from .validation import validate_network_mode
from .validation import validate_service_constraints
from .validation import validate_top_level_object
@ -580,6 +581,7 @@ def validate_service(service_config, service_names, version):
validate_ulimits(service_config)
validate_network_mode(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):
raise ConfigurationError(

View File

@ -171,6 +171,14 @@ def validate_network_mode(service_config, service_names):
"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):
for dependency in service_config.config.get('depends_on', []):
if dependency not in service_names:

View File

@ -1,3 +1,5 @@
mydb:
build: '.'
myweb:
build: '.'
extends:

View File

@ -1360,6 +1360,17 @@ class ConfigTest(unittest.TestCase):
config.load(config_details)
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):
config_details = build_config_details({
'version': '2',