osbuild: auto-detect best available runner

Use the new `Index.detect_runner` method that will give us the best
available runner for a requested one. To do so a new `pipeline.Runner`
class is introduced that stores the `meta.RunnerInfo` class for the
specific runner and the original name that was requested.
In the manifest loading and describing functions of the formats, use
`Index.detect_runner` to get the `RunnerInfo` for a requested runner
and then wrap it in a `pipeline.Runner` object, which is then passed
to the `Manifest.add_pipeline` method.
See also commit "meta: ability to auto-detect runner".
Adjust all test.
This commit is contained in:
Christian Kellner 2022-10-01 11:11:07 +02:00
parent 0554ac652b
commit 5bdc8d030c
8 changed files with 71 additions and 43 deletions

View file

@ -11,7 +11,7 @@ from typing import Any, Dict
from osbuild.meta import Index, ValidationResult
from ..pipeline import BuildResult, Manifest, Pipeline, detect_host_runner
from ..pipeline import BuildResult, Manifest, Pipeline, Runner
VERSION = "1"
@ -32,7 +32,7 @@ def describe(manifest: Manifest, *, with_id=False) -> Dict[str, Any]:
build = manifest[pipeline.build]
description["build"] = {
"pipeline": describe_pipeline(build),
"runner": pipeline.runner
"runner": pipeline.runner.name
}
if pipeline.stages:
@ -91,7 +91,10 @@ def load_build(description: Dict, index: Index, manifest: Manifest, n: int):
else:
build_pipeline = None
return build_pipeline, description["runner"]
runner_name = description["runner"]
runner_info = index.detect_runner(runner_name)
return build_pipeline, Runner(runner_info, runner_name)
def load_stage(description: Dict, index: Index, pipeline: Pipeline):
@ -146,7 +149,7 @@ def load_pipeline(description: Dict, index: Index, manifest: Manifest, n: int =
if build:
build_pipeline, runner = load_build(build, index, manifest, n)
else:
build_pipeline, runner = None, detect_host_runner()
build_pipeline, runner = None, Runner(index.detect_host_runner())
# the "main" pipeline is called `tree`, since it is building the
# tree that will later be used by the `assembler`. Nested build

View file

@ -7,7 +7,7 @@ from typing import Any, Dict
from osbuild.meta import Index, ModuleInfo, ValidationResult
from ..inputs import Input
from ..pipeline import Manifest, Pipeline, Stage, detect_host_runner
from ..pipeline import Manifest, Pipeline, Runner, Stage
from ..sources import Source
VERSION = "2"
@ -130,7 +130,7 @@ def describe(manifest: Manifest, *, with_id=False) -> Dict:
runner = runners.get(p.id)
if runner:
desc["runner"] = runner
desc["runner"] = runner.name
stages = [
describe_stage(stage)
@ -325,13 +325,22 @@ def load_stage(description: Dict, index: Index, pipeline: Pipeline, manifest: Ma
def load_pipeline(description: Dict, index: Index, manifest: Manifest, source_refs: set):
name = description["name"]
build = description.get("build")
runner = description.get("runner")
source_epoch = description.get("source-epoch")
if build and build.startswith("name:"):
target = resolve_ref(build, manifest)
build = target
# NB: The runner mapping will later be changed in `load`.
# The host runner here is just to always have a Runner
# (instead of a Optional[Runner]) to make mypy happy
runner_name = description.get("runner")
runner = None
if runner_name:
runner = Runner(index.detect_runner(runner_name), runner_name)
else:
runner = Runner(index.detect_host_runner())
pl = manifest.add_pipeline(name, runner, build, source_epoch)
for desc in description.get("stages", []):
@ -365,7 +374,7 @@ def load(description: Dict, index: Index) -> Manifest:
# go through the pipelines and fix things up
pipelines = manifest.pipelines.values()
host_runner = detect_host_runner()
host_runner = Runner(index.detect_host_runner())
runners = {
pl.id: pl.runner for pl in pipelines
}