Allow integer value for ports

While it was intended as a positive to be stricter in validation
it would in fact break backwards compatibility, which we do not
want to be doing.

Consider re-visiting this later and include a deprecation warning if
we want to be stricter.

Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
Mazz Mosley 2015-08-10 14:55:33 +01:00
parent df74b131ff
commit b4872de213
3 changed files with 27 additions and 7 deletions

View File

@ -75,11 +75,23 @@
"pid": {"type": "string"},
"ports": {
"oneOf": [
{
"type": "array",
"items": {"type": "string"},
"uniqueItems": true,
"format": "ports"
},
{
"type": "string",
"format": "ports"
},
{
"type": "number",
"format": "ports"
}
]
},
"privileged": {"type": "string"},
"read_only": {"type": "boolean"},

View File

@ -84,6 +84,13 @@ def process_errors(errors):
required.append("Service '{}' has neither an image nor a build path specified. Exactly one must be provided.".format(service_name))
else:
required.append(error.message)
elif error.validator == 'oneOf':
config_key = error.path[1]
valid_types = [context.validator_value for context in error.context]
valid_type_msg = " or ".join(valid_types)
type_errors.append("Service '{}' configuration key '{}' contains an invalid type, it should be either {}".format(
service_name, config_key, valid_type_msg)
)
elif error.validator == 'type':
msg = "a"
if error.validator_value == "array":

View File

@ -75,8 +75,9 @@ class ConfigTest(unittest.TestCase):
)
def test_config_invalid_ports_format_validation(self):
with self.assertRaises(ConfigurationError):
for invalid_ports in [{"1": "8000"}, "whatport", "625", "8000:8050"]:
expected_error_msg = "Service 'web' configuration key 'ports' contains an invalid type"
with self.assertRaisesRegexp(ConfigurationError, expected_error_msg):
for invalid_ports in [{"1": "8000"}, False, 0]:
config.load(
config.ConfigDetails(
{'web': {'image': 'busybox', 'ports': invalid_ports}},
@ -86,7 +87,7 @@ class ConfigTest(unittest.TestCase):
)
def test_config_valid_ports_format_validation(self):
valid_ports = [["8000", "9000"], ["8000/8050"], ["8000"]]
valid_ports = [["8000", "9000"], ["8000/8050"], ["8000"], "8000", 8000]
for ports in valid_ports:
config.load(
config.ConfigDetails(