From 9194eb3d0987c575dc661796bdb245e7b07ca5e2 Mon Sep 17 00:00:00 2001 From: Digimer Date: Thu, 15 Dec 2022 19:28:00 -0500 Subject: [PATCH] * Updated System->check_if_configured() to record that a host is configured in /etc/anvil to make the system auto-mark as configured if the host is removed from the DB (or, more specifically, variables -> system::configured is lost). * Updated Database->get_anvils() to record dr_links to reference DR hosts to Anvil! systems. Signed-off-by: Digimer --- Anvil/Tools.pm | 3 ++- Anvil/Tools/Database.pm | 30 ++++++++++++++++++++++++ Anvil/Tools/System.pm | 49 ++++++++++++++++++++++++++++++++++++++++ tools/anvil-daemon | 37 ++---------------------------- tools/anvil-manage-files | 2 ++ 5 files changed, 85 insertions(+), 36 deletions(-) diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index 8ecd3ea5..3193ad7d 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -1074,10 +1074,11 @@ sub _set_paths '.htpasswd' => "/etc/httpd/.htpasswd", 'chrony.conf' => "/etc/chrony.conf", group => "/etc/group", - issue => "/etc/issue", httpd_conf => "/etc/httpd/conf/httpd.conf", + host_configured => "/etc/anvil/host.configured", host_ssh_key => "/etc/ssh/ssh_host_ecdsa_key.pub", host_uuid => "/etc/anvil/host.uuid", + issue => "/etc/issue", network_cache => "/tmp/network_cache.anvil", passwd => "/etc/passwd", 'redhat-release' => "/etc/redhat-release", diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index eacccd7b..c8f563d5 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -2650,6 +2650,9 @@ sub get_anvils $anvil->Database->get_files({debug => $debug}); $anvil->Database->get_file_locations({debug => $debug}); + # Also pull in DRs so we can link them. + $anvil->Database->get_dr_links({debug => $debug}); + my $query = " SELECT anvil_uuid, @@ -2759,6 +2762,7 @@ WHERE "anvils::host_uuid::${anvil_node2_host_uuid}::role" => $anvil->data->{anvils}{host_uuid}{$anvil_node2_host_uuid}{role}, }}); } + ### TODO: Remove this once the switch over to 'dr_links' is done. if ($anvil_dr1_host_uuid) { $anvil->data->{anvils}{host_uuid}{$anvil_dr1_host_uuid}{anvil_name} = $anvil_name; @@ -2812,6 +2816,32 @@ WHERE "anvils::anvil_uuid::${anvil_uuid}::file_name::${file_name}::file_uuid" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_name}{$file_name}{file_uuid}, }}); } + + # Process DR hosts this Anvil! is allowed to use. + if (exists $anvil->data->{dr_links}{by_anvil_uuid}{$anvil_uuid}) + { + foreach my $dr_link_host_uuid (sort {$a cmp $b} keys %{$anvil->data->{dr_links}{by_anvil_uuid}{$anvil_uuid}{dr_link_host_uuid}}) + { + my $dr_link_uuid = $anvil->data->{dr_links}{by_anvil_uuid}{$anvil_uuid}{dr_link_host_uuid}{$dr_link_host_uuid}{dr_link_uuid}; + my $dr_link_note = $anvil->data->{dr_links}{dr_link_uuid}{$dr_link_uuid}{dr_link_note}; + my $dr_link_short_host_name = $anvil->data->{hosts}{host_uuid}{$dr_link_host_uuid}{short_host_name}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "s1:dr_link_host_uuid" => $dr_link_host_uuid, + "s2:dr_link_uuid" => $dr_link_uuid, + "s3:dr_link_note" => $dr_link_note, + "s4:dr_link_short_host_name" => $dr_link_short_host_name, + }}); + + next if $dr_link_note eq "DELETED"; + + $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{dr_host}{$dr_link_host_uuid}{dr_link_uuid} = $dr_link_uuid; + $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{dr_host}{$dr_link_host_uuid}{short_host_name} = $dr_link_short_host_name; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "s1:anvils::anvil_uuid::${anvil_uuid}::dr_host::${dr_link_host_uuid}::dr_link_uuid" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{dr_host}{$dr_link_host_uuid}{dr_link_uuid}, + "s2:anvils::anvil_uuid::${anvil_uuid}::dr_host::${dr_link_host_uuid}::short_host_name" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{dr_host}{$dr_link_host_uuid}{short_host_name}, + }}); + } + } } return(0); diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index e128f57e..17f70a8a 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -605,6 +605,55 @@ sub check_if_configured $configured = 0 if not defined $configured; $configured = 0 if $configured eq ""; + + if ((not $configured) && (-f $anvil->data->{path}{data}{host_configured})) + { + # See if there's a configured file. + my $body = $anvil->Storage->read_file({debug => $debug, file => $anvil->data->{path}{data}{host_configured}}); + foreach my $line (split/\n/, $body) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); + if ($line =~ /^(.*)=(.*)$/) + { + my $variable = $anvil->Words->clean_spaces({string => $1}); + my $value = $anvil->Words->clean_spaces({string => $2}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + variable => $variable, + value => $value, + }}); + + if (($variable eq "system::configured") && ($value eq "1")) + { + # Write the database entry. + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => "system::configured", + variable_value => 1, + variable_default => "", + variable_description => "striker_0048", + variable_section => "system", + variable_source_uuid => $anvil->data->{sys}{host_uuid}, + variable_source_table => "hosts", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_uuid => $variable_uuid }}); + + # mark it as configured. + $configured = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { configured => $configured }}); + } + } + } + } + + if (($configured) && (not -f $anvil->data->{path}{data}{host_configured})) + { + my $failed = $anvil->Storage->write_file({ + debug => $debug, + file => $anvil->data->{path}{data}{host_configured}, + body => "system::configured = 1\n", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }}); + } + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { configured => $configured }}); return($configured); } diff --git a/tools/anvil-daemon b/tools/anvil-daemon index c24a4410..b8afc1f3 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -20,6 +20,8 @@ # - # - Increase DRBD's default timeout # - Check for and enable persistent journald logging +# - +# - Record that a machine is configured /etc/anvil/host.is_configred # # NOTE: # - For later; 'reboot --force --force' immediately kills the OS, like disabling ACPI on EL6 and hitting the @@ -1305,41 +1307,6 @@ sub handle_special_cases }}); return(0); - - - my $host_type = $anvil->Get->host_type(); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_type => $host_type }}); - if ($host_type ne "striker") - { - ### TODO: Test that this is fixed. The bug is now ERRATA - # RHBZ #1961562 - https://bugzilla.redhat.com/show_bug.cgi?id=1961562#c16 - # We're a node or DR host. We need to touch this file. - my $work_around_file = "/etc/qemu/firmware/50-edk2-ovmf-cc.json"; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { work_around_file => $work_around_file }}); - if (not -e $work_around_file) - { - $anvil->Storage->write_file({ - debug => 2, - file => $work_around_file, - body => "", - overwrite => 0, - backup => 0, - mode => "0644", - user => "root", - group => "root", - }); - } - - # Make sure DRBD compiled after a kernel upgrade. - $anvil->DRBD->_initialize_kmod({debug => 2}); - } - - if ($host_type eq "striker") - { - - } - - return(0); } # Configure the local database, if needed. diff --git a/tools/anvil-manage-files b/tools/anvil-manage-files index 03ab133d..4a0257c1 100755 --- a/tools/anvil-manage-files +++ b/tools/anvil-manage-files @@ -30,6 +30,8 @@ # TODO: # - If two Strikers have the same file name, but different sizes, we get into a yo-yo of updating the two # sides. If this happens, we need to rsync the larger one over the smaller one. +# +# - Create a ".done." when the upload completes so that we know it's time to add it to the database. # # NOTE: # - remove unsyncs, add syncs.