From b5355c46ac826cdf20da5045f9d4d0f4a7713e58 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 21 Feb 2024 17:07:15 +0100 Subject: [PATCH] inputs: tweak `containers-storage` implementation This commit tweaks the excellent work from Gianluca in PR#1550 a little bit. Now that the container inputs are their own input type some of the code that used to be part of the original `inputs/org.osbuild.containers` can be simplified. --- inputs/org.osbuild.containers-storage | 28 ++++++++------------------- inputs/test/test_containers.py | 2 +- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/inputs/org.osbuild.containers-storage b/inputs/org.osbuild.containers-storage index 60fd0621..49b60328 100755 --- a/inputs/org.osbuild.containers-storage +++ b/inputs/org.osbuild.containers-storage @@ -84,20 +84,14 @@ SCHEMA = r""" """ -class ContainersInput(inputs.InputService): +class ContainersStorageInput(inputs.InputService): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.mg = MountGuard() - self.storage_conf = None - - def map_storage_ref(self, _source, ref, target): - # we only want to read the host once and only for inputs that - # require it. If we do this for all inputs, reading the host - # may cause unexpected errors. - if self.storage_conf is None: - self.storage_conf = containers.get_host_storage() + self.storage_conf = containers.get_host_storage() + def bind_mount_local_storage(self, target): source = self.storage_conf["storage"]["graphroot"] dest = os.path.join(target, "storage") @@ -105,23 +99,17 @@ class ContainersInput(inputs.InputService): os.makedirs(dest, exist_ok=True) self.mg.mount(source, dest) - return ref, "containers-storage" - def map(self, store, origin, refs, target, _options): + self.bind_mount_local_storage(target) + images = {} - for ref, data in refs.items(): - source = "org.osbuild.containers-storage" - ref, container_format = self.map_storage_ref(source, ref, target) - images[ref] = { - "format": container_format, + "format": "containers-storage", "name": data["name"] } images[ref]["name"] = data["name"] - - if container_format == "containers-storage" and self.storage_conf is not None: - images[ref]["storage"] = self.storage_conf["storage"] + images[ref]["storage"] = self.storage_conf["storage"] reply = { "path": target, @@ -137,7 +125,7 @@ class ContainersInput(inputs.InputService): def main(): - service = ContainersInput.from_args(sys.argv[1:]) + service = ContainersStorageInput.from_args(sys.argv[1:]) service.main() diff --git a/inputs/test/test_containers.py b/inputs/test/test_containers.py index 43b578de..1b972c10 100644 --- a/inputs/test/test_containers.py +++ b/inputs/test/test_containers.py @@ -55,7 +55,7 @@ def test_containers_local_inputs_integration(tmp_path, inputs_module): } } sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - cnt_inputs = inputs_module.ContainersInput.from_args(["--service-fd", str(sock.fileno())]) + cnt_inputs = inputs_module.ContainersStorageInput.from_args(["--service-fd", str(sock.fileno())]) store = FakeStoreClient(tmp_path / "fake-sources") # not using "tmp_path" here as it will "rm -rf" on cleanup and # that is dangerous as during the tests we bind mount the