Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cpu and memory config validation in JSON schema #1013

Merged
merged 8 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/topic/tljh-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
("", ""),
],
)
Expand Down
4 changes: 2 additions & 2 deletions tljh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 14 additions & 1 deletion tljh/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,20 @@
"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",
Expand Down