From 54370618bc63e42ff5a40c2134de8359fa101cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 13 Nov 2018 16:35:28 +0200 Subject: [PATCH] Stop keepalived after the tests Once the tests are done keepalived must be stopped. This is done to prevent it from affecting other tests. --- maxscale-system-test/keepalived.cpp | 5 +++++ .../keepalived_masterdown.cpp | 20 +++++++++++-------- maxscale-system-test/testconnections.cpp | 5 +++++ maxscale-system-test/testconnections.h | 13 ++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/maxscale-system-test/keepalived.cpp b/maxscale-system-test/keepalived.cpp index 236e9c6cf..ef07e1b77 100644 --- a/maxscale-system-test/keepalived.cpp +++ b/maxscale-system-test/keepalived.cpp @@ -33,6 +33,11 @@ int main(int argc, char* argv[]) exit(0); } + Test->on_destroy([&](){ + Test->maxscales->ssh_node_f(0, true, "service keepalived stop"); + Test->maxscales->ssh_node_f(1, true, "service keepalived stop"); + }); + Test->check_maxscale_alive(0); Test->check_maxscale_alive(1); diff --git a/maxscale-system-test/keepalived_masterdown.cpp b/maxscale-system-test/keepalived_masterdown.cpp index c5089976c..d556a5c25 100644 --- a/maxscale-system-test/keepalived_masterdown.cpp +++ b/maxscale-system-test/keepalived_masterdown.cpp @@ -23,19 +23,23 @@ int main(int argc, char* argv[]) TestConnections::multiple_maxscales(true); Mariadb_nodes::require_gtid(true); TestConnections test(argc, argv); + + if (test.maxscales->N < 2) + { + test.tprintf("At least 2 Maxscales are needed for this test. Exiting"); + exit(0); + } + + test.on_destroy([&](){ + test.maxscales->ssh_node_f(0, true, "service keepalived stop"); + test.maxscales->ssh_node_f(1, true, "service keepalived stop"); + }); + test.repl->connect(); delete_slave_binlogs(test); basic_test(test); print_gtids(test); - test.tprintf("Number of MaxScales: %d\n", test.maxscales->N); - test.expect(test.maxscales->N == 2, - "Two Maxscales are needed for this test, %i nodes was/were detected.", test.maxscales->N); - if (test.global_result != 0) - { - return test.global_result; - } - test.tprintf("Configuring 'keepalived'\n"); // Get test client IP, replace last number in it with 253 and use it as Virtual IP configure_keepalived(&test, (char*) "masterdown"); diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index 5ed609fd1..4f093e46b 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -366,6 +366,11 @@ TestConnections::TestConnections(int argc, char* argv[]) TestConnections::~TestConnections() { + for (auto& a : m_on_destroy) + { + a(); + } + if (backend_ssl) { repl->disable_ssl(); diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index cde79455f..e3a873d7b 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -597,9 +598,21 @@ public: */ int get_master_server_id(int m = 0); + /** + * Add a callback that is called when the test ends + * + * @param func Function to call + */ + void on_destroy(std::function func) + { + m_on_destroy.push_back(func); + } + private: void report_result(const char* format, va_list argp); void copy_one_mariadb_log(int i, std::string filename); + + std::vector> m_on_destroy; }; /**