Skip to content

Commit

Permalink
plugins: Add bootc provision plugin
Browse files Browse the repository at this point in the history
This creates a new provision plugin that is built on top of the existing
TestCloud (virtual) plugin. It adds new parameters to pass a
Containerfile or container image. The plugin will then build a container
image (if necessary) then build a bootc disk image from the container
image using bootc image builder. Currently, bootc requires podman to be
run as root when building a disk image. This is typically handled by
running a podman machine as root.

An additional parameter "add-deps" toggles building a derived container
image with the tmt test requirements.

Signed-off-by: Chris Kyrouac <ckyrouac@redhat.com>
  • Loading branch information
ckyrouac committed Sep 10, 2024
1 parent 54dfd29 commit e3058f9
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 0 deletions.
34 changes: 34 additions & 0 deletions plans/provision/bootc.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
summary: Bootc virtual machine via testcloud

description: |
bootc tests

discover:
how: fmf
filter: 'tag:provision-bootc'


environment:
PROVISION_HOW: virtual

adjust+:
- enabled: true
when: how == provision

- provision:
hardware:
virtualization:
is-supported: true
memory: ">= 4 GB"
when: trigger == commit

- prepare+:
- name: Disable IPv6
how: shell
script:
- sysctl -w net.ipv6.conf.all.disable_ipv6=1
- sysctl -w net.ipv6.conf.default.disable_ipv6=1
because: Disable IPv6 in CI to avoid IPv6 connections that are disabled in CI
when: trigger == commit

enabled: true
1 change: 1 addition & 0 deletions tests/provision/bootc/data/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
13 changes: 13 additions & 0 deletions tests/provision/bootc/data/containerfile_includes_deps.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
execute:
how: tmt
discover:
how: shell
tests:
- name: booted image
test: bootc status && bootc status | grep localhost/tmtbase
provision:
how: bootc
add-deps: false
containerfile: "$TMT_BOOTC_CONTAINERFILE_RUNDIR/includes_deps.containerfile"
containerfile-workdir: .
disk: 20
13 changes: 13 additions & 0 deletions tests/provision/bootc/data/containerfile_needs_deps.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
execute:
how: tmt
discover:
how: shell
tests:
- name: booted image
test: bootc status | grep localhost/tmtmodified
provision:
how: bootc
add-deps: true
containerfile: "$TMT_BOOTC_CONTAINERFILE_RUNDIR/needs_deps.containerfile"
containerfile-workdir: .
disk: 20
12 changes: 12 additions & 0 deletions tests/provision/bootc/data/image_includes_deps.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
execute:
how: tmt
discover:
how: shell
tests:
- name: booted image
test: bootc status | grep localhost/tmt-bootc-includes-deps
provision:
how: bootc
add-deps: false
containerimage: localhost/tmt-bootc-includes-deps
disk: 20
12 changes: 12 additions & 0 deletions tests/provision/bootc/data/image_needs_deps.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
execute:
how: tmt
discover:
how: shell
tests:
- name: booted image
test: bootc status | grep localhost/tmtmodified
provision:
how: bootc
add-deps: true
containerimage: localhost/tmt-bootc-needs-deps
disk: 20
6 changes: 6 additions & 0 deletions tests/provision/bootc/data/includes_deps.containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM quay.io/centos-bootc/centos-bootc:stream9

RUN dnf -y install cloud-init rsync && \
ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \
rm /usr/local -rf && ln -sr /var/usrlocal /usr/local && mkdir -p /var/usrlocal/bin && \
dnf clean all
1 change: 1 addition & 0 deletions tests/provision/bootc/data/needs_deps.containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM quay.io/centos-bootc/centos-bootc:stream9
6 changes: 6 additions & 0 deletions tests/provision/bootc/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
summary: Make sure that bootc provision method works
tag+:
- provision-only
- provision-bootc
require:
- tmt+provision-virtual
63 changes: 63 additions & 0 deletions tests/provision/bootc/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

IMAGE_NEEDS_DEPS="localhost/tmt-bootc-needs-deps"
IMAGE_NEEDS_DEPS_PLAN="$(pwd)/data/image_needs_deps.fmf"
IMAGE_INCLUDES_DEPS="localhost/tmt-bootc-includes-deps"
IMAGE_INCLUDES_DEPS_PLAN="$(pwd)/data/image_includes_deps.fmf"

CONTAINERFILE_NEEDS_DEPS="$(pwd)/data/needs_deps.containerfile"
CONTAINERFILE_NEEDS_DEPS_PLAN="$(pwd)/data/containerfile_needs_deps.fmf"
CONTAINERFILE_INCLUDES_DEPS="$(pwd)/data/includes_deps.containerfile"
CONTAINERFILE_INCLUDES_DEPS_PLAN="$(pwd)/data/containerfile_includes_deps.fmf"


rlJournalStart
rlPhaseStartSetup
# cleanup previous runs
test -d /var/tmp/tmt/testcloud && rlRun "rm -rf /var/tmp/tmt/testcloud"

# use /var/tmp/tmt so the temp directories are accessible
# in the podman machine mount
rlRun "tmp=\$(mktemp -d --tmpdir=/var/tmp/tmt)" 0 "Create tmp directory"
rlRun "run=\$(mktemp -d --tmpdir=/var/tmp/tmt)" 0 "Create run directory"
rlRun "pushd $tmp"
rlRun "set -o pipefail"
rlRun "tmt init"
rlPhaseEnd

rlPhaseStartTest "Image that needs dependencies"
rlRun "podman build . -f $CONTAINERFILE_NEEDS_DEPS -t $IMAGE_NEEDS_DEPS"
rlRun "cp $IMAGE_NEEDS_DEPS_PLAN ."
rlRun "tmt -vvvvv run -i $run"
rlPhaseEnd

rlPhaseStartTest "Image that already includes dependencies"
rlRun "podman build . -f $CONTAINERFILE_INCLUDES_DEPS -t $IMAGE_INCLUDES_DEPS"
rlRun "cp $IMAGE_INCLUDES_DEPS_PLAN ."
rlRun "tmt -vvvvv run -i $run"
rlPhaseEnd

rlPhaseStartTest "Containerfile that needs dependencies"
rlRun "cp $CONTAINERFILE_NEEDS_DEPS_PLAN ."
rlRun "cp $CONTAINERFILE_NEEDS_DEPS $run"
rlRun "tmt -vvvvv run --environment TMT_BOOTC_CONTAINERFILE_RUNDIR=$run -i $run"
rlPhaseEnd

rlPhaseStartTest "Containerfile that already includes dependencies"
rlRun "cp $CONTAINERFILE_INCLUDES_DEPS_PLAN ."
rlRun "cp $CONTAINERFILE_INCLUDES_DEPS $run"
rlRun "tmt -vvvvv run --environment TMT_BOOTC_CONTAINERFILE_RUNDIR=$run -i $run"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlRun "rm -r $run" 0 "Remove run directory"

rlRun "podman rmi $IMAGE_INCLUDES_DEPS" 0,1
rlRun "podman rmi $IMAGE_NEEDS_DEPS" 0,1

test -d /var/tmp/tmt/testcloud && rlRun "rm -rf /var/tmp/tmt/testcloud"
rlPhaseEnd
rlJournalEnd
Loading

0 comments on commit e3058f9

Please sign in to comment.