فهرست منبع

Raise configuration error when trying to extend service that does not exist. Fixes #1826

Signed-off-by: Karol Duleba <[email protected]>
Karol Duleba 10 سال پیش
والد
کامیت
2e7f08c2ef
3فایلهای تغییر یافته به همراه18 افزوده شده و 1 حذف شده
  1. 9 1
      compose/config/config.py
  2. 4 0
      tests/fixtures/extends/nonexistent-service.yml
  3. 5 0
      tests/unit/config_test.py

+ 9 - 1
compose/config/config.py

@@ -186,8 +186,16 @@ class ServiceLoader(object):
             already_seen=other_already_seen,
         )
 
+        base_service = extends_options['service']
         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_service_dict = other_loader.make_service_dict(
             service_dict['name'],

+ 4 - 0
tests/fixtures/extends/nonexistent-service.yml

@@ -0,0 +1,4 @@
+web:
+  image: busybox
+  extends:
+    service: foo

+ 5 - 0
tests/unit/config_test.py

@@ -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):
     def setUp(self):