From a7fb34b1ef0e141e76cc0138aa30563646975eb3 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Fri, 1 Oct 2021 18:09:43 +0200 Subject: [PATCH] systemtests: configurable database credentials 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. --- CMakeLists.txt | 1 + core/cmake/BareosFindAllLibraries.cmake | 2 -- core/cmake/BareosSetVariableDefaults.cmake | 10 ++++++++++ .../catalog/bareos-dir.d/catalog/.gitignore | 1 + .../{MyCatalog.conf => MyCatalog.conf.in} | 8 ++++---- .../BuildAndTestBareos/systemtests.rst | 20 ++----------------- systemtests/CMakeLists.txt | 16 +++------------ .../cmake/BareosSystemtestFunctions.cmake | 4 ++-- 8 files changed, 23 insertions(+), 39 deletions(-) create mode 100644 core/src/tests/configs/catalog/bareos-dir.d/catalog/.gitignore rename core/src/tests/configs/catalog/bareos-dir.d/catalog/{MyCatalog.conf => MyCatalog.conf.in} (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f63c394a7a0..49dc7d9dbfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ add_custom_target( set(default_build_type "Debug") +include(CMakePrintHelpers) find_package(Git) include(BareosVersionFromGit) include(BareosExtractVersionInfo) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 0b0d3148277..f70f77e3494 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -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() diff --git a/core/cmake/BareosSetVariableDefaults.cmake b/core/cmake/BareosSetVariableDefaults.cmake index e3e84caf062..e6e32de9139 100644 --- a/core/cmake/BareosSetVariableDefaults.cmake +++ b/core/cmake/BareosSetVariableDefaults.cmake @@ -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 "") diff --git a/core/src/tests/configs/catalog/bareos-dir.d/catalog/.gitignore b/core/src/tests/configs/catalog/bareos-dir.d/catalog/.gitignore new file mode 100644 index 00000000000..f2d4429a71e --- /dev/null +++ b/core/src/tests/configs/catalog/bareos-dir.d/catalog/.gitignore @@ -0,0 +1 @@ +MyCatalog.conf diff --git a/core/src/tests/configs/catalog/bareos-dir.d/catalog/MyCatalog.conf b/core/src/tests/configs/catalog/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 64% rename from core/src/tests/configs/catalog/bareos-dir.d/catalog/MyCatalog.conf rename to core/src/tests/configs/catalog/bareos-dir.d/catalog/MyCatalog.conf.in index ececcbc1d06..16e4c9ddd89 100644 --- a/core/src/tests/configs/catalog/bareos-dir.d/catalog/MyCatalog.conf +++ b/core/src/tests/configs/catalog/bareos-dir.d/catalog/MyCatalog.conf.in @@ -2,8 +2,8 @@ Catalog { Name = postgresql dbdriver = "postgresql" dbname = "regress_catalog" - dbuser = "regress" - dbpassword = "" + dbuser = "@systemtest_db_user@" + dbpassword = "@systemtest_db_password@" } Catalog { @@ -18,6 +18,6 @@ Catalog { Name = mysql dbdriver = "mysql" dbname = "regress_catalog" - dbuser = "regress" - dbpassword = "" + dbuser = "@systemtest_db_user@" + dbpassword = "@systemtest_db_password@" } diff --git a/docs/manuals/source/DeveloperGuide/BuildAndTestBareos/systemtests.rst b/docs/manuals/source/DeveloperGuide/BuildAndTestBareos/systemtests.rst index 7e9ccfc59b9..b37a975597e 100644 --- a/docs/manuals/source/DeveloperGuide/BuildAndTestBareos/systemtests.rst +++ b/docs/manuals/source/DeveloperGuide/BuildAndTestBareos/systemtests.rst @@ -14,7 +14,7 @@ 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 @@ -22,22 +22,6 @@ must be given permission to create databases and database user. 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 ---------------------------- @@ -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 diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index a204e33ab2b..d312ce4ae57 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -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) @@ -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) diff --git a/systemtests/cmake/BareosSystemtestFunctions.cmake b/systemtests/cmake/BareosSystemtestFunctions.cmake index bf98c7aec95..73133287f7a 100644 --- a/systemtests/cmake/BareosSystemtestFunctions.cmake +++ b/systemtests/cmake/BareosSystemtestFunctions.cmake @@ -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}") @@ -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)