Skip to content

Commit fc6835a

Browse files
committed
feat(convert): add check for legacy compilers (#483)
- Introduced a new task `check_legacy_compilers.rb` to verify legacy compilers. - Updated `convert.pp` to run the new task and display warnings if legacy compilers are detected.
1 parent 671839c commit fc6835a

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

plans/convert.pp

+11
Original file line numberDiff line numberDiff line change
@@ -309,5 +309,16 @@
309309
run_task('peadm::puppet_runonce', $all_targets)
310310
}
311311

312+
if $legacy_compilers {
313+
# lint:ignore:strict_indent
314+
$warning_msg = run_task('peadm::check_legacy_compilers', $primary_host, legacy_compilers => $legacy_compilers.join(',') ).first.message
315+
if $warning_msg.length > 0 {
316+
out::message(@("WARN"/L))
317+
WARNING: ${warning_msg}
318+
| WARN
319+
}
320+
# lint:endignore
321+
}
322+
312323
return("Conversion to peadm Puppet Enterprise ${arch['architecture']} completed.")
313324
}

tasks/check_legacy_compilers.rb

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/opt/puppetlabs/puppet/bin/ruby
2+
# frozen_string_literal: true
3+
4+
require 'json'
5+
require 'uri'
6+
require 'net/http'
7+
require 'puppet'
8+
9+
# CheckLegacyCompilers task class
10+
class CheckLegacyCompilers
11+
def initialize(params)
12+
@nodes = params['legacy_compilers'].split(',') if params['legacy_compilers'].is_a?(String)
13+
end
14+
15+
def execute!
16+
pinned_nodes = []
17+
@nodes.each do |node|
18+
node_classification = get_node_classification(node)
19+
pinned = false
20+
node_classification['groups'].each do |group|
21+
if group['name'] == 'PE Master'
22+
pinned_nodes << node
23+
pinned = true
24+
end
25+
end
26+
next if pinned
27+
next unless node_classification.key?('parameters')
28+
next unless node_classification['parameters'].key?('pe_master')
29+
if node_classification['parameters']['pe_master']
30+
pinned_nodes << node
31+
end
32+
end
33+
34+
return unless !pinned_nodes.empty?
35+
puts 'The following legacy compilers are classified as Puppet primary:'
36+
puts pinned_nodes.join(', ')
37+
puts 'You will not be able to upgrade if you dont remediate this.'
38+
end
39+
40+
def https(port)
41+
https = Net::HTTP.new('localhost', port)
42+
https.use_ssl = true
43+
https.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
44+
https.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
45+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
46+
https
47+
end
48+
49+
def get_node_classification(certname)
50+
pdb = https(4433)
51+
pdb_request = Net::HTTP::Post.new('/classifier-api/v2/classified/nodes/' + certname)
52+
pdb_request['Content-Type'] = 'application/json'
53+
54+
response = JSON.parse(pdb.request(pdb_request).body)
55+
56+
response
57+
end
58+
end
59+
60+
# Run the task unless an environment flag has been set, signaling not to. The
61+
# environment flag is used to disable auto-execution and enable Ruby unit
62+
# testing of this task.
63+
unless ENV['RSPEC_UNIT_TEST_MODE']
64+
Puppet.initialize_settings
65+
task = CheckLegacyCompilers.new(JSON.parse(STDIN.read))
66+
task.execute!
67+
end

0 commit comments

Comments
 (0)