[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-exchange] 02/02: [exchange] fix auditor tests in container (actua
From: |
gnunet |
Subject: |
[taler-exchange] 02/02: [exchange] fix auditor tests in container (actual) |
Date: |
Thu, 12 Dec 2024 22:54:46 +0100 |
This is an automated email from the git hooks/post-receive script.
oec pushed a commit to branch master
in repository exchange.
commit 9efa30cdd3a39d95e766cd1d9bfdeeefe4f87e06
Author: Özgür Kesim <oec-taler@kesim.org>
AuthorDate: Thu Dec 12 22:52:59 2024 +0100
[exchange] fix auditor tests in container (actual)
(previous commit lacked files)
Multiple issues fixed:
- missing debian packages for auditor tests added to Containerfile:
faketime, libeufin-{common,nexus,bank}, taler-wallet-cli, taler-merchant
- missing TALER_*_PREFIX environment set prior to tests,
some /usr/local, some /usr (merchant from debian, f.e.).
- LD_LIBRARY_PATH adjusted for /usr/local and debian-merchant lib
- initdb step skipped in case of root user calling the test-scripts
Fixes #9380
---
contrib/ci/Containerfile | 8 +-
contrib/ci/jobs/002-test/job.sh | 5 +-
contrib/ci/jobs/002-test/test.sh | 50 ------------
src/auditor/generate-auditor-basedb.sh | 4 +-
src/auditor/test-auditor.sh | 142 ++++++++++++++++++---------------
src/auditor/test-kyc.sh | 111 ++++++++++++++------------
src/auditor/test-revocation.sh | 100 ++++++++++++-----------
src/auditor/test-sync.sh | 90 +++++++++++----------
8 files changed, 254 insertions(+), 256 deletions(-)
diff --git a/contrib/ci/Containerfile b/contrib/ci/Containerfile
index b00b59433..5fb900773 100644
--- a/contrib/ci/Containerfile
+++ b/contrib/ci/Containerfile
@@ -45,7 +45,8 @@ RUN apt-get update -yqq && \
jq \
postgresql \
sudo \
- wget
+ wget \
+ faketime
# Install Taler (and friends) packages
RUN curl -sS https://deb.taler.net/apt-nightly/taler-bookworm-ci.sources \
@@ -62,6 +63,11 @@ RUN cat /etc/apt/preferences.d/taler && \
libgnunet-dev \
libgnunet \
gnunet \
+ taler-wallet-cli \
+ taler-merchant \
+ libeufin-common \
+ libeufin-bank \
+ libeufin-nexus \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /workdir
diff --git a/contrib/ci/jobs/002-test/job.sh b/contrib/ci/jobs/002-test/job.sh
index bfb24e335..149ce1fab 100755
--- a/contrib/ci/jobs/002-test/job.sh
+++ b/contrib/ci/jobs/002-test/job.sh
@@ -3,4 +3,7 @@ set -exuo pipefail
job_dir=$(dirname "${BASH_SOURCE[0]}")
-"${job_dir}"/test.sh
+. "${job_dir}"/1-build.sh
+. "${job_dir}"/2-install.sh
+. "${job_dir}"/3-startdb.sh
+. "${job_dir}"/4-test.sh
diff --git a/contrib/ci/jobs/002-test/test.sh b/contrib/ci/jobs/002-test/test.sh
deleted file mode 100755
index 529c4f29f..000000000
--- a/contrib/ci/jobs/002-test/test.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/bash
-set -evux
-
-apt-get update
-apt-get upgrade -yqq
-
-./bootstrap
-./configure CFLAGS="-ggdb -O0" \
- --enable-logging=verbose \
- --disable-doc
-
-nump=$(grep processor /proc/cpuinfo | wc -l)
-make clean
-make -j$(( $nump / 2 ))
-cd src/templating/
-./run-original-tests.sh
-make clean
-cd -
-make -j$(( $nump / 2 ))
-make install
-
-sudo -u postgres /usr/lib/postgresql/15/bin/pg_ctl start -D
/etc/postgresql/15/main -o '-h localhost -p 5432'
-sudo -u postgres createuser -p 5432 root
-sudo -u postgres createdb -p 5432 -O root talercheck
-
-check_command()
-{
- # Set LD_LIBRARY_PATH so tests can find the installed libs
- LD_LIBRARY_PATH=/usr/local/lib PGPORT=5432 make check
-}
-
-print_logs()
-{
- set +e
- for i in src/*/test-suite.log
- do
- echo "Printing ${i}"
- cat "$i"
- for FAILURE in $(grep '^FAIL:' ${i} | cut -d' ' -f2)
- do
- echo "Printing $(dirname $i)/${FAILURE}.log"
- cat "$(dirname $i)/${FAILURE}.log"
- done
- done
-}
-
-if ! check_command ; then
- print_logs
- exit 1
-fi
diff --git a/src/auditor/generate-auditor-basedb.sh
b/src/auditor/generate-auditor-basedb.sh
index fdd2ab5b3..9a7a27e28 100755
--- a/src/auditor/generate-auditor-basedb.sh
+++ b/src/auditor/generate-auditor-basedb.sh
@@ -47,9 +47,9 @@ curl --help >/dev/null </dev/null || exit_skip " MISSING"
echo " FOUND"
# reset database
-echo -n "Reset 'auditor-basedb' database at $PGHOST ..."
+echo -n "Reset 'auditor-basedb' database at ${PGHOST:-} ..."
dropdb --if-exists "auditor-basedb" > /dev/null 2> /dev/null || true
-createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB' at
$PGHOST"
+createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB' at
${PGHOST:-}"
echo " DONE"
# Launch exchange, merchant and bank.
diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh
index 4679a9791..c4c35052e 100755
--- a/src/auditor/test-auditor.sh
+++ b/src/auditor/test-auditor.sh
@@ -402,10 +402,10 @@ function stop_auditor_httpd() {
# Do a full reload of the (original) database
function full_reload()
{
- echo -n "Doing full reload of the database (loading ${BASEDB}.sql into $DB
at $PGHOST)... "
+ echo -n "Doing full reload of the database (loading ${BASEDB}.sql into $DB
at ${PGHOST:-})... "
dropdb -f "$DB" &>> ${MY_TMP_DIR}/drop.log || true
createdb -T template0 "$DB" \
- || exit_skip "could not create database $DB (at $PGHOST)"
+ || exit_skip "could not create database $DB (at ${PGHOST:-})"
# Import pre-generated database, -q(ietly) using single (-1) transaction
psql -Aqt "$DB" \
-q \
@@ -2162,7 +2162,78 @@ function check_with_database()
# dropdb $DB
}
+# When the script is not run as root, setup a temporary directory for the
+# postgres database.
+# Sets PGHOST accordingly to the freshly created socket.
+function perform_initdb() {
+ # Available directly in path?
+ INITDB_BIN=$(command -v initdb) || true
+ if [[ -n "$INITDB_BIN" ]]; then
+ echo " FOUND (in path) at $INITDB_BIN"
+ else
+ HAVE_INITDB=$(find /usr -name "initdb" 2> /dev/null \
+ | head -1 2> /dev/null \
+ | grep postgres) \
+ || exit_skip " MISSING"
+ echo " FOUND at $(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres |
sort -n | tail -n1)
+ fi
+ POSTGRES_PATH=$(dirname "$INITDB_BIN")
+
+ TMPDIR="$MY_TMP_DIR/postgres"
+ mkdir -p "$TMPDIR"
+ echo -n "Setting up Postgres DB at $TMPDIR ..."
+ $INITDB_BIN \
+ --no-sync \
+ --auth=trust \
+ -D "${TMPDIR}" \
+ > "${MY_TMP_DIR}/postgres-dbinit.log" \
+ 2> "${MY_TMP_DIR}/postgres-dbinit.err" \
+ || {
+ echo "FAILED!"
+ echo "Last entries in ${MY_TMP_DIR}/postgres-dbinit.err:"
+ tail "${MY_TMP_DIR}/postgres-dbinit.err"
+ exit 1
+ }
+ echo "DONE"
+
+ # Once we move to PG16, we can use:
+ # --set listen_addresses='' \
+ # --set fsync=off \
+ # --set max_wal_senders=0 \
+ # --set synchronous_commit=off \
+ # --set wal_level=minimal \
+ # --set unix_socket_directories="${TMPDIR}/sockets" \
+
+
+ SOCKETDIR="${TMPDIR}/sockets"
+ mkdir "${SOCKETDIR}"
+
+ echo -n "Launching Postgres service"
+
+ cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+ grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+ mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+ "${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l "${MY_TMP_DIR}/postgres.log" \
+ start \
+ > "${MY_TMP_DIR}/postgres-start.log" \
+ 2> "${MY_TMP_DIR}/postgres-start.err"
+ echo " DONE"
+ PGHOST="$TMPDIR/sockets"
+ export PGHOST
+}
# *************** Main logic starts here **************
@@ -2184,69 +2255,14 @@ taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null
|| exit_skip "taler-wallet
echo -n "Testing for Postgres"
-# Available directly in path?
-INITDB_BIN=$(command -v initdb) || true
-if [[ -n "$INITDB_BIN" ]]; then
- echo " FOUND (in path) at $INITDB_BIN"
-else
- HAVE_INITDB=$(find /usr -name "initdb" 2> /dev/null \
- | head -1 2> /dev/null \
- | grep postgres) \
- || exit_skip " MISSING"
- echo " FOUND at $(dirname "$HAVE_INITDB")"
- INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n
| tail -n1)
-fi
-POSTGRES_PATH=$(dirname "$INITDB_BIN")
MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
echo "Using $MY_TMP_DIR for logging and temporary data"
-TMPDIR="$MY_TMP_DIR/postgres"
-mkdir -p "$TMPDIR"
-echo -n "Setting up Postgres DB at $TMPDIR ..."
-$INITDB_BIN \
- --no-sync \
- --auth=trust \
- -D "${TMPDIR}" \
- > "${MY_TMP_DIR}/postgres-dbinit.log" \
- 2> "${MY_TMP_DIR}/postgres-dbinit.err"
-echo "DONE"
-
-# Once we move to PG16, we can use:
-# --set listen_addresses='' \
-# --set fsync=off \
-# --set max_wal_senders=0 \
-# --set synchronous_commit=off \
-# --set wal_level=minimal \
-# --set unix_socket_directories="${TMPDIR}/sockets" \
-
-
-SOCKETDIR="${TMPDIR}/sockets"
-mkdir "${SOCKETDIR}"
-
-echo -n "Launching Postgres service"
-
-cat - >> "$TMPDIR/postgresql.conf" <<EOF
-unix_socket_directories='${TMPDIR}/sockets'
-fsync=off
-max_wal_senders=0
-synchronous_commit=off
-wal_level=minimal
-listen_addresses=''
-EOF
-grep -v host \
- < "$TMPDIR/pg_hba.conf" \
- > "$TMPDIR/pg_hba.conf.new"
-mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
-"${POSTGRES_PATH}/pg_ctl" \
- -D "$TMPDIR" \
- -l "${MY_TMP_DIR}/postgres.log" \
- start \
- > "${MY_TMP_DIR}/postgres-start.log" \
- 2> "${MY_TMP_DIR}/postgres-start.err"
-echo " DONE"
-PGHOST="$TMPDIR/sockets"
-export PGHOST
+# If run as root, simply use the running postgres instance.
+# Otherwise create a temporary storage space for postgres.
+[ $(id -u) == 0 ] || perform_initdb
+
MYDIR="${MY_TMP_DIR}/basedb"
mkdir -p "${MYDIR}"
@@ -2256,9 +2272,9 @@ then
if faketime -f '-1 d' ./generate-auditor-basedb.sh -d "$MYDIR/$DB"
then
- echo -n "Reset 'auditor-basedb' database at $PGHOST ..."
+ echo -n "Reset 'auditor-basedb' database at ${PGHOST:-} ..."
dropdb --if-exists "auditor-basedb" > /dev/null 2> /dev/null || true
- createdb "auditor-basedb" || exit_skip "Could not create database
'$BASEDB' at $PGHOST"
+ createdb "auditor-basedb" || exit_skip "Could not create database
'$BASEDB' at ${PGHOST:-}"
echo " DONE"
else
echo "Generation failed"
diff --git a/src/auditor/test-kyc.sh b/src/auditor/test-kyc.sh
index 8efdc45b5..2a4c49986 100755
--- a/src/auditor/test-kyc.sh
+++ b/src/auditor/test-kyc.sh
@@ -355,10 +355,10 @@ function run_audit () {
# Do a full reload of the (original) database
function full_reload()
{
- echo -n "Doing full reload of the database (loading ${BASEDB}.sql into $DB
at $PGHOST)... "
+ echo -n "Doing full reload of the database (loading ${BASEDB}.sql into $DB
at ${PGHOST:-})... "
dropdb "$DB" 2> /dev/null || true
createdb -T template0 "$DB" \
- || exit_skip "could not create database $DB (at $PGHOST)"
+ || exit_skip "could not create database $DB (at ${PGHOST:-})"
# Import pre-generated database, -q(ietly) using single (-1) transaction
psql -Aqt "$DB" \
-q \
@@ -635,6 +635,59 @@ function check_with_database()
# dropdb $DB
}
+# If this script is not run as root, create the temporary
+# storage space for postgres.
+# Sets PGHOST accordingly
+function perform_initdb() {
+ # Available directly in path?
+ INITDB_BIN=$(command -v initdb) || true
+ if [[ -n "$INITDB_BIN" ]]; then
+ echo " FOUND (in path) at $INITDB_BIN"
+ else
+ HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep
postgres) \
+ || exit_skip " MISSING"
+ echo " FOUND at $(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres |
sort -n | tail -n1)
+ fi
+ POSTGRES_PATH=$(dirname "$INITDB_BIN")
+
+ echo "Using $MY_TMP_DIR for logging and temporary data"
+ TMPDIR="$MY_TMP_DIR/postgres"
+ mkdir -p "$TMPDIR"
+ echo -n "Setting up Postgres DB at $TMPDIR ..."
+ $INITDB_BIN \
+ --no-sync \
+ --auth=trust \
+ -D "${TMPDIR}" \
+ > "${MY_TMP_DIR}/postgres-dbinit.log" \
+ 2> "${MY_TMP_DIR}/postgres-dbinit.err"
+ echo "DONE"
+ SOCKETDIR="${TMPDIR}/sockets"
+ mkdir "${SOCKETDIR}"
+ echo -n "Launching Postgres service"
+ cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+ grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+ mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+ "${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ start \
+ > "${MY_TMP_DIR}/postgres-start.log" \
+ 2> "${MY_TMP_DIR}/postgres-start.err"
+ echo " DONE"
+ PGHOST="$TMPDIR/sockets"
+ export PGHOST
+
+}
@@ -655,56 +708,10 @@ libeufin-bank --help >/dev/null 2> /dev/null </dev/null
|| exit_skip "libeufin-b
echo "Testing for taler-wallet-cli"
taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip
"taler-wallet-cli required"
+MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
echo -n "Testing for Postgres"
-# Available directly in path?
-INITDB_BIN=$(command -v initdb) || true
-if [[ -n "$INITDB_BIN" ]]; then
- echo " FOUND (in path) at $INITDB_BIN"
-else
- HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep
postgres) \
- || exit_skip " MISSING"
- echo " FOUND at $(dirname "$HAVE_INITDB")"
- INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n
| tail -n1)
-fi
-POSTGRES_PATH=$(dirname "$INITDB_BIN")
-
-MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
-echo "Using $MY_TMP_DIR for logging and temporary data"
-TMPDIR="$MY_TMP_DIR/postgres"
-mkdir -p "$TMPDIR"
-echo -n "Setting up Postgres DB at $TMPDIR ..."
-$INITDB_BIN \
- --no-sync \
- --auth=trust \
- -D "${TMPDIR}" \
- > "${MY_TMP_DIR}/postgres-dbinit.log" \
- 2> "${MY_TMP_DIR}/postgres-dbinit.err"
-echo "DONE"
-SOCKETDIR="${TMPDIR}/sockets"
-mkdir "${SOCKETDIR}"
-echo -n "Launching Postgres service"
-cat - >> "$TMPDIR/postgresql.conf" <<EOF
-unix_socket_directories='${TMPDIR}/sockets'
-fsync=off
-max_wal_senders=0
-synchronous_commit=off
-wal_level=minimal
-listen_addresses=''
-EOF
-grep -v host \
- < "$TMPDIR/pg_hba.conf" \
- > "$TMPDIR/pg_hba.conf.new"
-mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
-"${POSTGRES_PATH}/pg_ctl" \
- -D "$TMPDIR" \
- -l /dev/null \
- start \
- > "${MY_TMP_DIR}/postgres-start.log" \
- 2> "${MY_TMP_DIR}/postgres-start.err"
-echo " DONE"
-PGHOST="$TMPDIR/sockets"
-export PGHOST
+[ $(id -u) == 0 ] || perform_initdb
MYDIR="${MY_TMP_DIR}/basedb"
mkdir -p "${MYDIR}"
@@ -713,9 +720,9 @@ if faketime -f '-1 d' ./generate-auditor-basedb.sh \
-c generate-kyc-basedb.conf \
-d "$MYDIR/$DB"
then
- echo -n "Reset 'auditor-basedb' database at $PGHOST ..."
+ echo -n "Reset 'auditor-basedb' database at ${PGHOST:-} ..."
dropdb "auditor-basedb" >/dev/null 2>/dev/null || true
- createdb "auditor-basedb" || exit_skip "Could not create database
'$BASEDB' at $PGHOST"
+ createdb "auditor-basedb" || exit_skip "Could not create database
'$BASEDB' at ${PGHOST:-}"
echo " DONE"
check_with_database "$MYDIR/$DB"
if [ "$fail" != "0" ]
diff --git a/src/auditor/test-revocation.sh b/src/auditor/test-revocation.sh
index 310a4e14e..5d5ea7db5 100755
--- a/src/auditor/test-revocation.sh
+++ b/src/auditor/test-revocation.sh
@@ -271,7 +271,7 @@ function full_reload()
echo -n "Doing full reload of the database... "
dropdb "$DB" 2> /dev/null || true
createdb -T template0 "$DB" \
- || exit_skip "could not create database $DB (at $PGHOST)"
+ || exit_skip "could not create database $DB (at ${PGHOST:-})"
# Import pre-generated database, -q(ietly) using single (-1) transaction
psql -Aqt "$DB" \
-q \
@@ -638,6 +638,55 @@ function check_with_database()
dropdb "$DB"
}
+# If this script is not running as root, create
+# the temporary directory structure for storage for postgres
+# Will set PGHOST accordingly
+function perform_dbinit() {
+ # Available directly in path?
+ INITDB_BIN=$(command -v initdb) || true
+ if [[ -n "$INITDB_BIN" ]]; then
+ echo "FOUND (in path) at $INITDB_BIN"
+ else
+ HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep
postgres) || exit_skip " MISSING"
+ echo "FOUND at " "$(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres |
sort -n | tail -n1)
+ fi
+ echo -n "Setting up Postgres DB"
+ POSTGRES_PATH=$(dirname "$INITDB_BIN")
+ TMPDIR="${MY_TMP_DIR}/postgres/"
+ mkdir -p "$TMPDIR"
+ echo -n "Setting up Postgres DB at $TMPDIR ..."
+ "$INITDB_BIN" \
+ --no-sync \
+ --auth=trust \
+ -D "${TMPDIR}" \
+ > "${MY_TMP_DIR}/postgres-dbinit.log" \
+ 2> "${MY_TMP_DIR}/postgres-dbinit.err"
+ echo " DONE"
+ mkdir "${TMPDIR}/sockets"
+ echo -n "Launching Postgres service at $POSTGRES_PATH"
+ cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+ grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+ mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+ "${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ start \
+ > "${MY_TMP_DIR}/postgres-start.log" \
+ 2> "${MY_TMP_DIR}/postgres-start.err"
+ echo " DONE"
+ PGHOST="$TMPDIR/sockets"
+ export PGHOST
+}
# *************** Main logic starts here **************
@@ -666,52 +715,11 @@ taler-wallet-cli -h \
2>/dev/null \
|| exit_skip "taler-wallet-cli required"
-echo -n "Testing for Postgres "
-# Available directly in path?
-INITDB_BIN=$(command -v initdb) || true
-if [[ -n "$INITDB_BIN" ]]; then
- echo "FOUND (in path) at $INITDB_BIN"
-else
- HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep
postgres) || exit_skip " MISSING"
- echo "FOUND at " "$(dirname "$HAVE_INITDB")"
- INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n
| tail -n1)
-fi
-echo -n "Setting up Postgres DB"
-POSTGRES_PATH=$(dirname "$INITDB_BIN")
MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
-TMPDIR="${MY_TMP_DIR}/postgres/"
-mkdir -p "$TMPDIR"
-echo -n "Setting up Postgres DB at $TMPDIR ..."
-"$INITDB_BIN" \
- --no-sync \
- --auth=trust \
- -D "${TMPDIR}" \
- > "${MY_TMP_DIR}/postgres-dbinit.log" \
- 2> "${MY_TMP_DIR}/postgres-dbinit.err"
-echo " DONE"
-mkdir "${TMPDIR}/sockets"
-echo -n "Launching Postgres service at $POSTGRES_PATH"
-cat - >> "$TMPDIR/postgresql.conf" <<EOF
-unix_socket_directories='${TMPDIR}/sockets'
-fsync=off
-max_wal_senders=0
-synchronous_commit=off
-wal_level=minimal
-listen_addresses=''
-EOF
-grep -v host \
- < "$TMPDIR/pg_hba.conf" \
- > "$TMPDIR/pg_hba.conf.new"
-mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
-"${POSTGRES_PATH}/pg_ctl" \
- -D "$TMPDIR" \
- -l /dev/null \
- start \
- > "${MY_TMP_DIR}/postgres-start.log" \
- 2> "${MY_TMP_DIR}/postgres-start.err"
-echo " DONE"
-PGHOST="$TMPDIR/sockets"
-export PGHOST
+
+echo -n "Testing for Postgres "
+[ $(id -u) == 0 ] || perform_dbinit
+
echo "Generating fresh database at $MY_TMP_DIR"
if faketime -f '-1 d' ./generate-revoke-basedb.sh "$MY_TMP_DIR/$DB"
diff --git a/src/auditor/test-sync.sh b/src/auditor/test-sync.sh
index 60ea392eb..ed34d8651 100755
--- a/src/auditor/test-sync.sh
+++ b/src/auditor/test-sync.sh
@@ -46,6 +46,52 @@ function cleanup() {
# Install cleanup handler (except for kill -9)
trap cleanup EXIT
+# If this script is not run as root,
+# create the temporary storage space for postgres.
+# Will set PGHOST accordingly
+function perform_initdb() {
+ # Available directly in path?
+ INITDB_BIN=$(command -v initdb) || true
+ if [[ -n "$INITDB_BIN" ]]; then
+ echo " FOUND (in path) at $INITDB_BIN"
+ else
+ HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep
postgres) || exit_skip " MISSING"
+ echo " FOUND at " "$(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres |
sort -n | tail -n1)
+ fi
+ echo -n "Setting up Postgres DB"
+ POSTGRES_PATH=$(dirname "$INITDB_BIN")
+ TMPDIR="$MYDIR/postgres/"
+ mkdir -p "$TMPDIR"
+ "$INITDB_BIN" --no-sync --auth=trust -D "${TMPDIR}" \
+ > "${MYDIR}/postgres-dbinit.log" \
+ 2> "${MYDIR}/postgres-dbinit.err"
+ echo " DONE"
+ mkdir "${TMPDIR}/sockets"
+ echo -n "Launching Postgres service"
+ cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+ grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+ mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+ "${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ start \
+ > "${MYDIR}/postgres-start.log" \
+ 2> "${MYDIR}/postgres-start.err"
+ echo " DONE"
+ PGHOST="$TMPDIR/sockets"
+ export PGHOST
+}
+
function check_with_database()
{
echo -n "Testing synchronization logic ..."
@@ -104,48 +150,10 @@ libeufin-bank --help >/dev/null </dev/null 2> /dev/null
|| exit_skip "libeufin-b
echo "Testing for taler-wallet-cli"
taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip
"taler-wallet-cli required"
-echo -n "Testing for Postgres"
-# Available directly in path?
-INITDB_BIN=$(command -v initdb) || true
-if [[ -n "$INITDB_BIN" ]]; then
- echo " FOUND (in path) at $INITDB_BIN"
-else
- HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep
postgres) || exit_skip " MISSING"
- echo " FOUND at " "$(dirname "$HAVE_INITDB")"
- INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n
| tail -n1)
-fi
-echo -n "Setting up Postgres DB"
-POSTGRES_PATH=$(dirname "$INITDB_BIN")
MYDIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
-TMPDIR="$MYDIR/postgres/"
-mkdir -p "$TMPDIR"
-"$INITDB_BIN" --no-sync --auth=trust -D "${TMPDIR}" \
- > "${MYDIR}/postgres-dbinit.log" \
- 2> "${MYDIR}/postgres-dbinit.err"
-echo " DONE"
-mkdir "${TMPDIR}/sockets"
-echo -n "Launching Postgres service"
-cat - >> "$TMPDIR/postgresql.conf" <<EOF
-unix_socket_directories='${TMPDIR}/sockets'
-fsync=off
-max_wal_senders=0
-synchronous_commit=off
-wal_level=minimal
-listen_addresses=''
-EOF
-grep -v host \
- < "$TMPDIR/pg_hba.conf" \
- > "$TMPDIR/pg_hba.conf.new"
-mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
-"${POSTGRES_PATH}/pg_ctl" \
- -D "$TMPDIR" \
- -l /dev/null \
- start \
- > "${MYDIR}/postgres-start.log" \
- 2> "${MYDIR}/postgres-start.err"
-echo " DONE"
-PGHOST="$TMPDIR/sockets"
-export PGHOST
+
+echo -n "Testing for Postgres"
+[ $(id -u == 0) ] || perform_initdb
echo "Generating fresh database at $MYDIR"
if faketime -f '-1 d' ./generate-auditor-basedb.sh -d "$MYDIR/auditor-basedb"
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.