pipeline: run method takes store object not dir

Instead of passing the store directory to Pipeline.run, pass an
already initialized ObjectStore object. This binds the lifetime
of the store and its (temporary) objects to the run of osbuild
not the run of the pipeline.
This prepares re-using the stores with multiple (non-nested)
pipelines.
This commit is contained in:
Christian Kellner 2020-12-17 12:54:19 +01:00 committed by Tom Gundersen
parent 8d2c7f8160
commit f38c48086e
3 changed files with 38 additions and 35 deletions

View file

@ -14,6 +14,7 @@ import sys
import osbuild
import osbuild.meta
import osbuild.monitor
from osbuild.objectstore import ObjectStore
from osbuild.formats import v1 as fmt
@ -114,12 +115,13 @@ def osbuild_cli():
monitor = osbuild.monitor.make(monitor_name, sys.stdout.fileno())
try:
r = manifest.build(
args.store,
monitor,
args.libdir,
output_directory=args.output_directory
)
with ObjectStore(args.store) as object_store:
r = manifest.build(
object_store,
monitor,
args.libdir,
output_directory=args.output_directory
)
except KeyboardInterrupt:
print()
print(f"{RESET}{BOLD}{RED}Aborted{RESET}")

View file

@ -294,34 +294,33 @@ class Pipeline:
monitor.begin(self)
with objectstore.ObjectStore(store) as object_store:
# If the final result is already in the store, no need to attempt
# building it. Just fetch the cached information. If the associated
# tree exists, we return it as well, but we do not care if it is
# missing, since it is not a mandatory part of the result and would
# usually be needless overhead.
obj = object_store.get(self.output_id)
# If the final result is already in the store, no need to attempt
# building it. Just fetch the cached information. If the associated
# tree exists, we return it as well, but we do not care if it is
# missing, since it is not a mandatory part of the result and would
# usually be needless overhead.
obj = store.get(self.output_id)
if not obj:
results, build_tree, tree = self.build_stages(object_store,
monitor,
libdir)
if not obj:
results, build_tree, tree = self.build_stages(store,
monitor,
libdir)
if not results["success"]:
return results
if not results["success"]:
return results
r, obj = self.assemble(object_store,
build_tree,
tree,
monitor,
libdir)
r, obj = self.assemble(store,
build_tree,
tree,
monitor,
libdir)
results.update(r) # This will also update 'success'
results.update(r) # This will also update 'success'
if obj:
if output_directory:
obj.export(output_directory)
obj.cleanup()
if obj:
if output_directory:
obj.export(output_directory)
obj.cleanup()
monitor.finish(results)

View file

@ -12,6 +12,7 @@ from collections import defaultdict
import osbuild
import osbuild.meta
from osbuild.monitor import LogMonitor
from osbuild.objectstore import ObjectStore
from osbuild.pipeline import detect_host_runner
from .. import test
@ -67,9 +68,9 @@ class TestMonitor(unittest.TestCase):
logfile = os.path.join(tmpdir, "log.txt")
with open(logfile, "w") as log:
with open(logfile, "w") as log, ObjectStore(storedir) as store:
monitor = LogMonitor(log.fileno())
res = pipeline.run(storedir,
res = pipeline.run(store,
monitor,
libdir=os.path.abspath(os.curdir),
output_directory=outputdir)
@ -100,10 +101,11 @@ class TestMonitor(unittest.TestCase):
outputdir = os.path.join(tmpdir, "output")
tape = TapeMonitor()
res = pipeline.run(storedir,
tape,
libdir=os.path.abspath(os.curdir),
output_directory=outputdir)
with ObjectStore(storedir) as store:
res = pipeline.run(store,
tape,
libdir=os.path.abspath(os.curdir),
output_directory=outputdir)
assert res
self.assertEqual(tape.counter["begin"], 1)