Skip to content

Commit 3397e75

Browse files
authored
Merge pull request #1013 from jrdnbradford/fix-cpu-schema
Fix `cpu` and `memory` config validation in JSON schema
2 parents c0563ab + cd53b41 commit 3397e75

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

docs/topic/tljh-config.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ it after an argument like `remove-item` gives information about this specific co
227227
```bash
228228
sudo tljh-config --help
229229

230-
usage: tljh-config [-h] [--config-path CONFIG_PATH] {show,unset,set,add-item,remove-item,reload} ...
230+
usage: tljh-config [-h] [--config-path CONFIG_PATH] [--validate] [--no-validate] {show,unset,set,add-item,remove-item,reload} ...
231231

232232
positional arguments:
233233
{show,unset,set,add-item,remove-item,reload}
@@ -238,10 +238,12 @@ positional arguments:
238238
remove-item Remove a value from a list for a configuration property
239239
reload Reload a component to apply configuration change
240240

241-
optional arguments:
241+
options:
242242
-h, --help show this help message and exit
243243
--config-path CONFIG_PATH
244244
Path to TLJH config.yaml file
245+
--validate Validate the TLJH config
246+
--no-validate Do not validate the TLJH config
245247
```
246248

247249
```bash

tests/test_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def test_cli_remove_int(tljh_dir):
220220
("x", "x"),
221221
("1x", "1x"),
222222
("1.2x", "1.2x"),
223-
(None, None),
223+
("None", None),
224+
("none", None),
224225
("", ""),
225226
],
226227
)

tljh/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ def reload_component(component):
317317

318318
def parse_value(value_str):
319319
"""Parse a value string"""
320-
if value_str is None:
321-
return value_str
320+
if value_str.lower() == "none":
321+
return None
322322
if re.match(r"^\d+$", value_str):
323323
return int(value_str)
324324
elif re.match(r"^\d+\.\d*$", value_str):

tljh/config_schema.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,20 @@
7979
"description": "User CPU and memory limits.",
8080
"type": "object",
8181
"additionalProperties": False,
82-
"properties": {"memory": {"type": "string"}, "cpu": {"type": "integer"}},
82+
"properties": {
83+
"memory": {
84+
"anyOf": [
85+
{"type": "string"},
86+
{"type": "null"},
87+
]
88+
},
89+
"cpu": {
90+
"anyOf": [
91+
{"type": "number", "minimum": 0},
92+
{"type": "null"},
93+
]
94+
},
95+
},
8396
},
8497
"UserEnvironment": {
8598
"type": "object",

0 commit comments

Comments
 (0)