formats: describe now takes a manifest

Instead of a pipeline, describe now takes a Manifest instance.
The reason is that a manifest fully describes the build, which
includes the sources. Now that the describe function takes the
manifest, the sources can be included as well.
Adapt the tests to refelect that change.
This commit is contained in:
Christian Kellner 2020-12-16 19:08:04 +01:00 committed by Tom Gundersen
parent 945914b195
commit d25936a028
3 changed files with 48 additions and 37 deletions

View file

@ -5,7 +5,7 @@ from osbuild.meta import Index, ValidationResult
from ..pipeline import Manifest, Pipeline, detect_host_runner
def describe(pipeline: Pipeline, *, with_id=False) -> Dict:
def describe(manifest: Manifest, *, with_id=False) -> Dict:
"""Create the manifest description for the pipeline"""
def describe_stage(stage):
description = {"name": stage.name}
@ -15,21 +15,30 @@ def describe(pipeline: Pipeline, *, with_id=False) -> Dict:
description["id"] = stage.id
return description
description = {}
if pipeline.build:
build = pipeline.build
description["build"] = {
"pipeline": describe(build, with_id=with_id),
"runner": pipeline.runner
}
def describe_pipeline(pipeline: Pipeline) -> Dict:
description = {}
if pipeline.build:
build = pipeline.build
description["build"] = {
"pipeline": describe_pipeline(build),
"runner": pipeline.runner
}
if pipeline.stages:
stages = [describe_stage(s) for s in pipeline.stages]
description["stages"] = stages
if pipeline.stages:
stages = [describe_stage(s) for s in pipeline.stages]
description["stages"] = stages
if pipeline.assembler:
assembler = describe_stage(pipeline.assembler)
description["assembler"] = assembler
if pipeline.assembler:
assembler = describe_stage(pipeline.assembler)
description["assembler"] = assembler
return description
description = {
"pipeline": describe_pipeline(manifest.pipeline)
}
if manifest.sources:
description["sources"] = manifest.sources
return description

View file

@ -128,9 +128,7 @@ def osbuild_cli():
return 1
if args.inspect:
result = {"pipeline": fmt.describe(pipeline, with_id=True)}
if desc.get("sources_options"):
result["sources"] = desc["sources_options"]
result = fmt.describe(manifest, with_id=True)
json.dump(result, sys.stdout)
sys.stdout.write("\n")
return 0

View file

@ -32,8 +32,8 @@ class TestDescriptions(unittest.TestCase):
for pipeline in cases:
manifest = {"pipeline": pipeline}
with self.subTest(pipeline):
desc = fmt.describe(fmt.load(manifest).pipeline)
self.assertEqual(desc, {})
desc = fmt.describe(fmt.load(manifest))
self.assertEqual(desc["pipeline"], {})
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
def test_stage_run(self):
@ -86,26 +86,30 @@ class TestDescriptions(unittest.TestCase):
pipeline.add_stage("org.osbuild.test", {}, {"one": 2})
pipeline.set_assembler("org.osbuild.test")
self.assertEqual(fmt.describe(pipeline), {
"build": {
"pipeline": {
"stages": [
{
"name": "org.osbuild.test",
"options": {"one": 1}
}
]
manifest = osbuild.Manifest(pipeline, {})
self.assertEqual(fmt.describe(manifest), {
"pipeline": {
"build": {
"pipeline": {
"stages": [
{
"name": "org.osbuild.test",
"options": {"one": 1}
}
]
},
"runner": "org.osbuild.test"
},
"runner": "org.osbuild.test"
},
"stages": [
{
"name": "org.osbuild.test",
"options": {"one": 2}
"stages": [
{
"name": "org.osbuild.test",
"options": {"one": 2}
}
],
"assembler": {
"name": "org.osbuild.test"
}
],
"assembler": {
"name": "org.osbuild.test"
}
})