From e1b7573956194871c8518ae46a3aacd2959969f2 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 19 Aug 2020 14:56:41 +0200 Subject: [PATCH 1/2] cats: allow MySQL/SQLite db create and make tables during tests In order to still allow creation of MySQL and SQlite databases when running tests but forbid it otherwise, the environment variable BAREOS_TEST_RUNNING is defined in all tests. When this variable is undefined, creating databases and making tables of MySQL and SQLite is forbidden. --- core/src/cats/create_bareos_database.in | 21 +++++++++++++++---- core/src/cats/make_bareos_tables.in | 28 +++++++++++++++++++------ systemtests/environment.in | 3 +++ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/core/src/cats/create_bareos_database.in b/core/src/cats/create_bareos_database.in index 0c9ad1a8cb8..81ea74c6a67 100755 --- a/core/src/cats/create_bareos_database.in +++ b/core/src/cats/create_bareos_database.in @@ -81,12 +81,25 @@ fi case ${db_type} in sqlite3) - echo "The SQLite database backend is deprecated. Please use PostgreSQL instead." - retval=1 + if [ -n "$BAREOS_TEST_RUNNING" ]; then + sqlite3 $* ${working_dir}/${db_name}.db ".tables" + # Allow non root access + chown ${dir_user}:${dir_group} ${working_dir}/${db_name}.db + chmod 0640 ${working_dir}/${db_name}.db + retval=0 + else + echo "The SQLite database backend is deprecated. Please use PostgreSQL instead." + retval=1 + fi ;; mysql) - echo "The MySQL database backend is deprecated. Please use PostgreSQL instead." - retval=1 + if [ -n "$BAREOS_TEST_RUNNING" ]; then + mysql $* -e "CREATE DATABASE ${db_name};" + retval=$? + else + echo "The MySQL database backend is deprecated. Please use PostgreSQL instead." + retval=1 + fi ;; postgresql) # diff --git a/core/src/cats/make_bareos_tables.in b/core/src/cats/make_bareos_tables.in index 6644087bfa5..2cd09b02899 100755 --- a/core/src/cats/make_bareos_tables.in +++ b/core/src/cats/make_bareos_tables.in @@ -110,14 +110,30 @@ fi case ${db_type} in sqlite3) - echo "The SQLite database backend is deprecated. Please use PostgreSQL instead." - echo "Creation of Bareos SQLite tables aborted." - retval=1 + if [ -n "$BAREOS_TEST_RUNNING" ]; then + sqlite3 $* ${working_dir}/${db_name}.db < ${temp_sql_schema} + chmod 640 ${working_dir}/${db_name}.db + retval=0 + else + echo "The SQLite database backend is deprecated. Please use PostgreSQL instead." + echo "Creation of Bareos SQLite tables aborted." + retval=1 + fi ;; mysql) - echo "The MySQL database backend is deprecated. Please use PostgreSQL instead." - echo "Creation of Bareos MySQL tables aborted." - retval=1 + if [ -n "$BAREOS_TEST_RUNNING" ]; then + mysql $* --database=${db_name} -f < ${temp_sql_schema} + retval=$? + if test $retval = 0; then + echo "Creation of Bareos MySQL tables succeeded." + else + echo "Creation of Bareos MySQL tables failed." + fi + else + echo "The MySQL database backend is deprecated. Please use PostgreSQL instead." + echo "Creation of Bareos MySQL tables aborted." + retval=1 + fi ;; postgresql) PGOPTIONS='--client-min-messages=warning' psql -f ${temp_sql_schema} -d ${db_name} $* diff --git a/systemtests/environment.in b/systemtests/environment.in index bf075a59f84..ffb68b5318b 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -114,3 +114,6 @@ if [ -d /usr/lib/postgresql ]; then else export PATH=/sbin:/usr/sbin:$PATH fi + +# enable deprecated database handling in scripts +export BAREOS_TEST_RUNNING=yes From 9e01247654786b21928f95e760891811b7c00c32 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 19 Aug 2020 14:02:38 +0200 Subject: [PATCH 2/2] tests: dbcopy-mysql-postgresql: removed unneded python module in test fileset --- .../etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in index 3ca91592f60..a85a027804b 100644 --- a/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in +++ b/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in @@ -5,8 +5,6 @@ FileSet { Options { Signature = MD5 # calculate md5 checksum per file } - #File = "@sbindir@" File=<@tmpdir@/file-list - Plugin = "python:module_path=@python_plugin_module_src_test_dir_relative@:module_name=bareos-fd-local-fileset-with-restoreobjects:filename=@tmpdir@/file-list-python-plugin" } }