diff --git a/hooks/boot/01-kafo-hook-extensions.rb b/hooks/boot/01-kafo-hook-extensions.rb index 32826ff4..25b13e2b 100644 --- a/hooks/boot/01-kafo-hook-extensions.rb +++ b/hooks/boot/01-kafo-hook-extensions.rb @@ -113,6 +113,7 @@ def execute!(command, do_say = true, do_log = true) log_and_say(:error, "#{command} failed! Check the output for error!", do_say, do_log) exit 1 end + stdout_stderr end def execute_as!(user, command, do_say = true, do_log = true) diff --git a/hooks/pre/35-change-evr-extension-ownership.rb b/hooks/pre/35-change-evr-extension-ownership.rb new file mode 100644 index 00000000..5c0db969 --- /dev/null +++ b/hooks/pre/35-change-evr-extension-ownership.rb @@ -0,0 +1,24 @@ +# In Katello 4.14, the 'evr' extension is removed from PostgreSQL and integrated into the Katello database via a migration. +# This hook ensures the 'evr' extension's ownership is transferred to the 'foreman' user so migrations can act on it. + +if local_postgresql? && execute("rpm -q postgresql-evr", false, false) + is_postgresql_active = execute_command("systemctl is-active postgresql", false, true)&.first&.strip == "active" + + # Ensure the PostgreSQL service is running + unless is_postgresql_active || app_value(:noop) + logger.debug("Starting postgresql service") + start_services(['postgresql']) + end + + # Update the ownership of the evr extension + unless app_value(:noop) + logger.debug("Updating ownership of the evr extension if it is enabled") + execute!("runuser -l postgres -c \"psql -d foreman -c \\\"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman') WHERE extname='evr';\\\"\"", false, true) + end + + # Stop the PostgreSQL service if it was not running + unless is_postgresql_active || app_value(:noop) + logger.debug("Stopping postgresql service") + stop_services(['postgresql']) + end +end diff --git a/spec/hook_context_extension_spec.rb b/spec/hook_context_extension_spec.rb index 9116430d..603b4956 100644 --- a/spec/hook_context_extension_spec.rb +++ b/spec/hook_context_extension_spec.rb @@ -152,7 +152,7 @@ end it 'executes a command' do - expect(subject).to be_nil + expect(subject).to eq(command) expect(context).to have_received(:execute_command).with(command, true, true) end end