From 19f2c708e40e5a4e405516f8f3bad5ef951490b8 Mon Sep 17 00:00:00 2001 From: Xiaofeng Wang Date: Fri, 16 Aug 2024 00:02:43 +0800 Subject: [PATCH] test: add logically bound images Signed-off-by: Xiaofeng Wang --- tests/e2e/bootc-install.sh | 13 ++++++- tests/e2e/files/caddy.container | 11 ++++++ tests/e2e/files/node_exporter.container | 13 +++++++ tests/e2e/playbooks/check-system.yaml | 45 +++++++++++++++++++++++++ tests/e2e/playbooks/install.yaml | 7 ++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/files/caddy.container create mode 100644 tests/e2e/files/node_exporter.container diff --git a/tests/e2e/bootc-install.sh b/tests/e2e/bootc-install.sh index 154e4966a..015a55622 100755 --- a/tests/e2e/bootc-install.sh +++ b/tests/e2e/bootc-install.sh @@ -137,21 +137,30 @@ case "$TEST_CASE" in "to-existing-root") SSH_USER="root" SSH_KEY_PUB_CONTENT=$(cat "${SSH_KEY_PUB}") + mkdir -p "${TEMPDIR}/usr/share/containers/systemd" + cp files/caddy.container files/node_exporter.container "${TEMPDIR}/usr/share/containers/systemd" tee -a "$INSTALL_CONTAINERFILE" > /dev/null << EOF +COPY usr/ usr/ RUN mkdir -p /usr/etc-system/ && \ echo 'AuthorizedKeysFile /usr/etc-system/%u.keys' >> /etc/ssh/sshd_config.d/30-auth-system.conf && \ echo "$SSH_KEY_PUB_CONTENT" > /usr/etc-system/root.keys && \ chmod 0600 /usr/etc-system/root.keys && \ dnf -y install qemu-guest-agent && \ dnf clean all && \ - systemctl enable qemu-guest-agent + systemctl enable qemu-guest-agent && \ + ln -s /usr/share/containers/systemd/caddy.container /usr/lib/bootc/bound-images.d/caddy.container && \ + ln -s /usr/share/containers/systemd/node_exporter.container /usr/lib/bootc/bound-images.d/node_exporter.container EOF + # logical bound image + LBI="enabled" ;; "to-disk") tee -a "$INSTALL_CONTAINERFILE" > /dev/null << EOF RUN dnf -y install python3 cloud-init && \ dnf -y clean all EOF + # LBI is disabled in to-disk test + LBI="disabled" ;; esac @@ -264,6 +273,7 @@ ansible-playbook -v \ -e bootc_image="$TEST_IMAGE_URL" \ -e image_label_version_id="$REDHAT_VERSION_ID" \ -e kargs="mitigations=on,nosmt,console=ttyS0,panic=0" \ + -e lbi="$LBI" \ playbooks/check-system.yaml # Prepare upgrade containerfile @@ -309,6 +319,7 @@ ansible-playbook -v \ -e image_label_version_id="$REDHAT_VERSION_ID" \ -e upgrade="true" \ -e kargs="systemd.unified_cgroup_hierarchy=1,console=ttyS,panic=0" \ + -e lbi="$LBI" \ playbooks/check-system.yaml # bootc rollback test diff --git a/tests/e2e/files/caddy.container b/tests/e2e/files/caddy.container new file mode 100644 index 000000000..507917ef1 --- /dev/null +++ b/tests/e2e/files/caddy.container @@ -0,0 +1,11 @@ +[Unit] +Description=Run a demo webserver + +[Container] +GlobalArgs=--storage-opt=additionalimagestore=/usr/lib/bootc/storage +Image=docker.io/library/caddy:2.8.4 +PublishPort=80:80 +ReadOnly=true + +[Install] +WantedBy=default.target diff --git a/tests/e2e/files/node_exporter.container b/tests/e2e/files/node_exporter.container new file mode 100644 index 000000000..cf3a69c82 --- /dev/null +++ b/tests/e2e/files/node_exporter.container @@ -0,0 +1,13 @@ +[Unit] +Description=Prometheus node exporter + +[Container] +Network=host +PodmanArgs=--pid=host --storage-opt=additionalimagestore=/usr/lib/bootc/storage +Volume=/:/host,ro,rslave +Image=quay.io/prometheus/node-exporter:v1.8.2 +Exec=--path.rootfs=/host +ReadOnly=true + +[Install] +WantedBy=default.target diff --git a/tests/e2e/playbooks/check-system.yaml b/tests/e2e/playbooks/check-system.yaml index 793b87080..5e17e1133 100644 --- a/tests/e2e/playbooks/check-system.yaml +++ b/tests/e2e/playbooks/check-system.yaml @@ -5,6 +5,7 @@ bootc_image: "" upgrade: "" kargs: "" + lbi: "" total_counter: "0" failed_counter: "0" @@ -437,6 +438,50 @@ set_fact: failed_counter: "{{ failed_counter | int + 1 }}" + # case: check logically bound image caddy container status + - name: check LBI caddy container status + shell: podman ps --filter "name=systemd-caddy" --format json | jq -r '.[].State' + register: result_caddy_state + when: lbi == "enabled" + + - name: run caddy container status test + block: + - assert: + that: + - result_caddy_state.stdout == "running" + fail_msg: "failed to run caddy container" + success_msg: "running caddy container" + always: + - set_fact: + total_counter: "{{ total_counter | int + 1 }}" + rescue: + - name: failed count + 1 + set_fact: + failed_counter: "{{ failed_counter | int + 1 }}" + when: lbi == "enabled" + + # case: check logically bound image node_exporter container status + - name: check LBI node_exporter container status + shell: podman ps --filter "name=systemd-node_exporter" --format json | jq -r '.[].State' + register: result_node_exporter_state + when: lbi == "enabled" + + - name: run node_exporter container status test + block: + - assert: + that: + - result_node_exporter_state.stdout == "running" + fail_msg: "failed to run node_exporter container" + success_msg: "running node_exporter container" + always: + - set_fact: + total_counter: "{{ total_counter | int + 1 }}" + rescue: + - name: failed count + 1 + set_fact: + failed_counter: "{{ failed_counter | int + 1 }}" + when: lbi == "enabled" + # case: check system reboot - name: check system reboot block: diff --git a/tests/e2e/playbooks/install.yaml b/tests/e2e/playbooks/install.yaml index a3d8ca50e..876c0ddeb 100644 --- a/tests/e2e/playbooks/install.yaml +++ b/tests/e2e/playbooks/install.yaml @@ -40,6 +40,13 @@ command: dnf -y install podman become: true + - name: Pull logical bound image + command: podman pull --tls-verify=false {{ item }} + become: true + loop: + - "docker.io/library/caddy:2.8.4" + - "quay.io/prometheus/node-exporter:v1.8.2" + - name: Install image command: "podman run \