stage: add module information about itself

Add a new `info` property that holds the `meta.ModuleInfo` info
for the stage. This gives each instance of a stage access to
meta (or class) information about it, i.e. its schema, docs but,
more importantly, also its name and path to the executable.
Thefore the `name` property is coverted into a transient property
which access the `name` member of `info`.
Change the `formats/v1` load mechanism to carry a new `index`
argument which is used to load the `ModuleInfo` for each stage.
Adapt all tests to load the info as well when creating stages.
This commit is contained in:
Christian Kellner 2021-01-05 19:43:11 +01:00 committed by Tom Gundersen
parent a26b7291d1
commit 7a6c2df910
6 changed files with 41 additions and 20 deletions

View file

@ -55,9 +55,12 @@ class TestMonitor(unittest.TestCase):
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
def test_log_monitor_vfuncs(self):
# Checks the basic functioning of the LogMonitor
index = osbuild.meta.Index(os.curdir)
runner = detect_host_runner()
pipeline = osbuild.Pipeline(runner=runner)
pipeline.add_stage("org.osbuild.noop", {
info = index.get_module_info("Stage", "org.osbuild.noop")
pipeline.add_stage(info, {
"isthisthereallife": False
})
pipeline.set_assembler("org.osbuild.noop")
@ -87,11 +90,14 @@ class TestMonitor(unittest.TestCase):
def test_monitor_integration(self):
# Checks the monitoring API is called properly from the pipeline
runner = detect_host_runner()
index = osbuild.meta.Index(os.curdir)
pipeline = osbuild.Pipeline(runner=runner)
pipeline.add_stage("org.osbuild.noop", {
noop_info = index.get_module_info("Stage", "org.osbuild.noop")
pipeline.add_stage(noop_info, {
"isthisthereallife": False
})
pipeline.add_stage("org.osbuild.noop", {
pipeline.add_stage(noop_info, {
"isthisjustfantasy": True
})
pipeline.set_assembler("org.osbuild.noop")

View file

@ -22,6 +22,8 @@ class TestDescriptions(unittest.TestCase):
"""Degenerate case. Make sure we always return the same canonical
description when passing empty or null values."""
index = osbuild.meta.Index(os.curdir)
cases = [
{},
{"assembler": None},
@ -32,12 +34,14 @@ class TestDescriptions(unittest.TestCase):
for pipeline in cases:
manifest = {"pipeline": pipeline}
with self.subTest(pipeline):
desc = fmt.describe(fmt.load(manifest))
desc = fmt.describe(fmt.load(manifest, index))
self.assertEqual(desc["pipeline"], {})
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
def test_stage_run(self):
stage = osbuild.Stage("org.osbuild.noop", {}, None, None, {})
index = osbuild.meta.Index(os.curdir)
info = index.get_module_info("Stage", "org.osbuild.noop")
stage = osbuild.Stage(info, {}, None, None, {})
with tempfile.TemporaryDirectory() as tmpdir:
@ -79,11 +83,14 @@ class TestDescriptions(unittest.TestCase):
self.assertEqual(res.id, asm.id)
def test_pipeline(self):
index = osbuild.meta.Index(os.curdir)
test_info = index.get_module_info("Stage", "org.osbuild.test")
build = osbuild.Pipeline("org.osbuild.test")
build.add_stage("org.osbuild.test", {"one": 1})
build.add_stage(test_info, {"one": 1})
pipeline = osbuild.Pipeline("org.osbuild.test", build.tree_id)
pipeline.add_stage("org.osbuild.test", {"one": 2})
pipeline.add_stage(test_info, {"one": 2})
pipeline.set_assembler("org.osbuild.test")
manifest = osbuild.Manifest([build, pipeline], {})