BUG-1595678 Added --slave-user, --slave-password params

This commit is contained in:
Carlos Salguero
2016-07-06 19:04:21 -03:00
parent c0aa88eb4f
commit 2c1db036b5
3 changed files with 75 additions and 17 deletions

View File

@@ -4110,6 +4110,7 @@ sub get_slaves {
die "I need a $arg argument" unless $args{$arg};
}
my ($dbh, $dsn) = @args{@required_args};
my $o = $self->{OptionParser};
$self->recurse_to_slaves(
{ dbh => $dbh,
@@ -4118,7 +4119,16 @@ sub get_slaves {
my ( $dsn, $dbh, $level, $parent ) = @_;
return unless $level;
PTDEBUG && _d('Found slave:', $dp->as_string($dsn));
push @$slaves, $make_cxn->(dsn => $dsn, dbh => $dbh);
my $slave_dsn = $dsn;
if ($o->got('slave-user')) {
$slave_dsn->{u} = $o->get('slave-user');
PTDEBUG && _d("Using slave user ".$o->get('slave-user')." on ".$slave_dsn->{h}.":".$slave_dsn->{P});
}
if ($o->got('slave-password')) {
$slave_dsn->{p} = $o->get('slave-password');
PTDEBUG && _d("Slave password set");
}
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh);
return;
},
}
@@ -11956,6 +11966,22 @@ replication lag, insert the values C<h=10.10.1.16> and C<h=10.10.1.17> into the
table. Currently, the DSNs are ordered by id, but id and parent_id are otherwise
ignored.
=item --slave-user
type: string
Sets the user to be used to connect to the slaves.
This parameter allows you to have a different user with less privileges on the
slaves but that user must exist on all slaves.
=item --slave-password
type: string
Sets the password to be used to connect to the slaves.
It can be used with --slave-user and the password for the user must be the same
on all slaves.
=item --set-vars
type: Array

View File

@@ -80,7 +80,8 @@ sub get_slaves {
die "I need a $arg argument" unless $args{$arg};
}
my ($dbh, $dsn) = @args{@required_args};
my $o = $self->{OptionParser};
$self->recurse_to_slaves(
{ dbh => $dbh,
dsn => $dsn,
@@ -88,7 +89,16 @@ sub get_slaves {
my ( $dsn, $dbh, $level, $parent ) = @_;
return unless $level;
PTDEBUG && _d('Found slave:', $dp->as_string($dsn));
push @$slaves, $make_cxn->(dsn => $dsn, dbh => $dbh);
my $slave_dsn = $dsn;
if ($o->got('slave-user')) {
$slave_dsn->{u} = $o->get('slave-user');
PTDEBUG && _d("Using slave user ".$o->get('slave-user')." on ".$slave_dsn->{h}.":".$slave_dsn->{P});
}
if ($o->got('slave-password')) {
$slave_dsn->{p} = $o->get('slave-password');
PTDEBUG && _d("Slave password set");
}
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh);
return;
},
}

View File

@@ -837,33 +837,55 @@ test_alter_table(
);
test_alter_table(
name => "--preserve-triggers --no-swap-table",
table => "pt_osc.account",
pk_col => "id",
name => "--preserve-triggers --no-swap-tables",
table => "pt_osc.t",
file => "basic_no_fks_innodb.sql",
max_id => 20,
test_type => "add_col",
new_col => "foo",
no_change => 1,
cmds => [
qw(--execute --preserve-triggers --no-swap-table), '--alter', 'ADD COLUMN foo2 INT',
qw(--execute --no-swap-tables --preserve-triggers), '--alter', 'ADD COLUMN foo INT'
],
);
test_alter_table(
name => "FK rebuild_constraints --preserve-triggers",
table => "sakila.film",
pk_col => "film_id",
test_type => "add_col",
file => "sakila_triggers.sql",
new_col => "foo",
check_fks => "rebuild_constraints",
cmds => [
qw(--execute --preserve-triggers --alter-foreign-keys-method rebuild_constraints), '--alter', 'ADD COLUMN foo INT',
name => "Basic FK auto --execute",
table => "pt_osc.country",
pk_col => "country_id",
file => "basic_with_fks.sql",
test_type => "drop_col",
drop_col => "last_update",
check_fks => "rebuild_constraints",
cmds => [
qw(
--execute
--alter-foreign-keys-method rebuild_constraints
--preserve-triggers
),
'--alter', 'DROP COLUMN last_update',
],
);
$sb->do_as_root("master", q/GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'slave_password'/);
$sb->do_as_root("master", q/set sql_log_bin=0/);
$sb->do_as_root("master", q/DROP USER 'slave_user'/);
$sb->do_as_root("master", q/set sql_log_bin=1/);
test_alter_table(
name => "--slave-user --slave-password",
file => "basic_no_fks_innodb.sql",
table => "pt_osc.t",
test_type => "add_col",
new_col => "bar",
cmds => [
qw(--execute --slave-user slave_user --slave-password slave_password), '--alter', 'ADD COLUMN bar INT',
],
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
#
#
done_testing;