Skip to content

Commit

Permalink
setup become virtual provision test
Browse files Browse the repository at this point in the history
The virtual provision test includes the basic
functionality and also when using with usmak 0027

Signed-off-by: Carlos Rodriguez-Fernandez <[email protected]>
  • Loading branch information
carlosrodfern committed Dec 10, 2023
1 parent 9b5ad48 commit 1019b67
Show file tree
Hide file tree
Showing 23 changed files with 170 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/basic/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/basic/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/basic/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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

test "$(whoami)" == "root"
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/basic/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/basic/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/basic/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
1 change: 1 addition & 0 deletions tests/provision/become/virtual/umask/data/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
17 changes: 17 additions & 0 deletions tests/provision/become/virtual/umask/data/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
summary: Basic smoke test
provision:
how: virtual
image: fedora
user: fedora
become: true
discover:
tests:
- name: Beakerlib test to generate report files on guest
test: ./test.sh
framework: beakerlib
execute:
how: tmt
prepare:
how: shell
script: "echo 'umask 0027' >> /etc/profile; echo 'umask 0027' >> /etc/bashrc"

21 changes: 21 additions & 0 deletions tests/provision/become/virtual/umask/data/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
. /usr/share/beakerlib/beakerlib.sh || exit 1

rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
rlRun "set -o pipefail"
rlPhaseEnd

rlPhaseStartTest
rlRun -s "echo HELLO > output" 0 "Say something"
rlAssertGrep "HELLO" "output"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd
2 changes: 2 additions & 0 deletions tests/provision/become/virtual/umask/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
summary: Check that become works when instance umask is restricted
description: Ensures that become works when used in virtual instances with umask set to 0027 like in hardened OSs.
20 changes: 20 additions & 0 deletions tests/provision/become/virtual/umask/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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 "Test become=true with umask 0027"
rlRun "tmt run -rvvv --all"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlPhaseEnd
fi
rlJournalEnd

0 comments on commit 1019b67

Please sign in to comment.