Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the become key under virtual provision #2659

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/provision/become/data/Containerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM quay.io/fedora/fedora:latest

RUN useradd user; usermod -aG wheel user; echo -e 'user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
RUN useradd fedora; usermod -aG wheel fedora; echo -e 'fedora\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers

USER user
USER fedora
13 changes: 10 additions & 3 deletions tests/provision/become/data/main.fmf
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
provision:
how: container
image: localhost/become-container-test:latest
user: user
user: fedora
adjust:
- when: provisiontest == virtual
provision+:
how: virtual
image: fedora
- when: provisiontest == container
provision+:
how: container
image: localhost/become-container-test:latest

execute:
how: tmt
4 changes: 2 additions & 2 deletions tests/provision/become/data/prepare-finish.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ discover:

/inline:
prepare:
script: test "$(whoami)" == "user"
script: test "$(whoami)" == "fedora"
finish:
script: test "$(whoami)" == "user"
script: test "$(whoami)" == "fedora"

/scripts:
prepare:
Expand Down
2 changes: 1 addition & 1 deletion tests/provision/become/data/scripts/is_user_test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash -e

test "$(whoami)" == "user"
test "$(whoami)" == "fedora"
2 changes: 1 addition & 1 deletion tests/provision/become/data/test.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
discover:
tests:
- name: user-is-user
test: test "$(whoami)" == "user"
test: test "$(whoami)" == "fedora"
7 changes: 5 additions & 2 deletions tests/provision/become/main.fmf
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
summary: Check that become works
description: As for now covers podman provision only.
summary: Check that become works on virtual and container provision
description: Ensures that become works when used in virtual instances and on containers.
tag+: [provision-virtual,provision-container]
duration: 20m
tier: null
75 changes: 41 additions & 34 deletions tests/provision/become/test.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

PROVISION_METHODS=${PROVISION_METHODS:-container}
PROVISION_METHODS=${PROVISION_METHODS:-container virtual}

rlJournalStart
if [[ "$PROVISION_METHODS" =~ container ]]; then
rlPhaseStartSetup
rlRun "pushd data"

rlPhaseStartSetup
rlRun "pushd data"
if [[ "$PROVISION_METHODS" =~ "container" ]]; then
# Try several times to build the container
# https:/teemtee/tmt/issues/2063
build="podman build -t become-container-test:latest ."
rlRun "rlWaitForCmd '$build' -m 5 -d 5" || rlDie "Unable to prepare the image"
rlPhaseEnd

rlPhaseStartTest "Container, test with become=true"
rlRun "tmt run -rvvv plan --name /test/root"
rlPhaseEnd

rlPhaseStartTest "Container, test with become=false"
rlRun "tmt run -rvvv plan --name /test/user"
rlPhaseEnd

rlPhaseStartTest "Container, prepare/finish inline with become=true"
rlRun "tmt run -rvvv plan --name /prepare-finish/root/inline"
rlPhaseEnd

rlPhaseStartTest "Container, prepare/finish inline with become=false"
rlRun "tmt run -rvvv plan --name /prepare-finish/user/inline"
rlPhaseEnd

rlPhaseStartTest "Container, prepare/finish scripts with become=true"
rlRun "tmt run -rvvv plan --name /prepare-finish/root/scripts"
rlPhaseEnd

rlPhaseStartTest "Container, prepare/finish scripts with become=false"
rlRun "tmt run -rvvv plan --name /prepare-finish/user/scripts"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
fi
rlPhaseEnd

for method in ${PROVISION_METHODS}; do
if [ "$method" = "container" ] || [ "$method" = "virtual" ]; then
rlPhaseStartTest "$method, test with become=true"
rlRun "tmt --context provisiontest=$method run -rvvv plan --name /test/root"
rlPhaseEnd

rlPhaseStartTest "$method, test with become=false"
rlRun "tmt --context provisiontest=$method run -rvvv plan --name /test/user"
rlPhaseEnd

rlPhaseStartTest "$method, prepare/finish inline with become=true"
rlRun "tmt --context provisiontest=$method run -rvvv plan --name /prepare-finish/root/inline"
rlPhaseEnd

rlPhaseStartTest "$method, prepare/finish inline with become=false"
rlRun "tmt --context provisiontest=$method run -rvvv plan --name /prepare-finish/user/inline"
rlPhaseEnd

rlPhaseStartTest "$method, prepare/finish scripts with become=true"
rlRun "tmt --context provisiontest=$method run -rvvv plan --name /prepare-finish/root/scripts"
rlPhaseEnd

rlPhaseStartTest "$method, prepare/finish scripts with become=false"
rlRun "tmt --context provisiontest=$method run -rvvv plan --name /prepare-finish/user/scripts"
rlPhaseEnd
fi
done

rlPhaseStartCleanup
rlRun "popd"
if [[ "$PROVISION_METHODS" =~ "container" ]]; then
rlRun "podman image rm -f localhost/become-container-test:latest" 0 "Remove custom image"
rlPhaseEnd
fi
fi
rlPhaseEnd
rlJournalEnd
Loading