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

(PE-38769) Task/Plan to identify conflicting classifications on legacy compilers and warn the user #483

Merged
merged 1 commit into from
Sep 2, 2024
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
11 changes: 11 additions & 0 deletions plans/convert.pp
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,16 @@
run_task('peadm::puppet_runonce', $all_targets)
}

if $legacy_compilers {
# lint:ignore:strict_indent
$warning_msg = run_task('peadm::check_legacy_compilers', $primary_host, legacy_compilers => $legacy_compilers.join(',') ).first.message
if $warning_msg.length > 0 {
out::message(@("WARN"/L))
WARNING: ${warning_msg}
| WARN
}
# lint:endignore
}

return("Conversion to peadm Puppet Enterprise ${arch['architecture']} completed.")
}
67 changes: 67 additions & 0 deletions tasks/check_legacy_compilers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/opt/puppetlabs/puppet/bin/ruby
# frozen_string_literal: true

require 'json'
require 'uri'
require 'net/http'
require 'puppet'

# CheckLegacyCompilers task class
class CheckLegacyCompilers
def initialize(params)
@nodes = params['legacy_compilers'].split(',') if params['legacy_compilers'].is_a?(String)
end

def execute!
pinned_nodes = []
@nodes.each do |node|
node_classification = get_node_classification(node)
pinned = false
node_classification['groups'].each do |group|
if group['name'] == 'PE Master'
pinned_nodes << node
pinned = true
end
end
next if pinned
next unless node_classification.key?('parameters')
next unless node_classification['parameters'].key?('pe_master')
if node_classification['parameters']['pe_master']
pinned_nodes << node
end
end

return unless !pinned_nodes.empty?
puts 'The following legacy compilers are classified as Puppet primary:'
puts pinned_nodes.join(', ')
puts 'You will not be able to upgrade if you dont remediate this.'
Comment on lines +35 to +37
Copy link
Contributor

@mtaggart13 mtaggart13 Sep 2, 2024

Choose a reason for hiding this comment

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

The phrase "remediate this" is possibly too vague - however, we don't want to recommend a specific action as the required remedial action depends on customer workflow.
We could use something that is a little clearer but still high level. For example:
"To continue with the upgrade, ensure that these compilers are no longer classified as Puppet primary."

end

def https(port)
https = Net::HTTP.new('localhost', port)
https.use_ssl = true
https.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
https.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
https
end

def get_node_classification(certname)
pdb = https(4433)
pdb_request = Net::HTTP::Post.new('/classifier-api/v2/classified/nodes/' + certname)
pdb_request['Content-Type'] = 'application/json'

response = JSON.parse(pdb.request(pdb_request).body)

response
end
end

# Run the task unless an environment flag has been set, signaling not to. The
# environment flag is used to disable auto-execution and enable Ruby unit
# testing of this task.
unless ENV['RSPEC_UNIT_TEST_MODE']
Puppet.initialize_settings
task = CheckLegacyCompilers.new(JSON.parse(STDIN.read))
task.execute!
end
Loading