Skip to content

Commit

Permalink
Merge pull request #1013 from jrdnbradford/fix-cpu-schema
Browse files Browse the repository at this point in the history
Fix `cpu` and `memory` config validation in JSON schema
  • Loading branch information
minrk authored Nov 15, 2024
2 parents c0563ab + cd53b41 commit 3397e75
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
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

0 comments on commit 3397e75

Please sign in to comment.