From f5caec52dcf1e23d99b3a159b8fa61899626bb08 Mon Sep 17 00:00:00 2001 From: Digimer Date: Tue, 20 Aug 2019 00:59:41 -0400 Subject: [PATCH] * Made DRBD->allow_two_primaries() smarter about finding the 'target_node_id' when it wasn't passed. * Fixed a couple bugs, and now ocf:alteeve:server properly can pull and push servers between nodes. Signed-off-by: Digimer --- Anvil/Tools/DRBD.pm | 10 ++++++++ ocf/alteeve/server | 58 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Anvil/Tools/DRBD.pm b/Anvil/Tools/DRBD.pm index a8127fdc..0b30c99e 100755 --- a/Anvil/Tools/DRBD.pm +++ b/Anvil/Tools/DRBD.pm @@ -156,6 +156,16 @@ sub allow_two_primaries if ($target_node_id !~ /^\d+$/) { # Can we find it? + if (not exists $anvil->data->{drbd}{status}) + { + $anvil->DRBD->get_status({ + debug => 2, + password => $password, + port => $port, + remote_user => $remote_user, + target => $target, + }); + } if ($anvil->data->{drbd}{status}{$host}{resource}{$resource}{connection}{$peer_name}{'peer-node-id'} =~ /^\d+$/) { $target_node_id = $anvil->data->{drbd}{status}{$host}{resource}{$resource}{connection}{$peer_name}{'peer-node-id'}; diff --git a/ocf/alteeve/server b/ocf/alteeve/server index d6a96ecf..eb0c79ae 100755 --- a/ocf/alteeve/server +++ b/ocf/alteeve/server @@ -627,9 +627,6 @@ sub migrate_server 'switches::migrate_from' => $anvil->data->{switches}{migrate_from}, }}); - # Get a view of the servers locally and our peer. - validate_all($anvil); - # The actual migration command will involve enabling dual primary, then beginning the migration. The # virsh call will depend on if we're pushing or pulling. Once the migration completes, regardless of # success or failure, dual primary will be disabled again. @@ -650,6 +647,9 @@ sub migrate_server $anvil->nice_exit({exit_code => 5}); } + # Get a view of the servers locally and our peer. + validate_all($anvil); + # Find the server $anvil->Server->find({debug => 3}); @@ -770,14 +770,56 @@ sub migrate_server } elsif ($anvil->data->{switches}{migrate_from}) { - $anvil->Server->find({debug => 3, target => $target}); + # Pull the server here. Start by verifying it's on the 'meta_on_node' host. + my $meta_on_node = $anvil->data->{environment}{OCF_RESKEY_CRM_meta_on_node}; + my $host = defined $anvil->data->{server}{location}{$server}{host} ? $anvil->data->{server}{location}{$server}{host} : ""; + my $status = defined $anvil->data->{server}{location}{$server}{status} ? $anvil->data->{server}{location}{$server}{status} : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + host => $host, + status => $status, + meta_on_node => $meta_on_node, + target => $target, + }}); + $anvil->Server->find({debug => 2, target => $meta_on_node}); - my $host = defined $anvil->data->{server}{location}{$server}{host} ? $anvil->data->{server}{location}{$server}{host} : ""; - my $status = defined $anvil->data->{server}{location}{$server}{status} ? $anvil->data->{server}{location}{$server}{status} : ""; + my $server_host = defined $anvil->data->{server}{location}{$server}{host} ? $anvil->data->{server}{location}{$server}{host} : ""; + my $server_status = defined $anvil->data->{server}{location}{$server}{status} ? $anvil->data->{server}{location}{$server}{status} : ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - host => $host, - status => $status, + server_host => $server_host, + server_status => $server_status, }}); + + # This is called after a migration. If that is the case here, the target will be us. Just + # make sure it is running and, if so, return '0'. The 'meta_on_node' is the new host. + if ($meta_on_node eq $target) + { + # Yup. All we want to do if make sure it is running here. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0345", variables => { server => $server }}); + + # If it's running, we're succesfully out. + if ($status eq "running") + { + # Success! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0347", variables => { server => $server }}); + $anvil->nice_exit({exit_code => 0}); + } + + # If we're still alive, we'll proceed as if we're pulling the server to us, and maybe + # that will work. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0348", variables => { server => $server }}); + } + + # Validate as if we were about to boot the server. + validate_all($anvil); + + # Call the pull migation. + ($migrated) = $anvil->Server->migrate({ + debug => 2, + server => $server, + source => $source, + target => $target + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { migrated => $migrated }}); } $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { migrated => $migrated }});