Skip to content

Commit f577208

Browse files
Add FMF tests and test scripts
1 parent 86f674b commit f577208

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

.fmf/version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

plans/all.fmf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
discover:
2+
how: fmf
3+
execute:
4+
how: tmt
5+
6+
/system:
7+
summary: Run tests on system podman
8+
discover+:
9+
test: /test/browser/system
10+
11+
/user:
12+
summary: Run tests on user podman
13+
discover+:
14+
test: /test/browser/user
15+
16+
/misc:
17+
summary: Run other tests
18+
discover+:
19+
test: /test/browser/other

test/browser/browser.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
set -eux
3+
4+
TESTS="$(realpath $(dirname "$0"))"
5+
SOURCE="$(realpath $TESTS/../..)"
6+
LOGS="$(pwd)/logs"
7+
mkdir -p "$LOGS"
8+
chmod a+w "$LOGS"
9+
10+
# HACK: https://bugzilla.redhat.com/show_bug.cgi?id=2033020
11+
dnf update -y pam || true
12+
13+
# install firefox (available everywhere in Fedora and RHEL)
14+
# we don't need the H.264 codec, and it is sometimes not available (rhbz#2005760)
15+
dnf install --disablerepo=fedora-cisco-openh264 -y --setopt=install_weak_deps=False firefox
16+
17+
# nodejs 10 is too old for current Cockpit test API
18+
if grep -q platform:el8 /etc/os-release; then
19+
dnf module switch-to -y nodejs:16
20+
fi
21+
22+
# create user account for logging in
23+
if ! id admin 2>/dev/null; then
24+
useradd -c Administrator -G wheel admin
25+
echo admin:foobar | chpasswd
26+
fi
27+
28+
# set root's password
29+
echo root:foobar | chpasswd
30+
31+
# avoid sudo lecture during tests
32+
su -c 'echo foobar | sudo --stdin whoami' - admin
33+
34+
# create user account for running the test
35+
if ! id runtest 2>/dev/null; then
36+
useradd -c 'Test runner' runtest
37+
# allow test to set up things on the machine
38+
mkdir -p /root/.ssh
39+
curl https://raw.githubusercontent.com/cockpit-project/bots/main/machine/identity.pub >> /root/.ssh/authorized_keys
40+
chmod 600 /root/.ssh/authorized_keys
41+
fi
42+
chown -R runtest "$SOURCE"
43+
44+
# disable core dumps, we rather investigate them upstream where test VMs are accessible
45+
echo core > /proc/sys/kernel/core_pattern
46+
47+
## CSR specific setup ##
48+
# install cockpit-packagekit and glibc-langpack-en for testAppMenu
49+
dnf install -y cockpit-packagekit glibc-langpack-en
50+
51+
mkdir -p /var/log/journal/
52+
cp 1.journal /var/log/journal/1.journal
53+
cp binary-rec.journal /var/log/journal/binary-rec.journal
54+
55+
# Add proxy provider domain for sssd for testSessionRecordingConf test
56+
cat > /etc/sssd/sssd.conf <<EOF
57+
[sssd]
58+
services=nss, pam
59+
domains=nssfiles
60+
61+
[domain/nssfiles]
62+
id_provider=proxy
63+
proxy_lib_name=files
64+
proxy_pam_target=sssd-shadowutils
65+
EOF
66+
chmod 600 /etc/sssd/sssd.conf
67+
systemctl start sssd
68+
69+
systemctl enable --now cockpit.socket
70+
71+
# Run tests as unprivileged user
72+
su - -c "env TEST_BROWSER=firefox SOURCE=$SOURCE LOGS=$LOGS $TESTS/run-test.sh" runtest
73+
74+
RC=$(cat $LOGS/exitcode)
75+
exit ${RC:-1}

test/browser/main.fmf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require:
2+
- cockpit-session-recording
3+
- tlog
4+
- cockpit-ws
5+
- cockpit-system
6+
- cockpit-packagekit
7+
- bzip2
8+
- git-core
9+
- libvirt-python3
10+
- make
11+
- nodejs
12+
- python3
13+
duration: 30m
14+
15+
/system:
16+
test: ./browser.sh system
17+
summary: Run *System tests
18+
19+
/user:
20+
test: ./browser.sh user
21+
summary: Run *User tests
22+
23+
/other:
24+
test: ./browser.sh other
25+
summary: Run all other tests

test/browser/run-test.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
set -eux
3+
4+
PLAN="$1"
5+
6+
# tests need cockpit's bots/ libraries and test infrastructure
7+
cd $SOURCE
8+
rm -f bots # common local case: existing bots symlink
9+
make bots test/common
10+
11+
if [ -e .git ]; then
12+
tools/node-modules checkout
13+
# disable detection of affected tests; testing takes too long as there is no parallelization
14+
mv .git dot-git
15+
else
16+
# upstream tarballs ship test dependencies; print version for debugging
17+
grep '"version"' node_modules/chrome-remote-interface/package.json
18+
fi
19+
20+
. /etc/os-release
21+
export TEST_OS="${ID}-${VERSION_ID/./-}"
22+
export TEST_AUDIT_NO_SELINUX=1
23+
24+
if [ "${TEST_OS#centos-}" != "$TEST_OS" ]; then
25+
TEST_OS="${TEST_OS}-stream"
26+
fi
27+
28+
# select subset of tests according to plan
29+
TESTS="$(test/common/run-tests -l)"
30+
case "$PLAN" in
31+
system) TESTS="$(echo "$TESTS" | grep 'System$')" ;;
32+
user) TESTS="$(echo "$TESTS" | grep 'User$')" ;;
33+
other) TESTS="$(echo "$TESTS" | grep -vE '(System|User)$')" ;;
34+
*) echo "Unknown test plan: $PLAN" >&2; exit 1 ;;
35+
esac
36+
37+
EXCLUDES=""
38+
39+
RC=0
40+
test/common/run-tests --nondestructive --machine 127.0.0.1:22 --browser 127.0.0.1:9090 $TESTS $EXCLUDES || RC=$?
41+
42+
echo $RC > "$LOGS/exitcode"
43+
cp --verbose Test* "$LOGS" || true
44+
# deliver test result via exitcode file
45+
exit 0

0 commit comments

Comments
 (0)