mirror of
https://github.com/docker/compose.git
synced 2025-06-24 15:40:14 +02:00
Merge pull request #1859 from mrfuxi/extend-unexisting-service
Raise configuration error when trying to extend service that does not exist
This commit is contained in:
commit
30b64e65cd
@ -186,8 +186,16 @@ class ServiceLoader(object):
|
|||||||
already_seen=other_already_seen,
|
already_seen=other_already_seen,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
base_service = extends_options['service']
|
||||||
other_config = load_yaml(other_config_path)
|
other_config = load_yaml(other_config_path)
|
||||||
other_service_dict = other_config[extends_options['service']]
|
|
||||||
|
if base_service not in other_config:
|
||||||
|
msg = (
|
||||||
|
"Cannot extend service '%s' in %s: Service not found"
|
||||||
|
) % (base_service, other_config_path)
|
||||||
|
raise ConfigurationError(msg)
|
||||||
|
|
||||||
|
other_service_dict = other_config[base_service]
|
||||||
other_loader.detect_cycle(extends_options['service'])
|
other_loader.detect_cycle(extends_options['service'])
|
||||||
other_service_dict = other_loader.make_service_dict(
|
other_service_dict = other_loader.make_service_dict(
|
||||||
service_dict['name'],
|
service_dict['name'],
|
||||||
|
4
tests/fixtures/extends/nonexistent-service.yml
vendored
Normal file
4
tests/fixtures/extends/nonexistent-service.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
web:
|
||||||
|
image: busybox
|
||||||
|
extends:
|
||||||
|
service: foo
|
@ -917,6 +917,11 @@ class ExtendsTest(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_load_throws_error_when_base_service_does_not_exist(self):
|
||||||
|
err_msg = r'''Cannot extend service 'foo' in .*: Service not found'''
|
||||||
|
with self.assertRaisesRegexp(ConfigurationError, err_msg):
|
||||||
|
load_from_filename('tests/fixtures/extends/nonexistent-service.yml')
|
||||||
|
|
||||||
|
|
||||||
class BuildPathTest(unittest.TestCase):
|
class BuildPathTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user