summaryrefslogtreecommitdiff
path: root/mysql-test/mysql-test-run.pl
diff options
context:
space:
mode:
authorunknown <anozdrin@mysql.com>2005-08-29 22:28:42 +0400
committerunknown <anozdrin@mysql.com>2005-08-29 22:28:42 +0400
commitd508afd4704b7b4a18eb6210d75ecd0fd83bd9dc (patch)
tree651b2387bb97a1fcbe581a36ee4b0b0ca9ea8822 /mysql-test/mysql-test-run.pl
parent7e128939011785e3f6cc1feb297e21a07e79af48 (diff)
downloadmariadb-git-d508afd4704b7b4a18eb6210d75ecd0fd83bd9dc.tar.gz
Implement WL#2789 "Instance Manager: test using mysql-test-run testing framework"
mysql-test/Makefile.am: Make installation procedure aware of the Instance Manager tests. mysql-test/lib/mtr_cases.pl: Make collect_one_test_case() aware of the Instance Manager tests. mysql-test/lib/mtr_process.pl: Minor changes: - open log files for append, not for overwrite. Append mode is very useful for debugging of several tests; - extract the code for killing processes into a separate function: mtr_kill_processes(). The function is used to stop IM-related processes. mysql-test/mysql-test-run.pl: Added support for the Instance Manager tests.
Diffstat (limited to 'mysql-test/mysql-test-run.pl')
-rwxr-xr-xmysql-test/mysql-test-run.pl339
1 files changed, 307 insertions, 32 deletions
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index a59cce4b0eb..17017c11215 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -178,6 +178,7 @@ our $exe_mysqlshow; # Called from test case
our $exe_mysql_fix_system_tables;
our $exe_mysqltest;
our $exe_slave_mysqld;
+our $exe_im;
our $opt_bench= 0;
our $opt_small_bench= 0;
@@ -216,12 +217,11 @@ our $opt_local_master;
our $master; # Will be struct in C
our $slave;
+our $instance_manager;
+
our $opt_ndbcluster_port;
our $opt_ndbconnectstring;
-our $opt_no_manager; # Does nothing now, we never use manager
-our $opt_manager_port; # Does nothing now, we never use manager
-
our $opt_old_master;
our $opt_record;
@@ -309,6 +309,8 @@ sub mysqld_arguments ($$$$$);
sub stop_masters_slaves ();
sub stop_masters ();
sub stop_slaves ();
+sub im_start ($$);
+sub im_stop ($);
sub run_mysqltest ($);
sub usage ($);
@@ -460,6 +462,9 @@ sub command_line_setup () {
my $opt_master_myport= 9306;
my $opt_slave_myport= 9308;
$opt_ndbcluster_port= 9350;
+ my $im_port= 9310;
+ my $im_mysqld1_port= 9312;
+ my $im_mysqld2_port= 9314;
# Read the command line
# Note: Keep list, and the order, in sync with usage at end of this file
@@ -470,7 +475,6 @@ sub command_line_setup () {
'ps-protocol' => \$opt_ps_protocol,
'bench' => \$opt_bench,
'small-bench' => \$opt_small_bench,
- 'no-manager' => \$opt_no_manager, # Currently not used
# Control what test suites or cases to run
'force' => \$opt_force,
@@ -485,7 +489,9 @@ sub command_line_setup () {
'master_port=i' => \$opt_master_myport,
'slave_port=i' => \$opt_slave_myport,
'ndbcluster_port=i' => \$opt_ndbcluster_port,
- 'manager-port=i' => \$opt_manager_port, # Currently not used
+ 'im-port=i' => \$im_port, # Instance Manager port.
+ 'im-mysqld1-port=i' => \$im_mysqld1_port, # Port of mysqld, controlled by IM
+ 'im-mysqld2-port=i' => \$im_mysqld2_port, # Port of mysqld, controlled by IM
# Test case authoring
'record' => \$opt_record,
@@ -768,6 +774,37 @@ sub command_line_setup () {
$slave->[2]->{'path_myport'}= $opt_slave_myport + 2;
$slave->[2]->{'start_timeout'}= 300;
+ $instance_manager->{'path_err'}= "$opt_vardir/log/im.err";
+ $instance_manager->{'path_log'}= "$opt_vardir/log/im.log";
+ $instance_manager->{'path_pid'}= "$opt_vardir/run/im.pid";
+ $instance_manager->{'path_sock'}= "$opt_tmpdir/im.sock";
+ $instance_manager->{'port'}= $im_port;
+ $instance_manager->{'start_timeout'}= $master->[0]->{'start_timeout'};
+ $instance_manager->{'admin_login'}= 'im_admin';
+ $instance_manager->{'admin_password'}= 'im_admin_secret';
+ $instance_manager->{'admin_sha1'}= '*598D51AD2DFF7792045D6DF3DDF9AA1AF737B295';
+ $instance_manager->{'password_file'}= "$opt_vardir/im.passwd";
+ $instance_manager->{'defaults_file'}= "$opt_vardir/im.cnf";
+
+ $instance_manager->{'instances'}->[0]->{'server_id'}= 1;
+ $instance_manager->{'instances'}->[0]->{'port'}= $im_mysqld1_port;
+ $instance_manager->{'instances'}->[0]->{'path_datadir'}=
+ "$opt_vardir/im_mysqld_1.data";
+ $instance_manager->{'instances'}->[0]->{'path_sock'}=
+ "$opt_vardir/mysqld_1.sock";
+ $instance_manager->{'instances'}->[0]->{'path_pid'}=
+ "$opt_vardir/mysqld_1.pid";
+
+ $instance_manager->{'instances'}->[1]->{'server_id'}= 2;
+ $instance_manager->{'instances'}->[1]->{'port'}= $im_mysqld2_port;
+ $instance_manager->{'instances'}->[1]->{'path_datadir'}=
+ "$opt_vardir/im_mysqld_2.data";
+ $instance_manager->{'instances'}->[1]->{'path_sock'}=
+ "$opt_vardir/mysqld_2.sock";
+ $instance_manager->{'instances'}->[1]->{'path_pid'}=
+ "$opt_vardir/mysqld_2.pid";
+ $instance_manager->{'instances'}->[1]->{'nonguarded'}= 1;
+
if ( $opt_extern )
{
$glob_use_running_server= 1;
@@ -803,6 +840,9 @@ sub executable_setup () {
$exe_mysqld= mtr_exe_exists ("$glob_basedir/sql/mysqld");
$path_language= mtr_path_exists("$glob_basedir/sql/share/english/");
$path_charsetsdir= mtr_path_exists("$glob_basedir/sql/share/charsets");
+
+ $exe_im= mtr_exe_exists(
+ "$glob_basedir/server-tools/instance-manager/mysqlmanager");
}
if ( $glob_use_embedded_server )
@@ -850,6 +890,8 @@ sub executable_setup () {
$exe_mysqld= mtr_exe_exists ("$glob_basedir/libexec/mysqld",
"$glob_basedir/bin/mysqld");
+ $exe_im= mtr_exe_exists("$glob_basedir/libexec/mysqlmanager",
+ "$glob_basedir/bin/mysqlmanager");
if ( $glob_use_embedded_server )
{
$exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest_embedded");
@@ -923,6 +965,11 @@ sub environment_setup () {
# $ENV{'MYSQL_TCP_PORT'}= '@MYSQL_TCP_PORT@'; # FIXME
$ENV{'MYSQL_TCP_PORT'}= 3306;
+ $ENV{'IM_MYSQLD1_SOCK'}= $instance_manager->{instances}->[0]->{path_sock};
+ $ENV{'IM_MYSQLD1_PORT'}= $instance_manager->{instances}->[0]->{port};
+ $ENV{'IM_MYSQLD2_SOCK'}= $instance_manager->{instances}->[1]->{path_sock};
+ $ENV{'IM_MYSQLD2_PORT'}= $instance_manager->{instances}->[1]->{port};
+
if ( $glob_cygwin_perl )
{
foreach my $key ('MYSQL_TEST_WINDIR','MASTER_MYSOCK')
@@ -1006,25 +1053,24 @@ sub kill_and_cleanup () {
# FIXME do we really need to create these all, or are they
# created for us when tables are created?
- rmtree("$master->[0]->{'path_myddir'}");
- mkpath("$master->[0]->{'path_myddir'}/mysql");
- mkpath("$master->[0]->{'path_myddir'}/test");
-
- rmtree("$master->[1]->{'path_myddir'}");
- mkpath("$master->[1]->{'path_myddir'}/mysql");
- mkpath("$master->[1]->{'path_myddir'}/test");
-
- rmtree("$slave->[0]->{'path_myddir'}");
- mkpath("$slave->[0]->{'path_myddir'}/mysql");
- mkpath("$slave->[0]->{'path_myddir'}/test");
-
- rmtree("$slave->[1]->{'path_myddir'}");
- mkpath("$slave->[1]->{'path_myddir'}/mysql");
- mkpath("$slave->[1]->{'path_myddir'}/test");
+ my @data_dir_lst = (
+ $master->[0]->{'path_myddir'},
+ $master->[1]->{'path_myddir'},
+ $slave->[0]->{'path_myddir'},
+ $slave->[1]->{'path_myddir'},
+ $slave->[2]->{'path_myddir'});
+
+ foreach my $instance (@{$instance_manager->{'instances'}})
+ {
+ push (@data_dir_lst, $instance->{'path_datadir'});
+ }
- rmtree("$slave->[2]->{'path_myddir'}");
- mkpath("$slave->[2]->{'path_myddir'}/mysql");
- mkpath("$slave->[2]->{'path_myddir'}/test");
+ foreach my $data_dir (@data_dir_lst)
+ {
+ rmtree("$data_dir");
+ mkpath("$data_dir/mysql");
+ mkpath("$data_dir/test");
+ }
# To make some old test cases work, we create a soft
# link from the old "var" location to the new one
@@ -1262,6 +1308,11 @@ sub mysql_install_db () {
install_db('slave', $slave->[1]->{'path_myddir'});
install_db('slave', $slave->[2]->{'path_myddir'});
+ if ( defined $exe_im)
+ {
+ im_prepare_env($instance_manager);
+ }
+
if ( ndbcluster_install() )
{
# failed to install, disable usage but flag that its no ok
@@ -1336,6 +1387,101 @@ sub install_db ($$) {
}
+sub im_prepare_env($) {
+ my $instance_manager = shift;
+
+ im_create_passwd_file($instance_manager);
+ im_prepare_data_dir($instance_manager);
+}
+
+
+sub im_create_passwd_file($) {
+ my $instance_manager = shift;
+
+ my $pwd_file_path = $instance_manager->{'password_file'};
+
+ mtr_report("Creating IM password file ($pwd_file_path)");
+
+ open(OUT, ">", $pwd_file_path)
+ or mtr_error("Can't write to $pwd_file_path: $!");
+
+ print OUT $instance_manager->{'admin_login'}, ":",
+ $instance_manager->{'admin_sha1'}, "\n";
+
+ close(OUT);
+}
+
+
+sub im_create_defaults_file($) {
+ my $instance_manager = shift;
+
+ my $defaults_file = $instance_manager->{'defaults_file'};
+
+ open(OUT, ">", $defaults_file)
+ or mtr_error("Can't write to $defaults_file: $!");
+
+ print OUT <<EOF
+[mysql]
+
+[manager]
+pid-file = $instance_manager->{path_pid}
+socket = $instance_manager->{path_sock}
+port = $instance_manager->{port}
+password-file = $instance_manager->{password_file}
+default-mysqld-path = $exe_mysqld
+
+EOF
+;
+
+ foreach my $instance (@{$instance_manager->{'instances'}})
+ {
+ my $server_id = $instance->{'server_id'};
+
+ print OUT <<EOF
+[mysqld$server_id]
+socket = $instance->{path_sock}
+pid-file = $instance->{path_pid}
+port = $instance->{port}
+datadir = $instance->{path_datadir}
+log = $instance->{path_datadir}/mysqld$server_id.log
+log-error = $instance->{path_datadir}/mysqld$server_id.err.log
+log-slow-queries = $instance->{path_datadir}/mysqld$server_id.slow.log
+language = $path_language
+character-sets-dir = $path_charsetsdir
+basedir = $path_my_basedir
+server_id =$server_id
+skip-stack-trace
+skip-innodb
+skip-bdb
+skip-ndbcluster
+EOF
+;
+
+ if ( exists $instance->{nonguarded} and
+ defined $instance->{nonguarded} )
+ {
+ print OUT "nonguarded\n";
+ }
+
+ print OUT "\n";
+ }
+
+ close(OUT);
+}
+
+
+sub im_prepare_data_dir($) {
+ my $instance_manager = shift;
+
+ foreach my $instance (@{$instance_manager->{'instances'}})
+ {
+ install_db(
+ 'im_mysqld_' . $instance->{'server_id'},
+ $instance->{'path_datadir'});
+ }
+}
+
+
##############################################################################
#
# Run a single test case
@@ -1437,7 +1583,7 @@ sub run_testcase ($) {
# FIXME split up start and check that started so that can do
# starts in parallel, masters and slaves at the same time.
- if ( ! $opt_local_master )
+ if ( $tinfo->{'component_id'} eq 'mysqld' and ! $opt_local_master )
{
if ( $master->[0]->{'ndbcluster'} )
{
@@ -1476,6 +1622,17 @@ sub run_testcase ($) {
$master->[0]->{'running_master_is_special'}= 1;
}
}
+ elsif ( $tinfo->{'component_id'} eq 'im')
+ {
+ # We have to create defaults file every time, in order to ensure that it
+ # will be the same for each test. The problem is that test can change the
+ # file (by SET/UNSET commands), so w/o recreating the file, execution of
+ # one test can affect the other.
+
+ im_create_defaults_file($instance_manager);
+
+ im_start($instance_manager, $tinfo->{im_opts});
+ }
# ----------------------------------------------------------------------
# Start slaves - if needed
@@ -1558,6 +1715,15 @@ sub run_testcase ($) {
report_failure_and_restart($tinfo);
}
}
+
+ # ----------------------------------------------------------------------
+ # Stop Instance Manager if we are processing an IM-test case.
+ # ----------------------------------------------------------------------
+
+ if ( ! $glob_use_running_server and $tinfo->{'component_id'} eq 'im' )
+ {
+ im_stop($instance_manager);
+ }
}
@@ -1988,6 +2154,13 @@ sub mysqld_start ($$$$) {
sub stop_masters_slaves () {
print "Ending Tests\n";
+
+ if (defined $instance_manager->{'pid'})
+ {
+ print "Shutting-down Instance Manager\n";
+ im_stop($instance_manager);
+ }
+
print "Shutting-down MySQL daemon\n\n";
stop_masters();
print "Master(s) shutdown finished\n";
@@ -2046,6 +2219,97 @@ sub stop_slaves () {
mtr_stop_mysqld_servers(\@args);
}
+##############################################################################
+#
+# Instance Manager management routines.
+#
+##############################################################################
+
+sub im_start($$) {
+ my $instance_manager = shift;
+ my $opts = shift;
+
+ if ( ! defined $exe_im)
+ {
+ return;
+ }
+
+ my $args;
+ mtr_init_args(\$args);
+ mtr_add_arg($args, "--defaults-file=" . $instance_manager->{'defaults_file'});
+
+ foreach my $opt (@{$opts})
+ {
+ mtr_add_arg($args, $opt);
+ }
+
+ $instance_manager->{'pid'} =
+ mtr_spawn(
+ $exe_im, # path to the executable
+ $args, # cmd-line args
+ '', # stdin
+ $instance_manager->{'path_log'}, # stdout
+ $instance_manager->{'path_err'}, # stderr
+ '', # pid file path (not used)
+ { append_log_file => 1 } # append log files
+ );
+
+ if ( ! defined $instance_manager->{'pid'} )
+ {
+ mtr_report('Could not start Instance Manager');
+ return;
+ }
+
+ # Instance Manager can be run in daemon mode. In this case, it creates
+ # several processes and the parent process, created by mtr_spawn(), exits just
+ # after start. So, we have to obtain Instance Manager PID from the PID file.
+
+ sleep_until_file_created(
+ $instance_manager->{'path_pid'},
+ $instance_manager->{'start_timeout'},
+ -1); # real PID is still unknown
+
+ $instance_manager->{'pid'} =
+ mtr_get_pid_from_file($instance_manager->{'path_pid'});
+}
+
+sub im_stop($) {
+ my $instance_manager = shift;
+
+ if (! defined $instance_manager->{'pid'})
+ {
+ return;
+ }
+
+ # Inspired from mtr_stop_mysqld_servers().
+
+ start_reap_all();
+
+ # Create list of pids. We should stop Instance Manager and all started
+ # mysqld-instances. Some of them may be nonguarded, so IM will not stop them
+ # on shutdown.
+
+ my @pids = ( $instance_manager->{'pid'} );
+ my $instances = $instance_manager->{'instances'};
+
+ if ( -r $instances->[0]->{'path_pid'} )
+ {
+ push @pids, mtr_get_pid_from_file($instances->[0]->{'path_pid'});
+ }
+
+ if ( -r $instances->[1]->{'path_pid'} )
+ {
+ push @pids, mtr_get_pid_from_file($instances->[1]->{'path_pid'});
+ }
+
+ # Kill processes.
+
+ mtr_kill_processes(\@pids);
+
+ stop_reap_all();
+
+ $instance_manager->{'pid'} = undef;
+}
sub run_mysqltest ($) {
my $tinfo= shift;
@@ -2069,7 +2333,9 @@ sub run_mysqltest ($) {
}
my $cmdline_mysqlbinlog=
- "$exe_mysqlbinlog --no-defaults --local-load=$opt_tmpdir --character-sets-dir=$path_charsetsdir";
+ "$exe_mysqlbinlog" .
+ " --no-defaults --local-load=$opt_tmpdir" .
+ " --character-sets-dir=$path_charsetsdir";
if ( $opt_debug )
{
@@ -2127,15 +2393,26 @@ sub run_mysqltest ($) {
mtr_init_args(\$args);
mtr_add_arg($args, "--no-defaults");
- mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_mysock'});
- mtr_add_arg($args, "--database=test");
- mtr_add_arg($args, "--user=%s", $opt_user);
- mtr_add_arg($args, "--password=");
mtr_add_arg($args, "--silent");
mtr_add_arg($args, "-v");
mtr_add_arg($args, "--skip-safemalloc");
mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
- mtr_add_arg($args, "--port=%d", $master->[0]->{'path_myport'});
+
+ if ($tinfo->{'component_id'} eq 'im')
+ {
+ mtr_add_arg($args, "--socket=%s", $instance_manager->{'path_sock'});
+ mtr_add_arg($args, "--port=%d", $instance_manager->{'port'});
+ mtr_add_arg($args, "--user=%s", $instance_manager->{'admin_login'});
+ mtr_add_arg($args, "--password=%s", $instance_manager->{'admin_password'});
+ }
+ else # component_id == mysqld
+ {
+ mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_mysock'});
+ mtr_add_arg($args, "--port=%d", $master->[0]->{'path_myport'});
+ mtr_add_arg($args, "--database=test");
+ mtr_add_arg($args, "--user=%s", $opt_user);
+ mtr_add_arg($args, "--password=");
+ }
if ( $opt_ps_protocol )
{
@@ -2224,7 +2501,6 @@ Options to control what engine/variation to run
ps-protocol Use the binary protocol between client and server
bench Run the benchmark suite FIXME
small-bench FIXME
- no-manager Use the istanse manager (currently disabled)
Options to control what test suites or cases to run
@@ -2241,7 +2517,6 @@ Options that specify ports
master_port=PORT Specify the port number used by the first master
slave_port=PORT Specify the port number used by the first slave
ndbcluster_port=PORT Specify the port number used by cluster
- manager-port=PORT Specify the port number used by manager (currently not used)
Options for test case authoring