From e0d91c23b37cf0dd55bda379b774a5a9d3f3ab2b Mon Sep 17 00:00:00 2001 From: Bernhard Suttner Date: Fri, 31 May 2024 12:24:57 +0200 Subject: [PATCH] Fixes #36940 - Add necessary migration for host_config tftp directory --- ...31091300_foreman_proxy_tftp_host_config.rb | 8 ++++ ..._foreman_proxy_tftp_bootloader_universe.rb | 9 ++++ ...31091300_foreman_proxy_tftp_host_config.rb | 8 ++++ ..._foreman_proxy_tftp_bootloader_universe.rb | 9 ++++ ...31091300_foreman_proxy_tftp_host_config.rb | 8 ++++ ..._foreman_proxy_tftp_bootloader_universe.rb | 9 ++++ ...300_foreman_proxy_tftp_host_config_spec.rb | 42 +++++++++++++++++ ..._foreman_proxy_tftp_bootloader_universe.rb | 46 +++++++++++++++++++ 8 files changed, 139 insertions(+) create mode 100644 config/foreman-proxy-content.migrations/240531091300_foreman_proxy_tftp_host_config.rb create mode 100644 config/foreman-proxy-content.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb create mode 100644 config/foreman.migrations/20240531091300_foreman_proxy_tftp_host_config.rb create mode 100644 config/foreman.migrations/20240805150555_foreman_proxy_tftp_bootloader_universe.rb create mode 100644 config/katello.migrations/240531091300_foreman_proxy_tftp_host_config.rb create mode 100644 config/katello.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb create mode 100644 spec/migrations/20240531091300_foreman_proxy_tftp_host_config_spec.rb create mode 100644 spec/migrations/20240805150500_foreman_proxy_tftp_bootloader_universe.rb diff --git a/config/foreman-proxy-content.migrations/240531091300_foreman_proxy_tftp_host_config.rb b/config/foreman-proxy-content.migrations/240531091300_foreman_proxy_tftp_host_config.rb new file mode 100644 index 00000000..8b3c9b46 --- /dev/null +++ b/config/foreman-proxy-content.migrations/240531091300_foreman_proxy_tftp_host_config.rb @@ -0,0 +1,8 @@ +if answers['foreman_proxy'] + root = answers['foreman_proxy']['tftp_root'] + if answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/host-config" + dirs.uniq! + end +end diff --git a/config/foreman-proxy-content.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb b/config/foreman-proxy-content.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb new file mode 100644 index 00000000..5f219f87 --- /dev/null +++ b/config/foreman-proxy-content.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb @@ -0,0 +1,9 @@ +if answers['foreman_proxy'] + root = answers['foreman_proxy']['tftp_root'] + if answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/bootloader-universe" + dirs << "#{root}/bootloader-universe/pxegrub2" + dirs.uniq! + end +end diff --git a/config/foreman.migrations/20240531091300_foreman_proxy_tftp_host_config.rb b/config/foreman.migrations/20240531091300_foreman_proxy_tftp_host_config.rb new file mode 100644 index 00000000..8b3c9b46 --- /dev/null +++ b/config/foreman.migrations/20240531091300_foreman_proxy_tftp_host_config.rb @@ -0,0 +1,8 @@ +if answers['foreman_proxy'] + root = answers['foreman_proxy']['tftp_root'] + if answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/host-config" + dirs.uniq! + end +end diff --git a/config/foreman.migrations/20240805150555_foreman_proxy_tftp_bootloader_universe.rb b/config/foreman.migrations/20240805150555_foreman_proxy_tftp_bootloader_universe.rb new file mode 100644 index 00000000..5f219f87 --- /dev/null +++ b/config/foreman.migrations/20240805150555_foreman_proxy_tftp_bootloader_universe.rb @@ -0,0 +1,9 @@ +if answers['foreman_proxy'] + root = answers['foreman_proxy']['tftp_root'] + if answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/bootloader-universe" + dirs << "#{root}/bootloader-universe/pxegrub2" + dirs.uniq! + end +end diff --git a/config/katello.migrations/240531091300_foreman_proxy_tftp_host_config.rb b/config/katello.migrations/240531091300_foreman_proxy_tftp_host_config.rb new file mode 100644 index 00000000..8b3c9b46 --- /dev/null +++ b/config/katello.migrations/240531091300_foreman_proxy_tftp_host_config.rb @@ -0,0 +1,8 @@ +if answers['foreman_proxy'] + root = answers['foreman_proxy']['tftp_root'] + if answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/host-config" + dirs.uniq! + end +end diff --git a/config/katello.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb b/config/katello.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb new file mode 100644 index 00000000..5f219f87 --- /dev/null +++ b/config/katello.migrations/240805150500_foreman_proxy_tftp_bootloader_universe.rb @@ -0,0 +1,9 @@ +if answers['foreman_proxy'] + root = answers['foreman_proxy']['tftp_root'] + if answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/bootloader-universe" + dirs << "#{root}/bootloader-universe/pxegrub2" + dirs.uniq! + end +end diff --git a/spec/migrations/20240531091300_foreman_proxy_tftp_host_config_spec.rb b/spec/migrations/20240531091300_foreman_proxy_tftp_host_config_spec.rb new file mode 100644 index 00000000..85dc5d86 --- /dev/null +++ b/spec/migrations/20240531091300_foreman_proxy_tftp_host_config_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +migration '20240531091300_foreman_proxy_tftp_host_config' do + scenarios %w[foreman katello foreman-proxy-content] do + context 'host-config in tftp_dirs missing' do + let(:answers) do + { + 'foreman_proxy' => { + 'tftp_root' => '/var/lib/tftpboot', + 'tftp_dirs' => [ + '/var/lib/tftpboot/pxelinux.cfg', + '/var/lib/tftpboot/grub', + '/var/lib/tftpboot/grub2', + '/var/lib/tftpboot/boot', + '/var/lib/tftpboot/ztp.cfg', + '/var/lib/tftpboot/poap.cfg', + ], + }, + } + end + + it 'adds host-config to tftp_dirs' do + expect(migrated_answers['foreman_proxy']['tftp_dirs']).to include '/var/lib/tftpboot/host-config' + end + end + + context 'tftp_dirs empty' do + let(:answers) do + { + 'foreman_proxy' => { + 'tftp_root' => '/var/lib/tftpboot', + 'tftp_dirs' => nil, + }, + } + end + + it 'keeps tftp_dirs unchanged' do + expect(migrated_answers['foreman_proxy']['tftp_dirs']).to eq answers['foreman_proxy']['tftp_dirs'] + end + end + end +end diff --git a/spec/migrations/20240805150500_foreman_proxy_tftp_bootloader_universe.rb b/spec/migrations/20240805150500_foreman_proxy_tftp_bootloader_universe.rb new file mode 100644 index 00000000..93e76868 --- /dev/null +++ b/spec/migrations/20240805150500_foreman_proxy_tftp_bootloader_universe.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +migration '20240531091300_foreman_proxy_tftp_bootloader_universe' do + scenarios %w[foreman katello foreman-proxy-content] do + context 'bootloader-universe in tftp_dirs missing' do + let(:answers) do + { + 'foreman_proxy' => { + 'tftp_root' => '/var/lib/tftpboot', + 'tftp_dirs' => [ + '/var/lib/tftpboot/pxelinux.cfg', + '/var/lib/tftpboot/grub', + '/var/lib/tftpboot/grub2', + '/var/lib/tftpboot/boot', + '/var/lib/tftpboot/ztp.cfg', + '/var/lib/tftpboot/poap.cfg', + ], + }, + } + end + + it 'adds bootloader-universe to tftp_dirs' do + expect(migrated_answers['foreman_proxy']['tftp_dirs']).to include '/var/lib/tftpboot/bootloader-universe' + end + + it 'adds bootloader-universe/pxegrub2 to tftp_dirs' do + expect(migrated_answers['foreman_proxy']['tftp_dirs']).to include '/var/lib/tftpboot/bootloader-universe/pxegrub2' + end + end + + context 'tftp_dirs empty' do + let(:answers) do + { + 'foreman_proxy' => { + 'tftp_root' => '/var/lib/tftpboot', + 'tftp_dirs' => nil, + }, + } + end + + it 'keeps tftp_dirs unchanged' do + expect(migrated_answers['foreman_proxy']['tftp_dirs']).to eq answers['foreman_proxy']['tftp_dirs'] + end + end + end +end