From dcfe13a1532f57e333ab00475d0325f104624476 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 4 Jun 2024 08:54:23 +0200 Subject: [PATCH] always validate hostname from metadata We introduced this metadata field in https://github.com/theforeman/foreman_maintain/pull/536 which landed in 0.9.1, which is old enough to rely on and not care for backups that don't have this metadata field --- lib/foreman_maintain/utils/backup.rb | 19 +--------------- .../metadata.yml | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 test/files/backups/katello_standard_pulpcore_database/metadata.yml diff --git a/lib/foreman_maintain/utils/backup.rb b/lib/foreman_maintain/utils/backup.rb index aa2d9ade5..a6351c43a 100644 --- a/lib/foreman_maintain/utils/backup.rb +++ b/lib/foreman_maintain/utils/backup.rb @@ -183,24 +183,7 @@ def dumps_for_hybrid_db_setup(dbs_hash) def validate_hostname? # make sure that the system hostname is the same as the backup - hostname_from_metadata = metadata.fetch('hostname', nil) - if hostname_from_metadata - hostname_from_metadata == hostname - else - config_tarball = file_map[:config_files][:path] - tar_cmd = "tar zxf #{config_tarball} etc/httpd/conf/httpd.conf --to-stdout --occurrence=1" - status, httpd_config = execute_with_status(tar_cmd) - - # Incremental backups sometimes don't include httpd.conf. Since a "base" backup - # is restored before an incremental, we can assume that the hostname is checked - # during the base backup restore - if status == 0 - match = httpd_config.match(/\s*ServerName\s+"*([^ "]+)"*\s*$/) - match ? match[1] == hostname : false - else - true - end - end + metadata.fetch('hostname', nil) == hostname end def validate_interfaces diff --git a/test/files/backups/katello_standard_pulpcore_database/metadata.yml b/test/files/backups/katello_standard_pulpcore_database/metadata.yml new file mode 100644 index 000000000..8b6b86367 --- /dev/null +++ b/test/files/backups/katello_standard_pulpcore_database/metadata.yml @@ -0,0 +1,22 @@ +--- +os_version: CentOS Stream 8 +plugin_list: +- foreman-tasks-9.1.1 +- foreman_puppet-6.3.0 +- foreman_remote_execution-13.1.0 +- katello-4.13.0.pre.master +proxy_features: +- dynflow +- logs +- pulpcore +- puppet +- puppetca +- script +incremental: false +online: false +hostname: sat-6.example.com +proxy_config: + dhcp: false + dhcp_interface: eth0 + dns: false + dns_interface: eth0