diff --git a/.cirrus.yml b/.cirrus.yml index f26f927fbd..b928d6601c 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -910,6 +910,24 @@ minikube_test_task: main_script: *main always: *logs_artifacts +farm_test_task: + name: *std_name_fmt + alias: farm_test + # Docs: ./contrib/cirrus/CIModes.md + only_if: *not_tag_build_docs + depends_on: + - build + - rootless_system_test + gce_instance: *standardvm + env: + <<: *stdenvars + TEST_FLAVOR: farm + PRIV_NAME: rootless + clone_script: *get_gosrc + setup_script: *setup + main_script: *main + always: *logs_artifacts + buildah_bud_test_task: name: *std_name_fmt alias: buildah_bud_test @@ -1054,6 +1072,7 @@ success_task: - rootless_system_test - rootless_remote_system_test - minikube_test + - farm_test - buildah_bud_test - rootless_buildah_bud_test - upgrade_test diff --git a/contrib/cirrus/lib.sh b/contrib/cirrus/lib.sh index 662f7b32c5..9e6938fbf5 100644 --- a/contrib/cirrus/lib.sh +++ b/contrib/cirrus/lib.sh @@ -137,7 +137,11 @@ setup_rootless() { # shellcheck disable=SC2154 if passwd --status $ROOTLESS_USER then - if [[ $PRIV_NAME = "rootless" ]]; then + # Farm tests utilize the rootless user to simulate a "remote" podman instance. + # Root still needs to own the repo. clone and all things under `$GOPATH`. The + # opposite is true for the lower-level podman e2e tests, the rootless user + # runs them, and therefore needs permissions. + if [[ $PRIV_NAME = "rootless" ]] && [[ "$TEST_FLAVOR" != "farm" ]]; then msg "Updating $ROOTLESS_USER user permissions on possibly changed libpod code" chown -R $ROOTLESS_USER:$ROOTLESS_USER "$GOPATH" "$GOSRC" return 0 @@ -184,6 +188,13 @@ setup_rootless() { # Maintain access-permission consistency with all other .ssh files. install -Z -m 700 -o $ROOTLESS_USER -g $ROOTLESS_USER \ /root/.ssh/known_hosts /home/$ROOTLESS_USER/.ssh/known_hosts + + if [[ -n "$ROOTLESS_USER" ]]; then + showrun echo "conditional setup for ROOTLESS_USER [=$ROOTLESS_USER]" + # Make all future CI scripts aware of these values + echo "ROOTLESS_USER=$ROOTLESS_USER" >> /etc/ci_environment + echo "ROOTLESS_UID=$ROOTLESS_UID" >> /etc/ci_environment + fi } install_test_configs() { diff --git a/contrib/cirrus/runner.sh b/contrib/cirrus/runner.sh index 798bac6bde..36c6e3352b 100755 --- a/contrib/cirrus/runner.sh +++ b/contrib/cirrus/runner.sh @@ -126,6 +126,12 @@ function _run_minikube() { showrun bats test/minikube |& logformatter } +function _run_farm() { + _bail_if_test_can_be_skipped test/farm test/system + msg "Testing podman farm." + showrun bats test/farm |& logformatter +} + exec_container() { local var_val local cmd diff --git a/contrib/cirrus/setup_environment.sh b/contrib/cirrus/setup_environment.sh index 0f4929f161..d8540d7f0d 100755 --- a/contrib/cirrus/setup_environment.sh +++ b/contrib/cirrus/setup_environment.sh @@ -269,13 +269,6 @@ case "$PRIV_NAME" in *) die_unknown PRIV_NAME esac -# shellcheck disable=SC2154 -if [[ -n "$ROOTLESS_USER" ]]; then - showrun echo "conditional setup for ROOTLESS_USER [=$ROOTLESS_USER]" - echo "ROOTLESS_USER=$ROOTLESS_USER" >> /etc/ci_environment - echo "ROOTLESS_UID=$ROOTLESS_UID" >> /etc/ci_environment -fi - # FIXME! experimental workaround for #16973, the "lookup cdn03.quay.io" flake. # # If you are reading this on or after April 2023: @@ -403,6 +396,13 @@ case "$TEST_FLAVOR" in die "Invalid value for \$TEST_ENVIRON=$TEST_ENVIRON" fi + install_test_configs + ;; + farm) + showrun loginctl enable-linger $ROOTLESS_USER + showrun ssh $ROOTLESS_USER@localhost systemctl --user enable --now podman.socket + remove_packaged_podman_files + showrun make install PREFIX=/usr ETCDIR=/etc install_test_configs ;; minikube) diff --git a/pkg/bindings/test/images_test.go b/pkg/bindings/test/images_test.go index 60eb1f56f4..06c939c8f1 100644 --- a/pkg/bindings/test/images_test.go +++ b/pkg/bindings/test/images_test.go @@ -9,6 +9,7 @@ import ( "time" podmanRegistry "github.com/containers/podman/v4/hack/podman-registry-go" + "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/bindings" "github.com/containers/podman/v4/pkg/bindings/containers" "github.com/containers/podman/v4/pkg/bindings/images" @@ -409,7 +410,8 @@ var _ = Describe("Podman images", func() { results, err := images.Build(bt.conn, []string{"fixture/Containerfile"}, entities.BuildOptions{}) Expect(err).ToNot(HaveOccurred()) Expect(*results).To(MatchFields(IgnoreMissing, Fields{ - "ID": Not(BeEmpty()), + "ID": Not(BeEmpty()), + "SaveFormat": ContainSubstring(define.OCIArchive), })) }) }) diff --git a/test/farm/001-farm.bats b/test/farm/001-farm.bats new file mode 100644 index 0000000000..1d960d9dc3 --- /dev/null +++ b/test/farm/001-farm.bats @@ -0,0 +1,77 @@ +#!/usr/bin/env bats +# +# Tests of podman farm commands +# + +load helpers.bash + +############################################################################### +# BEGIN tests + +fname="test-farm" +containerfile="test/farm/Containerfile" + +@test "farm - check farm has been created" { + run_podman farm ls + assert "$output" =~ $fname + assert "$output" =~ "test-node" +} + +@test "farm - build on local only" { + iname="test-image-1" + empty_farm="empty-farm" + # create an empty farm + run_podman farm create $empty_farm + run_podman farm --farm $empty_farm build -f $containerfile -t $iname . + assert "$output" =~ "Local builder ready" + # get the system architecture + run_podman info --format '{{.Host.Arch}}' + ARCH=$output + # inspect manifest list built and saved in local containers-storage + run_podman manifest inspect $iname + assert "$output" =~ $ARCH +} + +@test "farm - build on farm node only with --cleanup" { + iname="test-image-2" + run_podman farm build -f $containerfile --cleanup --local=false -t $iname . + assert "$output" =~ "Farm \"$fname\" ready" + # get the system architecture + run_podman info --format '{{.Host.Arch}}' + ARCH=$output + # inspect manifest list built and saved in dir + manifest=$(cat $iname/manifest.json) + assert "$manifest" =~ $ARCH + # see if we can ssh into node to check the image was cleaned up + nodeimg=$(ssh $ROOTLESS_USER@localhost podman images --filter dangling=true --noheading 2>&1) + assert "$nodeimg" = "" + # check that no image was built locally + run_podman images --filter dangling=true --noheading + assert "$output" = "" +} + +@test "farm - build on farm node and local" { + iname="test-image-3" + run_podman farm build -f $containerfile -t $iname . + assert "$output" =~ "Farm \"$fname\" ready" + # get the system architecture + run_podman info --format '{{.Host.Arch}}' + ARCH=$output + # inspect manifest list built and saved in dir + run_podman manifest inspect $iname + assert "$output" =~ $ARCH +} + +# Test out podman-remote + +@test "farm - build on farm node only (podman-remote)" { + iname="test-image-4" + run_podman --remote farm build -f $containerfile -t $iname . + assert "$output" =~ "Farm \"$fname\" ready" + # get the system architecture + run_podman --remote info --format '{{.Host.Arch}}' + ARCH=$output + # inspect manifest list built and saved in dir + manifest=$(cat $iname/manifest.json) + assert "$manifest" =~ $ARCH +} diff --git a/test/farm/Containerfile b/test/farm/Containerfile new file mode 100644 index 0000000000..feb5d5cb53 --- /dev/null +++ b/test/farm/Containerfile @@ -0,0 +1,3 @@ +FROM alpine +RUN arch | tee /arch.txt +RUN date | tee /built.txt diff --git a/test/farm/helpers.bash b/test/farm/helpers.bash new file mode 100644 index 0000000000..a02dae7b86 --- /dev/null +++ b/test/farm/helpers.bash @@ -0,0 +1,11 @@ +# -*- bash -*- + +load ../system/helpers.bash + +function setup(){ + basic_setup +} + +function teardown(){ + basic_teardown +} diff --git a/test/farm/setup_suite.bash b/test/farm/setup_suite.bash new file mode 100644 index 0000000000..06a6b8910b --- /dev/null +++ b/test/farm/setup_suite.bash @@ -0,0 +1,14 @@ +# -*- bash -*- + +load helpers.bash + +function setup_suite(){ + # only set up the podman farm before the first test + run_podman system connection add --identity /home/$ROOTLESS_USER/.ssh/id_rsa test-node $ROOTLESS_USER@localhost + run_podman farm create test-farm test-node +} + +function teardown(){ + # clear out the farms after the last farm test + run podman farm rm --all +}