Merge pull request #64 from ClusterLabs/scancore-debugging

* Created Storage->manage_lvm_conf() that checks / updates lvm.conf t…
main
digimer-bot 4 years ago committed by GitHub
commit f93a5eccc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Anvil/Tools.pm
  2. 168
      Anvil/Tools/Storage.pm
  3. 4
      scancore-agents/scan-drbd/scan-drbd
  4. 6
      share/words.xml
  5. 34
      tools/striker-initialize-host

@ -1029,6 +1029,7 @@ sub _set_paths
hosts => "/etc/hosts",
'httpd.conf' => "/etc/httpd/conf/httpd.conf",
'journald_anvil' => "/etc/systemd/journald.conf.d/anvil.conf",
'lvm.conf' => "/etc/lvm/lvm.conf",
'pg_hba.conf' => "/var/lib/pgsql/data/pg_hba.conf",
'postgresql.conf' => "/var/lib/pgsql/data/postgresql.conf",
pxe_default => "/var/lib/tftpboot/pxelinux.cfg/default",

@ -25,6 +25,7 @@ my $THIS_FILE = "Storage.pm";
# get_file_stats
# get_storage_group_details
# make_directory
# manage_lvm_conf
# move_file
# parse_df
# parse_lsblk
@ -1778,6 +1779,173 @@ fi;";
return($failed);
}
=head2 manage_lvm_conf
This method configures C<< lvm.conf >> to add the C<< filter = [ ... ] >> to ensure DRBD devices aren't scanned.
If there was a problem, C<< 1 >> is returned. Otherwise, C<< 0 >> is returned.
Parameters;
=head3 port (optional, default 22)
If C<< target >> is set, this is the TCP port number used to connect to the remote machine.
=head3 password (optional)
If C<< target >> is set, this is the password used to log into the remote system as the C<< remote_user >>. If it is not set, an attempt to connect without a password will be made (though this will usually fail).
=head3 target (optional)
If set, the file will be copied on the target machine. This must be either an IP address or a resolvable host name.
=head3 remote_user (optional, default root)
If C<< target >> is set, this is the user account that will be used when connecting to the remote system.
=cut
sub manage_lvm_conf
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Storage->manage_lvm_conf()" }});
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->is_secure($password),
port => $port,
remote_user => $remote_user,
target => $target,
}});
my $body = $anvil->Storage->read_file({
debug => $debug,
file => $anvil->data->{path}{configs}{'lvm.conf'},
password => $password,
port => $port,
target => $target,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { body => $body }});
if ($body eq "!!error!!")
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0254"});
return(1);
}
my $in_device = 0;
foreach my $line (split/\n/, $body)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
next if $line =~ /^#/ or $line =~ /^\s+#/;
if ($line =~ /^devices \{/)
{
$in_device = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_device => $in_device }});
}
if ($in_device)
{
$line =~ s/^\s+//;
if ($line =~ /^\}/)
{
$in_device = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_device => $in_device }});
last;
}
if ($line =~ /^filter = \[(.*?)\]/)
{
# Filter exists, we won't change it.
my $filter = $1;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0594", variables => { filter => $filter }});
return(0);
}
}
}
# If I made it here, I need to add the filter.
$in_device = 0;
my $filter_added = 0;
my $new_body = "";
my $filter_line = 'filter = [ "r|/dev/drbd*|" ]';
foreach my $line (split/\n/, $body)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
if ($line =~ /^devices \{/)
{
$in_device = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_device => $in_device }});
}
if ($in_device)
{
if ($line =~ /^\}/)
{
$in_device = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_device => $in_device }});
# If we didn't find where to inject the filter, do it now.
if (not $filter_added)
{
$new_body .= "\t".$filter_line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { filter_line => $filter_line }});
}
}
if (($line =~ /# filter = \[ "a\|\.\*\|" \]/) && (not $filter_added))
{
# Add the filter here
$new_body .= $line."\n";
$new_body .= "\t".$filter_line."\n";
$filter_added = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
filter_added => $filter_added,
filter_line => $filter_line,
}});
next;
}
}
$new_body .= $line."\n";
}
# Write the file out.
my $error = $anvil->Storage->write_file({
debug => $debug,
body => $new_body,
file => $anvil->data->{path}{configs}{'lvm.conf'},
group => "root",
mode => "0644",
overwrite => 1,
backup => 1,
user => "root",
password => $password,
port => $port,
target => $target,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { error => $error }});
if ($error)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0255"});
return(1);
}
else
{
# Record that we updated the lvm.conf.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0595", variables => { filter => $filter_line }});
}
return(0);
}
=head2 move_file
This moves a file, with a few additional checks like creating the target directory if it doesn't exist, aborting if the file already exists in the target, etc. It can move files on the local or a remote machine.

@ -93,6 +93,10 @@ if ($anvil->DRBD->gather_data())
$anvil->nice_exit({exit_code => 2});
}
# Make sure that lvm.conf's filter of DRBD devices is in place.
$problem = $anvil->Storage->manage_lvm_conf();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
read_last_scan($anvil);
find_changes($anvil);

@ -355,6 +355,8 @@ The error was:
#!variable!error!#
========
</key>
<key name="error_0254">Failed to read the lvm.conf file. The reason why should be logged above.</key>
<key name="error_0255">Failed to write the lvm.conf file. The reason why should be logged above.</key>
<!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which likes are translatable -->
@ -745,6 +747,8 @@ It should be provisioned in the next minute or two.</key>
<key name="job_0270">All machines are now available on the first BCN!</key>
<key name="job_0271">One of the Striker dashboards has not yet updated network information in the database. We need this to know which IP to tell the peer to use to connect to us. We'll wait a moment and check again.</key>
<key name="job_0272">The cluster still hasn't started. Calling startup again (will try once per minute).</key>
<key name="job_0273">Successfully added/confirmed the filter in lvm.conf.</key>
<key name="job_0274">Failed to add/confirmed the filter in lvm.conf! This should be corrected later by 'scan-drbd' though.</key>
<!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key>
@ -1432,6 +1436,8 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<key name="log_0591">Wiping any file system signatures and then deleting the logical volume: [#!variable!device_path!#].</key>
<key name="log_0592">The resource name: [#!variable!resource_name!#] was found, returning the first TCP port and minor number.</key>
<key name="log_0593">The job: [#!variable!command!#] with UUID: [#!variable!job_uuid!#] is a start-time job, not running it now.</key>
<key name="log_0594">The lvm.conf already has the filter: [#!variable!filter!#], will not change it.</key>
<key name="log_0595">Updated the lvm.conf file to add the filter: [#!variable!filter!#] to prevent LVM from seeing the DRBD devices as LVM devices.</key>
<!-- Messages for users (less technical than log entries), though sometimes used for logs, too. -->
<key name="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key>

@ -57,6 +57,7 @@ get_job_details($anvil);
wait_for_access($anvil);
set_host_name($anvil);
add_repos($anvil);
configure_lvm($anvil);
add_databases($anvil);
update_progress($anvil, 100, "job_0047");
@ -67,15 +68,40 @@ $anvil->nice_exit({exit_code => 0});
# Functions #
#############################################################################################################
# This configures filtering on LVM
sub configure_lvm
{
my ($anvil) = @_;
my $problem = $anvil->Storage->manage_lvm_conf({
debug => 2,
password => $anvil->data->{data}{password},
port => $anvil->data->{data}{ssh_port},
target => $anvil->data->{data}{host_ip_address},
remote_user => "root",
})
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ($problem)
{
$anvil->data->{job}{progress} += 5;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "job_0274"});
update_progress($anvil, $anvil->data->{job}{progress}, "job_0274");
}
else
{
$anvil->data->{job}{progress} += 5;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "job_0273"});
update_progress($anvil, $anvil->data->{job}{progress}, "job_0273");
}
return(0);
}
# Set the host name, if needed.
sub set_host_name
{
my ($anvil) = @_;
### TODO: Left off here;
### - Validate host name
### - Update progress values
### - Set host_namectl
if ((not defined $anvil->data->{data}{host_name}) or (not $anvil->data->{data}{host_name}))
{
return(0);

Loading…
Cancel
Save