stages(ostree.post-copy): add stage unit test and comment

This commit adds a small stage unit test and most importantly
a comemnt why `devices` is part of the schema (but appears unused).

The reason "devices" is explained by Alex Larsson:
"""
The mounts don't work without devices that have the filesystems.
In sample-images for example, this is typically used like so:
```
type: org.osbuild.ostree.post-copy
devices:
  root:
    type: org.osbuild.loopback
    options:
      filename: disk.img
mounts:
- name: root
  type: org.osbuild.ext4
  source: root
  target: /
```
"""
This commit is contained in:
Michael Vogt 2023-11-22 16:16:28 +01:00 committed by Simon de Vlieger
parent 158acaac78
commit 4884dc882d
2 changed files with 63 additions and 1 deletions

View file

@ -162,9 +162,10 @@ TEST_INPUT = [
def schema_validate_kickstart_stage(test_data):
name = "org.osbuild.kickstart"
version = "1"
root = os.path.join(os.path.dirname(__file__), "../..")
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", name)
schema = osbuild.meta.Schema(mod_info.get_schema(), name)
schema = osbuild.meta.Schema(mod_info.get_schema(version=version), name)
test_input = {
"name": "org.osbuild.kickstart",
"options": {

View file

@ -0,0 +1,61 @@
#!/usr/bin/python3
import os.path
from unittest.mock import call, patch
import pytest
import osbuild.meta
from osbuild.testutil.imports import import_module_from_path
def schema_validate_stage_ostree_post_copy(test_data):
name = "org.osbuild.ostree.post-copy"
version = "2"
root = os.path.join(os.path.dirname(__file__), "../..")
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", name)
schema = osbuild.meta.Schema(mod_info.get_schema(version=version), name)
test_input = {
"type": "org.osbuild.ostree.post-copy",
"options": {
"sysroot": "/some/sysroot",
},
}
test_input.update(test_data)
return schema.validate(test_input)
@patch("osbuild.util.ostree.cli")
def test_ostree_post_copy_smoke(mock_ostree_cli):
stage_path = os.path.join(os.path.dirname(__file__), "../org.osbuild.ostree.post-copy")
stage = import_module_from_path("stage", stage_path)
paths = {
"mounts": "/run/osbuild/mounts",
}
options = {
"sysroot": "/some/sysroot",
}
stage.main(paths, options)
assert mock_ostree_cli.call_args_list == [
call("admin", "post-copy", sysroot="/run/osbuild/mounts/some/sysroot")]
@pytest.mark.parametrize(
"test_data,expected_err",
[
# devices is not used directly in the stage but it's required
# because it's used as input for "mounts", see
# https://github.com/osbuild/osbuild/pull/1343/files#r1402161208
({"devices": "must-be-object"}, " is not of type 'object'"),
({"mounts": "must-be-array"}, " is not of type 'array'"),
],
)
def test_schema_validation_ostree_post_copy(test_data, expected_err):
res = schema_validate_stage_ostree_post_copy(test_data)
assert res.valid is False
err_msgs = [e.as_dict()["message"] for e in res.errors]
assert len(res.errors) == 1, err_msgs
assert expected_err in err_msgs[0]