From 59a0dee373dc7b5f5c7a679c6aaf880bc4fdbf63 Mon Sep 17 00:00:00 2001 From: Sergey <6213510+sshnaidm@users.noreply.github.com> Date: Sun, 26 Nov 2023 21:31:47 +0200 Subject: [PATCH] Fix multi-image support for podman_save (#672) Fix #670 Signed-off-by: Sagi Shnaidman --- plugins/modules/podman_save.py | 19 ++++++---- .../targets/podman_save/tasks/main.yml | 36 +++++++++++++++---- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/plugins/modules/podman_save.py b/plugins/modules/podman_save.py index bc7ce252..e23f3102 100644 --- a/plugins/modules/podman_save.py +++ b/plugins/modules/podman_save.py @@ -20,7 +20,8 @@ image: description: - Image to save. - type: str + type: list + elements: str required: true compress: description: @@ -70,9 +71,14 @@ EXAMPLES = ''' # What modules does for example - containers.podman.podman_save: - dest: /path/to/tar/file - compress: true - format: oci-dir + image: nginx + dest: /tmp/file123.tar +- containers.podman.podman_save: + image: + - nginx + - fedora + dest: /tmp/file456.tar + multi_image_archive: true ''' import os # noqa: E402 @@ -92,7 +98,8 @@ def save(module, executable): for param in module.params: if module.params[param] is not None and param in cmd_args: command += cmd_args[param] - command.append(module.params['image']) + for img in module.params['image']: + command.append(img) if module.params['force']: dest = module.params['dest'] if os.path.exists(dest): @@ -116,7 +123,7 @@ def save(module, executable): def main(): module = AnsibleModule( argument_spec=dict( - image=dict(type='str', required=True), + image=dict(type='list', elements='str', required=True), compress=dict(type='bool'), dest=dict(type='str', required=True, aliases=['path']), format=dict(type='str', choices=['docker-archive', 'oci-archive', 'oci-dir', 'docker-dir']), diff --git a/tests/integration/targets/podman_save/tasks/main.yml b/tests/integration/targets/podman_save/tasks/main.yml index 97c8a66f..f78753f7 100644 --- a/tests/integration/targets/podman_save/tasks/main.yml +++ b/tests/integration/targets/podman_save/tasks/main.yml @@ -2,12 +2,15 @@ - name: Pull image containers.podman.podman_image: executable: "{{ test_executable | default('podman') }}" - name: k8s.gcr.io/pause + name: "{{ item }}" + loop: + - registry.k8s.io/pause + - registry.k8s.io/coredns/coredns:v1.9.3 - name: Save image containers.podman.podman_save: executable: "{{ test_executable | default('podman') }}" - image: k8s.gcr.io/pause + image: registry.k8s.io/pause dest: /tmp/image.tar - name: Check file @@ -23,7 +26,7 @@ - name: Save image containers.podman.podman_save: executable: "{{ test_executable | default('podman') }}" - image: k8s.gcr.io/pause + image: registry.k8s.io/pause dest: /tmp/image.tar force: true @@ -40,7 +43,7 @@ - name: Save image containers.podman.podman_save: executable: "{{ test_executable | default('podman') }}" - image: k8s.gcr.io/pause + image: registry.k8s.io/pause dest: /tmp/imagedir format: oci-dir @@ -57,7 +60,7 @@ - name: Save image containers.podman.podman_save: executable: "{{ test_executable | default('podman') }}" - image: k8s.gcr.io/pause + image: registry.k8s.io/pause dest: /tmp/imagedir-docker force: true format: docker-dir @@ -66,7 +69,7 @@ - name: Save image containers.podman.podman_save: executable: "{{ test_executable | default('podman') }}" - image: k8s.gcr.io/pause + image: registry.k8s.io/pause dest: /tmp/imagedir force: true format: oci-dir @@ -84,7 +87,7 @@ - name: Save image containers.podman.podman_save: executable: "{{ test_executable | default('podman') }}" - image: k8s.gcr.io/pause + image: registry.k8s.io/pause dest: /tmp/image2.tar multi_image_archive: true @@ -97,3 +100,22 @@ assert: that: - img.stat.exists + +- name: Save multi image + containers.podman.podman_save: + executable: "{{ test_executable | default('podman') }}" + image: + - registry.k8s.io/pause + - registry.k8s.io/coredns/coredns:v1.9.3 + dest: /tmp/image-multi.tar + multi_image_archive: true + +- name: Check mult image file + stat: + path: /tmp/image-multi.tar + register: img + +- name: Check multi image is saved + assert: + that: + - img.stat.exists