Make sandbox scripts simpler and more reliable. Remove "remove" option from stop-sandbox and update tests that used it.

This commit is contained in:
Daniel Nichter
2011-08-23 09:11:00 -06:00
parent 4715afc7c0
commit e93381d6b6
13 changed files with 39 additions and 78 deletions

View File

@@ -4,13 +4,9 @@
# It's a "low level" script that is not usually called directly.
# Exit 0 means everything was successful, else exit 1 on problems.
err() {
echo
for msg; do
echo $msg
done
echo "See http://code.google.com/p/maatkit/wiki/Testing for more information."
echo
die() {
echo $1 >&2
exit 1
}
make_sandbox() {
@@ -30,7 +26,7 @@ make_sandbox() {
# Use ! instead of / because the replacment has / (it's a directory)
sed -e "s!PERCONA_TOOLKIT_SANDBOX!$PERCONA_TOOLKIT_SANDBOX!g" -i.bak $file
done
rm /tmp/$port/*.bak
rm /tmp/$port/*.bak >/dev/null 2>&1
if [ -n "$BINLOG_FORMAT" ]; then
echo "binlog-format=$BINLOG_FORMAT" >> /tmp/$port/my.sandbox.cnf
@@ -65,10 +61,7 @@ make_sandbox() {
# Sanity check the cmd line options.
# ###########################################################################
if [ $# -lt 2 ]; then
err "Usage: start-sandbox master|slave|master-master port [master port]" \
"Example: start-sandbox master 12345" \
"Example: start-sandbox slave 12346 12345"
exit 1
die "Usage: start-sandbox master|slave|master-master port [master port]"
fi
type=$1 # master, slave or master-master

View File

@@ -1,60 +1,26 @@
#!/bin/sh
err() {
echo
for msg; do
echo $msg
done
echo "See http://code.google.com/p/maatkit/wiki/Testing for more information."
echo
die() {
echo $1 >&2
exit 1
}
# ###########################################################################
# Sanity check the cmd line options.
# ###########################################################################
if [ $# -lt 1 ]; then
err "Usage: stop-sandbox [remove] all|port [port...]" \
"The 'all' option stops sandboxes /tmp/123[0-9]*." \
"The sandbox directories are removed if the first option is 'remove'."
exit 1
die "Usage: stop-sandbox PORTS"
fi
# ###########################################################################
# Stop the sandboxes.
# ###########################################################################
exit_status=0
for port in $@; do
if [ "$port" = "remove" ]; then
for port in "$@"; do
if ! [ -d "/tmp/$port" ]; then
echo "MySQL test server on port $port does not exist."
continue
fi
if [ "$port" = "all" ]; then
ls /tmp/1234* >/dev/null 2>&1
if [ $? -eq 0 ]; then
for a in /tmp/123[0-9]*; do
$a/stop
if [ $? -ne 0 ]; then
exit_status=1
fi
if [ $1 = "remove" ]; then
rm -rf $a
fi
done
break
fi
fi
if [ -d "/tmp/$port" ]; then
/tmp/$port/stop
if [ $? -ne 0 ]; then
exit_status=1
fi
if [ $1 = "remove" ]; then
rm -rf /tmp/$port
fi
fi
/tmp/$port/stop
exit_status=$((exit_status | $?))
rm -rf /tmp/$port
exit_status=$((exit_status | $?))
done
exit $exit_status

View File

@@ -309,21 +309,19 @@ case $opt in
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 Percona Toolkit test environment."
fi
;;
stop)
cd $PERCONA_TOOLKIT_BRANCH/sandbox
./stop-sandbox remove all
exit_status=$?
./stop-sandbox 12349 12348 12347 12346 12345
exit_status=$((exit_status | $?))
./stop-sandbox 2903 2902 2901 2900
exit_status=$((exit_status | $?))
if [ $exit_status -eq 0 ]; then
echo "Percona Toolkit test environment stopped."
else
err "There was an error stopping the Percona Toolkit test environment." \
"The MySQL test servers may still be running."
err "Error stopping the Percona Toolkit test environment."
fi
;;
kill)

View File

@@ -457,7 +457,7 @@ SKIP: {
);
$dbh->disconnect();
diag(`$trunk/sandbox/stop-sandbox remove 12348 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
};
# #############################################################################

View File

@@ -40,7 +40,9 @@ my %port_for = (
slave2 => 2903,
);
foreach my $port ( values %port_for ) {
diag(`$trunk/sandbox/stop-sandbox remove $port >/dev/null`);
if ( -d "/tmp/$port" ) {
diag(`$trunk/sandbox/stop-sandbox $port >/dev/null`);
}
}
diag(`$trunk/sandbox/start-sandbox master 2900 >/dev/null`);
diag(`$trunk/sandbox/start-sandbox slave 2903 2900 >/dev/null`);
@@ -464,5 +466,5 @@ ok(
# #############################################################################
# Done.
# #############################################################################
diag(`$trunk/sandbox/stop-sandbox remove 2903 2902 2901 2900 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 2903 2902 2901 2900 >/dev/null`);
exit;

View File

@@ -946,7 +946,7 @@ SKIP: {
);
$sb->wipe_clean($dbh2);
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null &`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null &`);
}
}

View File

@@ -17,7 +17,7 @@ use Sandbox;
require "$trunk/bin/pt-heartbeat";
diag(`$trunk/sandbox/test-env reset`); # don't repl sakila db to 12347
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`);
my $dp = new DSNParser(opts=>$dsn_opts);
@@ -247,7 +247,7 @@ foreach my $port (@ports) {
}
diag(`rm -rf /tmp/mk-heartbeat-sentinel >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
# #############################################################################
# Done.

View File

@@ -30,6 +30,8 @@ else {
plan tests => 2;
}
`$trunk/sandbox/test-env reset >/dev/null`;
my $output;
my $cnf='/tmp/12345/my.sandbox.cnf';
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";

View File

@@ -16,7 +16,7 @@ use Sandbox;
require "$trunk/bin/pt-table-checksum";
diag(`$trunk/sandbox/test-env reset`);
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`);
my $dp = new DSNParser(opts=>$dsn_opts);
@@ -94,7 +94,7 @@ like(
# #############################################################################
# Done.
# #############################################################################
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
diag(`/tmp/12346/stop >/dev/null`); # Start/stop clears SHOW SLAVE HOSTS.
diag(`/tmp/12346/start >/dev/null`);
$sb->wipe_clean($master_dbh);

View File

@@ -16,7 +16,7 @@ use Sandbox;
require "$trunk/bin/pt-table-checksum";
diag(`$trunk/sandbox/test-env reset`);
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`);
my $dp = new DSNParser(opts=>$dsn_opts);
@@ -280,7 +280,7 @@ is(
# #############################################################################
# Done.
# #############################################################################
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
$sb->wipe_clean($master_dbh);
diag(`$trunk/sandbox/test-env reset >/dev/null`);
exit;

View File

@@ -534,7 +534,7 @@ SKIP: {
# #############################################################################
# Done.
# #############################################################################
diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null &`);
diag(`$trunk/sandbox/stop-sandbox remove 12348 >/dev/null &`);
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
$sb->wipe_clean($c1_dbh);
exit;

View File

@@ -39,7 +39,7 @@ SKIP: {
$output = `/tmp/12348/use -e 'select b from test.test1 where a=1' -N`;
like($output, qr/mm/, 'Master-master sync worked');
diag(`$trunk/sandbox/stop-sandbox remove 12348 12349 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12348 12349 >/dev/null`);
};
# #############################################################################

View File

@@ -121,7 +121,7 @@ is_deeply(
);
$dbh3->disconnect();
diag(`$trunk/sandbox/stop-sandbox remove 12348 >/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
# #############################################################################
# Done.