stages: add "devices/mounts" as allowed inputs for users/selinux

When moving to `bootc install to-filesystem` we will need support
for mounting the deployed disk and writing to the deployment root
this requires that we teach the users and selinux stages to
have them available. This is a first step towards this.

It also adds tests to ensure the options can be passed.
This commit is contained in:
Michael Vogt 2024-04-05 10:31:14 +02:00 committed by Achilleas Koutsou
parent ba85d30cee
commit 2f858d32e4
5 changed files with 64 additions and 0 deletions

View file

@ -48,6 +48,13 @@
"default": false
}
}
},
"devices": {
"type": "object",
"additionalProperties": true
},
"mounts": {
"type": "array"
}
}
}

View file

@ -72,6 +72,13 @@
}
}
}
},
"devices": {
"type": "object",
"additionalProperties": true
},
"mounts": {
"type": "array"
}
}
}

View file

@ -43,3 +43,39 @@ def stage_schema(request: pytest.FixtureRequest) -> osbuild.meta.Schema:
root = caller_dir.parent.parent
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", stage_name)
return osbuild.meta.Schema(mod_info.get_schema(version=schema_version), stage_name)
@pytest.fixture
def bootc_devices_mounts_dict() -> dict:
""" bootc_devices_mounts_dict returns a dict with a typical bootc
devices/mount dict
"""
return {
"devices": {
"disk": {
"type": "org.osbuild.loopback",
"options": {
"filename": "disk.raw",
"partscan": True,
}
}
},
"mounts": [
{
"name": "root",
"type": "org.osbuild.ext4",
"source": "disk",
"partition": 4,
"target": "/"
}, {
"name": "ostree.deployment",
"type": "org.osbuild.ostree.deployment",
"options": {
"source": "mount",
"deployment": {
"default": True,
}
}
}
]
}

View file

@ -48,6 +48,13 @@ def test_schema_validation_selinux_file_context_required(stage_schema):
testutil.assert_jsonschema_error_contains(res, expected_err, expected_num_errs=1)
def test_schema_supports_bootc_style_mounts(stage_schema, bootc_devices_mounts_dict):
test_input = bootc_devices_mounts_dict
test_input["type"] = STAGE_NAME
res = stage_schema.validate(test_input)
assert res.valid is True, f"err: {[e.as_dict() for e in res.errors]}"
@patch("osbuild.util.selinux.setfiles")
def test_selinux_file_contexts(mocked_setfiles, tmp_path, stage_module):
options = {

View file

@ -36,6 +36,13 @@ def test_schema_validation(stage_schema, test_data, expected_err):
assert_jsonschema_error_contains(res, expected_err, expected_num_errs=1)
def test_schema_supports_bootc_style_mounts(stage_schema, bootc_devices_mounts_dict):
test_input = bootc_devices_mounts_dict
test_input["type"] = STAGE_NAME
res = stage_schema.validate(test_input)
assert res.valid is True, f"err: {[e.as_dict() for e in res.errors]}"
TEST_CASES = [
# user_opts,expected commandline args
({}, []),