From d2daf7262ebb140696b4afcfecd295ab940e307e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dost=C3=A1l?= Date: Tue, 5 Sep 2023 10:28:58 +0200 Subject: [PATCH] Optimize the podman_runlabel integration test (#640) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used [1] as example. [1]: https://fossies.org/linux/podman/test/system/037-runlabel.bats Signed-off-by: Pavel Dostál --- plugins/modules/podman_runlabel.py | 2 +- .../targets/podman_runlabel/files/Dockerfile | 34 ++----------------- .../targets/podman_runlabel/files/start.sh | 5 --- .../podman_runlabel/files/testinstall.sh | 2 ++ .../targets/podman_runlabel/tasks/main.yml | 21 ++++++------ 5 files changed, 16 insertions(+), 48 deletions(-) delete mode 100755 tests/integration/targets/podman_runlabel/files/start.sh create mode 100644 tests/integration/targets/podman_runlabel/files/testinstall.sh diff --git a/plugins/modules/podman_runlabel.py b/plugins/modules/podman_runlabel.py index a85ecbc..e5b6cf3 100644 --- a/plugins/modules/podman_runlabel.py +++ b/plugins/modules/podman_runlabel.py @@ -77,7 +77,7 @@ def main(): results = { "changed": changed, "stdout": out, - "stderr": err, + "stderr": err } module.exit_json(**results) diff --git a/tests/integration/targets/podman_runlabel/files/Dockerfile b/tests/integration/targets/podman_runlabel/files/Dockerfile index 36c24d0..8c97ff6 100644 --- a/tests/integration/targets/podman_runlabel/files/Dockerfile +++ b/tests/integration/targets/podman_runlabel/files/Dockerfile @@ -1,34 +1,6 @@ FROM alpine -LABEL "key"="amazing value" -LABEL nobody=cares -LABEL install="touch /tmp/testedinstallfortests" -LABEL run="touch /tmp/testedrunfortests" - -ARG build_arg - -ENV password root -ENV username root - -WORKDIR /work - -RUN adduser -D user && \ - adduser -D user2 - -COPY start.sh /start - -RUN chmod a+rwx /start - -EXPOSE 80 -EXPOSE 8080/tcp -VOLUME ["/data", "/data2"] -USER user -STOPSIGNAL KILL - -# problem with OS w/o systemd -# HEALTHCHECK --interval=5m --timeout=3s \ -# CMD date - -CMD ["1d"] -ENTRYPOINT ["/start"] +LABEL install="podman run --env IMAGE=IMAGE --rm IMAGE /bin/sh /testinstall.sh" +LABEL run="/usr/bin/touch /tmp/testedrunfortests" +ADD testinstall.sh / diff --git a/tests/integration/targets/podman_runlabel/files/start.sh b/tests/integration/targets/podman_runlabel/files/start.sh deleted file mode 100755 index 1217239..0000000 --- a/tests/integration/targets/podman_runlabel/files/start.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -s=${1:-"3h"} -sleep "$s" - diff --git a/tests/integration/targets/podman_runlabel/files/testinstall.sh b/tests/integration/targets/podman_runlabel/files/testinstall.sh new file mode 100644 index 0000000..d9fe1ee --- /dev/null +++ b/tests/integration/targets/podman_runlabel/files/testinstall.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo -n "Installed." diff --git a/tests/integration/targets/podman_runlabel/tasks/main.yml b/tests/integration/targets/podman_runlabel/tasks/main.yml index e4c4fcc..2ddc8bf 100644 --- a/tests/integration/targets/podman_runlabel/tasks/main.yml +++ b/tests/integration/targets/podman_runlabel/tasks/main.yml @@ -4,14 +4,14 @@ path: /tmp/usr_img state: directory -- name: Copy files to container build directory +- name: Copy Dockerfile to container build directory copy: src: "{{ item }}" dest: "/tmp/usr_img/{{ item }}" - mode: 777 + mode: 755 loop: - Dockerfile - - start.sh + - testinstall.sh - name: Build test docker image for regular user containers.podman.podman_image: @@ -22,21 +22,17 @@ format: docker extra_args: --cgroup-manager=cgroupfs -- name: Run container runlabel install +- name: Run container label install containers.podman.podman_runlabel: image: "{{ runlabel_image }}" label: install + register: install_runlabel -- name: Run container runlabel run +- name: Run container label run containers.podman.podman_runlabel: image: "{{ runlabel_image }}" label: run -- name: Check file for install exists - stat: - path: /tmp/testedinstallfortests - register: testedinstallfortests - - name: Check file for run exists stat: path: /tmp/testedrunfortests @@ -45,5 +41,8 @@ - name: Make sure files exist assert: that: - - testedinstallfortests.stat.exists - testedrunfortests.stat.exists + +- name: Make sure install label exited with 128 + assert: + that: install_runlabel.stdout == 'Installed.'