Stages/waagent.conf: support additional options

Extend the stage to support setting new options:
 - Provisioning.UseCloudInit
 - Provisioning.Enabled

Extend the stage test to use them and add a simple stage unit test for
the schema.

Related to https://github.com/osbuild/images/issues/1416

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2025-04-11 14:11:59 +02:00 committed by Tomáš Hozza
parent d41d8ecb3f
commit 7ff3fe0b50
6 changed files with 70 additions and 1 deletions

View file

@ -0,0 +1,45 @@
#!/usr/bin/python3
import re
import pytest
from osbuild.testutil import (
assert_jsonschema_error_contains,
)
STAGE_NAME = "org.osbuild.waagent.conf"
@pytest.mark.parametrize("test_data,expected_err", [
# bad
({}, r"'config' is a required property"),
({"config": {"Unsupported": True}}, r"Additional properties are not allowed \('Unsupported' was unexpected\)"),
({"config": {"Provisioning.UseCloudInit": 42}}, r"42 is not of type 'boolean'"),
({"config": {"Provisioning.Enabled": "abc"}}, r"'abc' is not of type 'boolean'"),
({"config": {"ResourceDisk.Format": 42}}, r"42 is not of type 'boolean'"),
({"config": {"ResourceDisk.EnableSwap": "abc"}}, r"'abc' is not of type 'boolean'"),
# good
({"config": {}}, ""),
({
"config": {
"Provisioning.UseCloudInit": True,
"Provisioning.Enabled": True,
"ResourceDisk.Format": False,
"ResourceDisk.EnableSwap": False,
},
}, ""),
])
def test_schema_validation(stage_schema, test_data, expected_err):
test_input = {
"type": STAGE_NAME,
"options": {},
}
test_input["options"].update(test_data)
res = stage_schema.validate(test_input)
if expected_err == "":
assert res.valid is True, f"err: {[e.as_dict() for e in res.errors]}"
else:
assert res.valid is False
assert_jsonschema_error_contains(res, re.compile(expected_err), expected_num_errs=1)