From ddd43d640fc61f78650b3069e44899b2841d425e Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Tue, 6 Aug 2024 13:01:43 -0400 Subject: [PATCH] Refs #37678 - Update evr extension ownership after postgresql upgrade --- hooks/boot/01-kafo-hook-extensions.rb | 1 + hooks/pre/35-change-evr-extension-ownership.rb | 5 +++++ spec/hook_context_extension_spec.rb | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 hooks/pre/35-change-evr-extension-ownership.rb 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..ceb03e32 --- /dev/null +++ b/hooks/pre/35-change-evr-extension-ownership.rb @@ -0,0 +1,5 @@ +logger.notice("Updating ownership of the evr extension if it is enabled") +result = execute!("runuser -l postgres -c \"psql -d foreman -c \\\"SELECT 1 from pg_extension WHERE extname='evr';\\\"\"", false, true) +unless result.include? '(0 rows)' + 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 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