Skip to content

Commit

Permalink
Test become in virtual provision
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Rodriguez-Fernandez <[email protected]>
  • Loading branch information
carlosrodfern committed Jan 31, 2024
1 parent 195da33 commit ec94ffb
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 2 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/provision/become/container/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
summary: Check that become works on podman provision
description: Ensures that become works when used in containers.
File renamed without changes.
2 changes: 0 additions & 2 deletions tests/provision/become/main.fmf

This file was deleted.

1 change: 1 addition & 0 deletions tests/provision/become/virtual/data/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
7 changes: 7 additions & 0 deletions tests/provision/become/virtual/data/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provision:
how: virtual
image: fedora
user: fedora

execute:
how: tmt
36 changes: 36 additions & 0 deletions tests/provision/become/virtual/data/prepare-finish.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
discover:
tests:
- name: dummy-test
test: echo "pass"

/root:
provision+:
become: true

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

/scripts:
prepare:
script: scripts/is_root_test.sh
finish:
script: scripts/is_root_test.sh

/user:
provision+:
become: false

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

/scripts:
prepare:
script: scripts/is_user_test.sh
finish:
script: scripts/is_user_test.sh
3 changes: 3 additions & 0 deletions tests/provision/become/virtual/data/scripts/is_root_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

test "$(whoami)" == "root"
3 changes: 3 additions & 0 deletions tests/provision/become/virtual/data/scripts/is_user_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

test "$(whoami)" == "fedora"
15 changes: 15 additions & 0 deletions tests/provision/become/virtual/data/test.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/root:
provision+:
become: true
discover:
tests:
- name: user-is-root
test: test "$(whoami)" == "root"

/user:
provision+:
become: false
discover:
tests:
- name: user-is-user
test: test "$(whoami)" == "fedora"
2 changes: 2 additions & 0 deletions tests/provision/become/virtual/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
summary: Check that become works on virtual provision
description: Ensures that become works when used in virtual instances.
40 changes: 40 additions & 0 deletions tests/provision/become/virtual/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

PROVISION_METHODS=${PROVISION_METHODS:-virtual}

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

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

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

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

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

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

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

rlPhaseStartCleanup
rlRun "popd"
rlPhaseEnd
fi
rlJournalEnd

0 comments on commit ec94ffb

Please sign in to comment.