Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37717 - Update evr extension ownership to foreman #955

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

sjha4
Copy link
Contributor

@sjha4 sjha4 commented Aug 6, 2024

Update ownership of evr extension to owner foreman to allow migrations to operate on it, specifically disable it.

@sjha4 sjha4 force-pushed the change_evr_owner branch 3 times, most recently from 13d9cc2 to 19812e3 Compare August 6, 2024 17:22
@sjha4 sjha4 marked this pull request as ready for review August 6, 2024 17:22
@sjha4 sjha4 changed the title Refs #11098 - Update evr extension ownership after postgresql upgrade Refs #37678 - Update evr extension ownership after postgresql upgrade Aug 6, 2024
@ianballou
Copy link
Contributor

@ekohl mentioned before that the pg_shdepend table might also need updating, but at least functionally it doesn't seem necessary since the migration passes with @sjha4 's changes alone. The bits that would get updated in pg_shdepend may get dropped with the evr extension.

@ianballou
Copy link
Contributor

I confirmed that dropping the extension also drops the related entry from pg_shdepend.

@sjha4 sjha4 force-pushed the change_evr_owner branch from 19812e3 to 89a7fd2 Compare August 6, 2024 19:50
@sjha4
Copy link
Contributor Author

sjha4 commented Aug 6, 2024

I tested the installer with the chages here although I had to put the new code in a separate pre-hook file to be run..Suggestions on where to put this code if not this file?

@evgeni
Copy link
Member

evgeni commented Aug 7, 2024

What about remote db users? Will those need to perform manual steps (we usually don't have enough permissions to change ownership of objects there) before the upgrade?

@sjha4
Copy link
Contributor Author

sjha4 commented Aug 7, 2024

What about remote db users? Will those need to perform manual steps (we usually don't have enough permissions to change ownership of objects there) before the upgrade?

Ya..They'll need to run the update ownership query manually as part of their upgrades. Will need to be documented.

@ianballou
Copy link
Contributor

ianballou commented Aug 7, 2024

@evgeni docs update will go in theforeman/foreman-documentation#3167 unless someone gets to it first.

@ianballou
Copy link
Contributor

Prepping a system for a test.

@ianballou
Copy link
Contributor

Found an issue -- the postgres command cannot run because the postgres service is down during the installer run. We'll need to turn postgres on first.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the noop mode implementation here. I'd be tempted to change the log messages to Would do X instead of Doing x`.

hooks/pre/35-change-evr-extension-ownership.rb Outdated Show resolved Hide resolved
@sjha4 sjha4 force-pushed the change_evr_owner branch 2 times, most recently from 5f2813a to 83e3115 Compare November 25, 2024 20:46
Copy link
Member

@ehelms ehelms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- I'll let @ekohl have the final say.

@sjha4 sjha4 requested a review from ekohl December 2, 2024 14:46
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style wise I'm not that happy with the many conditionals and prefer the more verbose:

if app_value(:noop)
  logger.debug('Would do X')
else
  logger.debug('Doing X')
  x()
end

My reasoning is that it's very easy to visually see the control flow.

Additionally, we already have debug statements in various methods, like start_services and stop_services. So you can simplify it to:

if app_value(:noop)
  logger.debug('Would stop service postgresql')
else
  stop_services(['postgresql'])
end

I'm wondering what you think about this.

hooks/pre/35-change-evr-extension-ownership.rb Outdated Show resolved Hide resolved
hooks/pre/35-change-evr-extension-ownership.rb Outdated Show resolved Hide resolved
@sjha4 sjha4 requested a review from ekohl December 2, 2024 17:02
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating. I think this is much easier to reason about and see where it could fail.

hooks/pre/35-change-evr-extension-ownership.rb Outdated Show resolved Hide resolved
hooks/pre/35-change-evr-extension-ownership.rb Outdated Show resolved Hide resolved
@sjha4 sjha4 force-pushed the change_evr_owner branch 3 times, most recently from 8837316 to 14eb259 Compare December 3, 2024 17:56
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how this is shaping up now. Some minor style comments.

hooks/boot/01-kafo-hook-extensions.rb Outdated Show resolved Hide resolved
hooks/boot/01-kafo-hook-extensions.rb Outdated Show resolved Hide resolved
hooks/pre/35-change-evr-extension-ownership.rb Outdated Show resolved Hide resolved
hooks/pre/35-change-evr-extension-ownership.rb Outdated Show resolved Hide resolved
@sjha4 sjha4 requested a review from ekohl December 3, 2024 20:01
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evgeni I made may suggestions so I'd appreciate if you gave it a final ACK.

logger.debug("Updating ownership of the evr extension")
_, success = execute_preformatted_as('postgres', "psql -d #{database} -c \"#{sql}\"", false, true)
unless success
logger.notice("Failed to update ownership of the evr extension.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think failing to update should be a warning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning or even error that halts execution?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. It was a warning before, so that's what caught my eye.

What happens if it is not updated? Later the removal of the extension fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya..The evr extension is dropped in katello migration here Katello/katello#11159 which assumes the foreman user is the owner of the extension. We could fail here instead of later on during db:migrate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to fail and exit:

fail_and_exit("Failed to update ownership of the evr extension. Please make sure the following sql succeeds before proceeding: #{sql}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evgeni @ekohl Is this what y'all had in mind?

@sjha4
Copy link
Contributor Author

sjha4 commented Dec 12, 2024

I will need someone with superpowers to merge this one if this is good to go..
Thanks @ekohl , @ehelms , @evgeni and @ianballou ❤️

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ekohl ekohl merged commit d4a78ff into theforeman:develop Dec 12, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants