diff --git a/Anvil/Tools/Cluster.pm b/Anvil/Tools/Cluster.pm index 4408d171..8d63d444 100644 --- a/Anvil/Tools/Cluster.pm +++ b/Anvil/Tools/Cluster.pm @@ -241,16 +241,28 @@ sub add_server ### ### TODO: If the target_role is 'started' because the server was running, we may need to later do an ### update to set it to 'stopped' after we've verified it's in the cluster below. - my $resource_command = $anvil->data->{path}{exe}{pcs}." resource create ".$server_name." ocf:alteeve:server name=\"".$server_name."\" meta allow-migrate=\"true\" target-role=\"".$target_role."\" op monitor interval=\"60\" start timeout=\"60\" on-fail=\"block\" stop timeout=\"300\" on-fail=\"block\" migrate_to timeout=\"600\" on-fail=\"block\" migrate_from timeout=\"600\" on-fail=\"block\""; + my $pcs_file = "/tmp/anvil.add_server.".$server_name.".cib"; + my $pcs_cib_file_command = $anvil->data->{path}{exe}{pcs}." cluster cib ".$pcs_file; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { pcs_cib_file_command => $pcs_cib_file_command }}); + + my ($output, $return_code) = $anvil->System->call({shell_call => $pcs_cib_file_command}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + output => $output, + return_code => $return_code, + }}); + undef $output; + undef $return_code; + + my $resource_command = $anvil->data->{path}{exe}{pcs}." -f ".$pcs_file." resource create ".$server_name." ocf:alteeve:server name=\"".$server_name."\" meta allow-migrate=\"true\" target-role=\"".$target_role."\" op monitor interval=\"60\" start timeout=\"60\" on-fail=\"block\" stop timeout=\"300\" on-fail=\"block\" migrate_to timeout=\"600\" on-fail=\"block\" migrate_from timeout=\"600\" on-fail=\"block\""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { resource_command => $resource_command }}); - my ($output, $return_code) = $anvil->System->call({shell_call => $resource_command}); + ($output, $return_code) = $anvil->System->call({shell_call => $resource_command}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code, }}); - my $constraint_command = $anvil->data->{path}{exe}{pcs}." constraint location ".$server_name." prefers "; + my $constraint_command = $anvil->data->{path}{exe}{pcs}." -f ".$pcs_file." constraint location ".$server_name." prefers "; if (($server_state eq "running") && ($server_host ne $host_name)) { # Set the peer as primary. @@ -271,6 +283,19 @@ sub add_server return_code => $return_code, }}); + # Commit + my $commit_command = $anvil->data->{path}{exe}{pcs}." cluster cib-push ".$pcs_file; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { commit_command => $commit_command }}); + + ($output, $return_code) = $anvil->System->call({shell_call => $commit_command}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + output => $output, + return_code => $return_code, + }}); + + # Unlink the temp CIB + unlink $pcs_file; + # Reload the CIB ($problem) = $anvil->Cluster->parse_cib({debug => 2}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { problem => $problem }}); diff --git a/scancore-agents/scan-cluster/scan-cluster b/scancore-agents/scan-cluster/scan-cluster index fb62d06f..b2ae2e88 100755 --- a/scancore-agents/scan-cluster/scan-cluster +++ b/scancore-agents/scan-cluster/scan-cluster @@ -298,7 +298,7 @@ sub check_resources if ($update) { - + # Update the resource config. my $resource_command = $anvil->data->{path}{exe}{pcs}." resource update ".$server." ocf:alteeve:server name=\"".$server."\" meta allow-migrate=\"true\" op monitor interval=\"60\" start timeout=\"60\" on-fail=\"block\" stop timeout=\"300\" on-fail=\"block\" migrate_to timeout=\"600\" on-fail=\"block\" migrate_from timeout=\"600\" on-fail=\"block\""; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0739", variables => { server => $server, diff --git a/scancore-agents/scan-lvm/scan-lvm b/scancore-agents/scan-lvm/scan-lvm index 7f59de3e..279fac3e 100755 --- a/scancore-agents/scan-lvm/scan-lvm +++ b/scancore-agents/scan-lvm/scan-lvm @@ -1000,15 +1000,41 @@ WHERE { # We've got an entry in the 'scan_lvm_pv' table, so now we'll look for data in the node and # services tables. - my $scan_lvm_pv_internal_uuid = $row->[1]; - my $scan_lvm_pv_name = $row->[2]; - $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_uuid} = $row->[0];; - $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_name} = $scan_lvm_pv_name; - $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_used_by_vg} = $row->[3]; - $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_attributes} = $row->[4]; - $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_size} = $row->[5]; - $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_free} = $row->[6]; - $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_sector_size} = $row->[7]; + my $scan_lvm_pv_uuid = $row->[0]; + my $scan_lvm_pv_internal_uuid = $row->[1]; + my $scan_lvm_pv_name = $row->[2]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + scan_lvm_pv_uuid => $scan_lvm_pv_uuid, + scan_lvm_pv_internal_uuid => $scan_lvm_pv_internal_uuid, + scan_lvm_pv_name => $scan_lvm_pv_name, + }}); + + # If there's an existing entry, delete this one, it's somehow a duplicate. + if (exists $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}) + { + # Duplicate! + my $variables = { + pv_name => $scan_lvm_pv_name, + pv_uuid => $scan_lvm_pv_uuid, + internal_uuid => $scan_lvm_pv_internal_uuid, + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_lvm_alert_0033", variables => $variables}); + $anvil->Alert->register({alert_level => "notice", message => "scan_lvm_alert_0033", variables => $variables, set_by => $THIS_FILE}); + + my $query = "DELETE FROM scan_lvm_pvs WHERE scan_lvm_pv_uuid = ".$anvil->Database->quote($scan_lvm_pv_uuid).";\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); + next; + } + + # Save + $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_uuid} = $scan_lvm_pv_uuid; + $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_name} = $scan_lvm_pv_name; + $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_used_by_vg} = $row->[3]; + $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_attributes} = $row->[4]; + $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_size} = $row->[5]; + $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_free} = $row->[6]; + $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_sector_size} = $row->[7]; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sql::scan_lvm_pvs::scan_lvm_pv_internal_uuid::${scan_lvm_pv_internal_uuid}::scan_lvm_pv_uuid" => $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_uuid}, "sql::scan_lvm_pvs::scan_lvm_pv_internal_uuid::${scan_lvm_pv_internal_uuid}::scan_lvm_pv_name" => $anvil->data->{sql}{scan_lvm_pvs}{scan_lvm_pv_internal_uuid}{$scan_lvm_pv_internal_uuid}{scan_lvm_pv_name}, @@ -1049,14 +1075,40 @@ WHERE { # We've got an entry in the 'scan_lvm_vg' table, so now we'll look for data in the node and # services tables. - my $scan_lvm_vg_internal_uuid = $row->[1]; - my $scan_lvm_vg_name = $row->[2]; - $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_uuid} = $row->[0]; - $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_name} = $scan_lvm_vg_name; - $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_attributes} = $row->[3]; - $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_extent_size} = $row->[4]; - $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_size} = $row->[5]; - $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_free} = $row->[6]; + my $scan_lvm_vg_uuid = $row->[0]; + my $scan_lvm_vg_internal_uuid = $row->[1]; + my $scan_lvm_vg_name = $row->[2]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + scan_lvm_vg_uuid => $scan_lvm_vg_uuid, + scan_lvm_vg_internal_uuid => $scan_lvm_vg_internal_uuid, + scan_lvm_vg_name => $scan_lvm_vg_name, + }}); + + # If there's an existing entry, delete this one, it's somehow a duplicate. + if (exists $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}) + { + # Duplicate! + my $variables = { + vg_name => $scan_lvm_vg_name, + vg_uuid => $scan_lvm_vg_uuid, + internal_uuid => $scan_lvm_vg_internal_uuid, + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_lvm_alert_0034", variables => $variables}); + $anvil->Alert->register({alert_level => "notice", message => "scan_lvm_alert_0034", variables => $variables, set_by => $THIS_FILE}); + + my $query = "DELETE FROM scan_lvm_vgs WHERE scan_lvm_vg_uuid = ".$anvil->Database->quote($scan_lvm_vg_uuid).";\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); + next; + } + + # Save + $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_uuid} = $scan_lvm_vg_uuid; + $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_name} = $scan_lvm_vg_name; + $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_attributes} = $row->[3]; + $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_extent_size} = $row->[4]; + $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_size} = $row->[5]; + $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_free} = $row->[6]; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sql::scan_lvm_vgs::scan_lvm_vg_internal_uuid::${scan_lvm_vg_internal_uuid}::scan_lvm_vg_uuid" => $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_uuid}, "sql::scan_lvm_vgs::scan_lvm_vg_internal_uuid::${scan_lvm_vg_internal_uuid}::scan_lvm_vg_name" => $anvil->data->{sql}{scan_lvm_vgs}{scan_lvm_vg_internal_uuid}{$scan_lvm_vg_internal_uuid}{scan_lvm_vg_name}, @@ -1097,15 +1149,70 @@ WHERE { # We've got an entry in the 'scan_lvm_lv' table, so now we'll look for data in the node and # services tables. - my $scan_lvm_lv_internal_uuid = $row->[1]; - my $scan_lvm_lv_name = $row->[2]; - $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_uuid} = $row->[0]; - $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_name} = $scan_lvm_lv_name; - $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_attributes} = $row->[3]; - $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_on_vg} = $row->[4]; - $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_size} = $row->[5]; - $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_path} = $row->[6]; - $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_on_pvs} = $row->[7]; + my $scan_lvm_lv_uuid = $row->[0]; + my $scan_lvm_lv_internal_uuid = $row->[1]; + my $scan_lvm_lv_name = $row->[2]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + scan_lvm_lv_uuid => $scan_lvm_lv_uuid, + scan_lvm_lv_internal_uuid => $scan_lvm_lv_internal_uuid, + scan_lvm_lv_name => $scan_lvm_lv_name, + }}); + + # If there's an existing entry, delete this one, it's somehow a duplicate. + if (exists $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}) + { + # Duplicate! Is one of them DELETED? + my $existing_name = $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_name}; + my $existing_uuid = $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_uuid}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + existing_name => $existing_name, + existing_uuid => $existing_uuid, + }}); + + if ($anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_name} eq "DELETED") + { + # Delete the one we already read. + my $variables = { + lv_name => $existing_name, + lv_uuid => $existing_uuid, + internal_uuid => $scan_lvm_lv_internal_uuid, + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_lvm_alert_0035", variables => $variables}); + $anvil->Alert->register({alert_level => "notice", message => "scan_lvm_alert_0034", variables => $variables, set_by => $THIS_FILE}); + + my $query = "DELETE FROM scan_lvm_lvs WHERE scan_lvm_lv_uuid = ".$anvil->Database->quote($existing_uuid).";\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); + + delete $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}; + } + else + { + # Delete the new one + my $variables = { + lv_name => $scan_lvm_lv_name, + lv_uuid => $scan_lvm_lv_uuid, + internal_uuid => $scan_lvm_lv_internal_uuid, + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_lvm_alert_0035", variables => $variables}); + $anvil->Alert->register({alert_level => "notice", message => "scan_lvm_alert_0034", variables => $variables, set_by => $THIS_FILE}); + + my $query = "DELETE FROM scan_lvm_lvs WHERE scan_lvm_lv_uuid = ".$anvil->Database->quote($scan_lvm_lv_uuid).";\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); + + next; + } + } + + # Save + $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_uuid} = $scan_lvm_lv_uuid; + $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_name} = $scan_lvm_lv_name; + $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_attributes} = $row->[3]; + $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_on_vg} = $row->[4]; + $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_size} = $row->[5]; + $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_path} = $row->[6]; + $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_on_pvs} = $row->[7]; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sql::scan_lvm_lvs::scan_lvm_lv_internal_uuid::${scan_lvm_lv_internal_uuid}::scan_lvm_lv_uuid" => $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_uuid}, "sql::scan_lvm_lvs::scan_lvm_lv_internal_uuid::${scan_lvm_lv_internal_uuid}::scan_lvm_lv_name" => $anvil->data->{sql}{scan_lvm_lvs}{scan_lvm_lv_internal_uuid}{$scan_lvm_lv_internal_uuid}{scan_lvm_lv_name}, diff --git a/scancore-agents/scan-lvm/scan-lvm.xml b/scancore-agents/scan-lvm/scan-lvm.xml index 9bb7cfea..45001484 100644 --- a/scancore-agents/scan-lvm/scan-lvm.xml +++ b/scancore-agents/scan-lvm/scan-lvm.xml @@ -220,6 +220,9 @@ The attribute bits are: The volume group: [#!variable!vg_name!#] (UUID: [#!variable!vg_uuid!#]) has vanished! If this is a removable device, like a USB drive, this is OK. Otherwise, it could be the sign of a disk failure. The logical volume: [#!variable!lv_name!#] (UUID: [#!variable!lv_uuid!#]) has been lost. This is normal if the LV is on a removable medium like a USB disk. Otherwise, it could be the sign of a disk failure. The physical volume: [#!variable!pv_name!#] (UUID: [#!variable!pv_uuid!#]) sector size changed from: [#!variable!old_pv_sector_size!#] (#!variable!old_pv_sector_size_bytes!# bytes) to: [#!variable!new_pv_sector_size!#] (#!variable!new_pv_sector_size_bytes!# bytes). This should not happen, unless the storage behind the PV was somehow rebuilt without recreating the LVM metadata. + The physical volume with the internal UUID: [#!variable!internal_uuid!#] (name: [#!variable!pv_name!#]) has a duplicate entry! Deleting the one with the scan_lvm_pv_uuid: [#!variable!pv_uuid!#]. + The volume group with the internal UUID: [#!variable!internal_uuid!#] (name: [#!variable!vg_name!#]) has a duplicate entry! Deleting the one with the scan_lvm_vg_uuid: [#!variable!vg_uuid!#]. + The logical volume with the internal UUID: [#!variable!internal_uuid!#] (name: [#!variable!lv_name!#]) has a duplicate entry! Deleting the one with the scan_lvm_lv_uuid: [#!variable!lv_uuid!#]. Starting: [#!variable!program!#].