Updated Server->update_definition() to undefine a server when needed.

* Boosted logging to debug anvil-delete-server hang in jenkins.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 1 year ago
parent 9b55504872
commit 8c97f478a8
  1. 61
      Anvil/Tools/Server.pm
  2. 8
      share/words.xml
  3. 4
      tools/anvil-delete-server

@ -3089,6 +3089,7 @@ sub update_definition
}});
# Define the server
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0818", variables => { server_name => $server_name }});
eval { $anvil->data->{libvirtd}{$short_host_name}{connection}->define_domain($new_definition_xml); };
if ($@)
{
@ -3099,6 +3100,66 @@ sub update_definition
error => $@,
}});
}
else
{
if (not ref($anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection}) eq "Sys::Virt::Domain")
{
# Connect to the server.
my @domains = $anvil->data->{libvirtd}{$short_host_name}{connection}->list_all_domains();
foreach my $domain_handle (@domains)
{
my $this_server_name = $domain_handle->get_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
domain_handle => $domain_handle,
this_server_name => $this_server_name,
}});
if ($this_server_name eq $server_name)
{
$anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection} = $domain_handle;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"libvirtd::${short_host_name}::server::${server_name}::connection" => $anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection},
}});
last;
}
}
}
# If this connection still valid?
if (ref($anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection}) eq "Sys::Virt::Domain")
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0819", variables => { server_name => $server_name }});
my $uuid = "";
eval { $uuid = $anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection}->get_uuid_string(); };
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "uuid" => $uuid }});
if ((not $@) && ($uuid))
{
# Connection is good.
my $updated = $anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection}->is_updated();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "updated" => $updated }});
if ($updated)
{
eval { $anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection}->undefine; };
if ($@)
{
# Throw an error, then clear the URI so that we just update the DB/on-disk definitions.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0167", variables => {
host_name => $short_host_name,
server_name => $server_name,
error => $@,
}});
}
else
{
my $updated = $anvil->data->{libvirtd}{$short_host_name}{server}{$server_name}{connection}->is_updated();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "updated" => $updated }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0817", variables => { server_name => $server_name }});
}
}
}
}
}
}
}
}

@ -2629,6 +2629,9 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<key name="log_0814">There is an existing a functioning connection to: [#!variable!target!#], no need to reconnect.</key>
<key name="log_0815">There is an existing a functioning connection to the server: [#!variable!server_name!#], no need to reconnect.</key>
<key name="log_0816">Waiting for: [#!variable!delay!#] seconds.</key>
<key name="log_0817">The server: [#!variable!server_name!#] libvirt definition was updated, undefining static config.</key>
<key name="log_0818">The server: [#!variable!server_name!#] libvirt definition will now be updated.</key>
<key name="log_0819">Check to verify that the connection to the server: [#!variable!server_name!#] is valid.</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>
@ -3960,6 +3963,11 @@ We will try to proceed anyway.</key>
====
#!variable!error!#
====
</key>
<key name="warning_0167">Failed to undefine the running server: [#!variable!server_name!#] on the host: [#!variable!host_name!#]. The error, if any, was:
====
#!variable!error!#
====
</key>
</language>

@ -36,6 +36,10 @@ $anvil->Get->switches({list => [
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => $anvil->data->{switches}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
### TODO: Remove this post testing
$anvil->Log->level({set => 2});
$anvil->Log->secure({set => 1});
$anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})

Loading…
Cancel
Save