From 9d75682490513ff21e884f6e0b086ff58dc90208 Mon Sep 17 00:00:00 2001 From: Stephan Duehr Date: Thu, 27 Jun 2024 18:41:30 +0200 Subject: [PATCH 01/14] mtx-changer: Fix for FreeBSD FreeBSD's awk unlike gawk does not have gensub(), now match() and substr() is used instead. - systemtests: Fix mtx-changer test on FreeBSD The scripts used /bin/true, but that doesn't exist on FreeBSD any more. Now using /usr/bin/env true, that should work on all systems. --- core/scripts/mtx-changer.in | 10 +++++++++- systemtests/tests/mtx-changer/test-cleanup | 2 +- systemtests/tests/mtx-changer/test-setup | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/scripts/mtx-changer.in b/core/scripts/mtx-changer.in index 479f6f73b08..0b64033e951 100755 --- a/core/scripts/mtx-changer.in +++ b/core/scripts/mtx-changer.in @@ -270,7 +270,15 @@ _EOT_ awk -F ":" -f - "${TMPFILE}" << '_EOT_' /^Data Transfer Element .*[0-9]:/ { gsub("Data Transfer Element ","",$1) - F=gensub(/Full \(Storage Element ([0-9]{1,}) Loaded\)/,":F:\\1",1,$2) + match($2,/Full \(Storage Element ([0-9]{1,}) Loaded\)/) + if (RSTART > 0 ) { + T=substr($2,RSTART,RLENGTH) + match(T,/[0-9]{1,}/) + F=":F:" substr(T,RSTART,RLENGTH) + } + else { + F=$2 + } gsub("Empty",":E",F) gsub("VolumeTag = ",":",$3) print "D:" $1 F $3 diff --git a/systemtests/tests/mtx-changer/test-cleanup b/systemtests/tests/mtx-changer/test-cleanup index b23e55619b2..a8bdb3d5608 100755 --- a/systemtests/tests/mtx-changer/test-cleanup +++ b/systemtests/tests/mtx-changer/test-cleanup @@ -1 +1 @@ -#!/bin/true +#!/usr/bin/env true diff --git a/systemtests/tests/mtx-changer/test-setup b/systemtests/tests/mtx-changer/test-setup index b23e55619b2..a8bdb3d5608 100755 --- a/systemtests/tests/mtx-changer/test-setup +++ b/systemtests/tests/mtx-changer/test-setup @@ -1 +1 @@ -#!/bin/true +#!/usr/bin/env true From 975c57f859f831d79af703b7143f10a6016574c5 Mon Sep 17 00:00:00 2001 From: Bruno Friedmann Date: Wed, 15 May 2024 13:20:42 +0200 Subject: [PATCH 02/14] systemtests: scripts mysql.sh use mysql_cleanup - replace shutdown_mysql_server by calling mysql_cleanup in case of startup error - function improve code by quoting variables - adjust copyright year Signed-off-by: Bruno Friedmann --- systemtests/scripts/functions | 4 ++-- systemtests/scripts/mysql.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/systemtests/scripts/functions b/systemtests/scripts/functions index fbde6ef9417..55033485ec5 100644 --- a/systemtests/scripts/functions +++ b/systemtests/scripts/functions @@ -1226,8 +1226,8 @@ fi # Used by mysqltest skip_if_root() { -USER=$(whoami) -if [ "$USER" == "root" ]; then +USER="$(whoami)" +if [ "${USER}" == "root" ]; then echo "${TestName} test skipped: test cannot be run as user root." exit 77; fi diff --git a/systemtests/scripts/mysql.sh b/systemtests/scripts/mysql.sh index 8c283d99d33..9426f9824c0 100644 --- a/systemtests/scripts/mysql.sh +++ b/systemtests/scripts/mysql.sh @@ -2,7 +2,7 @@ # BAREOS® - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2022-2022 Bareos GmbH & Co. KG +# Copyright (C) 2022-2024 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -86,7 +86,7 @@ mysql_server_start() [ $((tries-=1)) -eq 0 ] && { echo "Could not start MySQL server" cat mysql/mysql.log - shutdown_mysql_server + mysql_cleanup exit 1 } printf "." From ff049e6f7adbbccf4d92cc443d5f87b33eb3699d Mon Sep 17 00:00:00 2001 From: Bruno Friedmann Date: Wed, 29 May 2024 13:30:52 +0200 Subject: [PATCH 03/14] cmake: remove REPEAT_UNTIL arguments & fix copyright year Signed-off-by: Bruno Friedmann --- core/CMakeLists.txt | 2 +- core/cmake/BareosFindPrograms.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 7fc64077354..f2343e8cb41 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -913,7 +913,7 @@ print_variables("${DUMP_VARS}") # REPEAT_UNTIL requires cmake 3.17+ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") - set(REPEAT_UNTIL "REPEAT UNTIL_PASS:2") + set(REPEAT_UNTIL "") endif() configure_file( diff --git a/core/cmake/BareosFindPrograms.cmake b/core/cmake/BareosFindPrograms.cmake index da70bb24eb5..318d598a9d1 100644 --- a/core/cmake/BareosFindPrograms.cmake +++ b/core/cmake/BareosFindPrograms.cmake @@ -1,6 +1,6 @@ # BAREOS® - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2017-2023 Bareos GmbH & Co. KG +# Copyright (C) 2017-2024 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public From fc1e45d1ee6dcd18e97417dbaa097dc30c8f5125 Mon Sep 17 00:00:00 2001 From: Bruno Friedmann Date: Mon, 8 Jul 2024 15:52:17 +0200 Subject: [PATCH 04/14] matrix.yml: add sle156, leap15.6, remove eol centos stream 8 - set sle156 as new default Signed-off-by: Bruno Friedmann --- .matrix.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.matrix.yml b/.matrix.yml index 96b70fc9bee..aec8fb1f5fa 100644 --- a/.matrix.yml +++ b/.matrix.yml @@ -64,8 +64,8 @@ OS: SUSE: "15": TYPE: rpm - IMAGE: sle154 - CUSTOM_TEST_IMAGES: [ SLE-15_SP3, SLE-15_SP4, openSUSE-Leap_15.4, SLE-15_SP5, openSUSE-Leap_15.5 ] + IMAGE: sle156 + CUSTOM_TEST_IMAGES: [ SLE-15_SP3, SLE-15_SP4, openSUSE-Leap_15.4, SLE-15_SP5, openSUSE-Leap_15.5, SLE-15_SP6, openSUSE-Leap_15.6 ] ARCH: - x86_64 Fedora: @@ -106,7 +106,7 @@ OS: "8": TYPE: rpm IMAGE: rhel8 - CUSTOM_TEST_IMAGES: [ Rocky, Alma, Oracle, Stream, RHEL ] + CUSTOM_TEST_IMAGES: [ Rocky, Alma, Oracle, RHEL ] ARCH: - x86_64 FreeBSD: From 82a76ae9e4b5d933c66db67b6e21845ffed053a3 Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Tue, 9 Jul 2024 17:32:26 +0200 Subject: [PATCH 05/14] packaging: clean up suse macros --- core/platforms/packaging/bareos.spec | 38 ++++++---------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index 7598d251f54..8a29fcecd76 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -110,19 +110,9 @@ BuildRequires: devtoolset-8-gcc BuildRequires: devtoolset-8-gcc-c++ %endif -%if 0%{?sle_version} == 150400 -BuildRequires: gcc11 -BuildRequires: gcc11-c++ -%else - %if 0%{?sle_version} == 150300 || 0%{?suse_version} > 1500 -BuildRequires: gcc10 -BuildRequires: gcc10-c++ - %else - %if 0%{?suse_version} -BuildRequires: gcc9 -BuildRequires: gcc9-c++ - %endif - %endif +%if 0%{?suse_version} +BuildRequires: gcc13 +BuildRequires: gcc13-c++ %endif %if 0%{?systemd_support} @@ -263,7 +253,7 @@ Bareos source code has been released under the AGPL version 3 license. %{dscr} -%if 0%{?opensuse_version} || 0%{?sle_version} +%if 0%{?suse_version} %debug_package %endif @@ -661,7 +651,7 @@ Requires: httpd %define www_daemon_group apache %endif -%if 0%{?suse_version} || 0%{?sle_version} +%if 0%{?suse_version} Conflicts: mod_php_any %define _apache_conf_dir /etc/apache2/conf.d/ %define www_daemon_user wwwrun @@ -841,23 +831,11 @@ source /opt/rh/devtoolset-8/enable %endif # use modern compiler on suse -%if 0%{?sle_version} == 150400 -CC=gcc-11 ; export CC -CXX=g++-11 ; export CXX -%else - %if 0%{?sle_version} == 150300 || 0%{?suse_version} > 1500 -CC=gcc-10 ; export CC -CXX=g++-10 ; export CXX - %else - %if 0%{?suse_version} -CC=gcc-9 ; export CC -CXX=g++-9 ; export CXX - %endif - %endif +%if 0%{?suse_version} +CC=gcc-13 ; export CC +CXX=g++-13 ; export CXX %endif - - CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; From 4d0ebae19dba6b2a4055371c9616a7fbae097642 Mon Sep 17 00:00:00 2001 From: Bruno Friedmann Date: Tue, 7 May 2024 17:03:14 +0200 Subject: [PATCH 06/14] tests: remove generated config file - remove generated configuration commited by error --- .../etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 systemtests/tests/bscan-bextract-bls-bcopy/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf diff --git a/systemtests/tests/bscan-bextract-bls-bcopy/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf b/systemtests/tests/bscan-bextract-bls-bcopy/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf deleted file mode 100644 index ca1891f9620..00000000000 --- a/systemtests/tests/bscan-bextract-bls-bcopy/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf +++ /dev/null @@ -1,5 +0,0 @@ -Job { - Name = "backup-bareos-fd" - JobDefs = "DefaultJob" - Client = "bareos-fd" -} From 6d112f10476017b51e89f542906975fa017b21ee Mon Sep 17 00:00:00 2001 From: Bruno Friedmann Date: Mon, 8 Jul 2024 15:53:35 +0200 Subject: [PATCH 07/14] tests: postgresql increase start timeout to 15 Avoid failure on loaded hosts Signed-off-by: Bruno Friedmann --- .../tests/py3plug-fd-postgresql/database/setup_local_db.sh.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemtests/tests/py3plug-fd-postgresql/database/setup_local_db.sh.in b/systemtests/tests/py3plug-fd-postgresql/database/setup_local_db.sh.in index 7b63d5d4877..5643cb81b92 100755 --- a/systemtests/tests/py3plug-fd-postgresql/database/setup_local_db.sh.in +++ b/systemtests/tests/py3plug-fd-postgresql/database/setup_local_db.sh.in @@ -69,9 +69,9 @@ local_db_prepare_files() { local_db_start_server() { echo "start db server" if [ $UID -eq 0 ]; then - su postgres -c "${POSTGRES_BIN_PATH}/pg_ctl --timeout=10 --wait --pgdata=data --log=log/logfile start" + su postgres -c "${POSTGRES_BIN_PATH}/pg_ctl --timeout=15 --wait --pgdata=data --log=log/logfile start" else - ${POSTGRES_BIN_PATH}/pg_ctl --timeout=10 --wait --pgdata=data --log=log/logfile start + ${POSTGRES_BIN_PATH}/pg_ctl --timeout=15 --wait --pgdata=data --log=log/logfile start fi } From 74914c695931e9f9c6fdea9c1e6336dc47d5e3d1 Mon Sep 17 00:00:00 2001 From: Bruno Friedmann Date: Tue, 16 Jul 2024 09:54:43 +0200 Subject: [PATCH 08/14] matrix: set suse155 as default build suse156 has a newer glibc 2.38. --- .matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.matrix.yml b/.matrix.yml index aec8fb1f5fa..313def61400 100644 --- a/.matrix.yml +++ b/.matrix.yml @@ -64,7 +64,7 @@ OS: SUSE: "15": TYPE: rpm - IMAGE: sle156 + IMAGE: sle155 CUSTOM_TEST_IMAGES: [ SLE-15_SP3, SLE-15_SP4, openSUSE-Leap_15.4, SLE-15_SP5, openSUSE-Leap_15.5, SLE-15_SP6, openSUSE-Leap_15.6 ] ARCH: - x86_64 From ba96c6214028b6d739a8fb1e62e614014c5d8e16 Mon Sep 17 00:00:00 2001 From: Bruno Friedmann Date: Wed, 31 Jul 2024 09:41:18 +0200 Subject: [PATCH 09/14] fix fileset name called during restore --- systemtests/tests/py3plug-fd-mariabackup/testrunner-default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemtests/tests/py3plug-fd-mariabackup/testrunner-default b/systemtests/tests/py3plug-fd-mariabackup/testrunner-default index 13652878392..93a0bfa68dd 100755 --- a/systemtests/tests/py3plug-fd-mariabackup/testrunner-default +++ b/systemtests/tests/py3plug-fd-mariabackup/testrunner-default @@ -98,7 +98,7 @@ fi cat <"$tmp/bconcmds" @$out ${tmp}/log4.out -restore client=bareos-fd fileset=MariaBackupTest yes restorejob=RestoreFile select all done +restore client=bareos-fd fileset=MariabackupTest yes restorejob=RestoreFile select all done wait status dir wait From f1cdfff1ce3ffa5a52e2177b649dde5cfcf6c2ea Mon Sep 17 00:00:00 2001 From: Sebastian Sura Date: Wed, 31 Jul 2024 08:34:01 +0200 Subject: [PATCH 10/14] create-resource: fix setting unused ports This is in preparation of removing `create_unique_socket_number()`. As these configuration values are not currently used in the tests, it makes sense to just set them to 0 for now. --- core/src/tests/create_resource.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/tests/create_resource.cc b/core/src/tests/create_resource.cc index ddd83f0e809..1d7218ee063 100644 --- a/core/src/tests/create_resource.cc +++ b/core/src/tests/create_resource.cc @@ -1,7 +1,7 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2018-2023 Bareos GmbH & Co. KG + Copyright (C) 2018-2024 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -43,7 +43,7 @@ console::DirectorResource* CreateAndInitializeNewDirectorResource() { console::DirectorResource* dir = new (console::DirectorResource); dir->address = (char*)HOST; - dir->DIRport = htons(create_unique_socket_number()); + dir->DIRport = 0; dir->tls_enable_ = false; dir->tls_require_ = false; dir->tls_cert_.certfile_ = CERTDIR "/bareos-dir.bareos.org-cert.pem"; @@ -93,7 +93,7 @@ directordaemon::StorageResource* CreateAndInitializeNewStorageResource() directordaemon::StorageResource* store = new (directordaemon::StorageResource); store->address = (char*)HOST; - store->SDport = htons(create_unique_socket_number()); + store->SDport = 0; store->tls_enable_ = false; store->tls_require_ = false; store->tls_cert_.certfile_ = CERTDIR "/bareos-dir.bareos.org-cert.pem"; From 10da7e0e509c3c8bad5b29df07af19856fca3d2a Mon Sep 17 00:00:00 2001 From: Sebastian Sura Date: Wed, 31 Jul 2024 08:35:36 +0200 Subject: [PATCH 11/14] tls-openssl: fix bad assert (socket-) fds are allowed to be zero, so we should instead be checking for '< 0' to detect bad socket fds. --- core/src/lib/tls_openssl_private.cc | 2 +- core/src/lib/tls_openssl_private.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/lib/tls_openssl_private.cc b/core/src/lib/tls_openssl_private.cc index 76a8c555a1a..5ae363df216 100644 --- a/core/src/lib/tls_openssl_private.cc +++ b/core/src/lib/tls_openssl_private.cc @@ -267,7 +267,7 @@ bool TlsOpenSslPrivate::init() return false; } - ASSERT(tcp_file_descriptor_); + ASSERT(tcp_file_descriptor_ >= 0); // 0 is a good (socket-)fd BIO_set_fd(bio, tcp_file_descriptor_, BIO_NOCLOSE); SSL_set_bio(openssl_, bio, bio); diff --git a/core/src/lib/tls_openssl_private.h b/core/src/lib/tls_openssl_private.h index d749deb7db3..80785c513fe 100644 --- a/core/src/lib/tls_openssl_private.h +++ b/core/src/lib/tls_openssl_private.h @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2005-2010 Free Software Foundation Europe e.V. - Copyright (C) 2018-2023 Bareos GmbH & Co. KG + Copyright (C) 2018-2024 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -80,7 +80,7 @@ class TlsOpenSslPrivate { std::string protocol_; /* cert attributes */ - int tcp_file_descriptor_{}; + int tcp_file_descriptor_{kInvalidFiledescriptor}; std::string ca_certfile_; std::string ca_certdir_; std::string crlfile_; From 2be10c605f5e172db7ba49029109aeef7d7e27c6 Mon Sep 17 00:00:00 2001 From: Sebastian Sura Date: Wed, 31 Jul 2024 08:41:05 +0200 Subject: [PATCH 12/14] bareos-test-sockets: change api We were always trying to find an unused port, and then we try to bind that port. This is not a good way to do it as there is no guarantee that the port will still be free when we actually try to bind the port, especially if there are a lot of concurrent tests running. Now we do it the opposite way: First we bind a random os-provided free port and only then do we find out which port it actually is. That should make sure that no two unit tests should ever try to bind the same port. There may still be conflicts between unittest ports and system test ports, but that can be fixed in a different way (e.g. just do not run that at the same time). --- core/src/tests/bareos_test_sockets.cc | 99 +++++++++++++++++++-------- core/src/tests/bareos_test_sockets.h | 28 +++++++- core/src/tests/test_bsock.cc | 43 +++++++----- 3 files changed, 121 insertions(+), 49 deletions(-) diff --git a/core/src/tests/bareos_test_sockets.cc b/core/src/tests/bareos_test_sockets.cc index 63a1fc56af9..88b26c2f46d 100644 --- a/core/src/tests/bareos_test_sockets.cc +++ b/core/src/tests/bareos_test_sockets.cc @@ -158,23 +158,54 @@ static int accept_server_socket(int listen_file_descriptor) return new_socket; } -int create_accepted_server_socket(int port) +static std::optional port_number_of(int sockfd) { - int sock_fd = create_listening_server_socket(port); - if (sock_fd > 0) { sock_fd = accept_server_socket(sock_fd); } - return sock_fd; + union { + struct sockaddr addr; + struct sockaddr_in addr4; + struct sockaddr_in6 addr6; + } buf = {}; + + // the port gets chosen during StartSocketServer, so we need to query + // the port number afterwards. + socklen_t len = sizeof(buf); + auto error = getsockname(sockfd, &buf.addr, &len); + EXPECT_EQ(error, 0); + if (error != 0) { + perror("sock name error"); + return false; + } + + if (buf.addr.sa_family != AF_INET && buf.addr.sa_family != AF_INET6) { + return std::nullopt; + } + + auto nport = (buf.addr.sa_family == AF_INET) ? buf.addr4.sin_port + : buf.addr6.sin6_port; + + auto port = ntohs(nport); + + return port; } std::unique_ptr create_connected_server_and_client_bareos_socket() { std::unique_ptr test_sockets(new TestSockets); - uint16_t portnumber = create_unique_socket_number(); + int listen_fd = create_listening_server_socket(0); - int server_file_descriptor = create_listening_server_socket(portnumber); + EXPECT_GE(listen_fd, 0) << "Could not create listening socket"; + if (listen_fd < 0) { return nullptr; } - EXPECT_GE(server_file_descriptor, 0) << "Could not create listening socket"; - if (server_file_descriptor < 0) { return nullptr; } + auto portnumber_opt = port_number_of(listen_fd); + + EXPECT_NE(portnumber_opt, std::nullopt) << "Could not find used port number"; + if (!portnumber_opt) { + socketClose(listen_fd); + return nullptr; + } + + auto portnumber = *portnumber_opt; test_sockets->client.reset(new BareosSocketTCP); test_sockets->client->sleep_time_after_authentication_error = 0; @@ -182,13 +213,21 @@ std::unique_ptr create_connected_server_and_client_bareos_socket() bool ok = test_sockets->client->connect(NULL, 1, 1, 0, "Director daemon", HOST, NULL, portnumber, false); EXPECT_EQ(ok, true) << "Could not connect client socket with server socket."; - if (!ok) { return nullptr; } + if (!ok) { + socketClose(listen_fd); + return nullptr; + } - server_file_descriptor = accept_server_socket(server_file_descriptor); - EXPECT_GE(server_file_descriptor, 0) << "Could not accept server socket."; - if (server_file_descriptor <= 0) { return nullptr; } + auto server_fd = accept_server_socket(listen_fd); + EXPECT_GE(server_fd, 0) << "Could not accept server socket."; + if (server_fd <= 0) { + socketClose(listen_fd); + return nullptr; + } - test_sockets->server.reset(create_new_bareos_socket(server_file_descriptor)); + socketClose(listen_fd); + + test_sockets->server.reset(create_new_bareos_socket(server_fd)); return test_sockets; } @@ -204,23 +243,29 @@ BareosSocket* create_new_bareos_socket(int fd) return bs; } +std::optional create_listening_socket() +{ + int sock_fd = create_listening_server_socket(0); -#include -#if !defined(HAVE_MSVC) -# include -#endif + if (sock_fd < 0) { return std::nullopt; } -static uint16_t listening_server_port_number = 0; + auto port = port_number_of(sock_fd); -uint16_t create_unique_socket_number() -{ - if (listening_server_port_number == 0) { - pid_t pid = getpid(); - uint16_t port_number = 5 * (static_cast(pid) % 10000) + 10000; - listening_server_port_number = port_number; - } else { - ++listening_server_port_number; + if (!port) { + socketClose(sock_fd); + return std::nullopt; } - return listening_server_port_number; + return listening_socket{*port, sock_fd}; +} + +int accept_socket(const listening_socket& ls) +{ + auto fd = accept_server_socket(ls.sockfd); + return fd; +} + +listening_socket::~listening_socket() +{ + if (sockfd >= 0) { socketClose(sockfd); } } diff --git a/core/src/tests/bareos_test_sockets.h b/core/src/tests/bareos_test_sockets.h index ab37140c071..3d8f3e10070 100644 --- a/core/src/tests/bareos_test_sockets.h +++ b/core/src/tests/bareos_test_sockets.h @@ -1,7 +1,7 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2018-2021 Bareos GmbH & Co. KG + Copyright (C) 2018-2024 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -24,6 +24,7 @@ #define BAREOS_TESTS_BAREOS_TEST_SOCKETS_H_ #include +#include class BareosSocketTCP; class BareosSocket; @@ -37,9 +38,30 @@ class TestSockets { TestSockets(const TestSockets&) = delete; }; -int create_accepted_server_socket(int port); +struct listening_socket { + uint16_t port{}; + int sockfd{}; + + listening_socket() = default; + listening_socket(uint16_t port_, int sockfd_) : port{port_}, sockfd{sockfd_} + { + } + listening_socket(const listening_socket&) = delete; + listening_socket& operator=(const listening_socket&) = delete; + listening_socket(listening_socket&& other) { *this = std::move(other); } + listening_socket& operator=(listening_socket&& other) + { + std::swap(port, other.port); + std::swap(sockfd, other.sockfd); + return *this; + } + ~listening_socket(); +}; + +std::optional create_listening_socket(); +int accept_socket(const listening_socket& ls); + BareosSocket* create_new_bareos_socket(int fd); std::unique_ptr create_connected_server_and_client_bareos_socket(); -uint16_t create_unique_socket_number(); #endif // BAREOS_TESTS_BAREOS_TEST_SOCKETS_H_ diff --git a/core/src/tests/test_bsock.cc b/core/src/tests/test_bsock.cc index f8554500afe..34c65c05503 100644 --- a/core/src/tests/test_bsock.cc +++ b/core/src/tests/test_bsock.cc @@ -108,10 +108,10 @@ static void start_bareos_server(std::promise* promise, std::string console_name, std::string console_password, std::string, - int server_port) + const listening_socket& ls) { - int newsockfd = create_accepted_server_socket(server_port); + int newsockfd = accept_socket(ls); if (newsockfd < 0) { return; } @@ -256,8 +256,6 @@ std::string server_cons_password; TEST(bsock, auth_works) { - uint16_t portnumber = create_unique_socket_number(); - std::promise promise; std::future future = promise.get_future(); @@ -272,13 +270,16 @@ TEST(bsock, auth_works) cons_dir_config->tls_enable_ = false; dir_cons_config->tls_enable_ = false; + auto ls = create_listening_socket(); + ASSERT_NE(ls, std::nullopt); + Dmsg0(10, "starting listen thread...\n"); std::thread server_thread(start_bareos_server, &promise, server_cons_name, - server_cons_password, HOST, portnumber); + server_cons_password, HOST, std::ref(*ls)); Dmsg0(10, "connecting to server\n"); EXPECT_TRUE(connect_to_server(client_cons_name, client_cons_password, HOST, - portnumber)); + ls->port)); server_thread.join(); EXPECT_TRUE(future.get()); @@ -287,8 +288,6 @@ TEST(bsock, auth_works) TEST(bsock, auth_works_with_different_names) { - uint16_t portnumber = create_unique_socket_number(); - std::promise promise; std::future future = promise.get_future(); @@ -303,13 +302,16 @@ TEST(bsock, auth_works_with_different_names) cons_dir_config->tls_enable_ = false; dir_cons_config->tls_enable_ = false; + auto ls = create_listening_socket(); + ASSERT_NE(ls, std::nullopt); + Dmsg0(10, "starting listen thread...\n"); std::thread server_thread(start_bareos_server, &promise, server_cons_name, - server_cons_password, HOST, portnumber); + server_cons_password, HOST, std::ref(*ls)); Dmsg0(10, "connecting to server\n"); EXPECT_TRUE(connect_to_server(client_cons_name, client_cons_password, HOST, - portnumber)); + ls->port)); server_thread.join(); EXPECT_TRUE(future.get()); @@ -317,8 +319,6 @@ TEST(bsock, auth_works_with_different_names) TEST(bsock, auth_fails_with_different_passwords) { - uint16_t portnumber = create_unique_socket_number(); - std::promise promise; std::future future = promise.get_future(); @@ -333,13 +333,17 @@ TEST(bsock, auth_fails_with_different_passwords) cons_dir_config->tls_enable_ = false; dir_cons_config->tls_enable_ = false; + auto ls = create_listening_socket(); + ASSERT_NE(ls, std::nullopt); + Dmsg0(10, "starting listen thread...\n"); std::thread server_thread(start_bareos_server, &promise, server_cons_name, - server_cons_password, HOST, portnumber); + server_cons_password, HOST, std::ref(*ls)); Dmsg0(10, "connecting to server\n"); EXPECT_FALSE(connect_to_server(client_cons_name, client_cons_password, HOST, - portnumber)); + ls->port)); + server_thread.join(); EXPECT_FALSE(future.get()); @@ -347,8 +351,6 @@ TEST(bsock, auth_fails_with_different_passwords) TEST(bsock, auth_works_with_tls_cert) { - uint16_t portnumber = create_unique_socket_number(); - std::promise promise; std::future future = promise.get_future(); @@ -363,20 +365,23 @@ TEST(bsock, auth_works_with_tls_cert) cons_dir_config->tls_enable_ = true; dir_cons_config->tls_enable_ = true; + auto ls = create_listening_socket(); + ASSERT_NE(ls, std::nullopt); + Dmsg0(10, "starting listen thread...\n"); std::thread server_thread(start_bareos_server, &promise, server_cons_name, - server_cons_password, HOST, portnumber); + server_cons_password, HOST, std::ref(*ls)); Dmsg0(10, "connecting to server\n"); #if CLIENT_AS_A_THREAD std::thread client_thread(connect_to_server, client_cons_name, - client_cons_password, HOST, portnumber, + client_cons_password, HOST, ls->port, cons_dir_config.get()); client_thread.join(); #else EXPECT_TRUE(connect_to_server(client_cons_name, client_cons_password, HOST, - portnumber)); + ls->port)); #endif server_thread.join(); From 1fc1a23afcce60992cee80fe4b151b6e91bd6d8f Mon Sep 17 00:00:00 2001 From: Sebastian Sura Date: Wed, 31 Jul 2024 15:21:25 +0200 Subject: [PATCH 13/14] sd-reservation: fix not waiting long enough If we do not wait long enough, then the number of `send()`s changes. --- core/src/tests/sd_reservation.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/tests/sd_reservation.cc b/core/src/tests/sd_reservation.cc index a7092191406..d1b812465c7 100644 --- a/core/src/tests/sd_reservation.cc +++ b/core/src/tests/sd_reservation.cc @@ -132,7 +132,7 @@ struct TestJob { void WaitThenUnreserve(std::unique_ptr&); void WaitThenUnreserve(std::unique_ptr& job) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + std::this_thread::sleep_for(std::chrono::seconds(5)); job->jcr->sd_impl->dcr->UnreserveDevice(); ReleaseDeviceCond(); } From 6f4b09cc7c012315282db314703829f14799dc9f Mon Sep 17 00:00:00 2001 From: Bareos Bot Date: Thu, 1 Aug 2024 14:08:21 +0000 Subject: [PATCH 14/14] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa5e639010e..6c588d5e3b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - dird: disallow running always incremental virtual full jobs with empty jobid list [PR #1738] - msgchan: fix deadlock [PR #1858] - VMware Plugin: Add option restore_allow_disks_mismatch [PR #1876] +- matrix remove obsolete SUSE [PR #1888] ### Removed - plugins: remove old deprecated postgres plugin [PR #1606] @@ -233,4 +234,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [PR #1878]: https://github.com/bareos/bareos/pull/1878 [PR #1881]: https://github.com/bareos/bareos/pull/1881 [PR #1883]: https://github.com/bareos/bareos/pull/1883 +[PR #1888]: https://github.com/bareos/bareos/pull/1888 [unreleased]: https://github.com/bareos/bareos/tree/master