From 47b1004134bb8cf1fbf544209f4c4432b6ff13ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 11 Oct 2017 14:59:20 +0300 Subject: [PATCH] Add proper cluster testing scripts The scripts start MaxScale processes on two different servers. The support framework for the tests is in place but the tests themselves still need to be modified to allow the use of non-localhost addresses. --- maxctrl/test_utils.js | 8 ++-- maxscale-system-test/maxctrl_scripts.sh.in | 47 ++++++++++++++++++++++ maxscale-system-test/test_maxctrl.cpp | 10 +++++ maxscale-system-test/test_maxctrl.sh | 45 ++------------------- maxscale-system-test/testconnections.cpp | 19 +++++++++ maxscale-system-test/testconnections.h | 5 ++- 6 files changed, 87 insertions(+), 47 deletions(-) create mode 100644 maxscale-system-test/maxctrl_scripts.sh.in diff --git a/maxctrl/test_utils.js b/maxctrl/test_utils.js index 65fe6ae4e..e81bf4ae0 100644 --- a/maxctrl/test_utils.js +++ b/maxctrl/test_utils.js @@ -20,7 +20,7 @@ module.exports = function() { return new Promise(function(resolve, reject) { child_process.execFile("./start_maxscale.sh", function(err, stdout, stderr) { if (err) { - reject() + reject(err) } else { resolve() } @@ -33,7 +33,7 @@ module.exports = function() { return new Promise(function(resolve, reject) { child_process.execFile("./start_double_maxscale.sh", function(err, stdout, stderr) { if (err) { - reject() + reject(err) } else { resolve() } @@ -46,7 +46,7 @@ module.exports = function() { return new Promise(function(resolve, reject) { child_process.execFile("./stop_maxscale.sh", function(err, stdout, stderr) { if (err) { - reject() + reject(err) } else { resolve() } @@ -59,7 +59,7 @@ module.exports = function() { return new Promise(function(resolve, reject) { child_process.execFile("./stop_double_maxscale.sh", function(err, stdout, stderr) { if (err) { - reject() + reject(err) } else { resolve() } diff --git a/maxscale-system-test/maxctrl_scripts.sh.in b/maxscale-system-test/maxctrl_scripts.sh.in new file mode 100644 index 000000000..cae92084c --- /dev/null +++ b/maxscale-system-test/maxctrl_scripts.sh.in @@ -0,0 +1,47 @@ +#!/bin/bash + +cat < start_maxscale.sh +#!/bin/bash +sudo systemctl start maxscale +EOF + +cat <stop_maxscale.sh +#!/bin/bash + +sudo systemctl stop maxscale + +sudo rm -rf /var/lib/maxscale/* +sudo rm -rf /var/cache/maxscale/* +sudo rm -rf /var/run/maxscale/* + +if [ -f /tmp/maxadmin.sock ] +then + sudo rm /tmp/maxadmin.sock +fi + +EOF + +cat <start_double_maxscale.sh +#!/bin/bash +sudo systemctl start maxscale +ssh -i ~/maxscale_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet $galera_003_whoami@$galera_003_network "sudo systemctl start maxscale" +EOF + +cat <stop_double_maxscale.sh +#!/bin/bash + +sudo systemctl stop maxscale +sudo rm -rf /var/lib/maxscale/* +sudo rm -rf /var/cache/maxscale/* +sudo rm -rf /var/run/maxscale/* +test ! -f /tmp/maxadmin.sock || sudo rm /tmp/maxadmin.sock + +ssh -i ~/maxscale_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet $galera_003_whoami@$galera_003_network "sudo systemctl stop maxscale" +ssh -i ~/maxscale_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet $galera_003_whoami@$galera_003_network "sudo rm -rf /var/lib/maxscale/*" +ssh -i ~/maxscale_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet $galera_003_whoami@$galera_003_network "sudo rm -rf /var/cache/maxscale/*" +ssh -i ~/maxscale_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet $galera_003_whoami@$galera_003_network "sudo rm -rf /var/run/maxscale/*" +ssh -i ~/maxscale_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet $galera_003_whoami@$galera_003_network "sudo rm -rf /tmp/maxadmin.sock" + +EOF + +chmod +x *.sh diff --git a/maxscale-system-test/test_maxctrl.cpp b/maxscale-system-test/test_maxctrl.cpp index 4cf0bc603..a47161e8b 100644 --- a/maxscale-system-test/test_maxctrl.cpp +++ b/maxscale-system-test/test_maxctrl.cpp @@ -6,9 +6,19 @@ int main(int argc, char *argv[]) { + // Use galera_003 as the secondary MaxScale node + TestConnections::set_secondary_maxscale("galera_003_network", "galera_003_network6"); TestConnections test(argc, argv); + // This is not very nice as it's a bit too intrusive + system("envsubst < maxctrl_scripts.sh.in > maxctrl_scripts.sh"); + system("chmod +x maxctrl_scripts.sh"); test.copy_to_maxscale("test_maxctrl.sh", "~"); + test.copy_to_maxscale("maxctrl_scripts.sh", "~"); + test.ssh_maxscale(true,"ssh-keygen -f maxscale_key -P \"\""); + test.copy_from_maxscale((char*)"~/maxscale_key.pub", (char*)"."); + test.galera->copy_to_node("./maxscale_key.pub", "~", 3); + test.galera->ssh_node(3, false, "cat ~/maxscale_key.pub >> ~/.ssh/authorized_keys"); // TODO: Don't handle test dependencies in tests test.tprintf("Installing NPM"); diff --git a/maxscale-system-test/test_maxctrl.sh b/maxscale-system-test/test_maxctrl.sh index b40919f0f..177275757 100755 --- a/maxscale-system-test/test_maxctrl.sh +++ b/maxscale-system-test/test_maxctrl.sh @@ -18,49 +18,10 @@ cd MaxScale git checkout $ref cd maxctrl -cat < start_maxscale.sh -#!/bin/sh -sudo systemctl start maxscale -EOF - -cat <start_double_maxscale.sh -#!/bin/sh -exit 1 -EOF - -cat <stop_maxscale.sh -#!/bin/sh - -sudo systemctl stop maxscale - -sudo rm -rf /var/lib/maxscale/* -sudo rm -rf /var/cache/maxscale/* -sudo rm -rf /var/run/maxscale/* - -if [ -f /tmp/maxadmin.sock ] -then - sudo rm /tmp/maxadmin.sock -fi - -EOF - -cat <stop_double_maxscale.sh -#!/bin/sh - -sudo systemctl stop maxscale - -sudo rm -rf /var/lib/maxscale/* -sudo rm -rf /var/cache/maxscale/* -sudo rm -rf /var/run/maxscale/* - -if [ -f /tmp/maxadmin.sock ] -then - sudo rm /tmp/maxadmin.sock -fi - -EOF - +# Create the scripts that start and stop MaxScale +~/maxctrl_scripts.sh chmod +x *.sh + npm i # Export the value for --basedir where maxscale binaries are located diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index 5bb722b81..ce8cae0f1 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -68,6 +68,25 @@ void TestConnections::multiple_maxscales(bool value) maxscale::multiple_maxscales = value; } +void TestConnections::set_secondary_maxscale(const char* ip_var, const char* ip6_var) +{ + const char* ip = getenv(ip_var); + const char* ip6 = getenv(ip6_var); + + if (ip || ip6) + { + TestConnections::multiple_maxscales(true); + if (ip) + { + setenv("maxscale2_IP", ip, 1); + } + if (ip6) + { + setenv("maxscale2_network6", ip6, 1); + } + } +} + TestConnections::TestConnections(int argc, char *argv[]): enable_timeouts(true), global_result(0), diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index 72cbcdfa6..8607b000b 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -338,7 +338,10 @@ public: static void require_galera_version(const char *version); /** Initialize multiple MaxScale instances */ - void multiple_maxscales(bool value); + static void multiple_maxscales(bool value); + + /** Set secondary MaxScale address */ + static void set_secondary_maxscale(const char* ip_var, const char* ip6_var); /** * @brief add_result adds result to global_result and prints error message if result is not 0