示例#1
0
    def test_log_monitor_vfuncs(self):
        # Checks the basic functioning of the LogMonitor
        runner = detect_host_runner()
        pipeline = osbuild.Pipeline(runner=runner)
        pipeline.add_stage("org.osbuild.noop", {}, {
            "isthisthereallife": False
        })
        pipeline.set_assembler("org.osbuild.noop")

        with tempfile.TemporaryDirectory() as tmpdir:
            storedir = os.path.join(tmpdir, "store")
            outputdir = os.path.join(tmpdir, "output")

            logfile = os.path.join(tmpdir, "log.txt")

            with open(logfile, "w") as log:
                monitor = LogMonitor(log.fileno())
                res = pipeline.run(storedir,
                                   monitor,
                                   libdir=os.path.abspath(os.curdir),
                                   output_directory=outputdir)

                with open(logfile) as f:
                    log = f.read()

            assert res
            self.assertIn(pipeline.stages[0].id, log)
            self.assertIn(pipeline.assembler.id, log)
            self.assertIn("isthisthereallife", log)
示例#2
0
    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("pipeline", runner=runner)
        info = index.get_module_info("Stage", "org.osbuild.noop")
        pipeline.add_stage(info, {
            "isthisthereallife": False
        })

        with tempfile.TemporaryDirectory() as tmpdir:
            storedir = os.path.join(tmpdir, "store")

            logfile = os.path.join(tmpdir, "log.txt")

            with open(logfile, "w") as log, ObjectStore(storedir) as store:
                monitor = LogMonitor(log.fileno())
                res = pipeline.run(store,
                                   monitor,
                                   libdir=os.path.abspath(os.curdir))

                with open(logfile) as f:
                    log = f.read()

            assert res
            self.assertIn(pipeline.stages[0].id, log)
            self.assertIn("isthisthereallife", log)
示例#3
0
    def test_runner_fail(self):
        runner = "org.osbuild.nonexistantrunner"
        libdir = os.path.abspath(os.curdir)
        var = pathlib.Path(self.tmp.name, "var")
        var.mkdir()

        logfile = os.path.join(self.tmp.name, "log.txt")

        with BuildRoot("/", runner, libdir, var) as root, \
             open(logfile, "w") as log:

            monitor = LogMonitor(log.fileno())

            r = root.run(["/usr/bin/true"], monitor)

        self.assertEqual(r.returncode, 1)
        with open(logfile) as f:
            log = f.read()
        assert log
        assert r.output
        self.assertEqual(log, r.output)