From ba91599c45eeb8f3578cd34092302b2394b9ea69 Mon Sep 17 00:00:00 2001 From: Michael Goulish Date: Mon, 24 May 2010 18:25:46 +0000 Subject: Jira QPID-2617 -- make sasl-based tests config files relocatable Before this change, sasl-based testing cannot be fully automated because the sasl db must be located in the standard installation location of /etc/sasl2. * Created a new directory "sasl_config" under cpp/src/tests * added a new makefile fragment "sasl.mk" to cpp/src/Makefile.am conditionally included basedon HAVE_SASL, which is defined by configure. ( NOTE: should be in cpp/src/tests/Makefile.am, but getting an "saslpasswd2: generic failure" when I try that. ) * The sasl.mk fragment uses saslpasswd2 to create a sasl db in cpp/src/tests/sasl_config that defines two users with eponymous passwords. * In test cluster_authentication_soak.cpp, make the cluster name random. * make SaslAuthenticator code accept and use a config path * give cluster_authentication_soak self-test capability. the test is meant to detect two problems: - broker failure - perftest hang so give it flags that will force either of those conditions. This allows me to (anually) ensure that the test really does detect those conditions when they occur. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@947748 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/ForkedBroker.cpp | 5 +- qpid/cpp/src/tests/ForkedBroker.h | 4 + qpid/cpp/src/tests/Makefile.am | 11 +- qpid/cpp/src/tests/cluster_authentication_soak.cpp | 121 ++++++++++++++++----- qpid/cpp/src/tests/run_cluster_authentication_soak | 4 + qpid/cpp/src/tests/run_cluster_authentication_test | 4 + qpid/cpp/src/tests/sasl_config/qpidd.conf | 45 ++++++++ 7 files changed, 161 insertions(+), 33 deletions(-) create mode 100755 qpid/cpp/src/tests/run_cluster_authentication_soak create mode 100755 qpid/cpp/src/tests/run_cluster_authentication_test create mode 100644 qpid/cpp/src/tests/sasl_config/qpidd.conf (limited to 'qpid/cpp/src/tests') diff --git a/qpid/cpp/src/tests/ForkedBroker.cpp b/qpid/cpp/src/tests/ForkedBroker.cpp index 529774df98..0aedb50ec1 100644 --- a/qpid/cpp/src/tests/ForkedBroker.cpp +++ b/qpid/cpp/src/tests/ForkedBroker.cpp @@ -40,7 +40,7 @@ return o; namespace qpid { namespace tests { -ForkedBroker::ForkedBroker(const Args& constArgs) { +ForkedBroker::ForkedBroker(const Args& constArgs) : running(false), exitStatus(0) { Args args(constArgs); Args::iterator i = find(args.begin(), args.end(), string("TMP_DATA_DIR")); if (i != args.end()) { @@ -79,6 +79,8 @@ void ForkedBroker::kill(int sig) { throw ErrnoException("wait for forked process failed"); if (WEXITSTATUS(status) != 0 && sig != 9) throw qpid::Exception(QPID_MSG("Forked broker exited with: " << WEXITSTATUS(status))); + running = false; + exitStatus = status; } bool isLogOption(const std::string& s) { @@ -122,6 +124,7 @@ void ForkedBroker::init(const Args& userArgs) { else throw qpid::Exception("EOF reading port number from child."); } ::close(pipeFds[0]); + running = true; } else { // child ::close(pipeFds[0]); diff --git a/qpid/cpp/src/tests/ForkedBroker.h b/qpid/cpp/src/tests/ForkedBroker.h index ddbad185d8..87e141a425 100644 --- a/qpid/cpp/src/tests/ForkedBroker.h +++ b/qpid/cpp/src/tests/ForkedBroker.h @@ -63,11 +63,15 @@ class ForkedBroker { int wait(); // Wait for exit, return exit status. uint16_t getPort() { return port; } pid_t getPID() { return pid; } + bool isRunning() { return running; } private: void init(const Args& args); + bool running; + int exitStatus; + pid_t pid; int port; std::string dataDir; diff --git a/qpid/cpp/src/tests/Makefile.am b/qpid/cpp/src/tests/Makefile.am index 92e4e858f7..99b226b004 100644 --- a/qpid/cpp/src/tests/Makefile.am +++ b/qpid/cpp/src/tests/Makefile.am @@ -314,7 +314,7 @@ TESTS_ENVIRONMENT = \ $(srcdir)/run_test system_tests = qpid-client-test quick_perftest quick_topictest run_header_test quick_txtest -TESTS += start_broker $(system_tests) python_tests stop_broker run_federation_tests run_acl_tests run_cli_tests replication_test +TESTS += start_broker $(system_tests) python_tests stop_broker run_federation_tests run_acl_tests run_cli_tests replication_test run_cluster_authentication_test EXTRA_DIST += \ run_test vg_check \ @@ -351,7 +351,8 @@ EXTRA_DIST += \ run_test.ps1 \ start_broker.ps1 \ stop_broker.ps1 \ - topictest.ps1 + topictest.ps1 \ + run_cluster_authentication_test check_LTLIBRARIES += libdlclose_noop.la libdlclose_noop_la_LDFLAGS = -module -rpath $(abs_builddir) @@ -364,7 +365,8 @@ CLEANFILES+=valgrind.out *.log *.vglog* dummy_test qpidd.port $(unit_wrappers) LONG_TESTS+=start_broker fanout_perftest shared_perftest multiq_perftest topic_perftest run_ring_queue_test stop_broker \ run_failover_soak reliable_replication_test \ - federated_cluster_test_with_node_failure + federated_cluster_test_with_node_failure \ + run_cluster_authentication_soak EXTRA_DIST+= \ fanout_perftest \ @@ -373,7 +375,8 @@ EXTRA_DIST+= \ topic_perftest \ run_failover_soak \ reliable_replication_test \ - federated_cluster_test_with_node_failure + federated_cluster_test_with_node_failure \ + run_cluster_authentication_soak check-long: $(MAKE) check TESTS="$(LONG_TESTS)" VALGRIND= diff --git a/qpid/cpp/src/tests/cluster_authentication_soak.cpp b/qpid/cpp/src/tests/cluster_authentication_soak.cpp index ccf4d278c0..6963438d5f 100644 --- a/qpid/cpp/src/tests/cluster_authentication_soak.cpp +++ b/qpid/cpp/src/tests/cluster_authentication_soak.cpp @@ -44,6 +44,10 @@ #include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + @@ -64,32 +68,42 @@ typedef vector brokerVector; -int newbiePort = 0; +int runSilent = 1; +int newbiePort = 0; + +void +makeClusterName ( string & s ) { + stringstream ss; + ss << "authenticationSoakCluster_" << Uuid(true).str(); + s = ss.str(); +} void -startBroker ( brokerVector & brokers , - int brokerNumber ) { - stringstream portSS, prefix; +startBroker ( brokerVector & brokers , int brokerNumber, string const & clusterName ) { + stringstream prefix, clusterArg; prefix << "soak-" << brokerNumber; + clusterArg << "--cluster-name=" << clusterName; + std::vector argv; argv.push_back ("../qpidd"); argv.push_back ("--no-module-dir"); argv.push_back ("--load-module=../.libs/cluster.so"); - argv.push_back ("--cluster-name=micks_test_cluster"); - argv.push_back ("--cluster-username=guest"); - argv.push_back ("--cluster-password=guest"); + argv.push_back (clusterArg.str().c_str()); + argv.push_back ("--cluster-username=zig"); + argv.push_back ("--cluster-password=zig"); argv.push_back ("--cluster-mechanism=ANONYMOUS"); - argv.push_back ("TMP_DATA_DIR"); + argv.push_back ("--sasl-config=./sasl_config"); argv.push_back ("--auth=yes"); argv.push_back ("--mgmt-enable=yes"); argv.push_back ("--log-prefix"); argv.push_back (prefix.str()); argv.push_back ("--log-to-file"); argv.push_back (prefix.str()+".log"); + argv.push_back ("TMP_DATA_DIR"); ForkedBroker * newbie = new ForkedBroker (argv); newbiePort = newbie->getPort(); @@ -100,7 +114,7 @@ startBroker ( brokerVector & brokers , bool -runPerftest ( ) { +runPerftest ( bool hangTest ) { stringstream portSs; portSs << newbiePort; @@ -111,9 +125,9 @@ runPerftest ( ) { argv.push_back ( "-p" ); argv.push_back ( portSs.str().c_str() ); argv.push_back ( "--username" ); - argv.push_back ( "guest" ); + argv.push_back ( "zig" ); argv.push_back ( "--password" ); - argv.push_back ( "guest" ); + argv.push_back ( "zig" ); argv.push_back ( "--mechanism" ); argv.push_back ( "DIGEST-MD5" ); argv.push_back ( "--count" ); @@ -133,6 +147,12 @@ runPerftest ( ) { return false; } else { + if ( hangTest ) { + if ( ! runSilent ) + cerr << "Pausing perftest " << pid << endl; + kill ( pid, 19 ); + } + struct timeval startTime, currentTime, duration; @@ -140,7 +160,7 @@ runPerftest ( ) { gettimeofday ( & startTime, 0 ); while ( 1 ) { - sleep ( 5 ); + sleep ( 2 ); int status; int returned_pid = waitpid ( pid, &status, WNOHANG ); if ( returned_pid == pid ) { @@ -171,14 +191,9 @@ runPerftest ( ) { bool allBrokersAreAlive ( brokerVector & brokers ) { - for ( unsigned int i = 0; i < brokers.size(); ++ i ) { - pid_t pid = brokers[i]->getPID(); - int status; - int value; - if ( (value = waitpid ( pid, &status, WNOHANG ) ) ) { - return false; - } - } + for ( unsigned int i = 0; i < brokers.size(); ++ i ) + if ( ! brokers[i]->isRunning() ) + return false; return true; } @@ -186,10 +201,23 @@ allBrokersAreAlive ( brokerVector & brokers ) { + void killAllBrokers ( brokerVector & brokers ) { - for ( unsigned int i = 0; i < brokers.size(); ++ i ) + for ( unsigned int i = 0; i < brokers.size(); ++ i ) { brokers[i]->kill ( 9 ); + } +} + + + + +void +killOneBroker ( brokerVector & brokers ) { + int doomedBroker = getpid() % brokers.size(); + cout << "Killing broker " << brokers[doomedBroker]->getPID() << endl; + brokers[doomedBroker]->kill ( 9 ); + sleep ( 2 ); } @@ -201,15 +229,36 @@ using namespace qpid::tests; +/* + * Please note that this test has self-test capability. + * It is intended to detect + * 1. perftest hangs. + * 2. broker deaths + * Both of these condtions can be forced when running manually + * to ensure that the test really does detect them. + * See command-line arguments 3 and 4. + */ int main ( int argc, char ** argv ) { - int n_iterations = argc > 0 ? atoi(argv[1]) : 1; + int n_iterations = argc > 1 ? atoi(argv[1]) : 1; + runSilent = argc > 2 ? atoi(argv[2]) : 1; // default to silent + int killBroker = argc > 3 ? atoi(argv[3]) : 0; // Force the kill of one broker. + int hangTest = argc > 4 ? atoi(argv[4]) : 0; // Force the first perftest to hang. int n_brokers = 3; brokerVector brokers; + #ifndef HAVE_SASL + if ( ! runSilent ) + cout << "No SASL support. cluster_authentication_soak disabled."; + return 0; + #endif + + srand ( getpid() ); + string clusterName; + makeClusterName ( clusterName ); for ( int i = 0; i < n_brokers; ++ i ) { - startBroker ( brokers, i ); + startBroker ( brokers, i, clusterName ); } sleep ( 3 ); @@ -221,22 +270,38 @@ main ( int argc, char ** argv ) * set to 1. */ for ( int iteration = 0; iteration < n_iterations; ++ iteration ) { - if ( ! runPerftest ( ) ) { - cerr << "qpid-perftest " << iteration << " failed.\n"; + if ( ! runPerftest ( hangTest ) ) { + if ( ! runSilent ) + cerr << "qpid-perftest " << iteration << " failed.\n"; return 1; } if ( ! ( iteration % 10 ) ) { - cerr << "qpid-perftest " << iteration << " complete. -------------- \n"; + if ( ! runSilent ) + cerr << "qpid-perftest " << iteration << " complete. -------------- \n"; } } - cerr << "\nqpid-perftest " << n_iterations << " iterations complete. -------------- \n\n"; + if ( ! runSilent ) + cerr << "\nqpid-perftest " << n_iterations << " iterations complete. -------------- \n\n"; + + /* If the command-line tells us to kill a broker, do + * it now. Use this option to prove that this test + * really can detect broker-deaths. + */ + if ( killBroker ) { + killOneBroker ( brokers ); + } if ( ! allBrokersAreAlive ( brokers ) ) { - cerr << "not all brokers are alive.\n"; + if ( ! runSilent ) + cerr << "not all brokers are alive.\n"; + killAllBrokers ( brokers ); return 2; } killAllBrokers ( brokers ); + if ( ! runSilent ) + cout << "success.\n"; + return 0; } diff --git a/qpid/cpp/src/tests/run_cluster_authentication_soak b/qpid/cpp/src/tests/run_cluster_authentication_soak new file mode 100755 index 0000000000..d0a9059097 --- /dev/null +++ b/qpid/cpp/src/tests/run_cluster_authentication_soak @@ -0,0 +1,4 @@ +#! /bin/bash + +./cluster_authentication_soak 500 + diff --git a/qpid/cpp/src/tests/run_cluster_authentication_test b/qpid/cpp/src/tests/run_cluster_authentication_test new file mode 100755 index 0000000000..5e71baf2e5 --- /dev/null +++ b/qpid/cpp/src/tests/run_cluster_authentication_test @@ -0,0 +1,4 @@ +#! /bin/bash + +./cluster_authentication_soak + diff --git a/qpid/cpp/src/tests/sasl_config/qpidd.conf b/qpid/cpp/src/tests/sasl_config/qpidd.conf new file mode 100644 index 0000000000..62fd8d4dee --- /dev/null +++ b/qpid/cpp/src/tests/sasl_config/qpidd.conf @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# This configuation allows for either SASL PLAIN or ANONYMOUS +# authentication. The PLAIN authentication is done on a +# username+password, which is stored in the sasldb_path +# file. Usernames and passwords can be added to the file using the +# command: +# +# saslpasswd2 -f /var/lib/qpidd/qpidd.sasldb -u +# +# The REALM is important and should be the same as the --auth-realm +# option to the broker. This lets the broker properly find the user in +# the sasldb file. +# +# Existing user accounts may be listed with: +# +# sasldblistusers2 -f /var/lib/qpidd/qpidd.sasldb +# +# NOTE: The sasldb file must be readable by the user running the qpidd +# daemon, and should be readable only by that user. +# +pwcheck_method: auxprop +auxprop_plugin: sasldb +sasldb_path: ./sasl_config/qpidd.sasldb + +#following line stops spurious 'sql_select option missing' errors when +#cyrus-sql-sasl plugin is installed +sql_select: dummy select -- cgit v1.2.1