List:Commits« Previous MessageNext Message »
From:Serge Kozlov Date:April 1 2010 9:06am
Subject:bzr push into nuts branch (Serge.Kozlov:370 to 371) WL#5060
View as plain text  
  371 Serge Kozlov	2010-04-01
      WL#5060.
      1. Added support option --upgrade-server-order
      2. Added example of test case for upgrade samples::upgrade
      3. Added suite updown with for upgrade/downgrade servers in replication chain
      4. Support upgrade/downgrade in NUTS libraries

    added:
      suites/samples/upgrade.pm
      suites/updown/
      suites/updown/rep_basic_downgrade.pm
      suites/updown/rep_basic_upgrade.pm
    modified:
      bin/Driver.pm
      bin/Parameters.pm
      bin/nuts.pl
      lib/My/Nuts/Library/Kernel/Manager.pm
      lib/My/Nuts/Library/Kernel/Replication.pm
      lib/My/Nuts/Management/Manager.pm
      lib/My/Nuts/Management/SimpleDeployer.pm
  370 Serge Kozlov	2010-03-30
      WL#4806. Test case for testing Seconds_Behind_Master

    added:
      suites/rep/seconds_behind_master.pm
    modified:
      lib/My/Nuts/Library/Kernel/Replication.pm
      lib/My/Nuts/Library/Kernel/ServerResult.pm
=== modified file 'bin/Driver.pm'
--- a/bin/Driver.pm	2009-12-28 21:06:39 +0000
+++ b/bin/Driver.pm	2010-03-31 20:40:41 +0000
@@ -48,6 +48,7 @@ my @tests;
 my $fault_injection;
 my @build_paths;
 my @build_order;
+my $upgrade_server_order;
 
 sub opt_configure
 {
@@ -86,7 +87,9 @@ sub opt_configure
                        "env-setup-file=s"   => \$Parameters::env_setup_file,
                        "env-cleanup-file=s" => \$Parameters::env_cleanup_file,
                        "data-source=s" => \$Parameters::data_source,
-                       "data-source-option=s" => \@Parameters::data_source_options
+                       "data-source-option=s" => \@Parameters::data_source_options,
+                       "upgrade-server-order=s" => \$upgrade_server_order
+                       
           ) or pod2usage (2) && exit 1;
     }
     if ( $man or $help )
@@ -118,7 +121,28 @@ sub opt_configure
         @build_order= split(",", $Parameters::buildorder);
         map (int, @build_order);
       }
-
+      
+      if (defined $upgrade_server_order)
+      {
+        if ($upgrade_server_order =~ m/^([0-9]+\,[0-9]+[0-9\,]*)$/)
+        {
+          my @up_builds = split(",", $1);
+          for (my $up_idx = 0; $up_idx < scalar(@up_builds); $up_idx++ )
+          {            
+            if ($up_idx < ( scalar(@up_builds) - 1) )
+            {
+    	      $Parameters::upgrade_server{$up_builds[$up_idx]} = $up_builds[$up_idx + 1];
+            }
+    	  }
+    	}
+    	else
+    	{
+    	  print STDERR "\nInvalid --upgrade-server-order parameter\n";
+    	  print STDERR "Use following format: <number_of_build>,<number_of_build>[,<number_of_build>,....]\n";
+    	  exit 1;    	    
+    	}
+      }
+      
       my $build_paths_len= scalar(@build_paths);
       use List::Util qw(max);
       if (max(@build_order) >= $build_paths_len)

=== modified file 'bin/Parameters.pm'
--- a/bin/Parameters.pm	2009-11-23 01:00:20 +0000
+++ b/bin/Parameters.pm	2010-03-31 20:40:41 +0000
@@ -30,6 +30,7 @@ our $generator;
 our @build_paths;
 our @build_order;
 our $buildorder;
+our %upgrade_server;
 our $selftests = 0;
 our $doc_test;
 our $suites_dir = "$NUTS_HOME/suites";

=== modified file 'bin/nuts.pl'
--- a/bin/nuts.pl	2009-12-16 20:16:17 +0000
+++ b/bin/nuts.pl	2010-03-31 20:40:41 +0000
@@ -135,6 +135,11 @@ nuts.pl - script that starts the Nuts te
                     test case, then build allocation would restart
                     from start of buildorder, meaning that fourth
                     server would get b1.
+  --upgrade-server-order
+		    Must be used together with multiple builds. This allow user
+		    to set the number of build (number from command line like 
+		    --buildorder) that will be used in test case for command
+		    updown_server().
 
 . To run the self tests using an azalea building in the directory mysql-azalea:
 
@@ -148,6 +153,12 @@ $ bin/nuts.pl --suite samples --build my
 
 $ bin/nuts.pl --test start_stop --build mysql-azalea
 
+. To run test case basic_upgrade where started servers based on mysql-5.1 (--buildorder=0,0). 
+Command upgrade_server($server) in this case will stop $server and start new 
+from build-6.0 but all data files (data dir) will be reused:
+
+$ bin/nuts.pl --suite=updown --test=basic_upgrade --upgrade-server-order=0,1 --build=mysql-5.1 --build=mysql-6.0 --buildorder=0,0 
+
 For more information, see file $NUTS_HOME/README.
 
 =cut

=== modified file 'lib/My/Nuts/Library/Kernel/Manager.pm'
--- a/lib/My/Nuts/Library/Kernel/Manager.pm	2009-06-10 13:23:43 +0000
+++ b/lib/My/Nuts/Library/Kernel/Manager.pm	2010-03-31 20:40:41 +0000
@@ -2,7 +2,10 @@ package My::Nuts::Library::Kernel::Manag
 use Exporter;
 our @ISA = qw(Exporter);
 our @EXPORT =
-  qw(get_server start_server ok_start_server stop_server ok_stop_server deploy_server undeploy_server wait_start_server ok_wait_start_server wait_stop_server ok_wait_stop_server get_data_dir get_base_dir get_started_server);
+  qw(get_server start_server ok_start_server stop_server ok_stop_server deploy_server 
+    undeploy_server wait_start_server ok_wait_start_server wait_stop_server 
+    ok_wait_stop_server get_data_dir get_base_dir get_started_server
+    updown_server ok_updown_server);
 use strict;
 use warnings;
 use My;
@@ -50,6 +53,58 @@ sub get_server
     return $manager->get_server (%properties);
 }
 
+sub updown_server
+{
+    my ($server) = @_;
+    my $server_id= $server->get_server_id();
+    my $ret= set_updown_server($server);
+    return $ret if ($ret != My::SUCCESS);
+    $ret= undeploy_server($server);
+    if ($ret == My::SUCCESS )
+    {
+        $server = get_server( ( "my.server.id" => $server_id ) );
+        $logger->info ("deploy server: ($server_id)");
+        my $manager = $My::Nuts::Management::Manager::reference;
+        if ( $manager->deploy_server ($server) == My::SUCCESS )
+        {
+            $logger->info ("start server: ($server_id)");
+            if ( $manager->start_server ($server) == My::SUCCESS )
+            {
+    		$ret= $manager->wait_start_server ( $server );
+            }	    
+        }        
+        $ret= $manager->wait_start_server ( $server );
+    }        
+    return $ret;
+}
+
+sub ok_updown_server
+{
+    my ( $server ) = @_;
+    if ( is_server ($server) == My::FALSE )
+    {
+        ok ( 0, "Error in the parameters for ok_updown_server" )
+          or diag ("Check the parameters (server)");
+        return (My::FAILURE);
+    }
+    my $ret = updown_server ( $server );    
+    ok ( $ret == My::SUCCESS,
+         "server " . $server->get_server_id () . " was upgraded (downgraded)." )
+      or diag ("Error waiting for server upgrade (downgrade).");
+    return ($ret);
+}
+
+sub set_updown_server
+{
+    my ($server) = @_;
+    if ( is_server ($server) == My::FALSE )
+    {
+        return (My::FAILURE);
+    }
+    my $manager = $My::Nuts::Management::Manager::reference;
+    return $manager->set_updown_server ($server);
+}
+
 sub deploy_server
 {
     my ($server) = @_;

=== modified file 'lib/My/Nuts/Library/Kernel/Replication.pm'
--- a/lib/My/Nuts/Library/Kernel/Replication.pm	2010-03-30 19:58:02 +0000
+++ b/lib/My/Nuts/Library/Kernel/Replication.pm	2010-03-31 20:40:41 +0000
@@ -9,7 +9,7 @@ our @EXPORT =
   ok_wait_start_replication ok_reset_master ok_reset_slave ok_stop_replication 
   ok_wait_stop_replication ok_wait_stop_sql_replication ok_reset_replication 
   reset_replication ok_synchronize enable_semi_sync ok_enable_semi_sync 
-  disable_semi_sync ok_disable_semi_sync);
+  disable_semi_sync ok_disable_semi_sync ok_wait_slave_param);
 use strict;
 use warnings;
 use My;
@@ -265,12 +265,19 @@ sub ok_stop_replication
 
 sub stop_replication
 {
-    my ($slave) = @_;
+    my ($slave, $thread) = @_;
     if ( is_server ($slave) == My::FALSE )
     {
         return (undef);
     }
-    return ( $slave->execute ("STOP SLAVE") );
+    elsif ( defined $thread)
+    {
+	return ( $slave->execute ("STOP SLAVE ".lc($thread)) );
+    }
+    else
+    {
+	return ( $slave->execute ("STOP SLAVE") );
+    }
 }
 
 sub stop_sql_replication
@@ -657,6 +664,23 @@ sub ok_disable_semi_sync
     return $ret;
 }
 
+sub ok_wait_slave_param
+{
+    my ($server, $param, $cond, $wait_value, $timeout) = @_;
+    $timeout= 30 unless (defined $timeout);
+    my $cur_value= retrieve_slave_status($server, $param);
+    if (defined ($cur_value))
+    {
+	my $condition= "$cur_value $cond $wait_value";               
+	while (!(eval $condition) && !$@ && ($timeout > 0))
+        {
+    	    sleep 1;
+            $timeout --;
+        }
+    }
+    ok(!$@ && ($timeout>0), "Waiting slave parameter $param $cond '$wait_value'");
+} 
+
 1;
 __END__
 

=== modified file 'lib/My/Nuts/Management/Manager.pm'
--- a/lib/My/Nuts/Management/Manager.pm	2009-11-25 01:10:24 +0000
+++ b/lib/My/Nuts/Management/Manager.pm	2010-03-31 20:40:41 +0000
@@ -336,8 +336,14 @@ sub deploy_server
       my $build_order_idx=
         $active_tests_data{$ident}{$current_test}{$server_id}{"build_order_idx"};
       my $build_path_idx= $build_order{$ident}[$build_order_idx];
+      
+      if ( defined $Parameters::upgrade_server{$build_path_idx} && $deployer{$ident}->is_updown_server($server) == My::TRUE)
+      {
+	$logger->debug("Upgrade/downgrade server " . $server_id . " from build #$build_path_idx to build #" . $Parameters::upgrade_server{$build_path_idx} );
+        $build_path_idx= $Parameters::upgrade_server{$build_path_idx};
+      }
+      
       $build_path=$build_paths{$ident}[$build_path_idx];
-
       $logger->debug("Selected mandatory build #$build_path_idx: " . $build_path . " for test: " .
                      $current_test . ", server " . $server_id);
     }
@@ -355,6 +361,7 @@ sub undeploy_server
     $self->kill_server ($server);
     my $machine = $scheduler{$ident}->deallocate_machine ($server);
     $server->set_ip_address (undef);
+    $server->close_connection();
     return $deployer{$ident}->undeploy_server ($server);
 }
 
@@ -393,6 +400,13 @@ sub kill_server
     return $deployer{$ident}->kill_server ( $server, $test_name );
 }
 
+sub set_updown_server
+{
+    my ( $self, $server ) = @_;
+    my $ident = ident ($self);
+    return $deployer{$ident}->set_updown_server ( $server );
+}
+
 sub get_machines
 {
     my ($self) = @_;

=== modified file 'lib/My/Nuts/Management/SimpleDeployer.pm'
--- a/lib/My/Nuts/Management/SimpleDeployer.pm	2009-11-23 01:00:20 +0000
+++ b/lib/My/Nuts/Management/SimpleDeployer.pm	2010-03-31 20:40:41 +0000
@@ -20,6 +20,7 @@ my %builds;
 my %port;
 my %baseport;
 my %nuts_deployer_thread;
+my %updown_server_params;
 
 # maps $testname/$server_id id to build
 my %assigned_builds;
@@ -95,26 +96,40 @@ sub deploy_server
     $self->_mkdirs ($full_base_dir);
     rmtree ( [$full_base_dir], 0, 1 );
     $logger->debug (
-        "SYMLINKING: " . $build->get_build_location . " TO " . $full_base_dir );
+    	"SYMLINKING: " . $build->get_build_location . " TO " . $full_base_dir );
     if ( !symlink( $build->get_build_location, $full_base_dir ) )
     {
-        $server->set_state (My::UNABLE_TO_DEPLOY);
-        return My::FAILURE;
+    	$server->set_state (My::UNABLE_TO_DEPLOY);
+    	return My::FAILURE;
     }
-    rmtree ( [$full_data_dir], 0, 1 );
-    $self->_mkdirs  ($full_data_dir);
     $reportlog->log (   "DEPLOY "
                       . $server->get_my_properties ()->get_my_server_id () . " "
                       . $build->get_build_location
                       . " $full_base_dir" );
 
-    # install db
-    $self->_install_db ( $full_base_dir, $full_data_dir, $server );
-    $reportlog->log (   "INSTALL "
+    # For updown server we should use datadir/ip/port from previos server
+    if ( $self->is_updown_server($server) == My::TRUE )
+    {
+	$server->set_ip_address (  $updown_server_params{$server}{"ip_address"} );	
+	$server->set_port (  $updown_server_params{$server}{"port"} );	
+	$reportlog->log (   "REUSE_DATADIR "
                       . $server->get_my_properties ()->get_my_server_id ()
                       . " $full_data_dir" );
-    $server->set_port ( $port{$ident} );
-    $port{$ident}++;
+    }
+    else
+    {
+	# install db if the directory does not exist
+        rmtree ( [$full_data_dir], 0, 1 );
+        $self->_mkdirs  ($full_data_dir);
+    
+	$self->_install_db ( $full_base_dir, $full_data_dir, $server );
+	$reportlog->log (   "INSTALL_DATADIR "
+                      . $server->get_my_properties ()->get_my_server_id ()
+                      . " $full_data_dir" );
+                      
+	$server->set_port ( $port{$ident} );
+	$port{$ident}++;
+    }
     $logger->debug (   $server->get_my_properties->get_my_server_id
                      . " got PORT: "
                      . $server->get_port );
@@ -124,6 +139,28 @@ sub deploy_server
     return My::SUCCESS;
 }
 
+sub set_updown_server 
+{
+    my ( $self, $server ) = @_;
+    $updown_server_params{$server}{"port"}= $server->get_port();
+    return My::FALSE if ( !defined $updown_server_params{$server}{"port"} );
+    $updown_server_params{$server}{"ip_address"}= $server->get_ip_address();
+    return My::FALSE if ( !defined $updown_server_params{$server}{"ip_address"} );
+    my ( $full_base_dir, $full_data_dir ) = $self->get_server_dirs ($server);
+    $updown_server_params{$server}{"datadir"}= $full_data_dir;
+    return My::FALSE if ( !defined $updown_server_params{$server}{"datadir"} );
+    $updown_server_params{$server}{"updown"}= 1;
+    return My::SUCCESS;
+}
+
+sub is_updown_server 
+{
+    my ( $self, $server ) = @_;
+    my $ret= My::FALSE;
+    $ret= My::TRUE if (defined $updown_server_params{$server}{"updown"} );
+    return $ret;
+}
+
 sub archive_server_data
 {
     my ( $self, $server, $test_name ) = @_;
@@ -345,15 +382,25 @@ sub get_server_dirs
     my $test               = $server->get_test;
     my $server_id          = $server->get_my_properties->get_my_server_id;
     my $server_src_version = $server->get_build_properties->get_src_version;
-    my $server_data_dir    = $server->get_my_properties ()->get_my_var ();
     my $server_base_dir    = $server->get_my_properties ()->get_my_bin ();
-    $server_data_dir =
-      defined $server_data_dir
-      ? $server_data_dir
-      : "$test/$server_id/"
-      . $assigned_builds{$ident}
-      { $server->get_test . "/" . $server->get_my_properties->get_my_server_id }
-      ->get_src_version;
+    my $full_data_dir;
+    if ( defined $updown_server_params{$server}{"updown"} )
+    {
+      $full_data_dir= $updown_server_params{$server}{"datadir"};
+    }
+    else
+    {
+      my $server_data_dir    = $server->get_my_properties ()->get_my_var ();
+      $server_data_dir =
+    	defined $server_data_dir
+        ? $server_data_dir
+        : "$test/$server_id/"
+        . $assigned_builds{$ident}
+        { $server->get_test . "/" . $server->get_my_properties->get_my_server_id }
+        ->get_src_version;
+	$full_data_dir =
+        $directories{$ident}->get_data_dir_root . "/$server_data_dir";
+    }
     $server_base_dir =
       defined $server_base_dir
       ? $server_base_dir
@@ -363,8 +410,6 @@ sub get_server_dirs
       ->get_src_version;
     my $full_base_dir =
       $directories{$ident}->get_base_dir_root . "/$server_base_dir";
-    my $full_data_dir =
-      $directories{$ident}->get_data_dir_root . "/$server_data_dir";
     return ( $full_base_dir, $full_data_dir );
 }
 

=== added file 'suites/samples/upgrade.pm'
--- a/suites/samples/upgrade.pm	1970-01-01 00:00:00 +0000
+++ b/suites/samples/upgrade.pm	2010-03-31 20:40:41 +0000
@@ -0,0 +1,55 @@
+package samples::upgrade;
+use Exporter;
+our @ISA = qw(Exporter My::Nuts::Library::Tests::SimpleTest);
+use strict;
+use warnings;
+use My;
+use My::Nuts::Library::Kernel::Server;
+use My::Nuts::Library::Kernel::Manager;
+use My::Nuts::Library::Kernel::Result;
+use My::Nuts::Library::Tests::SimpleTest;
+use Test::More;
+
+sub prepare
+{
+    return; 
+}
+
+sub startup
+{
+    return;
+}
+
+sub fire
+{
+    my ($test) = @_;
+    my $server = ok_server ($test);
+    plan tests => 8;
+    
+    # Test
+    ok_sql ( $server, "DROP DATABASE IF EXISTS test");
+    ok_sql ( $server, "CREATE DATABASE test");
+    ok_sql ( $server,   "USE test" );
+    ok_sql ( $server,   "CREATE TABLE t1 (a INT)" );
+    ok_sql ( $server,   "INSERT INTO t1 VALUES (1)" );
+    ok_updown_server($server);
+    ok_sql ( $server,   "USE test" );
+    ok_sql ( $server,   "INSERT INTO t1 VALUES (2)" );    
+}
+
+sub shutdown
+{
+    return;
+}
+1;
+__END__;
+
+=head1 NAME
+
+samples::upgrade - Upgrade server 
+
+=head1 SYNOPSIS
+
+Test case upgrades/downgrades server in the test case. Test requires option --upgrade-server-order and multiple builds.
+
+=back

=== added directory 'suites/updown'
=== added file 'suites/updown/rep_basic_downgrade.pm'
--- a/suites/updown/rep_basic_downgrade.pm	1970-01-01 00:00:00 +0000
+++ b/suites/updown/rep_basic_downgrade.pm	2010-03-31 20:40:41 +0000
@@ -0,0 +1,151 @@
+package updown::rep_basic_downgrade;
+use Exporter;
+our @ISA = qw(Exporter My::Nuts::Library::Tests::SimpleTest);
+use strict;
+use warnings;
+use My;
+use My::Nuts::Library::Kernel::Server;
+use My::Nuts::Library::Kernel::ServerResult;
+use My::Nuts::Library::Kernel::Manager;
+use My::Nuts::Library::Kernel::Result;
+use My::Nuts::Library::Tests::SimpleTest;
+use My::Nuts::Library::Kernel::Replication;
+use Test::More;
+use DataSource;
+
+
+sub prepare
+{
+    return;
+}
+
+sub startup
+{
+    return;
+}
+
+sub fire
+{
+    my ($test) = @_;
+    
+    # Get servers
+    my $master = ok_server ($test);
+    my $slave = ok_server ($test);
+    
+    # Read lists of statements from data source
+    my $data = get_data_from_source();
+    
+    # Summarize number of statements and ok_* command in test
+    plan tests => 5*scalar(@$data) + 36;
+
+    # Setup topology, binlog format, prepare test db
+    attach($master, $slave);
+    ok_synchronize ( $master, $slave );
+
+    # Main test
+    
+    # 0. Check replication to make sure that it works
+    ok_create_db_and_use($master, "test");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    ok_synchronize ( $master, $slave );
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test"},
+	{"conn" => $slave, "dbname" => "test"},
+    ]);
+    # 1. Store events in binlog but not send to slave
+    ok_stop_replication($slave);
+    ok_wait_stop_replication($slave);
+    ok_create_db_and_use($master, "test1");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    
+    # 2. Downgrade master
+    ok_updown_server($master);
+    
+    # 3. Start old version of master which should send events to slave created by new version of master
+    ok_start_replication($slave);
+    ok_wait_start_replication($slave);
+    ok_synchronize($master, $slave);
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test1"},
+	{"conn" => $slave, "dbname" => "test1"},
+    ]);
+    
+    # 4. Check replication old master -> new slave
+    ok_create_db_and_use($master, "test2");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    ok_synchronize($master, $slave);
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test2"},
+	{"conn" => $slave, "dbname" => "test2"},
+    ]);
+    
+    # 5. Store events into relay log
+    ok_stop_replication($slave, "SQL_THREAD");
+    ok_wait_stop_sql_replication($slave);
+    ok_create_db_and_use($master, "test3");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    
+    # 6. Downgrade slave
+    ok_updown_server($slave);
+    
+    # 7. Old slave must read and play stored events from relay log
+    ok_start_replication($slave);
+    ok_wait_start_replication($slave);
+    ok_synchronize($master, $slave);
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test3"},
+	{"conn" => $slave, "dbname" => "test3"},
+    ]);
+    
+    # 8. Check replication old master -> old slave
+    ok_create_db_and_use($master, "test4");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    ok_synchronize($master, $slave);    
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test4"},
+	{"conn" => $slave, "dbname" => "test4"},
+    ]);
+}
+
+sub shutdown
+{
+    return;
+}
+
+sub ok_create_db_and_use
+{
+    my ($server, $name)= @_;
+    ok_sql($server, "DROP DATABASE IF EXISTS ".$name);
+    ok_sql($server, "CREATE DATABASE ".$name);
+    ok_sql($server, "USE ".$name);    
+}
+
+1;
+__END__;
+
+=head1 NAME
+
+updown::rep_basic_downgrade - Stepwise downgrade master and slave
+
+=head1 SYNOPSIS
+
+Stepwise downgrade checks possibility to downgrade at first master and then slave for classic replication shema master-slave.
+
+=head1 AUTHOR
+
+Serge Kozlov S<< <Serge.Kozlov@stripped> >>

=== added file 'suites/updown/rep_basic_upgrade.pm'
--- a/suites/updown/rep_basic_upgrade.pm	1970-01-01 00:00:00 +0000
+++ b/suites/updown/rep_basic_upgrade.pm	2010-03-31 20:40:41 +0000
@@ -0,0 +1,162 @@
+package updown::rep_basic_upgrade;
+use Exporter;
+our @ISA = qw(Exporter My::Nuts::Library::Tests::SimpleTest);
+use strict;
+use warnings;
+use My;
+use My::Nuts::Library::Kernel::Server;
+use My::Nuts::Library::Kernel::ServerResult;
+use My::Nuts::Library::Kernel::Manager;
+use My::Nuts::Library::Kernel::Result;
+use My::Nuts::Library::Tests::SimpleTest;
+use My::Nuts::Library::Kernel::Replication;
+use Test::More;
+use DataSource;
+
+
+sub prepare
+{
+    return;
+}
+
+sub startup
+{
+    return;
+}
+
+sub fire
+{
+    my ($test) = @_;
+    
+    # Get servers
+    my $master = ok_server ($test);
+    my $slave = ok_server ($test);
+    
+    # Read lists of statements from data source
+    my $data = get_data_from_source();
+    
+    # Summarize number of statements and ok_* command in test
+    plan tests => 6*scalar(@$data) + 38;
+
+    # Setup topology, binlog format, prepare test db
+    attach($master, $slave);
+    ok_synchronize ( $master, $slave );
+
+    # Main test
+    
+    # 0. Check replication to make sure that it works
+    ok_create_db_and_use($master, "test");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    ok_synchronize ( $master, $slave );
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test"},
+	{"conn" => $slave, "dbname" => "test"},
+    ]);
+    
+    # 1. Store events on relay log but not play them
+    ok_stop_replication($slave, "SQL_THREAD");
+    ok_create_db_and_use($master, "test1");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    my $master_pos = retrieve_master_status($master, "Position");
+    ok_wait_slave_param($slave, "Read_Master_Log_Pos", "==", $master_pos);
+    
+    # 2. Create new events in binlog on master but not send them to slave
+    ok_stop_replication($slave);
+    ok_wait_stop_replication($slave);
+    ok_create_db_and_use($master, "test2");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    
+    # 3. Upgrade slave
+    ok_updown_server($slave);
+    
+    # 4. New slave must here: 
+    #  - play events stored in relay log  by old slave
+    #  - recieve events from master, store in relay log and play them
+    ok_synchronize($master, $slave);
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test1"},
+	{"conn" => $slave, "dbname" => "test1"},
+	{"conn" => $master, "dbname" => "test2"},
+	{"conn" => $slave, "dbname" => "test2"},
+    ]);
+    
+    # 5. Check replication old master -> new slave
+    ok_create_db_and_use($master, "test3");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    ok_synchronize($master, $slave);
+    
+    # 6. Store events in binlog but not send to slave
+    ok_stop_replication($slave);
+    ok_wait_stop_replication($slave);
+    ok_create_db_and_use($master, "test4");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    
+    # 7. Upgrade master
+    ok_updown_server($master);
+    ok_start_replication($slave);
+    ok_wait_start_replication($slave);
+    
+    # 8. New master will send events created by the old one
+    ok_synchronize($master, $slave);
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test3"},
+	{"conn" => $slave, "dbname" => "test3"},
+	{"conn" => $master, "dbname" => "test4"},
+	{"conn" => $slave, "dbname" => "test4"},
+    ]);
+    
+    # 9. Check replication new master -> new slave
+    ok_create_db_and_use($master, "test5");
+    foreach my $query (@$data)
+    {
+	ok_sql($master, $query);
+    }
+    ok_synchronize($master, $slave);    
+    ok_compare_dbs([
+	{"conn" => $master, "dbname" => "test5"},
+	{"conn" => $slave, "dbname" => "test5"},
+    ]);
+}
+
+sub shutdown
+{
+    return;
+}
+
+sub ok_create_db_and_use
+{
+    my ($server, $name)= @_;
+    ok_sql($server, "DROP DATABASE IF EXISTS ".$name);
+    ok_sql($server, "CREATE DATABASE ".$name);
+    ok_sql($server, "USE ".$name);    
+}
+
+1;
+__END__;
+
+=head1 NAME
+
+updown::rep_basic_upgrade - Stepwise upgrade master and slave
+
+=head1 SYNOPSIS
+
+Stepwise upgrade checks possibility to upgrade at first slave and then master for classic replication schema master-slave.
+
+=head1 AUTHOR
+
+Serge Kozlov S<< <Serge.Kozlov@stripped> >>


Attachment: [text/bzr-bundle] bzr/serge.kozlov@sun.com-20100331204041-eb4w3zvf6rxwcbq2.bundle
Thread
bzr push into nuts branch (Serge.Kozlov:370 to 371) WL#5060Serge Kozlov1 Apr