Skip to content

Commit

Permalink
systemtests: configurable database credentials
Browse files Browse the repository at this point in the history
This changes makes the PostgreSQL database configuration
for systemtests simpler.
Before it has be necessary to configure two database roles,
one for the current system user and one for the database user "regress".
The database admin scripts did run as the system user,
while the Bareos use the "regress" database user.
This did also require to adapt a PostgreSQL configuration file.

With this change, only database one role and no change
to the PostgreSQL default configuration is required.

For using the system user, run cmake with following parameter:

cmake -Dsystemtest_db_user=$USER ...

When systemtest_db_user is not given as parameter, the old default "regress" is used.
  • Loading branch information
joergsteffens committed Oct 8, 2021
1 parent e92dd6f commit a7fb34b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 39 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -31,6 +31,7 @@ add_custom_target(

set(default_build_type "Debug")

include(CMakePrintHelpers)
find_package(Git)
include(BareosVersionFromGit)
include(BareosExtractVersionInfo)
Expand Down
2 changes: 0 additions & 2 deletions core/cmake/BareosFindAllLibraries.cmake
Expand Up @@ -191,8 +191,6 @@ if(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES SunPro)
find_package(GTest 1.8 CONFIG)
endif()

bareosfindlibrary("pam_wrapper")

if(${HAVE_CAP})
set(HAVE_LIBCAP 1)
endif()
Expand Down
10 changes: 10 additions & 0 deletions core/cmake/BareosSetVariableDefaults.cmake
Expand Up @@ -264,6 +264,16 @@ if(NOT DEFINED db_password)
set(db_password "")
endif()

set(systemtest_db_user
"regress"
CACHE STRING "Database user for the systemtests"
)

set(systemtest_db_password
""
CACHE STRING "Database password for the systemtests"
)

# dir-user
if(NOT DEFINED dir-user)
set(dir-user "")
Expand Down
@@ -0,0 +1 @@
MyCatalog.conf
Expand Up @@ -2,8 +2,8 @@ Catalog {
Name = postgresql
dbdriver = "postgresql"
dbname = "regress_catalog"
dbuser = "regress"
dbpassword = ""
dbuser = "@systemtest_db_user@"
dbpassword = "@systemtest_db_password@"
}

Catalog {
Expand All @@ -18,6 +18,6 @@ Catalog {
Name = mysql
dbdriver = "mysql"
dbname = "regress_catalog"
dbuser = "regress"
dbpassword = ""
dbuser = "@systemtest_db_user@"
dbpassword = "@systemtest_db_password@"
}
Expand Up @@ -14,30 +14,14 @@ The |dir| requires a database backend. The default database is |postgresql|.
To run systemtests, some preparations are required.

The system user running the Bareos systemtests
must be given permission to create databases and database user.
must be given permission to create databases and database user:

.. code-block:: shell-session
:caption: Configure a PostgreSQL Server for systemtests
user@host:~$ sudo -u postgres createuser --createdb --createrole $USER
Each systemtest creates its own database.
The test scripts also create the database user **regress**
which needs access all created databases.
To achieve this, add the following lines to the :file:`pg_hba.conf` file:

.. code-block:: cfg
:caption: Allow access to all local databases for PostgresSQL user regress
# insert authentication methods for database user 'regress'
# BEFORE the general rules into file pg_hba.conf
local all regress trust
Make sure, to restart the |postgresql| server.


Build Bareos for Systemtests
----------------------------

Expand All @@ -56,7 +40,7 @@ This following shell script will show how to build the Bareos test-environment f
cd build
# configure build environment
cmake -Dpostgresql=yes -Dtraymonitor=yes ../bareos
cmake -Dpostgresql=yes -Dsystemtest_db_user=$USER -Dtraymonitor=yes ../bareos
# build Bareos
make
Expand Down
16 changes: 3 additions & 13 deletions systemtests/CMakeLists.txt
Expand Up @@ -24,7 +24,6 @@ project(bareos-systemtests)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(BareosSystemtestFunctions)
include(CMakePrintHelpers)

# set the data encryption and signature keys
set(pki_keypair ${CMAKE_CURRENT_SOURCE_DIR}/pki/fd.pem)
Expand Down Expand Up @@ -130,27 +129,18 @@ set(bindir ${PROJECT_BINARY_DIR}/bin)

set(BAREOS_CONFIG_DIR ${conf})
set(db_name "regress")
set(db_password "")
set(db_port "5432")
set(db_user "regress")
set(dir_password "dir_password")
set(dumps ${PROJECT_BINARY_DIR}/dumps)
set(fd_password "fd_password")
set(db_user "${systemtest_db_user}")
set(db_password "${systemtest_db_password}")

set(job_email "job_email")
set(logdir "log")
set(mon_dir_password "mon_dir_password")
set(mon_fd_password "mon_fd_password")
set(mon_sd_password "mon_sd_password")
set(python_plugin_module_src_test_dir_relative "python-modules")
set(dumps ${PROJECT_BINARY_DIR}/dumps)
set(plugindirtmp ${PROJECT_BINARY_DIR}/plugindirtmp)
set(rscripts ${PROJECT_BINARY_DIR}/scripts)

set(sbindir ${PROJECT_BINARY_DIR}/sbin)

set(scriptdir ${PROJECT_BINARY_DIR}/scripts)
set(scripts ${PROJECT_BINARY_DIR}/scripts)
set(sd_password "sd_password")
set(smtp_host "smtp_host")
set(src ${PROJECT_BINARY_DIR}/src)
set(subsysdir ${PROJECT_BINARY_DIR}/subsysdir)
Expand Down
4 changes: 2 additions & 2 deletions systemtests/cmake/BareosSystemtestFunctions.cmake
Expand Up @@ -275,6 +275,7 @@ endfunction()
macro(check_for_pamtest)
message(STATUS "Looking for pam test requirements ...")
bareosfindlibraryandheaders("pam" "security/pam_appl.h" "")
bareosfindlibrary("pam_wrapper")
find_program(PAMTESTER pamtester)

set(ENV{PAM_WRAPPER_LIBRARIES} "${PAM_WRAPPER_LIBRARIES}")
Expand Down Expand Up @@ -450,11 +451,10 @@ macro(prepare_test test_subdir)
set(basename ${TEST_NAME})

# db parameters
set(db_password "")

# db_name is regress-${TEST_NAME} replacing - by _
string(REPLACE "-" "_" db_name "regress-${TEST_NAME}")
# set(db_name "regress-${TEST_NAME}")
set(db_user "regress")
set(db_address "$current_test_directory/database/tmp")

set(job_email root@localhost)
Expand Down

0 comments on commit a7fb34b

Please sign in to comment.