Merge pull request #1013 from jrdnbradford/fix-cpu-schema

Fix `cpu` and `memory` config validation in JSON schema
This commit is contained in:
Min RK
2024-11-15 08:26:36 +01:00
committed by GitHub
4 changed files with 22 additions and 6 deletions

View File

@@ -227,7 +227,7 @@ it after an argument like `remove-item` gives information about this specific co
```bash
sudo tljh-config --help
usage: tljh-config [-h] [--config-path CONFIG_PATH] {show,unset,set,add-item,remove-item,reload} ...
usage: tljh-config [-h] [--config-path CONFIG_PATH] [--validate] [--no-validate] {show,unset,set,add-item,remove-item,reload} ...
positional arguments:
{show,unset,set,add-item,remove-item,reload}
@@ -238,10 +238,12 @@ positional arguments:
remove-item Remove a value from a list for a configuration property
reload Reload a component to apply configuration change
optional arguments:
options:
-h, --help show this help message and exit
--config-path CONFIG_PATH
Path to TLJH config.yaml file
--validate Validate the TLJH config
--no-validate Do not validate the TLJH config
```
```bash

View File

@@ -220,7 +220,8 @@ def test_cli_remove_int(tljh_dir):
("x", "x"),
("1x", "1x"),
("1.2x", "1.2x"),
(None, None),
("None", None),
("none", None),
("", ""),
],
)

View File

@@ -317,8 +317,8 @@ def reload_component(component):
def parse_value(value_str):
"""Parse a value string"""
if value_str is None:
return value_str
if value_str.lower() == "none":
return None
if re.match(r"^\d+$", value_str):
return int(value_str)
elif re.match(r"^\d+\.\d*$", value_str):

View File

@@ -79,7 +79,20 @@ config_schema = {
"description": "User CPU and memory limits.",
"type": "object",
"additionalProperties": False,
"properties": {"memory": {"type": "string"}, "cpu": {"type": "integer"}},
"properties": {
"memory": {
"anyOf": [
{"type": "string"},
{"type": "null"},
]
},
"cpu": {
"anyOf": [
{"type": "number", "minimum": 0},
{"type": "null"},
]
},
},
},
"UserEnvironment": {
"type": "object",