From 46d8d9030872f887c6727beb11ec50cec0639321 Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Tue, 12 Nov 2024 15:25:04 +0100 Subject: [PATCH] Fixes #36940 - Add necessary migration for host_config tftp directory --- ...31091300_foreman_proxy_tftp_host_config.rb | 10 ++++ ...31091300_foreman_proxy_tftp_host_config.rb | 10 ++++ ...31091300_foreman_proxy_tftp_host_config.rb | 10 ++++ ...300_foreman_proxy_tftp_host_config_spec.rb | 50 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 config/foreman-proxy-content.migrations/240531091300_foreman_proxy_tftp_host_config.rb create mode 100644 config/foreman.migrations/20240531091300_foreman_proxy_tftp_host_config.rb create mode 100644 config/katello.migrations/240531091300_foreman_proxy_tftp_host_config.rb create mode 100644 spec/migrations/20240531091300_foreman_proxy_tftp_host_config_spec.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..884f49b7 --- /dev/null +++ b/config/foreman-proxy-content.migrations/240531091300_foreman_proxy_tftp_host_config.rb @@ -0,0 +1,10 @@ +if answers['foreman_proxy'].is_a?(Hash) + root = answers['foreman_proxy']['tftp_root'] + if root && answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/bootloader-universe" + dirs << "#{root}/bootloader-universe/pxegrub2" + dirs << "#{root}/host-config" + 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..884f49b7 --- /dev/null +++ b/config/foreman.migrations/20240531091300_foreman_proxy_tftp_host_config.rb @@ -0,0 +1,10 @@ +if answers['foreman_proxy'].is_a?(Hash) + root = answers['foreman_proxy']['tftp_root'] + if root && answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/bootloader-universe" + dirs << "#{root}/bootloader-universe/pxegrub2" + dirs << "#{root}/host-config" + 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..884f49b7 --- /dev/null +++ b/config/katello.migrations/240531091300_foreman_proxy_tftp_host_config.rb @@ -0,0 +1,10 @@ +if answers['foreman_proxy'].is_a?(Hash) + root = answers['foreman_proxy']['tftp_root'] + if root && answers['foreman_proxy']['tftp_dirs'] + dirs = answers['foreman_proxy']['tftp_dirs'] + dirs << "#{root}/bootloader-universe" + dirs << "#{root}/bootloader-universe/pxegrub2" + dirs << "#{root}/host-config" + 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..1e19671d --- /dev/null +++ b/spec/migrations/20240531091300_foreman_proxy_tftp_host_config_spec.rb @@ -0,0 +1,50 @@ +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 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 + + 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