From 0ad6a1b3fbd3feaf72bb6cfe4838b6b448c35ad8 Mon Sep 17 00:00:00 2001 From: Nikola Davidova Date: Thu, 4 Sep 2025 15:06:25 +0200 Subject: [PATCH 1/6] Add container tests to pipeline --- .github/workflows/testing-farm.yaml | 86 ++++++++++++++++++++++++ tmt/plans/fedora-container-init.fmf | 12 ++++ tmt/plans/fedora-container-upgrade.fmf | 12 ++++ tmt/tests/container/sanity/init/main.fmf | 2 +- 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 tmt/plans/fedora-container-init.fmf create mode 100644 tmt/plans/fedora-container-upgrade.fmf diff --git a/.github/workflows/testing-farm.yaml b/.github/workflows/testing-farm.yaml index 49c6857..f6fb1b9 100644 --- a/.github/workflows/testing-farm.yaml +++ b/.github/workflows/testing-farm.yaml @@ -88,3 +88,89 @@ jobs: update_pull_request_status: "true" create_github_summary: "true" variables: "REPO_URL=${{ github.server_url }}/${{ github.repository }};PR_HEAD=${{ github.event.pull_request.head.sha }};" + container-test-init: + runs-on: ubuntu-latest + + + permissions: + contents: read + pull-requests: write + statuses: write + + steps: + - name: Get User Permission + id: checkAccess + uses: actions-cool/check-user-permission@v2 + with: + require: write + username: ${{ github.triggering_actor }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check User Permission + if: steps.checkAccess.outputs.require-result == 'false' + run: | + echo "${{ github.triggering_actor }} does not have permissions on this repo." + echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" + echo "Job originally triggered by ${{ github.actor }}" + exit 1 + + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Test init on Fedora container + uses: sclorg/testing-farm-as-github-action@main + with: + api_key: ${{ secrets.TESTING_FARM_API_TOKEN }} + compose: null + tmt_path: "tmt" + tmt_plan_regex: "fedora-container-init" + pull_request_status_name: "Fedora container init test" + update_pull_request_status: "true" + create_github_summary: "true" + variables: "REPO_URL=${{ github.server_url }}/${{ github.repository }};PR_HEAD=${{ github.event.pull_request.head.sha }};" + + container-test-upgrade: + runs-on: ubuntu-latest + + permissions: + contents: read + pull-requests: write + statuses: write + + steps: + - name: Get User Permission + id: checkAccess + uses: actions-cool/check-user-permission@v2 + with: + require: write + username: ${{ github.triggering_actor }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check User Permission + if: steps.checkAccess.outputs.require-result == 'false' + run: | + echo "${{ github.triggering_actor }} does not have permissions on this repo." + echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" + echo "Job originally triggered by ${{ github.actor }}" + exit 1 + + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Test upgrade on Fedora container + uses: sclorg/testing-farm-as-github-action@main + with: + api_key: ${{ secrets.TESTING_FARM_API_TOKEN }} + compose: null + tmt_path: "tmt" + tmt_plan_regex: "fedora-container-upgrade" + pull_request_status_name: "Fedora container upgrade test" + update_pull_request_status: "true" + create_github_summary: "true" + variables: "REPO_URL=${{ github.server_url }}/${{ github.repository }};PR_HEAD=${{ github.event.pull_request.head.sha }};" diff --git a/tmt/plans/fedora-container-init.fmf b/tmt/plans/fedora-container-init.fmf new file mode 100644 index 0000000..879a783 --- /dev/null +++ b/tmt/plans/fedora-container-init.fmf @@ -0,0 +1,12 @@ +name: /plans/fedora-init-container +summary: Run init test in a fedora container environment +provision: + how: container + image: fedora:latest +discover: + how: fmf + filter: tag:fedora-container-init +execute: + how: tmt + + diff --git a/tmt/plans/fedora-container-upgrade.fmf b/tmt/plans/fedora-container-upgrade.fmf new file mode 100644 index 0000000..d55484f --- /dev/null +++ b/tmt/plans/fedora-container-upgrade.fmf @@ -0,0 +1,12 @@ +name: /plans/fedora-upgrade-container +summary: Run upgrade test in a fedora container environment +provision: + how: container + image: fedora +discover: + how: fmf + filter: tag:fedora-container-upgrade +execute: + how: tmt + + diff --git a/tmt/tests/container/sanity/init/main.fmf b/tmt/tests/container/sanity/init/main.fmf index df0390a..6fa02b2 100644 --- a/tmt/tests/container/sanity/init/main.fmf +++ b/tmt/tests/container/sanity/init/main.fmf @@ -14,6 +14,6 @@ require: test: ./init.sh framework: shell duration: 10m -tag: container-init-fedora +tag: fedora-container-init contact: ndavidov@redhat.com From 50a49f8be92821b42d836180fd51dfcd4f9194d3 Mon Sep 17 00:00:00 2001 From: Nikola Davidova Date: Thu, 4 Sep 2025 15:09:57 +0200 Subject: [PATCH 2/6] Use /tmp for socket/lock files --- tmt/tests/container/sanity/init/init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmt/tests/container/sanity/init/init.sh b/tmt/tests/container/sanity/init/init.sh index 6bd4bac..b4e830b 100755 --- a/tmt/tests/container/sanity/init/init.sh +++ b/tmt/tests/container/sanity/init/init.sh @@ -20,7 +20,7 @@ make PGDATA=/var/lib/pgsql/data LOGFILE=/var/lib/pgsql/logfile su - postgres -c " -/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE start -pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } +/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o \"-c unix_socket_directories=/tmp\" start +/usr/bin/pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } " From e12715d3d7ab3b96a4313ce2b8886dea8b9f81c2 Mon Sep 17 00:00:00 2001 From: Nikola Davidova Date: Mon, 8 Sep 2025 12:30:08 +0200 Subject: [PATCH 3/6] Add container upgrade test --- tmt/tests/container/sanity/upgrade/main.fmf | 19 ++++++ tmt/tests/container/sanity/upgrade/upgrade.sh | 66 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tmt/tests/container/sanity/upgrade/main.fmf create mode 100755 tmt/tests/container/sanity/upgrade/upgrade.sh diff --git a/tmt/tests/container/sanity/upgrade/main.fmf b/tmt/tests/container/sanity/upgrade/main.fmf new file mode 100644 index 0000000..da425e2 --- /dev/null +++ b/tmt/tests/container/sanity/upgrade/main.fmf @@ -0,0 +1,19 @@ +summary: Postgresql-setup upgrade test in a fedora rawhide container +require: + - make + - m4 + - docbook-utils + - help2man + - elinks + - postgresql-server + - coreutils + - autoconf + - automake + - autoconf-archive + - git +test: ./upgrade.sh +framework: shell +duration: 10m +tag: fedora-container-upgrade +contact: ndavidov@redhat.com + diff --git a/tmt/tests/container/sanity/upgrade/upgrade.sh b/tmt/tests/container/sanity/upgrade/upgrade.sh new file mode 100755 index 0000000..9b20364 --- /dev/null +++ b/tmt/tests/container/sanity/upgrade/upgrade.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# prep +git clone "$REPO_URL" repo +cd repo +git fetch origin "$PR_HEAD" +git checkout FETCH_HEAD + +grep -q systemd /proc/1/comm +echo "Return value CONTAINER: $?" + +# setup +autoreconf -vfi +./configure --prefix=/usr +make + +# initialization +./bin/postgresql-setup --init + +# start postgresql and check if it's running +PGDATA=/var/lib/pgsql/data +LOGFILE=/var/lib/pgsql/logfile +su - postgres -c " +/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o \"-c unix_socket_directories=/tmp\" start +/usr/bin/pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } +" + +# insert data +su - postgres -c " +echo \"User switched\"; + +createdb -h /tmp testdb; +psql -h /tmp -U postgres -d testdb -c \"create table users (id serial primary key, name text)\"; +psql -h /tmp -U postgres -d testdb -c \"insert into users (name) values ('Alice'), ('Bob'), ('Celine')\" +" +su - postgres -c ' +psql -h /tmp -U postgres -d testdb -c "select * from users" +' > expected.txt + +echo "Expected:" +cat expected.txt + +test $(wc -l < expected.txt) -gt 0 || { echo "ERROR: expected.txt is empty!"; exit 1; } + +# uninstall postgresql +dnf -y remove postgresql-server postgresql-private-libs postgresql libicu + +# install postgresql17 +dnf -y install postgresql17-upgrade + +# run --upgrade +./bin/postgresql-setup --upgrade + +su - postgres -c " +/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o \"-c unix_socket_directories=/tmp\" start +/usr/bin/pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } +" + +su - postgres -c ' +psql -h /tmp -U postgres -d testdb -c "select * from users" +' > actual.txt + +echo "Actual:" +cat actual.txt + +diff -q expected.txt actual.txt && echo "Actual and expected outputs match" || { echo "Actual and expected outputs differ"; exit 1; } + From 1d41180363e0b954d19f230671f5d5045bf155cb Mon Sep 17 00:00:00 2001 From: Nikola Davidova Date: Wed, 10 Sep 2025 09:29:14 +0200 Subject: [PATCH 4/6] Edit socket directory --- tmt/tests/container/sanity/init/init.sh | 7 ++++++- tmt/tests/container/sanity/upgrade/upgrade.sh | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tmt/tests/container/sanity/init/init.sh b/tmt/tests/container/sanity/init/init.sh index b4e830b..e8b20d8 100755 --- a/tmt/tests/container/sanity/init/init.sh +++ b/tmt/tests/container/sanity/init/init.sh @@ -16,11 +16,16 @@ make # initialization ./bin/postgresql-setup --init +# create socket directory +mkdir -p /var/run/postgresql +chown postgres:postgres /var/run/postgresql +chmod 2775 /var/run/postgresql + # start postgresql and check if it's running PGDATA=/var/lib/pgsql/data LOGFILE=/var/lib/pgsql/logfile su - postgres -c " -/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o \"-c unix_socket_directories=/tmp\" start +/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE start /usr/bin/pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } " diff --git a/tmt/tests/container/sanity/upgrade/upgrade.sh b/tmt/tests/container/sanity/upgrade/upgrade.sh index 9b20364..2708dec 100755 --- a/tmt/tests/container/sanity/upgrade/upgrade.sh +++ b/tmt/tests/container/sanity/upgrade/upgrade.sh @@ -16,11 +16,16 @@ make # initialization ./bin/postgresql-setup --init +# Create unix_socket directory +mkdir -p /var/run/postgresql +chown postgres:postgres /var/run/postgresql +chmod 2775 /var/run/postgresql + # start postgresql and check if it's running PGDATA=/var/lib/pgsql/data LOGFILE=/var/lib/pgsql/logfile su - postgres -c " -/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o \"-c unix_socket_directories=/tmp\" start +/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE start /usr/bin/pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } " @@ -28,12 +33,12 @@ su - postgres -c " su - postgres -c " echo \"User switched\"; -createdb -h /tmp testdb; -psql -h /tmp -U postgres -d testdb -c \"create table users (id serial primary key, name text)\"; -psql -h /tmp -U postgres -d testdb -c \"insert into users (name) values ('Alice'), ('Bob'), ('Celine')\" +createdb testdb; +psql -U postgres -d testdb -c \"create table users (id serial primary key, name text)\"; +psql -U postgres -d testdb -c \"insert into users (name) values ('Alice'), ('Bob'), ('Celine')\" " su - postgres -c ' -psql -h /tmp -U postgres -d testdb -c "select * from users" +psql -U postgres -d testdb -c "select * from users" ' > expected.txt echo "Expected:" @@ -51,12 +56,12 @@ dnf -y install postgresql17-upgrade ./bin/postgresql-setup --upgrade su - postgres -c " -/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o \"-c unix_socket_directories=/tmp\" start +/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o start /usr/bin/pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } " su - postgres -c ' -psql -h /tmp -U postgres -d testdb -c "select * from users" +psql -U postgres -d testdb -c "select * from users" ' > actual.txt echo "Actual:" From 6635ff617b3ca05c2846e0bdc793e8f363e74d94 Mon Sep 17 00:00:00 2001 From: Nikola Davidova Date: Wed, 10 Sep 2025 09:35:19 +0200 Subject: [PATCH 5/6] Add debugging echos --- tmt/tests/container/sanity/init/init.sh | 1 + tmt/tests/container/sanity/upgrade/upgrade.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/tmt/tests/container/sanity/init/init.sh b/tmt/tests/container/sanity/init/init.sh index e8b20d8..7d7705c 100755 --- a/tmt/tests/container/sanity/init/init.sh +++ b/tmt/tests/container/sanity/init/init.sh @@ -1,5 +1,6 @@ #!/bin/bash # prep +set -x git clone "$REPO_URL" repo cd repo git fetch origin "$PR_HEAD" diff --git a/tmt/tests/container/sanity/upgrade/upgrade.sh b/tmt/tests/container/sanity/upgrade/upgrade.sh index 2708dec..3eb7f0f 100755 --- a/tmt/tests/container/sanity/upgrade/upgrade.sh +++ b/tmt/tests/container/sanity/upgrade/upgrade.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -x # prep git clone "$REPO_URL" repo cd repo From 310d59cb9810334e13fbf0817ea553dcb1a1b470 Mon Sep 17 00:00:00 2001 From: Nikola Davidova Date: Wed, 10 Sep 2025 09:38:15 +0200 Subject: [PATCH 6/6] Fix typo --- tmt/tests/container/sanity/upgrade/upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmt/tests/container/sanity/upgrade/upgrade.sh b/tmt/tests/container/sanity/upgrade/upgrade.sh index 3eb7f0f..a7fab7d 100755 --- a/tmt/tests/container/sanity/upgrade/upgrade.sh +++ b/tmt/tests/container/sanity/upgrade/upgrade.sh @@ -57,7 +57,7 @@ dnf -y install postgresql17-upgrade ./bin/postgresql-setup --upgrade su - postgres -c " -/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE -o start +/usr/bin/pg_ctl -D $PGDATA -l $LOGFILE start /usr/bin/pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } "