Skip to content

Commit

Permalink
Fix multi-image support for podman_save (#672)
Browse files Browse the repository at this point in the history
Fix #670
Signed-off-by: Sagi Shnaidman <[email protected]>
  • Loading branch information
sshnaidm authored Nov 26, 2023
1 parent b7e8711 commit 59a0dee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
19 changes: 13 additions & 6 deletions plugins/modules/podman_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
image:
description:
- Image to save.
type: str
type: list
elements: str
required: true
compress:
description:
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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']),
Expand Down
36 changes: 29 additions & 7 deletions tests/integration/targets/podman_save/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

0 comments on commit 59a0dee

Please sign in to comment.