Skip to content

Commit

Permalink
change test scripts to reflect move of the schema dir to /usr/share/s…
Browse files Browse the repository at this point in the history
…usemanager/db

Co-authored-by: Wiktor Maj <wiktor.maj@suse.com>
  • Loading branch information
mcalmer and szachovy committed Jan 18, 2024
1 parent 2785ff7 commit c75036f
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ cp -r /manager/schema /tmp
cd /tmp/schema/reportdb

# Build the schema
make -f Makefile.schema SCHEMA=uyuni-reportdb-schema VERSION=4.3 RELEASE=testing
make -f Makefile.schema SCHEMA=uyuni-reportdb-schema VERSION=5.0 RELEASE=testing

if [ -d /etc/sysconfig/rhn/reportdb-schema-upgrade ]; then
if [ -d /usr/share/susemanager/db/reportdb-schema-upgrade ]; then
# remove old migration directories before we install the new
rm -r /etc/sysconfig/rhn/reportdb-schema-upgrade
rm -r /usr/share/susemanager/db/reportdb-schema-upgrade
fi

# Install directories
install -m 0755 -d /etc/sysconfig/rhn
install -m 0755 -d /etc/sysconfig/rhn/reportdb
install -m 0755 -d /etc/sysconfig/rhn/reportdb-schema-upgrade
install -m 0755 -d /usr/share/susemanager/db
install -m 0755 -d /usr/share/susemanager/db/reportdb
install -m 0755 -d /usr/share/susemanager/db/reportdb-schema-upgrade

# Install sql files
install -m 0644 postgres/main.sql /etc/sysconfig/rhn/reportdb
install -m 0644 postgres/end.sql /etc/sysconfig/rhn/reportdb/upgrade-end.sql
install -m 0644 postgres/main.sql /usr/share/susemanager/db/reportdb
install -m 0644 postgres/end.sql /usr/share/susemanager/db/reportdb/upgrade-end.sql

( cd upgrade && tar cf - --exclude='*.sql' . | ( cd /etc/sysconfig/rhn/reportdb-schema-upgrade && tar xf - ) )
( cd upgrade && tar cf - --exclude='*.sql' . | ( cd /usr/share/susemanager/db/reportdb-schema-upgrade && tar xf - ) )
18 changes: 9 additions & 9 deletions susemanager-utils/testing/docker/scripts/build-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ cp -r /manager/schema /tmp
cd /tmp/schema/spacewalk

# Build the schema
make -f Makefile.schema SCHEMA=susemanager-schema VERSION=4.3 RELEASE=testing
make -f Makefile.schema SCHEMA=susemanager-schema VERSION=5.0 RELEASE=testing

if [ -d /etc/sysconfig/rhn/schema-upgrade ]; then
if [ -d /usr/share/susemanager/db/schema-upgrade ]; then
# remove old migration directories before we install the new
rm -r /etc/sysconfig/rhn/schema-upgrade
rm -r /usr/share/susemanager/db/schema-upgrade
fi

# Install directories
install -m 0755 -d /etc/sysconfig/rhn
install -m 0755 -d /etc/sysconfig/rhn/postgres
install -m 0755 -d /etc/sysconfig/rhn/schema-upgrade
install -m 0755 -d /usr/share/susemanager/db
install -m 0755 -d /usr/share/susemanager/db/postgres
install -m 0755 -d /usr/share/susemanager/db/schema-upgrade

# Install sql files
install -m 0644 postgres/main.sql /etc/sysconfig/rhn/postgres
install -m 0644 postgres/end.sql /etc/sysconfig/rhn/postgres/upgrade-end.sql
install -m 0644 postgres/main.sql /usr/share/susemanager/db/postgres
install -m 0644 postgres/end.sql /usr/share/susemanager/db/postgres/upgrade-end.sql

( cd upgrade && tar cf - --exclude='*.sql' . | ( cd /etc/sysconfig/rhn/schema-upgrade && tar xf - ) )
( cd upgrade && tar cf - --exclude='*.sql' . | ( cd /usr/share/susemanager/db/schema-upgrade && tar xf - ) )

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [ -z "$NEXTVERSION" ]; then
RPMVERSION=`rpm -q --qf "%{version}\n" --specfile /manager/schema/spacewalk/susemanager-schema.spec | head -n 1`
NEXTVERSION=`echo $RPMVERSION | awk '{ pre=post=$0; gsub("[0-9]+$","",pre); gsub(".*\\\\.","",post); print pre post+1; }'`

if [ -d /etc/sysconfig/rhn/schema-upgrade/susemanager-schema-$RPMVERSION-to-susemanager-schema-$NEXTVERSION ]; then
if [ -d /usr/share/susemanager/db/schema-upgrade/susemanager-schema-$RPMVERSION-to-susemanager-schema-$NEXTVERSION ]; then
export SUMA_TEST_SCHEMA_VERSION=$NEXTVERSION

else
Expand Down Expand Up @@ -60,7 +60,7 @@ if [ -z "$REPORTNEXTVERSION" ]; then
RPMVERSION=`rpm -q --qf "%{version}\n" --specfile /manager/schema/reportdb/uyuni-reportdb-schema.spec | head -n 1`
NEXTVERSION=`echo $RPMVERSION | awk '{ pre=post=$0; gsub("[0-9]+$","",pre); gsub(".*\\\\.","",post); print pre post+1; }'`

if [ -d /etc/sysconfig/rhn/reportdb-schema-upgrade/uyuni-reportdb-schema-$RPMVERSION-to-uyuni-reportdb-schema-$NEXTVERSION ]; then
if [ -d /usr/share/susemanager/db/reportdb-schema-upgrade/uyuni-reportdb-schema-$RPMVERSION-to-uyuni-reportdb-schema-$NEXTVERSION ]; then
export SUMA_TEST_SCHEMA_VERSION=$NEXTVERSION

else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -e

cd /manager/susemanager-utils/testing/docker/scripts/

# Move Postgres database to tmpfs to speed initialization and testing up
if [ ! -z $PG_TMPFS_DIR ]; then
trap "umount $PG_TMPFS_DIR" EXIT INT TERM
./docker-testing-pgsql-move-data-to-tmpfs.sh $PG_TMPFS_DIR
fi

export PERLLIB=/manager/spacewalk/setup/lib/:/manager/web/modules/rhn/:/manager/web/modules/pxt/:/manager/schema/spacewalk/lib
export PATH=/manager/schema/spacewalk/:/manager/spacewalk/setup/bin/:$PATH

echo Going to reset pgsql database

echo $PATH
echo $PERLLIB

export SYSTEMD_NO_WRAP=1
#sysctl -w kernel.shmmax=18446744073709551615
su - postgres -c "/usr/lib/postgresql/bin/pg_ctl restart" ||:

# this copy the latest schema from the git into the system
./build-reportdb-schema.sh

if [ -z "$NEXTVERSION" ]; then

RPMVERSION=`rpm -q --qf "%{version}\n" --specfile /manager/schema/reportdb/uyuni-reportdb-schema.spec | head -n 1`
NEXTVERSION=`echo $RPMVERSION | awk '{ pre=post=$0; gsub("[0-9]+$","",pre); gsub(".*\\\\.","",post); print pre post+1; }'`

if [ -d /usr/share/susemanager/db/reportdb-schema-upgrade/uyuni-reportdb-schema-$RPMVERSION-to-uyuni-reportdb-schema-$NEXTVERSION ]; then
export SUMA_TEST_SCHEMA_VERSION=$NEXTVERSION

else
export SUMA_TEST_SCHEMA_VERSION=$RPMVERSION
fi
else
export SUMA_TEST_SCHEMA_VERSION=$NEXTVERSION
fi

# run the schema upgrade from git repo
if ! /manager/schema/spacewalk/spacewalk-schema-upgrade -y --reportdb; then
cat /var/log/spacewalk/reportdb-schema-upgrade/schema-from-*.log
su - postgres -c "/usr/lib/postgresql/bin/pg_ctl stop" ||:
exit 1
fi

su - postgres -c "/usr/lib/postgresql/bin/pg_ctl stop" ||:
su - postgres -c '/usr/lib/postgresql/bin/postgres -D /var/lib/pgsql/data'

Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def argparser():
parser = argparse.ArgumentParser(
description="Test idempotency of SQL scripts. This script assumes a script schema_migration_test_pgsql-*to*.sh ran before, and PostgreSQL is stopped")
parser.add_argument("-s", "--schema-path", action="store", dest="schema_path",
help="Path where the directories with the schema upgrades are (default: /etc/sysconfig/rhn/schema-upgrade",
default="/etc/sysconfig/rhn/reportdb-schema-upgrade")
help="Path where the directories with the schema upgrades are (default: /usr/share/susemanager/db/reportdb-schema-upgrade",
default="/usr/share/susemanager/db/reportdb-schema-upgrade")
parser.add_argument("-p", "--from-pr", action="store", dest="pr_file",
help="Check files with changes from a PR by rerunning added or changed files. The value is the path to a JSON file with PR information generated by gitarro")
parser.add_argument("-v", "--from-version", action="store", dest="version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def argparser():
parser = argparse.ArgumentParser(
description="Test idempotency of SQL scripts. This script assumes a script schema_migration_test_pgsql-*to*.sh ran before, and PostgreSQL is stopped")
parser.add_argument("-s", "--schema-path", action="store", dest="schema_path",
help="Path where the directories with the schema upgrades are (default: /etc/sysconfig/rhn/schema-upgrade",
default="/etc/sysconfig/rhn/schema-upgrade")
help="Path where the directories with the schema upgrades are (default: /usr/share/susemanager/db/schema-upgrade",
default="/usr/share/susemanager/db/schema-upgrade")
parser.add_argument("-p", "--from-pr", action="store", dest="pr_file",
help="Check files with changes from a PR by rerunning added or changed files. The value is the path to a JSON file with PR information generated by gitarro")
parser.add_argument("-v", "--from-version", action="store", dest="version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ touch /var/lib/rhn/rhn-satellite-prep/etc/rhn/rhn.conf
cp /root/rhn.conf /etc/rhn/rhn.conf
smdba system-check autotuning --max_connections=50


# we changed the schema dir, but we start with a schema which live still in the old location
# provide a symlink to make the tooling work
if [ -d /etc/sysconfig/rhn/postgres -a ! -e /usr/share/susemanager/db/postgres ]; then
mkdir -p /usr/share/susemanager/db
ln -s /etc/sysconfig/rhn/postgres /usr/share/susemanager/db/postgres
ln -s /etc/sysconfig/rhn/reportdb /usr/share/susemanager/db/reportdb
fi


# this command will fail with certificate error. This is ok, so ignore the error
spacewalk-setup --skip-initial-configuration --skip-system-version-test --skip-selinux-test --skip-fqdn-test --skip-ssl-cert-generation --skip-ssl-vhost-setup --skip-services-check --clear-db --answer-file=clear-db-answers-pgsql.txt --external-postgresql --non-interactive ||:
/manager/spacewalk/uyuni-setup-reportdb/bin/uyuni-setup-reportdb remove --db reportdb --user pythia ||:
Expand All @@ -69,7 +79,7 @@ spacewalk-setup --skip-initial-configuration --skip-system-version-test --skip-s
RPMVERSION=`rpm -q --qf "%{version}\n" --specfile /manager/schema/reportdb/uyuni-reportdb-schema.spec | head -n 1`
NEXTVERSION=`echo $RPMVERSION | awk '{ pre=post=$0; gsub("[0-9]+$","",pre); gsub(".*\\\\.","",post); print pre post+1; }'`

if [ -d /etc/sysconfig/rhn/reportdb-schema-upgrade/uyuni-reportdb-schema-$RPMVERSION-to-uyuni-reportdb-schema-$NEXTVERSION ]; then
if [ -d /usr/share/susemanager/db/reportdb-schema-upgrade/uyuni-reportdb-schema-$RPMVERSION-to-uyuni-reportdb-schema-$NEXTVERSION ]; then
export SUMA_TEST_SCHEMA_VERSION=$NEXTVERSION

else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ touch /var/lib/rhn/rhn-satellite-prep/etc/rhn/rhn.conf
cp /root/rhn.conf /etc/rhn/rhn.conf
smdba system-check autotuning --max_connections=50

# we changed the schema dir, but we start with a schema which live still in the old location
# provide a symlink to make the tooling work
if [ -d /etc/sysconfig/rhn/postgres -a ! -e /usr/share/susemanager/db/postgres ]; then
mkdir -p /usr/share/susemanager/db
ln -s /etc/sysconfig/rhn/postgres /usr/share/susemanager/db/postgres
fi

# this command will fail with certificate error. This is ok, so ignore the error
spacewalk-setup --skip-initial-configuration --skip-system-version-test --skip-selinux-test --skip-fqdn-test --skip-ssl-cert-generation --skip-ssl-vhost-setup --skip-services-check --clear-db --answer-file=clear-db-answers-pgsql.txt --external-postgresql --non-interactive ||:

Expand All @@ -68,7 +75,7 @@ spacewalk-setup --skip-initial-configuration --skip-system-version-test --skip-s
RPMVERSION=`rpm -q --qf "%{version}\n" --specfile /manager/schema/spacewalk/susemanager-schema.spec | head -n 1`
NEXTVERSION=`echo $RPMVERSION | awk '{ pre=post=$0; gsub("[0-9]+$","",pre); gsub(".*\\\\.","",post); print pre post+1; }'`

if [ -d /etc/sysconfig/rhn/schema-upgrade/susemanager-schema-$RPMVERSION-to-susemanager-schema-$NEXTVERSION ]; then
if [ -d /usr/share/susemanager/db/schema-upgrade/susemanager-schema-$RPMVERSION-to-susemanager-schema-$NEXTVERSION ]; then
export SUMA_TEST_SCHEMA_VERSION=$NEXTVERSION

else
Expand Down
22 changes: 21 additions & 1 deletion testsuite/podman_runner/07_start_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,25 @@
set -xe
src_dir=$(cd $(dirname "$0")/../.. && pwd -P)

sudo -i podman run --rm --tmpfs /run -v ${src_dir}/schema/spacewalk/spacewalk-schema-upgrade:/usr/bin/spacewalk-schema-upgrade -v${src_dir}/testsuite:/testsuite -v ${src_dir}/schema/spacewalk/upgrade/:/etc/sysconfig/rhn/schema-upgrade/ -v ${src_dir}/schema/reportdb/upgrade/:/etc/sysconfig/rhn/reportdb-schema-upgrade/ -v ${src_dir}/web:/web -v ${src_dir}/branding:/branding -v ${src_dir}/java:/java -v ${src_dir}/client:/client -v /sys/fs/cgroup:/sys/fs/cgroup:rw -v /tmp/test-all-in-one:/tmp --cgroupns=host -h uyuni-server-all-in-one-test -p 8443:443 -p 8080:80 -p 4505:4505 -p 4506:4506 -d --name=uyuni-server-all-in-one-test --network uyuni-network-1 ghcr.io/$UYUNI_PROJECT/uyuni/ci-test-server-all-in-one-dev:$UYUNI_VERSION
sudo -i podman run --rm \
--tmpfs /run \
-v ${src_dir}/schema/spacewalk/spacewalk-schema-upgrade:/usr/bin/spacewalk-schema-upgrade \
-v ${src_dir}/testsuite:/testsuite \
-v ${src_dir}/schema/spacewalk/upgrade/:/usr/share/susemanager/db/schema-upgrade/ \
-v ${src_dir}/schema/reportdb/upgrade/:/usr/share/susemanager/db/reportdb-schema-upgrade/ \
-v ${src_dir}/web:/web \
-v ${src_dir}/branding:/branding \
-v ${src_dir}/java:/java \
-v ${src_dir}/client:/client \
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
-v /tmp/test-all-in-one:/tmp \
--cgroupns=host \
-h uyuni-server-all-in-one-test \
-p 8443:443 \
-p 8080:80 \
-p 4505:4505 \
-p 4506:4506 \
-d --name=uyuni-server-all-in-one-test \
--network uyuni-network-1 \
ghcr.io/$UYUNI_PROJECT/uyuni/ci-test-server-all-in-one-dev:$UYUNI_VERSION

4 changes: 2 additions & 2 deletions testsuite/podman_runner/run_db_migrations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ fi

if [[ "$1" == "susemanager-schema" ]];
then
upgrade_dir="/etc/sysconfig/rhn/schema-upgrade/"
upgrade_dir="/usr/share/susemanager/db/schema-upgrade/"
additional_params=""
elif [[ "$1" == "uyuni-reportdb-schema" ]];
then
upgrade_dir="/etc/sysconfig/rhn/reportdb-schema-upgrade/"
upgrade_dir="/usr/share/susemanager/db/reportdb-schema-upgrade/"
additional_params="--reportdb"
else
echo "Unknown schema $1. Use either susemanager-schema or uyuni-reportdb-schema."
Expand Down

0 comments on commit c75036f

Please sign in to comment.