diff --git a/.github/workflows/testing-farm.yaml b/.github/workflows/testing-farm.yaml index c0d98d3..d6139f1 100644 --- a/.github/workflows/testing-farm.yaml +++ b/.github/workflows/testing-farm.yaml @@ -2,8 +2,8 @@ name: Run tests on Testing Farm on: push: - branches: [ master ] - pull_request_trigger: + branches: [ master, container-tests ] + pull_request_target: types: [opened, synchronize, reopened] jobs: @@ -16,19 +16,37 @@ jobs: 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 VM - uses: sclorg/testing-farm-as-github-action@v4 + uses: sclorg/testing-farm-as-github-action@main with: api_key: ${{ secrets.TESTING_FARM_API_TOKEN }} compose: Fedora-Rawhide tmt_path: "tmt" tmt_plan_regex: "fedora-init" pull_request_status_name: "Fedora init test" - update_pull_request_status: "true" create_github_summary: "true" + update_pull_request_status: "true" + variables: "REPO_URL=${{ github.server_url }}/${{ github.repository }};PR_HEAD=${{ github.event.pull_request.head.sha }};" + test-upgrade: runs-on: ubuntu-latest @@ -38,11 +56,29 @@ jobs: 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 VM - uses: sclorg/testing-farm-as-github-action@v4 + uses: sclorg/testing-farm-as-github-action@main with: api_key: ${{ secrets.TESTING_FARM_API_TOKEN }} compose: Fedora-Rawhide @@ -51,4 +87,91 @@ jobs: pull_request_status_name: "Fedora 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 }};" + 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: "container-fedora-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: "container-fedora-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/readme.dummy b/readme.dummy new file mode 100644 index 0000000..e69de29 diff --git a/tmt/plans/container-fedora-init.fmf b/tmt/plans/container-fedora-init.fmf new file mode 100644 index 0000000..1b6ac65 --- /dev/null +++ b/tmt/plans/container-fedora-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:container-init-fedora +execute: + how: tmt + + diff --git a/tmt/plans/container-fedora-upgrade.fmf b/tmt/plans/container-fedora-upgrade.fmf new file mode 100644 index 0000000..e4553e6 --- /dev/null +++ b/tmt/plans/container-fedora-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-upgrade-container +execute: + how: tmt + + diff --git a/tmt/plans/fedora-init.fmf b/tmt/plans/fedora-init.fmf index e387013..e2d2225 100644 --- a/tmt/plans/fedora-init.fmf +++ b/tmt/plans/fedora-init.fmf @@ -1,4 +1,4 @@ -name: /plans/fedora +name: /plans/fedora-init summary: Run tests in a fedora virtual machine environment discover: how: fmf diff --git a/tmt/tests/container/sanity/init/init.sh b/tmt/tests/container/sanity/init/init.sh index afef6b9..6bd4bac 100755 --- a/tmt/tests/container/sanity/init/init.sh +++ b/tmt/tests/container/sanity/init/init.sh @@ -1,10 +1,13 @@ #!/bin/bash # prep -git clone "$TESTING_FARM_GIT_URL" repo +git clone "$REPO_URL" repo cd repo -git fetch origin "$TESTING_FARM_GIT_REF" +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 @@ -13,10 +16,11 @@ make # initialization ./bin/postgresql-setup --init -# start 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 start +pg_ctl -D $PGDATA status && echo \"PostgreSQL is running\" || { echo \"PostgreSQL is NOT running\"; exit 1; } +" -# check if it is running -pg_ctl -D $PGDATA status && echo "PostgreSQL is running" || { echo "PostgreSQL is NOT running"; exit 1; } diff --git a/tmt/tests/container/sanity/init/main.fmf b/tmt/tests/container/sanity/init/main.fmf index 4f63a78..df0390a 100644 --- a/tmt/tests/container/sanity/init/main.fmf +++ b/tmt/tests/container/sanity/init/main.fmf @@ -1,4 +1,4 @@ -summary: Check whether the machine is a container +summary: Postgresql-setup init test in a fedora rawhide container require: - make - m4 @@ -11,7 +11,9 @@ require: - automake - autoconf-archive - git +test: ./init.sh framework: shell +duration: 10m +tag: container-init-fedora contact: ndavidov@redhat.com -test: ./init.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..34c1d4c --- /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-upgrade-container +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..c8d0b76 --- /dev/null +++ b/tmt/tests/container/sanity/upgrade/upgrade.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# prep +git clone "$REPO_URL" repo +cd repo +git fetch origin "$PR_HEAD" +git checkout FETCH_HEAD + +echo "Fedora release:" +cat /etc/fedora-release + +# install postgresql16 +dnf -y install postgresql16-server + +# 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 start +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 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 -U postgres -d testdb -c "select * from users" +' > expected.txt + +echo "Expected:" +cat expected.txt + +# 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 + +# start postgresql and check if it's running +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; } +" + +su - postgres -c ' +psql -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; } + + + + + + diff --git a/tmt/tests/virtual/sanity/init/init.sh b/tmt/tests/virtual/sanity/init/init.sh index 9cb1502..d629ce4 100755 --- a/tmt/tests/virtual/sanity/init/init.sh +++ b/tmt/tests/virtual/sanity/init/init.sh @@ -1,9 +1,10 @@ #!/bin/bash # prep -git clone "$TESTING_FARM_GIT_URL" repo +git clone "$REPO_URL" repo cd repo -git fetch origin "$TESTING_FARM_GIT_REF" +git fetch origin "$PR_HEAD" git checkout FETCH_HEAD +git log -1 --oneline # setup autoreconf -vfi diff --git a/tmt/tests/virtual/sanity/upgrade/upgrade.sh b/tmt/tests/virtual/sanity/upgrade/upgrade.sh index 9d3277b..0f93597 100755 --- a/tmt/tests/virtual/sanity/upgrade/upgrade.sh +++ b/tmt/tests/virtual/sanity/upgrade/upgrade.sh @@ -1,8 +1,8 @@ #!/bin/bash # prep -git clone "$TESTING_FARM_GIT_URL" repo +git clone "$REPO_URL" repo cd repo -git fetch origin "$TESTING_FARM_GIT_REF" +git fetch origin "$PR_HEAD" git checkout FETCH_HEAD echo "Fedora release:" cat /etc/fedora-release