mirror of
https://github.com/docker/compose.git
synced 2025-07-01 10:54:29 +02:00
Move ulimits validation to validation.py and improve the error message.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
0bce467782
commit
146587643c
@ -31,6 +31,7 @@ from .validation import validate_depends_on
|
|||||||
from .validation import validate_extends_file_path
|
from .validation import validate_extends_file_path
|
||||||
from .validation import validate_top_level_object
|
from .validation import validate_top_level_object
|
||||||
from .validation import validate_top_level_service_objects
|
from .validation import validate_top_level_service_objects
|
||||||
|
from .validation import validate_ulimits
|
||||||
|
|
||||||
|
|
||||||
DOCKER_CONFIG_KEYS = [
|
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)
|
"%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):
|
def validate_service(service_config, service_names, version):
|
||||||
service_dict, service_name = service_config.config, service_config.name
|
service_dict, service_name = service_config.config, service_config.name
|
||||||
validate_against_service_schema(service_dict, service_name, version)
|
validate_against_service_schema(service_dict, service_name, version)
|
||||||
validate_paths(service_dict)
|
validate_paths(service_dict)
|
||||||
|
|
||||||
if 'ulimits' in service_dict:
|
validate_ulimits(service_config)
|
||||||
validate_ulimits(service_dict['ulimits'])
|
|
||||||
|
|
||||||
validate_depends_on(service_config, service_names)
|
validate_depends_on(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):
|
||||||
|
@ -110,6 +110,18 @@ def validate_top_level_object(config_file):
|
|||||||
type(config_file.config)))
|
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):
|
def validate_extends_file_path(service_name, extends_options, filename):
|
||||||
"""
|
"""
|
||||||
The service to be extended must either be defined in the config key 'file',
|
The service to be extended must either be defined in the config key 'file',
|
||||||
|
@ -700,7 +700,7 @@ class ConfigTest(unittest.TestCase):
|
|||||||
assert "'hard' is a required property" in exc.exconly()
|
assert "'hard' is a required property" in exc.exconly()
|
||||||
|
|
||||||
def test_config_ulimits_soft_greater_than_hard_error(self):
|
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:
|
with pytest.raises(ConfigurationError) as exc:
|
||||||
config.load(build_config_details(
|
config.load(build_config_details(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user