#7 Add sanity tests for libecpg, pgaudit and postgres-decodebufs
Closed 2 years ago by fjanus. Opened 2 years ago by hhorak.
tests/ hhorak/postgresql add-pgaudit-decodebufs  into  main

@@ -0,0 +1,28 @@ 

+ summary: Sanity test for libecpg library

+ description: ''

+ contact: Honza Horak <hhorak@redhat.com>

+ component:

+ - libecpg

+ test: ./runtest.sh

+ path: /Sanity/libecpg

+ framework: beakerlib

+ require:

+ - url: https://github.com/beakerlib/database.git

+   name: /postgresql

+   ref: master

+ recommend:

+ - postgresql-server

+ - libecpg-devel

+ - gcc-c++

+ duration: 5m

+ enabled: true

+ tag:

+ - NoRHEL4

+ - NoRHEL5

+ - NoRHEL6

+ - TIPfail

+ - TIPfail_Apps

+ - Tier1

+ - libecpg

+ tier: '1'

+ extra-task: /CoreOS/postgresql/Sanity/libecpg

@@ -0,0 +1,91 @@ 

+ #!/bin/bash

+ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/postgresql/Sanity/libecpg

+ #   Description: Sanity test for libecpg library

+ #   Author: Honza Horak <hhorak@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2015 Red Hat, Inc.

+ #

+ #   This program is free software: you can redistribute it and/or

+ #   modify it under the terms of the GNU General Public License as

+ #   published by the Free Software Foundation, either version 2 of

+ #   the License, or (at your option) any later version.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE.  See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public License

+ #   along with this program. If not, see http://www.gnu.org/licenses/.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="postgresql"

+ PACKAGE_LIBECPG_DEVEL="libecpg-devel"

+ 

+ rlJournalStart

+     rlPhaseStart FAIL "Setup"

+         rlRun "rlImport database/postgresql"

+         PGDATA="$postgresqlDataDir"

+         rlRun "rpm -q libecpg-devel || dnf --enablerepo '*CRB' -y install libecpg-devel" 0 "Workaround to install libecpg-devel from CRB"

+         PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE_LIBECPG_DEVEL} \

+                   ${postgresqlPackagePrefix}${PACKAGE} \

+                   ${postgresqlPackagePrefix}${PACKAGE}-server";

+         for PACKAGE in $PACKAGES; do

+             rlAssertRpm $PACKAGE

+         done

+         rlRun "TestDir=$PWD"

+         rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"

+         rlRun "chmod 777 $TmpDir"

+         rlRun "pushd $TmpDir"

+     rlPhaseEnd

+ 

+     rlPhaseStartSetup "Database setup"

+         varDump postgresqlDataDir;

+         [[ -d $postgresqlDataDir ]] && rlFileBackup $postgresqlDataDir;

+         postgresqlCleanup;

+         postgresqlInitDB;

+         rlRun "postgresqlChangeAuth trust" 0 "Allow 'trust' authentication"

+         #rlRun "sed -i -e 's/ident/trust/' ${postgresqlDataDir}/pg_hba.conf" 0 "Allow 'trust' authentication"

+         cat /var/lib/pgsql/data/pg_hba.conf

+         postgresqlStart;

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         postgresqlExec "createdb testdb" "postgres"

+         rlRun "cp $TestDir/testecpg-decimal.pgc ."

+         rlRun "ecpg testecpg-decimal.pgc"

+         rlRun "cc -o testecpg-decimal testecpg-decimal.c -lecpg -lpgtypes"

+         rlRun "chown postgres:postgres *"

+         rlRun -s "./testecpg-decimal"

+         rlAssertGrep "numeric = 12" $rlRun_LOG

+         rlAssertGrep "numeric = 12.4" $rlRun_LOG

+         rlAssertGrep "numeric = 12.35" $rlRun_LOG

+         rlAssertGrep "decimal = 23" $rlRun_LOG

+         rlAssertGrep "decimal = 23.5" $rlRun_LOG

+         rlAssertGrep "decimal = 23.46" $rlRun_LOG

+ 

+         rlRun "cp $TestDir/testecpg-interval.pgc ."

+         rlRun "ecpg testecpg-interval.pgc"

+         rlRun "cc -o testecpg-interval testecpg-interval.c -lecpg -lpgtypes"

+         rlRun -s "./testecpg-interval"

+         rlAssertGrep "interval = @ 1 min" $rlRun_LOG

+     rlPhaseEnd

+ 

+     rlPhaseStart WARN "Cleanup";

+         rlRun "popd"

+         rlRun "rm -r $TmpDir" 0 "Removing tmp directory"

+         rm -f $rlRun_LOG;

+         rlRun "postgresqlCleanup";

+         rlFileRestore;

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

@@ -0,0 +1,44 @@ 

+ // Taken from https://www.postgresql.org/docs/13/ecpg-variables.html

+ 

+ #include <stdio.h>

+ #include <stdlib.h>

+ #include <pgtypes_numeric.h>

+ 

+ EXEC SQL WHENEVER SQLERROR STOP;

+ 

+ int

+ main(void)

+ {

+ EXEC SQL BEGIN DECLARE SECTION;

+     numeric *num;

+     numeric *num2;

+     decimal *dec;

+ EXEC SQL END DECLARE SECTION;

+ 

+     EXEC SQL CONNECT TO testdb USER postgres;

+ 

+     num = PGTYPESnumeric_new();

+     dec = PGTYPESdecimal_new();

+ 

+     EXEC SQL SELECT 12.345::numeric(4,2), 23.456::decimal(4,2) INTO :num, :dec;

+ 

+     printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 0));

+     printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 1));

+     printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 2));

+ 

+     /* Convert decimal to numeric to show a decimal value. */

+     num2 = PGTYPESnumeric_new();

+     PGTYPESnumeric_from_decimal(dec, num2);

+ 

+     printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 0));

+     printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 1));

+     printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 2));

+ 

+     PGTYPESnumeric_free(num2);

+     PGTYPESdecimal_free(dec);

+     PGTYPESnumeric_free(num);

+ 

+     EXEC SQL COMMIT;

+     EXEC SQL DISCONNECT ALL;

+     return 0;

+ }

@@ -0,0 +1,24 @@ 

+ // Taken from https://www.postgresql.org/docs/13/ecpg-variables.html

+ 

+ #include <stdio.h>

+ #include <stdlib.h>

+ #include <pgtypes_interval.h>

+ 

+ int

+ main(void)

+ {

+ EXEC SQL BEGIN DECLARE SECTION;

+     interval *in;

+ EXEC SQL END DECLARE SECTION;

+ 

+     EXEC SQL CONNECT TO testdb USER postgres;

+ 

+     in = PGTYPESinterval_new();

+     EXEC SQL SELECT '1 min'::interval INTO :in;

+     printf("interval = %s\n", PGTYPESinterval_to_asc(in));

+     PGTYPESinterval_free(in);

+ 

+     EXEC SQL COMMIT;

+     EXEC SQL DISCONNECT ALL;

+     return 0;

+ }

@@ -0,0 +1,26 @@ 

+ summary: Sanity test for pgaudit extension

+ description: ''

+ contact: Vaclav Danek <vdanek@redhat.com>

+ component:

+ - postgresql

+ test: ./runtest.sh

+ path: /Sanity/pgaudit

+ framework: beakerlib

+ require:

+ - url: https://github.com/beakerlib/database.git

+   name: /postgresql

+   ref: master

+ recommend:

+ - postgresql-server

+ - pgaudit

+ duration: 5m

+ enabled: true

+ tag:

+ - NoRHEL4

+ - NoRHEL5

+ - NoRHEL6

+ - TIPfail

+ - TIPfail_Apps

+ - Tier1

+ tier: '1'

+ extra-task: /CoreOS/postgresql/Sanity/pgaudit

@@ -0,0 +1,74 @@ 

+ #!/bin/bash

+ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/postgresql/Sanity/pgaudit

+ #   Description: Sanity test for pgaudit extension

+ #   Author: Honza Horak <hhorak@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2015 Red Hat, Inc.

+ #

+ #   This program is free software: you can redistribute it and/or

+ #   modify it under the terms of the GNU General Public License as

+ #   published by the Free Software Foundation, either version 2 of

+ #   the License, or (at your option) any later version.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE.  See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public License

+ #   along with this program. If not, see http://www.gnu.org/licenses/.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="postgresql"

+ PACKAGE_AUDIT="pgaudit"

+ 

+ rlJournalStart

+     rlPhaseStart FAIL "Setup"

+         rlRun "rlImport database/postgresql"

+         PGDATA="$(postgresqlGetDataDir)";

+         PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE_AUDIT} \

+                   ${postgresqlPackagePrefix}${PACKAGE} \

+                   ${postgresqlPackagePrefix}${PACKAGE}-server";

+         for PACKAGE in $PACKAGES; do

+             rlAssertRpm $PACKAGE

+         done

+         rlRun "postgresqlStop";

+         [[ -d ${postgresqlDataDir} ]] && rlFileBackup "${postgresqlDataDir}"

+         rlRun "postgresqlCleanup"

+         rlRun "postgresqlStart"

+         rlRun "sed -i -e \"s/#shared_preload_libraries = ''/shared_preload_libraries = 'pgaudit'/\" ${PGDATA}/postgresql.conf" 0 "Adding pgaudit to the shared_preload_libraries in the config file ..."

+         rlRun "postgresqlStop";

+         rlRun "postgresqlStart"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlRun "postgresqlQuery \"DROP EXTENSION IF EXISTS pgaudit;\"";

+         rlRun "postgresqlQuery \"CREATE EXTENSION pgaudit;\"" 0;

+         rlRun "postgresqlQuery \"SET pgaudit.log = 'read, ddl';

+                                 DROP TABLE IF EXISTS account;

+                                 CREATE TABLE account (id int, name text, password text, description text);

+                                 INSERT INTO account (id, name, password, description) VALUES (1, 'user1', 'HASH1', 'blah, blah');\"" 0;

+         rlRun "postgresqlQuery \"SELECT * FROM account;\"" 0;

+         rlAssertGrep 'AUDIT: SESSION,.*,.*,DDL,DROP TABLE,,,DROP TABLE IF EXISTS account' ${postgresqlLogDir}/postgresql*.log -E

+         rlAssertGrep 'AUDIT: SESSION,.*,.*,DDL,CREATE TABLE,TABLE,public.account,"CREATE TABLE account' ${postgresqlLogDir}/postgresql*.log -E

+ cat ${postgresqlLogDir}/postgresql*.log

+         rlRun "postgresqlQuery \"DROP TABLE IF EXISTS account;\"" 0;

+         rlRun "postgresqlQuery \"DROP EXTENSION IF EXISTS pgaudit;\"";

+     rlPhaseEnd

+ 

+     rlPhaseStart WARN "Cleanup";

+         rm -f $rlRun_LOG;

+         rlRun "postgresqlCleanup";

+         rlFileRestore;

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

@@ -0,0 +1,26 @@ 

+ summary: Sanity test for postgres-decoderbufs plugin

+ description: ''

+ contact: Vaclav Danek <vdanek@redhat.com>

+ component:

+ - postgresql

+ test: ./runtest.sh

+ path: /Sanity/postgres-decoderbufs

+ framework: beakerlib

+ require:

+ - url: https://github.com/beakerlib/database.git

+   name: /postgresql

+   ref: master

+ recommend:

+ - postgresql-server

+ - postgres-decoderbufs

+ duration: 5m

+ enabled: true

+ tag:

+ - NoRHEL4

+ - NoRHEL5

+ - NoRHEL6

+ - TIPfail

+ - TIPfail_Apps

+ - Tier1

+ tier: '1'

+ extra-task: /CoreOS/postgresql/Sanity/postgres-decoderbufs

@@ -0,0 +1,72 @@ 

+ #!/bin/bash

+ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/postgresql/Sanity/postgres-decoderbufs

+ #   Description: Sanity test for postgres-decoderbufs plugin

+ #   Author: Jiri Pechanec <jpechane@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2015 Red Hat, Inc.

+ #

+ #   This program is free software: you can redistribute it and/or

+ #   modify it under the terms of the GNU General Public License as

+ #   published by the Free Software Foundation, either version 2 of

+ #   the License, or (at your option) any later version.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE.  See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public License

+ #   along with this program. If not, see http://www.gnu.org/licenses/.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="postgresql"

+ PACKAGE_DECODERBUFS="postgres-decoderbufs"

+ 

+ rlJournalStart

+     rlPhaseStart FAIL "Setup"

+         rlRun "rlImport database/postgresql"

+         PGDATA="$(postgresqlGetDataDir)";

+         PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE_DECODERBUFS} \

+                   ${postgresqlPackagePrefix}${PACKAGE} \

+                   ${postgresqlPackagePrefix}${PACKAGE}-server";

+         for PACKAGE in $PACKAGES; do

+             rlAssertRpm $PACKAGE

+         done

+         rlRun "postgresqlStop";

+         [[ -d ${postgresqlDataDir} ]] && rlFileBackup "${postgresqlDataDir}"

+         rlRun "postgresqlCleanup"

+         rlRun "postgresqlStart"

+         rlRun "sed -i -e \"s/#shared_preload_libraries = ''/shared_preload_libraries = 'decoderbufs'/\" ${PGDATA}/postgresql.conf" 0 "Adding decoderbufs to the shared_preload_libraries in the config file ..."

+         rlRun "sed -i -e \"s/#wal_level = replica/wal_level = logical/\" ${PGDATA}/postgresql.conf" 0 "Configuring wal_level to logical..."

+         rlRun "postgresqlStop";

+         rlRun "postgresqlStart"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlRun "postgresqlQuery \"DROP TABLE IF EXISTS streaming_table;\"";

+         rlRun "postgresqlQuery \"CREATE TABLE streaming_table (id int, name varchar(32));\"" 0;

+         rlRun "postgresqlQuery \"SELECT * FROM pg_drop_replication_slot('test');\"" 0,3;

+         rlRun "postgresqlQuery \"SELECT * FROM pg_create_logical_replication_slot('test', 'decoderbufs');\"" 0;

+         rlRun "postgresqlQuery \"INSERT INTO streaming_table VALUES (1, 'myname');\"" 0;

+         rlRun -s "postgresqlQuery \"SELECT data FROM pg_logical_slot_peek_changes('test', NULL, 1, 'debug-mode', 'true');\"" 0;

+         rlAssertGrep 'column_name\[id\], column_type\[23\], datum\[1\]' $rlRun_LOG -E

+         rlRun "postgresqlQuery \"DROP TABLE IF EXISTS streaming_table;\"" 0;

+         rlRun "postgresqlQuery \"SELECT * FROM pg_drop_replication_slot('test');\"" 0;

+     rlPhaseEnd

+ 

+     rlPhaseStart WARN "Cleanup";

+         rm -f $rlRun_LOG;

+         rlRun "postgresqlCleanup";

+         rlFileRestore;

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

file modified
+1 -2
@@ -27,8 +27,7 @@ 

  #

  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  

- # Include rhts environment

- . /usr/bin/rhts-environment.sh

+ # Include Beaker environment

  . /usr/lib/beakerlib/beakerlib.sh

  

  # TODO: This is temporary workaround till we have no /Library directory