From 2f858d32e416b7a42008f8295cbaf650e2e394cf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 5 Apr 2024 10:31:14 +0200 Subject: [PATCH] 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. --- stages/org.osbuild.selinux.meta.json | 7 ++++++ stages/org.osbuild.users.meta.json | 7 ++++++ stages/test/conftest.py | 36 ++++++++++++++++++++++++++++ stages/test/test_selinux.py | 7 ++++++ stages/test/test_users.py | 7 ++++++ 5 files changed, 64 insertions(+) diff --git a/stages/org.osbuild.selinux.meta.json b/stages/org.osbuild.selinux.meta.json index f9e701e5..ea1bb3ef 100644 --- a/stages/org.osbuild.selinux.meta.json +++ b/stages/org.osbuild.selinux.meta.json @@ -48,6 +48,13 @@ "default": false } } + }, + "devices": { + "type": "object", + "additionalProperties": true + }, + "mounts": { + "type": "array" } } } diff --git a/stages/org.osbuild.users.meta.json b/stages/org.osbuild.users.meta.json index 433e7811..6c8668a6 100644 --- a/stages/org.osbuild.users.meta.json +++ b/stages/org.osbuild.users.meta.json @@ -72,6 +72,13 @@ } } } + }, + "devices": { + "type": "object", + "additionalProperties": true + }, + "mounts": { + "type": "array" } } } diff --git a/stages/test/conftest.py b/stages/test/conftest.py index f2f9d5a7..d9a314e4 100644 --- a/stages/test/conftest.py +++ b/stages/test/conftest.py @@ -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, + } + } + } + ] + } diff --git a/stages/test/test_selinux.py b/stages/test/test_selinux.py index 98e78147..27eba4a5 100644 --- a/stages/test/test_selinux.py +++ b/stages/test/test_selinux.py @@ -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 = { diff --git a/stages/test/test_users.py b/stages/test/test_users.py index c74cbe55..392449fb 100644 --- a/stages/test/test_users.py +++ b/stages/test/test_users.py @@ -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 ({}, []),