-
Notifications
You must be signed in to change notification settings - Fork 54
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
(PE-38769) Task/Plan to identify conflicting classifications on legacy compilers and warn the user #483
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' | ||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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."