Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Fixes #18301 - Reset values don't persist in answers
Browse files Browse the repository at this point in the history
This required resetting parameters separately from the tasks that
install the new puppet bits. The puppet packages need to be performed
during the init phase, before Kafo reads in the default values
coming from the puppet modules. By installing Puppet 4 prior to
getting the default values, the puppet puppet module will see the
puppetversion fact as greater than version 4 and set the defaults
based upon that. During pre_validation, is when the params need to
use unset_value to force Kafo to use the new Puppet 4 defaults.
  • Loading branch information
ehelms authored and chris1984 committed Aug 24, 2017
1 parent 498d834 commit 9350459
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 53 deletions.
2 changes: 1 addition & 1 deletion hooks/boot/01-helpers.rb
Expand Up @@ -56,7 +56,7 @@ def execute_command(command, do_say)
end

def reset_value(param)
param.value = nil unless param.nil?
param.unset_value
end
end
end
69 changes: 69 additions & 0 deletions hooks/init/31-upgrade-puppet.rb
@@ -0,0 +1,69 @@
def puppet4_available?
success = []
success << Kafo::Helpers.execute('yum info puppet-agent')
success << Kafo::Helpers.execute('yum info puppetserver')
!success.include?(false)
end

def stop_services
Kafo::Helpers.execute('katello-service stop')
end

def upgrade_puppet_package
Kafo::Helpers.execute('yum remove -y puppet-server')
Kafo::Helpers.execute('yum install -y puppetserver')
Kafo::Helpers.execute('yum install -y puppet-agent')
end

def start_httpd
Kafo::Helpers.execute('katello-service start --only httpd')
end

def remove_puppet_port_httpd
Kafo::Helpers.execute('sed -i "/^Listen 8140$/d" /etc/httpd/conf/ports.conf')
end

def copy_data
success = []
success << Kafo::Helpers.execute('cp -rfp /etc/puppet/environments /etc/puppetlabs/code/environments') if File.directory?('/etc/puppet/environments')
success << Kafo::Helpers.execute('cp -rfp /var/lib/puppet/ssl /etc/puppetlabs/puppet') if File.directory?('/var/lib/puppet/ssl')
success << Kafo::Helpers.execute('cp -rfp /var/lib/puppet/foreman_cache_data /opt/puppetlabs/puppet/cache/') if File.directory?('/var/lib/puppet/foreman_cache_data')
!success.include?(false)
end

def upgrade_step(step)
noop = app_value(:noop) ? ' (noop)' : ''

Kafo::Helpers.log_and_say :info, "Upgrade Step: #{step}#{noop}..."
unless app_value(:noop)
status = send(step)
fail_and_exit "Upgrade step #{step} failed. Check logs for more information." unless status
end
end

def fail_and_exit(message)
Kafo::Helpers.log_and_say :error, message
kafo.class.exit 1
end

if app_value(:upgrade_puppet)
PUPPET_UPGRADE_COMPLETE = '/etc/foreman-installer/.puppet_4_upgrade'.freeze

fail_and_exit 'Puppet already installed and upgraded. Skipping.' if File.exist?(PUPPET_UPGRADE_COMPLETE)

katello = Kafo::Helpers.module_enabled?(@kafo, 'katello')
foreman_proxy_content = @kafo.param('foreman_proxy_plugin_pulp', 'pulpnode_enabled').value

fail_and_exit 'Puppet 3 to 4 upgrade is not currently supported for the chosen scenario.' unless katello || foreman_proxy_content

Kafo::Helpers.log_and_say :info, 'Upgrading puppet...'
fail_and_exit 'Unable to find Puppet 4 packages, is the repository enabled?' unless puppet4_available?

upgrade_step :upgrade_puppet_package
upgrade_step :stop_services
upgrade_step :copy_data
upgrade_step :remove_puppet_port_httpd
upgrade_step :start_httpd

Kafo::Helpers.log_and_say :info, "Puppet 3 to 4 upgrade initialization complete, continuing with installation"
end
@@ -1,46 +1,3 @@
def puppet4_available?
success = []
success << Kafo::Helpers.execute('yum info puppet-agent')
success << Kafo::Helpers.execute('yum info puppetserver')
!success.include?(false)
end

def stop_services
Kafo::Helpers.execute('katello-service stop')
end

def upgrade_puppet_package
Kafo::Helpers.execute('yum remove -y puppet-server')
Kafo::Helpers.execute('yum install -y puppetserver')
Kafo::Helpers.execute('yum install -y puppet-agent')
end

def start_httpd
Kafo::Helpers.execute('katello-service start --only httpd')
end

def remove_puppet_port_httpd
Kafo::Helpers.execute('sed -i "/^Listen 8140$/d" /etc/httpd/conf/ports.conf')
end

def copy_data
success = []
success << Kafo::Helpers.execute('cp -rfp /etc/puppet/environments /etc/puppetlabs/code/environments') if File.directory?('/etc/puppet/environments')
success << Kafo::Helpers.execute('cp -rfp /var/lib/puppet/ssl /etc/puppetlabs/puppet') if File.directory?('/var/lib/puppet/ssl')
success << Kafo::Helpers.execute('cp -rfp /var/lib/puppet/foreman_cache_data /opt/puppetlabs/puppet/cache/') if File.directory?('/var/lib/puppet/foreman_cache_data')
!success.include?(false)
end

def upgrade_step(step)
noop = app_value(:noop) ? ' (noop)' : ''

Kafo::Helpers.log_and_say :info, "Upgrade Step: #{step}#{noop}..."
unless app_value(:noop)
status = send(step)
fail_and_exit "Upgrade step #{step} failed. Check logs for more information." unless status
end
end

def fail_and_exit(message)
Kafo::Helpers.log_and_say :error, message
kafo.class.exit 1
Expand All @@ -56,8 +13,7 @@ def fail_and_exit(message)

fail_and_exit 'Puppet 3 to 4 upgrade is not currently supported for the chosen scenario.' unless katello || foreman_proxy_content

Kafo::Helpers.log_and_say :info, 'Upgrading puppet...'
fail_and_exit 'Unable to find Puppet 4 packages, is the repository enabled?' unless puppet4_available?
Kafo::Helpers.log_and_say :info, 'Resetting puppet params...'

if !app_value(:noop)
Kafo::Helpers.reset_value(param('foreman', 'puppet_home'))
Expand Down Expand Up @@ -95,11 +51,5 @@ def fail_and_exit(message)
Kafo::Helpers.reset_value(param('puppet', 'server_ssl_dir'))
end

upgrade_step :upgrade_puppet_package
upgrade_step :stop_services
upgrade_step :copy_data
upgrade_step :remove_puppet_port_httpd
upgrade_step :start_httpd

Kafo::Helpers.log_and_say :info, "Puppet 3 to 4 upgrade initialization complete, continuing with installation"
Kafo::Helpers.log_and_say :info, "Puppet 3 to 4 upgrade param reset, continuing with installation"
end

0 comments on commit 9350459

Please sign in to comment.