فهرست منبع

Move ulimits validation to validation.py and improve the error message.

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin 9 سال پیش
والد
کامیت
3f65bdcf46
3فایلهای تغییر یافته به همراه15 افزوده شده و 13 حذف شده
  1. 2 12
      compose/config/config.py
  2. 12 0
      compose/config/validation.py
  3. 1 1
      tests/unit/config/config_test.py

+ 2 - 12
compose/config/config.py

@@ -31,6 +31,7 @@ from .validation import validate_depends_on
 from .validation import validate_extends_file_path
 from .validation import validate_top_level_object
 from .validation import validate_top_level_service_objects
+from .validation import validate_ulimits
 
 
 DOCKER_CONFIG_KEYS = [
@@ -488,23 +489,12 @@ def validate_extended_service_dict(service_dict, filename, service):
             "%s services with 'depends_on' cannot be extended" % error_prefix)
 
 
-def validate_ulimits(ulimit_config):
-    for limit_name, soft_hard_values in six.iteritems(ulimit_config):
-        if isinstance(soft_hard_values, dict):
-            if not soft_hard_values['soft'] <= soft_hard_values['hard']:
-                raise ConfigurationError(
-                    "ulimit_config \"{}\" cannot contain a 'soft' value higher "
-                    "than 'hard' value".format(ulimit_config))
-
-
 def validate_service(service_config, service_names, version):
     service_dict, service_name = service_config.config, service_config.name
     validate_against_service_schema(service_dict, service_name, version)
     validate_paths(service_dict)
 
-    if 'ulimits' in service_dict:
-        validate_ulimits(service_dict['ulimits'])
-
+    validate_ulimits(service_config)
     validate_depends_on(service_config, service_names)
 
     if not service_dict.get('image') and has_uppercase(service_name):

+ 12 - 0
compose/config/validation.py

@@ -110,6 +110,18 @@ def validate_top_level_object(config_file):
                 type(config_file.config)))
 
 
+def validate_ulimits(service_config):
+    ulimit_config = service_config.config.get('ulimits', {})
+    for limit_name, soft_hard_values in six.iteritems(ulimit_config):
+        if isinstance(soft_hard_values, dict):
+            if not soft_hard_values['soft'] <= soft_hard_values['hard']:
+                raise ConfigurationError(
+                    "Service '{s.name}' has invalid ulimit '{ulimit}'. "
+                    "'soft' value can not be greater than 'hard' value ".format(
+                        s=service_config,
+                        ulimit=ulimit_config))
+
+
 def validate_extends_file_path(service_name, extends_options, filename):
     """
     The service to be extended must either be defined in the config key 'file',

+ 1 - 1
tests/unit/config/config_test.py

@@ -700,7 +700,7 @@ class ConfigTest(unittest.TestCase):
         assert "'hard' is a required property" in exc.exconly()
 
     def test_config_ulimits_soft_greater_than_hard_error(self):
-        expected = "cannot contain a 'soft' value higher than 'hard' value"
+        expected = "'soft' value can not be greater than 'hard' value"
 
         with pytest.raises(ConfigurationError) as exc:
             config.load(build_config_details(