Example #1
0
    def test_describe(self):
        index = osbuild.meta.Index(os.curdir)

        manifest = fmt.load(BASIC_PIPELINE, index)
        self.assertIsNotNone(manifest)

        self.assertEqual(fmt.describe(manifest), BASIC_PIPELINE)
Example #2
0
    def test_load(self):
        # Load a pipeline and check the resulting manifest
        def check_stage(have: osbuild.Stage, want: Dict):
            self.assertEqual(have.name, want["name"])
            self.assertEqual(have.options, want.get("options", {}))

        index = osbuild.meta.Index(os.curdir)

        description = BASIC_PIPELINE

        # load the manifest description, that will check all
        # the stages can be found in the index and have valid
        # arguments, i.e. the schema is correct
        manifest = fmt.load(description, index)
        self.assertIsNotNone(manifest)

        # We have to have two build pipelines and a main pipeline
        self.assertTrue(manifest.pipelines)
        self.assertTrue(len(manifest.pipelines) == 4)

        # access the individual pipelines via their names

        # the inner most build pipeline
        build = description["pipeline"]["build"]["pipeline"]["build"]
        pl = manifest["build-build"]
        have = pl.stages[0]
        want = build["pipeline"]["stages"][0]
        check_stage(have, want)

        runner = build["runner"]

        # the build pipeline for the 'tree' pipeline
        build = description["pipeline"]["build"]
        pl = manifest["build"]
        have = pl.stages[0]
        want = build["pipeline"]["stages"][0]
        self.assertEqual(pl.runner, runner)
        check_stage(have, want)

        runner = build["runner"]

        # the main, aka 'tree', pipeline
        pl = manifest["tree"]
        have = pl.stages[0]
        want = description["pipeline"]["stages"][0]
        self.assertEqual(pl.runner, runner)
        check_stage(have, want)

        # the assembler pipeline
        pl = manifest["assembler"]
        have = pl.stages[0]
        want = description["pipeline"]["assembler"]
        self.assertEqual(pl.runner, runner)
        check_stage(have, want)
Example #3
0
    def treeid_from_manifest(manifest_data):
        """Calculate Tree ID

        This takes an in-memory manifest, inspects it, and returns the ID of
        the final tree of the stage-array. This returns `None` if no stages
        are defined.
        """

        index = osbuild.meta.Index(os.curdir)

        manifest_json = json.loads(manifest_data)

        manifest = fmt.load(manifest_json, index)
        tree_id, _ = fmt.get_ids(manifest)
        return tree_id
Example #4
0
    def test_canonical(self):
        """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},
            {"stages": []},
            {"build": {}},
            {"build": None}
        ]

        for pipeline in cases:
            manifest = {"pipeline": pipeline}
            with self.subTest(pipeline):
                desc = fmt.describe(fmt.load(manifest, index))
                self.assertEqual(desc["pipeline"], {})
Example #5
0
    def test_format_output(self):
        """Test that output formatting is as expected"""
        index = osbuild.meta.Index(os.curdir)

        description = {
            "pipeline": {
                "stages": [
                    {
                        "name": "org.osbuild.noop"
                    },
                    {
                        "name": "org.osbuild.error"
                    }
                ]
            }
        }

        manifest = fmt.load(description, index)
        self.assertIsNotNone(manifest)

        with tempfile.TemporaryDirectory() as tmpdir:
            res = self.build_manifest(manifest, tmpdir)

        self.assertIsNotNone(res)
        result = fmt.output(manifest, res)
        self.assertIsNotNone(result)
        self.assertIn("success", result)
        self.assertFalse(result["success"])
        self.assertIn("stages", result)
        stages = result["stages"]
        self.assertEqual(len(stages), 2)
        self.assertTrue(stages[0]["success"])
        self.assertFalse(stages[1]["success"])

        # check we get results for the build pipeline
        description = {
            "pipeline": {
                "build": {
                    "pipeline": {
                        "stages": [
                            {
                                "name": "org.osbuild.error"
                            }
                        ]
                    },
                    "runner": "org.osbuild.test",
                    "stages": [
                        {
                            "name": "org.osbuild.noop"
                        }
                    ]
                }
            }
        }

        manifest = fmt.load(description, index)
        self.assertIsNotNone(manifest)

        with tempfile.TemporaryDirectory() as tmpdir:
            res = self.build_manifest(manifest, tmpdir)

        self.assertIsNotNone(res)
        result = fmt.output(manifest, res)
        self.assertIsNotNone(result)
        self.assertIn("success", result)
        self.assertFalse(result["success"])

        self.assertIn("build", result)
        self.assertIn("success", result["build"])
        self.assertFalse(result["build"]["success"])

        # check we get results for the assembler pipeline
        description = {
            "pipeline": {
                "stages": [
                    {
                        "name": "org.osbuild.noop"
                    },
                ],
                "assembler": {
                    "name": "org.osbuild.error"
                }
            }
        }

        manifest = fmt.load(description, index)
        self.assertIsNotNone(manifest)

        with tempfile.TemporaryDirectory() as tmpdir:
            res = self.build_manifest(manifest, tmpdir)

        self.assertIsNotNone(res)
        result = fmt.output(manifest, res)
        self.assertIsNotNone(result)

        self.assertIn("assembler", result)
        self.assertIn("success", result["assembler"])
        self.assertFalse(result["assembler"]["success"])

        # check the overall result is False as well
        self.assertIn("success", result)
        self.assertFalse(result["success"], result)

        # check we get all the output nodes for a successful build
        description = {
            "pipeline": {
                "stages": [
                    {
                        "name": "org.osbuild.noop"
                    },
                ],
                "assembler": {
                    "name": "org.osbuild.noop"
                }
            }
        }

        manifest = fmt.load(description, index)
        self.assertIsNotNone(manifest)

        with tempfile.TemporaryDirectory() as tmpdir:
            res = self.build_manifest(manifest, tmpdir)

        self.assertIsNotNone(res)
        result = fmt.output(manifest, res)
        self.assertIsNotNone(result)

        self.assertIn("stages", result)
        for stage in result["stages"]:
            self.assertIn("success", stage)
            self.assertTrue(stage["success"])

        self.assertIn("assembler", result)
        self.assertIn("success", result["assembler"])
        self.assertTrue(result["assembler"]["success"])