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 #28697: Add Postgres upgrade to Foreman scenario #444

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config/foreman.hiera/family/RedHat-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ mongodb::server::logpath: false
mongodb::server::config_template: 'mongodb/mongodb.conf.2.6.erb'
mongodb::server::manage_pidfile: false
mongodb::server::pidfilepath: '/var/opt/rh/rh-mongodb34/run/mongodb/mongod.pid'

redis::globals::scl: rh-redis5

postgresql::globals::version: '12'
postgresql::globals::client_package_name: rh-postgresql12-postgresql-syspaths
postgresql::globals::server_package_name: rh-postgresql12-postgresql-server-syspaths
postgresql::globals::contrib_package_name: rh-postgresql12-postgresql-contrib-syspaths
postgresql::globals::service_name: postgresql
postgresql::globals::datadir: /var/opt/rh/rh-postgresql12/lib/pgsql/data
postgresql::globals::confdir: /var/opt/rh/rh-postgresql12/lib/pgsql/data
postgresql::globals::bindir: /usr/bin

This file was deleted.

9 changes: 0 additions & 9 deletions config/foreman.hiera/scenario/katello/family/RedHat-7.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions hooks/boot/01-kafo-hook-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def local_redis?
(foreman_server? && !param_value('foreman', 'jobs_sidekiq_redis_url')) || param_value('foreman_proxy::plugin::pulp', 'pulpcore_enabled')
end

def needs_postgresql_scl_upgrade?
!File.exist?('/var/opt/rh/rh-postgresql12/lib/pgsql/data') && File.exist?('/var/lib/pgsql/data')
Copy link
Member Author

Choose a reason for hiding this comment

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

@evgeni I had to add a condition here for this to work on fresh installations. Before adding the && part, it attempted an upgrade on a fresh install.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

This will still try to upgrade if the user installed postgres before running the installer, but I think that's fine as being labeled "unsupported"?

end

def el7?
facts[:os][:release][:major] == '7' && facts[:os][:family] == 'RedHat'
end
Expand Down
15 changes: 15 additions & 0 deletions hooks/pre/30-el7_upgrade_postgresql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def postgresql_12_upgrade
execute('foreman-maintain service start --only=postgresql')
(_name, _owner, _enconding, collate, ctype, _privileges) = `runuser postgres -c 'psql -lt | grep -E "^\s+postgres"'`.chomp.split('|').map(&:strip)
execute('foreman-maintain service stop')
ensure_package('rh-postgresql12-postgresql-server', 'installed')
execute(%(scl enable rh-postgresql12 "PGSETUP_INITDB_OPTIONS='--lc-collate=#{collate} --lc-ctype=#{ctype} --locale=#{collate}' postgresql-setup --upgrade"))
ensure_package('postgresql-server', 'absent')
ensure_package('postgresql', 'absent')
execute('rm -f /etc/systemd/system/postgresql.service')
ensure_package('rh-postgresql12-syspaths', 'installed')
end

if local_postgresql? && el7? && foreman_server? && needs_postgresql_scl_upgrade?
postgresql_12_upgrade
end
4 changes: 4 additions & 0 deletions hooks/pre/31-el7_install_postgresql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Working around https://tickets.puppetlabs.com/browse/PUP-2169
if local_postgresql? && el7?
ensure_package('rh-postgresql12-postgresql-server', 'installed')
end
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def check_postgresql_storage
# Ensure there is at least 1x /var/lib/pgsql free disk space available on the main filesystem
current_postgres_dir = '/var/lib/pgsql'
new_postgres_dir = '/var/opt/rh/rh-postgresql10/lib/pgsql'
new_postgres_dir = '/var/opt/rh/rh-postgresql12/lib/pgsql'

begin
postgres_size = `du -b -s #{current_postgres_dir}`.split[0].to_i
postgres_size = `du --bytes --summarize #{current_postgres_dir}`.split[0].to_i

if available_space(new_postgres_dir) < postgres_size
fail_and_exit "The postgres upgrade requires at least #{(postgres_size / 1024) / 1024} MB of storage."
fail_and_exit "The PostgreSQL upgrade requires at least #{(postgres_size / 1024) / 1024} MB of storage to be available at #{new_postgres_dir}."
end
rescue StandardError
fail_and_exit 'Failed to verify available disk space'
Expand All @@ -23,6 +23,6 @@ def available_space(directory = nil)
mountpoint[:available_bytes]
end

if app_value(:upgrade)
check_postgresql_storage if local_postgresql?
if local_postgresql? && el7? && foreman_server? && needs_postgresql_scl_upgrade?
check_postgresql_storage
end
4 changes: 0 additions & 4 deletions katello/hooks/pre/29-install_postgresql.rb

This file was deleted.

20 changes: 0 additions & 20 deletions katello/hooks/pre/30-upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ def stop_services
execute('foreman-maintain service stop')
end

def start_postgresql
execute('systemctl start postgresql')
end

def postgresql_10_upgrade
start_postgresql
(_name, _owner, _enconding, collate, ctype, _privileges) = `runuser postgres -c 'psql -lt | grep -E "^\s+postgres"'`.chomp.split('|').map(&:strip)
stop_services
ensure_package('rh-postgresql10-postgresql-server', 'installed')
execute(%(scl enable rh-postgresql10 "PGSETUP_INITDB_OPTIONS='--lc-collate=#{collate} --lc-ctype=#{ctype} --locale=#{collate}' postgresql-setup --upgrade"))
ensure_package('postgresql-server', 'absent')
ensure_package('postgresql', 'absent')
execute('rm -f /etc/systemd/system/postgresql.service')
ensure_package('rh-postgresql10-syspaths', 'installed')
end

def upgrade_step(step, options = {})
noop = app_value(:noop) ? ' (noop)' : ''
long_running = options[:long_running] ? ' (this may take a while) ' : ''
Expand Down Expand Up @@ -69,9 +53,5 @@ def step_path(step)
File.unlink(CANDLEPIN_MIGRATION_MARKER_FILE)
end

if local_postgresql? && facts[:os][:release][:major] == '7'
upgrade_step :postgresql_10_upgrade
end

log_and_say :info, 'Upgrade Step: Running installer...'
end