formats: move pipeline description here
The description of a pipeline is format dependent and thus needs to be located at the specific format module. Temporarily remove two tests; they should be added back to a format specific test suit.
This commit is contained in:
parent
a13783f67b
commit
4ab52c3764
4 changed files with 33 additions and 59 deletions
|
|
@ -5,6 +5,35 @@ from osbuild.meta import Index, ValidationResult
|
||||||
from ..pipeline import Pipeline, detect_host_runner
|
from ..pipeline import Pipeline, detect_host_runner
|
||||||
|
|
||||||
|
|
||||||
|
def describe(pipeline: Pipeline, *, with_id=False) -> Dict:
|
||||||
|
"""Create the manifest description for the pipeline"""
|
||||||
|
def describe_stage(stage):
|
||||||
|
description = {"name": stage.name}
|
||||||
|
if stage.options:
|
||||||
|
description["options"] = stage.options
|
||||||
|
if with_id:
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
return description
|
||||||
|
|
||||||
|
|
||||||
def load_build(description: Dict, sources_options: Dict):
|
def load_build(description: Dict, sources_options: Dict):
|
||||||
pipeline = description.get("pipeline")
|
pipeline = description.get("pipeline")
|
||||||
if pipeline:
|
if pipeline:
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ def osbuild_cli():
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if args.inspect:
|
if args.inspect:
|
||||||
result = {"pipeline": pipeline.description(with_id=True)}
|
result = {"pipeline": fmt.describe(pipeline, with_id=True)}
|
||||||
if manifest.get("sources_options"):
|
if manifest.get("sources_options"):
|
||||||
result["sources"] = manifest["sources_options"]
|
result["sources"] = manifest["sources_options"]
|
||||||
json.dump(result, sys.stdout)
|
json.dump(result, sys.stdout)
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,6 @@ class Stage:
|
||||||
m.update(json.dumps(self.options, sort_keys=True).encode())
|
m.update(json.dumps(self.options, sort_keys=True).encode())
|
||||||
return m.hexdigest()
|
return m.hexdigest()
|
||||||
|
|
||||||
def description(self, *, with_id=False):
|
|
||||||
description = {"name": self.name}
|
|
||||||
if self.options:
|
|
||||||
description["options"] = self.options
|
|
||||||
if with_id:
|
|
||||||
description["id"] = self.id
|
|
||||||
return description
|
|
||||||
|
|
||||||
def run(self,
|
def run(self,
|
||||||
tree,
|
tree,
|
||||||
runner,
|
runner,
|
||||||
|
|
@ -113,14 +105,6 @@ class Assembler:
|
||||||
m.update(json.dumps(self.options, sort_keys=True).encode())
|
m.update(json.dumps(self.options, sort_keys=True).encode())
|
||||||
return m.hexdigest()
|
return m.hexdigest()
|
||||||
|
|
||||||
def description(self, *, with_id=False):
|
|
||||||
description = {"name": self.name}
|
|
||||||
if self.options:
|
|
||||||
description["options"] = self.options
|
|
||||||
if with_id:
|
|
||||||
description["id"] = self.id
|
|
||||||
return description
|
|
||||||
|
|
||||||
def run(self, tree, runner, build_tree, monitor, libdir, output_dir, var="/var/tmp"):
|
def run(self, tree, runner, build_tree, monitor, libdir, output_dir, var="/var/tmp"):
|
||||||
with buildroot.BuildRoot(build_tree, runner, libdir, var=var) as build_root:
|
with buildroot.BuildRoot(build_tree, runner, libdir, var=var) as build_root:
|
||||||
|
|
||||||
|
|
@ -181,22 +165,6 @@ class Pipeline:
|
||||||
build = self.build.tree_id if self.build else None
|
build = self.build.tree_id if self.build else None
|
||||||
self.assembler = Assembler(name, build, self.tree_id, options or {})
|
self.assembler = Assembler(name, build, self.tree_id, options or {})
|
||||||
|
|
||||||
def description(self, *, with_id=False):
|
|
||||||
description = {}
|
|
||||||
if self.build:
|
|
||||||
description["build"] = {
|
|
||||||
"pipeline": self.build.description(with_id=with_id),
|
|
||||||
"runner": self.runner
|
|
||||||
}
|
|
||||||
if self.stages:
|
|
||||||
stages = [s.description(with_id=with_id) for s in self.stages]
|
|
||||||
description["stages"] = stages
|
|
||||||
if self.assembler:
|
|
||||||
assembler = self.assembler.description(with_id=with_id)
|
|
||||||
description["assembler"] = assembler
|
|
||||||
|
|
||||||
return description
|
|
||||||
|
|
||||||
def build_stages(self, object_store, monitor, libdir):
|
def build_stages(self, object_store, monitor, libdir):
|
||||||
results = {"success": True}
|
results = {"success": True}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,19 +32,8 @@ class TestDescriptions(unittest.TestCase):
|
||||||
for pipeline in cases:
|
for pipeline in cases:
|
||||||
manifest = {"pipeline": pipeline}
|
manifest = {"pipeline": pipeline}
|
||||||
with self.subTest(pipeline):
|
with self.subTest(pipeline):
|
||||||
self.assertEqual(fmt.load(manifest).description(), {})
|
desc = fmt.describe(fmt.load(manifest))
|
||||||
|
self.assertEqual(desc, {})
|
||||||
def test_stage(self):
|
|
||||||
name = "org.osbuild.test"
|
|
||||||
options = {"one": 1}
|
|
||||||
cases = [
|
|
||||||
(osbuild.Stage(name, {}, None, None, {}), {"name": name}),
|
|
||||||
(osbuild.Stage(name, {}, None, None, None), {"name": name}),
|
|
||||||
(osbuild.Stage(name, {}, None, None, options), {"name": name, "options": options}),
|
|
||||||
]
|
|
||||||
for stage, description in cases:
|
|
||||||
with self.subTest(description):
|
|
||||||
self.assertEqual(stage.description(), description)
|
|
||||||
|
|
||||||
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
||||||
def test_stage_run(self):
|
def test_stage_run(self):
|
||||||
|
|
@ -67,18 +56,6 @@ class TestDescriptions(unittest.TestCase):
|
||||||
self.assertEqual(res.success, True)
|
self.assertEqual(res.success, True)
|
||||||
self.assertEqual(res.id, stage.id)
|
self.assertEqual(res.id, stage.id)
|
||||||
|
|
||||||
def test_assembler(self):
|
|
||||||
name = "org.osbuild.test"
|
|
||||||
options = {"one": 1}
|
|
||||||
cases = [
|
|
||||||
(osbuild.Assembler(name, None, None, {}), {"name": name}),
|
|
||||||
(osbuild.Assembler(name, None, None, None), {"name": name}),
|
|
||||||
(osbuild.Assembler(name, None, None, options), {"name": name, "options": options}),
|
|
||||||
]
|
|
||||||
for assembler, description in cases:
|
|
||||||
with self.subTest(description):
|
|
||||||
self.assertEqual(assembler.description(), description)
|
|
||||||
|
|
||||||
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
||||||
def test_assembler_run(self):
|
def test_assembler_run(self):
|
||||||
asm = osbuild.Assembler("org.osbuild.noop", None, None, {})
|
asm = osbuild.Assembler("org.osbuild.noop", None, None, {})
|
||||||
|
|
@ -109,7 +86,7 @@ class TestDescriptions(unittest.TestCase):
|
||||||
pipeline.add_stage("org.osbuild.test", {}, {"one": 2})
|
pipeline.add_stage("org.osbuild.test", {}, {"one": 2})
|
||||||
pipeline.set_assembler("org.osbuild.test")
|
pipeline.set_assembler("org.osbuild.test")
|
||||||
|
|
||||||
self.assertEqual(pipeline.description(), {
|
self.assertEqual(fmt.describe(pipeline), {
|
||||||
"build": {
|
"build": {
|
||||||
"pipeline": {
|
"pipeline": {
|
||||||
"stages": [
|
"stages": [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue