From 0faa1228671457fd90e3d6b48eea426a74d45d42 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 4 Aug 2011 16:23:01 -0600 Subject: [PATCH] Remove last references to Maakit. Update sandbox test env scripts. --- sandbox/load-sakila-db | 17 ++++--- sandbox/servers/start | 8 +-- sandbox/servers/stop | 6 +-- sandbox/start-sandbox | 2 +- sandbox/test-env | 110 +++++++++++++++++------------------------ util/check-dev-env | 9 ++-- util/check-tool | 6 +-- 7 files changed, 71 insertions(+), 87 deletions(-) diff --git a/sandbox/load-sakila-db b/sandbox/load-sakila-db index b444953d..82bae8d6 100755 --- a/sandbox/load-sakila-db +++ b/sandbox/load-sakila-db @@ -5,22 +5,21 @@ err() { for msg; do echo $msg done - echo "See http://code.google.com/p/maatkit/wiki/Testing for more information." - echo + exit_status=1 } # ########################################################################### # Sanity check the cmd line options. # ########################################################################### if [ $# -lt 1 ]; then - err "Usage: load-sakila-db port" + err "Usage: load-sakila-db PORT" exit 1 fi PORT=$1 if [ ! -d "/tmp/$PORT" ]; then - err "Sandbox does not exist: /tmp/$PORT" + err "MySQL test server does not exist: /tmp/$PORT" exit 1 fi @@ -33,15 +32,21 @@ if [ -z "$PERCONA_TOOLKIT_BRANCH" ]; then fi if [ ! -d "$PERCONA_TOOLKIT_BRANCH" ]; then - err "Invalid Maakit trunk directory: $PERCONA_TOOLKIT_BRANCH" + err "Invalid PERCONA_TOOLKIT_BRANCH directory: $PERCONA_TOOLKIT_BRANCH" exit 1 fi cd $PERCONA_TOOLKIT_BRANCH/sandbox +exit_status=0 + /tmp/$PORT/use < sakila-db/sakila-schema.sql +exit_status=$((exit_status | $?)) + /tmp/$PORT/use < sakila-db/sakila-data.sql +exit_status=$((exit_status | $?)) $PERCONA_TOOLKIT_BRANCH/sandbox/test-env reset +exit_status=$((exit_status | $?)) -exit 0 +exit $exit_status diff --git a/sandbox/servers/start b/sandbox/servers/start index 78089211..3d9a3fa4 100755 --- a/sandbox/servers/start +++ b/sandbox/servers/start @@ -25,7 +25,7 @@ sandbox_is_alive() { if [ -f "$PIDFILE" ] || [ -S "$SOCKETFILE" ]; then sandbox_is_alive if [ $? -eq 1 ]; then - echo "Maatkit sandbox PORT is running." + echo "MySQL test server on port PORT is running." exit 0 fi @@ -40,7 +40,7 @@ cd $BASEDIR $BASEDIR/bin/mysqld_safe --defaults-file=/tmp/PORT/my.sandbox.cnf > /dev/null 2>&1 & cd $PWD -echo -n "Starting Maatkit sandbox PORT... " +echo -n "Starting MySQL test server on port PORT... " for i in 1 2 3 4 5 6 7 8 9 10; do sleep 1 if [ -f $PIDFILE ] && [ -S $SOCKETFILE ]; then @@ -50,9 +50,9 @@ done sandbox_is_alive if [ $? -eq 1 ]; then - echo "success!" + echo "OK" exit 0 else - echo "failed." + echo "FAILED" exit 1 fi diff --git a/sandbox/servers/stop b/sandbox/servers/stop index 29d18835..83e1df6e 100755 --- a/sandbox/servers/stop +++ b/sandbox/servers/stop @@ -23,7 +23,7 @@ sandbox_is_alive() { exit_status=0 -echo -n "Stopping Maatkit sandbox PORT... " +echo -n "Stopping MySQL test server on port PORT... " sandbox_is_alive if [ $? -eq 1 ]; then @@ -32,9 +32,9 @@ if [ $? -eq 1 ]; then fi if [ $exit_status -eq 0 ]; then - echo "done." + echo "OK" else - echo "failed!" + echo "FAILED" fi exit $exit_status diff --git a/sandbox/start-sandbox b/sandbox/start-sandbox index c37508ec..da1386d7 100755 --- a/sandbox/start-sandbox +++ b/sandbox/start-sandbox @@ -106,7 +106,7 @@ if [ -z "$PERCONA_TOOLKIT_BRANCH" ]; then fi if [ ! -d "$PERCONA_TOOLKIT_BRANCH" ]; then - err "Invalid Maakit trunk directory: $PERCONA_TOOLKIT_BRANCH" + err "Invalid PERCONA_TOOLKIT_BRANCH directory: $PERCONA_TOOLKIT_BRANCH" exit 1 fi diff --git a/sandbox/test-env b/sandbox/test-env index 5e2eb6a9..9eab7b8f 100755 --- a/sandbox/test-env +++ b/sandbox/test-env @@ -1,58 +1,40 @@ #!/bin/sh -# This script controls the Maatkit test environment. The mk test env is -# a master-slave pair on ports 12345 and 12346, running from respective -# directories in /tmp. This script attempts to ensure that all environment -# vars like PERCONA_TOOLKIT_BRANCH and PERCONA_TOOLKIT_SANDBOX are correct. The -# exit status is 0 on success and 1 on any failure. There's no option to -# disable output, so just >/dev/null if you only care about the exit status. - -_d() { - if [ -z "$MKDEBUG" ]; then - return 0 - fi - - # Is there a way to echo directly to STDERR? - # This is my hackish way. - for msg; do - echo "$msg" 1>/dev/null 1>&2 - done -} +# This script controls the Percona Toolkit test environment. The basic +# environment is a master on port 12345 in /tmp/12345 and a slave on port +# 12346 in /tmp/12346. This script attempts to ensure that all environment +# vars like PERCONA_TOOLKIT_BRANCH and PERCONA_TOOLKIT_SANDBOX are correct. +# Exist 0 on success/no errors, or 1 on any warnings or errors. err() { echo for msg; do echo "$msg" done - echo "See http://code.google.com/p/maatkit/wiki/Testing for more information." - echo } usage() { - err "Usage: mk-test-env start|stop|restart|status|checkconfig|reset|kill" \ - "" \ - " start Start Maatkit test environment (mk test env)" \ - " stop Stop and remove mk test env" \ - " restart Stop and start mk test env" \ - " status Check and display status of mk test env" \ - " checkconfig Check and display configuration of mk test env" \ - " reset Reset mk test env master/slave bin logs" \ - " kill Kill mk test env (use if stop fails)" \ + err "Usage: test-env start|stop|restart|status|checkconfig|reset|kill" \ + "" \ + " start Start test servers in /tmp/PORT" \ + " stop Stop test servers and remvoe all /tmp/PORT" \ + " kill Kill test servers (use if stop fails)" \ + " restart Stop and start test servers" \ + " status Print status of test servers" \ + " checkconfig Check test env and test servers" \ + " reset Reset test server binary logs" \ + " version Print MySQL version of running test servers" \ "" } mysql_basedir_ok() { local basedir=$1 - _d "basedir=$basedir" if [ ! -d "$basedir" ] || [ ! -d "$basedir/bin" ]; then - _d "basedir invalid" return 0 fi if [ ! -x "$basedir/bin/mysqld_safe" ]; then - _d "$basedir/bin/mysqld_safe doesn't exist" return 0 fi - _d "basedir ok" return 1 # basedir is ok } @@ -62,14 +44,11 @@ set_mysql_basedir() { BASEDIR_AUTO_DETECTED=1 mysqld=`which mysqld 2>/dev/null` if [ -n "$mysqld" ]; then - _d "Found mysqld: $mysqld" PERCONA_TOOLKIT_SANDBOX=`$mysqld --verbose --help 2>/dev/null | grep 'basedir ' | awk '{print $2}'` if [ -z "$PERCONA_TOOLKIT_SANDBOX" ]; then - _d "$mysqld --verbose --help | grep | ask failed" return 0 fi else - _d "Could not find mysqld" return 0 fi else @@ -132,14 +111,13 @@ sandbox_status() { local master_port=$3 local status=0 # sandbox is ok, no problems - echo "Maatkit sandbox $type $port:" + echo "MySQL $type test server on port $port:" echo -n " PID file exists - " if [ -f "/tmp/$port/data/mysql_sandbox$port.pid" ]; then echo "yes" echo -n " PID file has a PID - " local pid=`cat /tmp/$port/data/mysql_sandbox$port.pid 2>/dev/null` - _d "$type $port PID: $pid" if [ -n "$pid" ]; then echo "yes" echo -n " process $pid is alive - " @@ -208,7 +186,7 @@ sandbox_status() { sandbox_is_running() { local p=$1 - ps axw | grep mysqld | grep /tmp/$p >/dev/null + ps axw | grep mysqld | grep -v grep | grep /tmp/$p >/dev/null } kill_sandbox() { @@ -237,13 +215,13 @@ kill_sandbox() { # Third and finaly check if the sandbox server is running. sandbox_is_running $p if [ $? -eq 0 ]; then - err "Failed to kill sandbox $p (PID $pid1, $pid2)" + err "Failed to kill MySQL test server on port $p (PID $pid1, $pid2)" rmdir=0 else - echo "Killed sandbox $p (PID $pid1, $pid2)" + echo "Killed MySQL test server on port $p (PID $pid1, $pid2)" fi else - echo "Killed sandbox $p" + echo "Killed MySQL test server on port $p" fi fi @@ -255,12 +233,10 @@ kill_sandbox() { return } -print_sandbox_version() { - if [ -n "$1" ]; then - echo -n "Maatkit sandboxes running MySQL version " - fi +MYSQL_VERSION="" +set_mysql_version() { if [ -d /tmp/12345 ] && [ -f /tmp/12345/use ]; then - /tmp/12345/use -N -e "select version()" | head -n 2 | tail -n 1 | cut -d'.' -f1,2 + MYSQL_VERSION=$(/tmp/12345/use -N -e "select version()" | head -n 2 | tail -n 1 | cut -d'.' -f1,2) fi } @@ -280,12 +256,9 @@ opt=$1 exit_status=0 -# Print some debug info about this run. -_d "" "`date`" "cwd: `pwd`" "`env | grep PATH`" "$0 $*" - if [ $opt = 'checkconfig' ]; then checkconfig 1 - echo -n "Maatkit test environment config is " + echo -n "Percona Toolkit test environment config is " if [ $conf_err -eq 0 ]; then echo "ok!" exit 0 @@ -296,7 +269,7 @@ if [ $opt = 'checkconfig' ]; then else checkconfig if [ $conf_err -eq 1 ]; then - err "The Maatkit test environment config is invalid." \ + err "The Percona Toolkit test environment config is invalid." \ "Run '$0 checkconfig' to see the current configuration." exit 1 fi @@ -307,7 +280,7 @@ fi # /usr/bin/mysqld Ver 5.1.34 for linux-gnu on x86_64 (MySQL Community Server) version=`$mysqld -V | awk '{print $3}' | cut -d. -f 1,2`; if [ ! -d "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version" ]; then - err "Maatkit sandbox server version $version does not exists." + err "Percona Toolkit sandbox server version $version does not exists." exit 1 fi @@ -321,31 +294,36 @@ case $opt in exit_status=$? if [ "$version" != "4.0" ] && [ "$version" != "4.1" ]; then if [ $? -eq 0 ]; then - echo "Loading sakila database..." + echo -n "Loading sakila database... " ./load-sakila-db 12345 exit_status=$? + if [ $? -ne 0 ]; then + echo "FAILED" + else + echo "OK" + fi fi fi fi if [ $exit_status -eq 0 ]; then - echo "Maatkit test environment started!" + set_mysql_version + echo "Percona Toolkit test environment started with MySQL v$MYSQL_VERSION." else # Stop but don't remove the sandboxes. The mysql error log # may say why MySQL failed to start. ./stop-sandbox all >/dev/null 2>&1 - err "There was an error starting the Maatkit test environment." + err "There was an error starting the Percona Toolkit test environment." fi - print_sandbox_version 1 ;; stop) cd $PERCONA_TOOLKIT_BRANCH/sandbox ./stop-sandbox remove all exit_status=$? if [ $exit_status -eq 0 ]; then - echo "Maatkit test environment stopped." + echo "Percona Toolkit test environment stopped." else - err "There was an error stopping the Maatkit test environment." \ - "The Maatkit sandboxes may still be running." + err "There was an error stopping the Percona Toolkit test environment." \ + "The MySQL test servers may still be running." fi ;; kill) @@ -364,7 +342,7 @@ case $opt in master_status=$? sandbox_status 'slave' '12346' '12345' slave_status=$? - echo -n "Maaktit test environment is " + echo -n "Percona Test test environment is " if [ $master_status -eq 0 ] && [ $slave_status -eq 0 ]; then echo "ok!" else @@ -373,9 +351,10 @@ case $opt in fi ;; reset) - # This resets the master and slave relay logs. It's used in - # mk-table-sync/t/110_replicate_do_db.t. It's not checked; - # user beware. + # Several tests reset the bin logs so that queries from prior tests + # don't replicate to new sandbox servers. This makes creating new + # sandbox servers a lot faster. There's no check if this works or + # not, so... yeah. /tmp/12345/use -e "RESET MASTER" /tmp/12346/use -e "RESET MASTER" /tmp/12346/use -e "STOP SLAVE" @@ -384,7 +363,8 @@ case $opt in exit_status=0 ;; version) - print_sandbox_version + set_mysql_version + echo $MYSQL_VERSION ;; *) usage diff --git a/util/check-dev-env b/util/check-dev-env index 6f812d22..7fbb1a48 100755 --- a/util/check-dev-env +++ b/util/check-dev-env @@ -1,9 +1,12 @@ #!/usr/bin/env perl # This pseudo-script is for developers to see if their box has all -# the modules necessary for testing Maatkit. Any missing modules -# will cause an error like "Can't locate Foo.pm in @INC ...". Else -# the version for each module used by this script will be printed. +# the modules necessary for testing Percona Toolkit. Any missing +# modules will cause an error like "Can't locate Foo.pm in @INC ...". +# Else the version for each module used by this script will be printed. +# +# In addition to these modules, many non-standard programs are needed +# for other tasks, like building packages, writing test coverage, etc. use Data::Dumper; use DBD::mysql; diff --git a/util/check-tool b/util/check-tool index 18ee1478..ca905fc2 100755 --- a/util/check-tool +++ b/util/check-tool @@ -209,13 +209,9 @@ sub check_module_usage { my $module = $_; my $unused = 0; if ( $not_obj{$module} ) { - # MaatkitCommon::_d - chomp(my $g = `grep -c '${_}::' $tool_file`); # Transformers->import chomp(my $i = `grep -c '${_}->import' $tool_file`); - $g ||= 0; - $i ||= 0; - $unused = 1 if $g + $i == 0; + $unused = 1 unless $i; } elsif ( $dynamic{$tool_name}->{$module} ) { # Can't detect these.