Merge pull request #618 from ClusterLabs/libvirt_fixes

Removed the check of the libvirtd daemon status.
main
Digimer 9 months ago committed by GitHub
commit 20d71781d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      Anvil/Tools.pm
  2. 142
      ocf/alteeve/server
  3. 7
      share/words.xml
  4. 155
      tools/striker-get-screenshots

@ -1278,6 +1278,7 @@ sub _set_paths
ps => "/usr/bin/ps",
psql => "/usr/bin/psql",
pamtopng => "/usr/bin/pamtopng",
pngtopam => "/usr/bin/pngtopam",
pnmtojpeg => "/usr/bin/pnmtojpeg",
'postgresql-setup' => "/usr/bin/postgresql-setup",
postmap => "/usr/sbin/postmap",

@ -1239,97 +1239,8 @@ sub server_status
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0331", variables => { timeout => $anvil->data->{environment}{OCF_RESKEY_CRM_meta_timeout} }});
}
# Is 'libvirtd' running? We'll wait up to half the timeout for it to start (in case it _just_ started)
# before timing out.
my $wait_until = time + ($anvil->data->{environment}{OCF_RESKEY_CRM_meta_timeout} / 2000); # Devide by 2000 to convert to seconds and total second halved.
my $look_for_pid = 0;
my $libvirtd_wait = 1;
my $warning_shown = 0;
while($libvirtd_wait)
{
my $running = $anvil->System->check_daemon({daemon => "libvirtd.service"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { running => $running }});
if ($running)
{
$libvirtd_wait = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { libvirtd_wait => $libvirtd_wait }});
}
else
{
# On EL8 and above, libvirtd starts on demand, so this error isn't
if (not $warning_shown)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0522", variables => { wait_time => ($wait_until - time) }});
$warning_shown = 1;
}
sleep 1;
if (time > $wait_until)
{
# Libvirtd isn't running, try to find the PID of the server (in case it's
# running and libvirtd isn't)
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, priority => "alert", key => "warning_0057"});
$look_for_pid = 1;
$libvirtd_wait = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
look_for_pid => $look_for_pid,
libvirtd_wait => $libvirtd_wait,
}});
}
}
}
# If libvirtd wasn't running, we'll manually look for a PID.
if ($look_for_pid)
{
my $server_up = 0;
my $shell_call = $anvil->data->{path}{exe}{ps}." aux";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
foreach my $line (split/\n/, $output)
{
next if $line !~ /qemu-kvm/;
$line = $anvil->Words->clean_spaces({ string => $line });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /guest=(.*?),/)
{
my $this_server = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { this_server => $this_server }});
if ($this_server eq $server)
{
# Found it.
$server_up = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_up => $server_up }});
last;
}
}
}
if ($server_up)
{
# The server is running. Exit with OCF_SUCCESS (rc 0);
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0523"});
$anvil->nice_exit({exit_code => 0});
}
else
{
# The server is not running. Exit with OCF_NOT_RUNNING (rc: 7)
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0524"});
$anvil->nice_exit({exit_code => 7});
}
}
else
{
# Parse the virsh state. If it's listed as 'crashed', return OCF_ERR_GENERIC (rc: 1). If it's
# 'in shutdown', 'loop' gets set to 1 and this will loop indefinitely. We don't put a timer
# on it, we let pacemaker handle that.
# libvirtd lists as disabled / stopped, but "starts" when called. So checking the daemon doesn't make
# sense. Given virsh might fail, if we don't find the server, we'll also look for it in 'ps'.
my $loop = 1;
while($loop)
{
@ -1343,6 +1254,8 @@ sub server_status
output => $output,
return_code => $return_code,
}});
if (not $return_code)
{
foreach my $line (split/\n/, $output)
{
$line = $anvil->Words->clean_spaces({ string => $line });
@ -1382,7 +1295,6 @@ pmsuspended - The domain has been suspended by guest power management, e.g. ente
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { loop => $loop }});
sleep 1;
last;
}
elsif ($state eq "shut off")
{
@ -1401,11 +1313,53 @@ pmsuspended - The domain has been suspended by guest power management, e.g. ente
}
}
}
}
# If it wasn't found at all, exit.
if (not $found)
if ((not $found) or ($return_code))
{
# Exit with OCF_NOT_RUNNING (rc: 7);
# If we've timed out, we'll look for it using it's PID.
my $server_up = 0;
my $shell_call = $anvil->data->{path}{exe}{ps}." aux";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
foreach my $line (split/\n/, $output)
{
next if $line !~ /qemu-kvm/;
$line = $anvil->Words->clean_spaces({ string => $line });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /guest=(.*?),/)
{
my $this_server = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { this_server => $this_server }});
if ($this_server eq $server)
{
# Found it.
$server_up = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_up => $server_up }});
last;
}
}
}
# Did we find it by PID?
if ($server_up)
{
# The server is running. Exit with OCF_SUCCESS (rc 0);
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0523"});
$anvil->nice_exit({exit_code => 0});
}
else
{
# The server is not running. Exit with OCF_NOT_RUNNING (rc: 7)
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0526", variables => { server_name => $server }});
$anvil->nice_exit({exit_code => 7});
}

@ -2377,10 +2377,10 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<key name="log_0520">The server: [#!variable!server!#] is indeed running. It will be shut down now.</key>
<key name="log_0521">Checking the status of the server: [#!variable!server!#].</key>
<key name="log_0522">The 'libvirtd' daemon is not running. It may be starting up, will wait: [#!variable!wait_time!#] seconds...</key>
<key name="log_0523">Found the server to be running using it's PID. The state of the server can't be determined, however. Please start the 'libvirtd' daemon!</key>
<key name="log_0523">Found the server to be running using it's PID. The state of the server can't be determined, however. There appears to be a problem with 'virsh'!</key>
<key name="log_0524">No PID for the server was found. It is not running on this host.</key>
<key name="log_0525">The server: [#!variable!server_name!#] is shutting down. Will wait for it to finish...</key>
<key name="log_0526">The server: [#!variable!server_name!#] is off.</key>
<key name="log_0526">The server: [#!variable!server_name!#] is off (not found in virsh or by PID).</key>
<key name="log_0527">The server: [#!variable!server_name!#] is running (state is: [#!variable!state!#]).</key>
<key name="log_0528">We've been asked to migrating the server: [#!variable!server!#] to: [#!variable!target_host!#].</key>
<key name="log_0529">Checking server state after: [#!variable!server!#] was migrated to this host.</key>
@ -2681,7 +2681,7 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<key name="log_0804">Connecting: [#!variable!host_name!#] via: [#!variable!target_ip!#]</key>
<key name="log_0805">Getting a screenshot from: [#!variable!server_name!#] (uuid: [#!variable!server_uuid!#]) from the host: [#!variable!host_name!#].</key>
<key name="log_0806">- Saving the screenshot: [#!variable!ppm_file!#].</key>
<key name="log_0807">- Converting: [#!variable!ppm_file!#] to:
<key name="log_0807">- Converting: [#!variable!source_file!#] to:
[#!variable!new_file!#]</key>
<key name="log_0808">Deleting screenshots older than: [#!variable!maximum_age!#].</key>
<key name="log_0809">- Deleting the server: [#!variable!server_name!#]'s screenshot: [#!variable!file!#].</key>
@ -4187,6 +4187,7 @@ We will try to proceed anyway.</key>
<key name="warning_0170">[ Warning ] - The attempt to boot: [#!variable!host_name!#] appears to have failed. The return code received was: [#!variable!return_code!#] (expected '0'). The output, if any, was: [#!variable!output!#].</key>
<key name="warning_0171">[ Warning ] - The daemon: [#!variable!daemon!#] appears to have failed! Attempting to restart it now.</key>
<key name="warning_0172">[ Warning ] - The line: [#!variable!line!#] that was going to be added to the hosts file is invalid, removing it.</key>
<key name="warning_0173">[ Warning ] - Failed to convert: [#!variable!source_file!#] to: [#!variable!new_file!#] (format: [#!variable!format!#]! Return code was: [#!variable!return_code!#], expected '0'.</key>
</language>
<!-- 日本語 -->

@ -381,6 +381,8 @@ sub get_screenshots
my $unix_time = time;
my $file_name = "server-uuid_".$server_uuid."_timestamp-".$unix_time;
my $ppm_file = $anvil->data->{path}{directories}{screenshots}."/".$file_name.".ppm";
my $jpg_file = $anvil->data->{path}{directories}{screenshots}."/".$file_name.".jpg";
my $png_file = $anvil->data->{path}{directories}{screenshots}."/".$file_name.".png";
my $mimetype = $domain->screenshot($stream, 0);
my $screenshot = "";
my $screenshot_size = 0;
@ -393,13 +395,88 @@ sub get_screenshots
unix_time => $unix_time,
file_name => $file_name,
ppm_file => $ppm_file,
jpg_file => $jpg_file,
png_file => $png_file,
mimetype => $mimetype,
screenshot_size => $screenshot_size." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $screenshot_size}).")",
}});
$stream->recv_all($handle_ss_chunk);
# Write out the screenshot.
### TODO: Delete this when EL8 support is dropped.
### TODO: When generating PNG, convert directly to JPEG
# On EL8, the mimetype is 'image/x-portable-pixmap'. On EL9, this is 'image/png'.
if ($mimetype eq "image/png")
{
# Write this out to png, and convert it to pmm.
$anvil->Storage->write_file({
debug => 2,
file => $png_file,
body => $screenshot,
mode => "0666",
binary => 1,
});
# Change the ownership
$anvil->Storage->change_owner({
debug => 2,
path => $png_file,
user => "striker-ui-api",
group => "striker-ui-api",
});
# Convert to PPM
my $shell_call = $anvil->data->{path}{exe}{pngtopam}." ".$png_file." > ".$ppm_file;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
if ($return_code)
{
# Failed
$anvil->Job->update_progress({
progress => $anvil->data->{job}{progress} < 99 ? ++$anvil->data->{job}{progress} : $anvil->data->{job}{progress},
message => "warning_0173",
log_level => 1,
variables => {
source_file => $png_file,
new_file => $ppm_file,
'format' => "ppm",
return_code => $return_code,
},
});
unlink $ppm_file;
}
else
{
$anvil->Job->update_progress({
progress => $anvil->data->{job}{progress} < 99 ? ++$anvil->data->{job}{progress} : $anvil->data->{job}{progress},
message => "log_0807",
log_level => 2,
variables => {
source_file => $png_file,
new_file => $ppm_file,
'format' => "ppm",
},
});
# Change the ownership
$anvil->Storage->change_owner({
debug => 2,
path => $png_file,
user => "striker-ui-api",
group => "striker-ui-api",
});
}
}
else
{
# Write out ppm the screenshot.
$anvil->Storage->write_file({
debug => 2,
file => $ppm_file,
@ -407,12 +484,23 @@ sub get_screenshots
mode => "0666",
binary => 1,
});
print "Wrote ppm: [".$ppm_file."]\n";
# Change the ownership
$anvil->Storage->change_owner({
debug => 2,
path => $ppm_file,
user => "striker-ui-api",
group => "striker-ui-api",
});
$anvil->Job->update_progress({
progress => $anvil->data->{job}{progress} < 99 ? ++$anvil->data->{job}{progress} : $anvil->data->{job}{progress},
message => "log_0806",
log_level => 2,
variables => { ppm_file => $ppm_file },
});
}
### TODO: Make these user-configurable later.
my $make_jpeg = 1;
@ -425,26 +513,41 @@ sub get_screenshots
}});
# Convert to jpg
if ($make_jpeg)
if ((-e $ppm_file) && ($make_jpeg))
{
my $jpg_file = $anvil->data->{path}{directories}{screenshots}."/".$file_name.".jpg";
my $shell_call = $anvil->data->{path}{exe}{pnmtojpeg}." ".$ppm_file." > ".$jpg_file;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
shell_call => $shell_call,
jpg_file => $jpg_file,
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
if ($return_code)
{
# Failed
$anvil->Job->update_progress({
progress => $anvil->data->{job}{progress} < 99 ? ++$anvil->data->{job}{progress} : $anvil->data->{job}{progress},
message => "warning_0173",
log_level => 1,
variables => {
source_file => $ppm_file,
new_file => $jpg_file,
'format' => "jpeg",
return_code => $return_code,
},
});
unlink $jpg_file;
}
else
{
$anvil->Job->update_progress({
progress => $anvil->data->{job}{progress} < 99 ? ++$anvil->data->{job}{progress} : $anvil->data->{job}{progress},
message => "log_0807",
log_level => 2,
variables => {
ppm_file => $ppm_file,
source_file => $ppm_file,
new_file => $jpg_file,
'format' => "jpeg",
},
@ -458,28 +561,44 @@ sub get_screenshots
group => "striker-ui-api",
});
}
}
# Convert to png
if ($make_png)
if ((-e $ppm_file) && ($make_png) && (not -e $png_file))
{
my $png_file = $anvil->data->{path}{directories}{screenshots}."/".$file_name.".png";
my $shell_call = $anvil->data->{path}{exe}{pamtopng}." ".$ppm_file." > ".$png_file;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
shell_call => $shell_call,
png_file => $png_file,
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
if ($return_code)
{
# Failed
$anvil->Job->update_progress({
progress => $anvil->data->{job}{progress} < 99 ? ++$anvil->data->{job}{progress} : $anvil->data->{job}{progress},
message => "warning_0173",
log_level => 1,
variables => {
source_file => $ppm_file,
new_file => $png_file,
'format' => "png",
return_code => $return_code,
},
});
unlink $png_file;
}
else
{
$anvil->Job->update_progress({
progress => $anvil->data->{job}{progress} < 99 ? ++$anvil->data->{job}{progress} : $anvil->data->{job}{progress},
message => "log_0807",
log_level => 2,
variables => {
ppm_file => $ppm_file,
source_file => $ppm_file,
new_file => $png_file,
'format' => "png",
},
@ -493,6 +612,12 @@ sub get_screenshots
group => "striker-ui-api",
});
}
}
elsif ((not $make_png) && (-e $png_file))
{
# Remove the source png file
unlink $png_file;
}
# Delete the original PPM file?
if ($delete_ppm)

Loading…
Cancel
Save