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:
parent
d41d8ecb3f
commit
7ff3fe0b50
6 changed files with 70 additions and 1 deletions
|
|
@ -13,9 +13,21 @@ def bool_to_y_n(b):
|
|||
|
||||
def main(tree, options):
|
||||
waagent_config = options.get("config", {})
|
||||
provisioning_use_cloud_init = waagent_config.get("Provisioning.UseCloudInit")
|
||||
provisioning_enabled = waagent_config.get("Provisioning.Enabled")
|
||||
resource_disk_format = waagent_config.get("ResourceDisk.Format")
|
||||
resource_disk_enable_swap = waagent_config.get("ResourceDisk.EnableSwap")
|
||||
changes = {}
|
||||
if provisioning_use_cloud_init is not None:
|
||||
changes["provisioning.usecloudinit"] = {
|
||||
"key": "Provisioning.UseCloudInit",
|
||||
"value": bool_to_y_n(provisioning_use_cloud_init)
|
||||
}
|
||||
if provisioning_enabled is not None:
|
||||
changes["provisioning.enabled"] = {
|
||||
"key": "Provisioning.Enabled",
|
||||
"value": bool_to_y_n(provisioning_enabled)
|
||||
}
|
||||
if resource_disk_format is not None:
|
||||
changes["resourcedisk.format"] = {
|
||||
"key": "ResourceDisk.Format",
|
||||
|
|
|
|||
|
|
@ -16,6 +16,14 @@
|
|||
"description": "WALinuxAgent config options",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Provisioning.UseCloudInit": {
|
||||
"description": "Enable or disable cloud-init provisioning.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"Provisioning.Enabled": {
|
||||
"description": "Enable or disable provisioning.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"ResourceDisk.Format": {
|
||||
"description": "Enable or disable disk formatting.",
|
||||
"type": "boolean"
|
||||
|
|
|
|||
45
stages/test/test_waagent_conf.py
Normal file
45
stages/test/test_waagent_conf.py
Normal 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)
|
||||
|
|
@ -681,6 +681,8 @@
|
|||
"type": "org.osbuild.waagent.conf",
|
||||
"options": {
|
||||
"config": {
|
||||
"Provisioning.UseCloudInit": true,
|
||||
"Provisioning.Enabled": false,
|
||||
"ResourceDisk.Format": false,
|
||||
"ResourceDisk.EnableSwap": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ pipelines:
|
|||
- type: org.osbuild.waagent.conf
|
||||
options:
|
||||
config:
|
||||
Provisioning.UseCloudInit: true
|
||||
Provisioning.Enabled: false
|
||||
ResourceDisk.Format: false
|
||||
ResourceDisk.EnableSwap: true
|
||||
- type: org.osbuild.waagent.conf
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
"/etc/waagent.conf": {
|
||||
"content": [
|
||||
"sha256:9908ed1eeb7f4cd29ef3f1baa4f87d1de6ad6adaa08a09d83861a4a1fb88fb3a",
|
||||
"sha256:7551a6a82c9133811b3e1a22504250fe8ced1f3bd4b47b14fceed028316ef5f5"
|
||||
"sha256:746a295fa3c6aa3d90295611a55401d6c4b0bff1d2bbc5fb45ec4112bee84354"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue