From 9350459f29bfa6ec89cdec30fc5378a84d4a5297 Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Fri, 11 Aug 2017 13:42:31 -0400 Subject: [PATCH] Fixes #18301 - Reset values don't persist in answers 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. --- hooks/boot/01-helpers.rb | 2 +- hooks/init/31-upgrade-puppet.rb | 69 +++++++++++++++++++ .../31-upgrade-puppet.rb | 54 +-------------- 3 files changed, 72 insertions(+), 53 deletions(-) create mode 100644 hooks/init/31-upgrade-puppet.rb rename hooks/{pre => pre_validations}/31-upgrade-puppet.rb (59%) diff --git a/hooks/boot/01-helpers.rb b/hooks/boot/01-helpers.rb index b551f96b..ddbe6f63 100644 --- a/hooks/boot/01-helpers.rb +++ b/hooks/boot/01-helpers.rb @@ -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 diff --git a/hooks/init/31-upgrade-puppet.rb b/hooks/init/31-upgrade-puppet.rb new file mode 100644 index 00000000..3ec2c944 --- /dev/null +++ b/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 diff --git a/hooks/pre/31-upgrade-puppet.rb b/hooks/pre_validations/31-upgrade-puppet.rb similarity index 59% rename from hooks/pre/31-upgrade-puppet.rb rename to hooks/pre_validations/31-upgrade-puppet.rb index deca3454..acc483f0 100644 --- a/hooks/pre/31-upgrade-puppet.rb +++ b/hooks/pre_validations/31-upgrade-puppet.rb @@ -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 @@ -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')) @@ -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