osbuild: introduce mount host service

Allows stages to access file systems provided by devices.
This makes mount handling transparent to the stages, i.e.
the individual stages do not need any code for different
file system types and the underlying devices.
This commit is contained in:
Christian Kellner 2021-06-07 18:50:10 +02:00 committed by Tom Gundersen
parent 92f936e15c
commit 367a044453
5 changed files with 227 additions and 7 deletions

View file

@ -12,6 +12,7 @@ from ..sources import Source
VERSION = "2"
# pylint: disable=too-many-statements
def describe(manifest: Manifest, *, with_id=False) -> Dict:
# Undo the build, runner pairing introduce by the loading
@ -72,6 +73,24 @@ def describe(manifest: Manifest, *, with_id=False) -> Dict:
}
return desc
def describe_mount(mnt):
desc = {
"type": mnt.info.name,
"device": mnt.device.name,
"target": mnt.target
}
if mnt.options:
desc["options"] = mnt.options
return desc
def describe_mounts(mounts: Dict):
desc = {
name: describe_mount(mnt)
for name, mnt in mounts.items()
}
return desc
def describe_stage(s: Stage):
desc = {
"type": s.info.name
@ -87,6 +106,10 @@ def describe(manifest: Manifest, *, with_id=False) -> Dict:
if devs:
desc["devices"] = devs
mounts = describe_mounts(s.mounts)
if mounts:
desc["mounts"] = mounts
ips = describe_inputs(s.inputs)
if ips:
desc["inputs"] = ips
@ -187,6 +210,22 @@ def load_input(name: str, description: Dict, index: Index, stage: Stage, manifes
ip.add_reference(r, desc)
def load_mount(name: str, description: Dict, index: Index, stage: Stage):
mount_type = description["type"]
info = index.get_module_info("Mount", mount_type)
source = description["source"]
target = description["target"]
options = description.get("options", {})
device = stage.devices.get(source)
if not device:
raise ValueError(f"Unknown device '{source}' for mount '{name}'")
stage.add_mount(name, info, device, target, options)
def load_stage(description: Dict, index: Index, pipeline: Pipeline, manifest: Manifest):
stage_type = description["type"]
opts = description.get("options", {})
@ -202,6 +241,10 @@ def load_stage(description: Dict, index: Index, pipeline: Pipeline, manifest: Ma
for name, desc in ips.items():
load_input(name, desc, index, stage, manifest)
mounts = description.get("mounts", {})
for name, desc in mounts.items():
load_mount(name, desc, index, stage)
return stage
@ -354,8 +397,8 @@ def validate(manifest: Dict, index: Index) -> ValidationResult:
res = schema.validate(stage)
result.merge(res, path=path)
validate_stage_modules("Device", stage, path)
validate_stage_modules("Input", stage, path)
for mod in ("Device", "Input", "Mount"):
validate_stage_modules(mod, stage, path)
def validate_pipeline(pipeline, path):
stages = pipeline.get("stages", [])