Module: MasterManipulator::Service
- Included in:
- Beaker::TestCase
- Defined in:
- lib/master_manipulator/service.rb
Instance Method Summary collapse
-
#pe_version(master_host) ⇒ String
Return the version of PE installed on the specified Puppet master.
-
#reload_puppet_server(master_host, opts = {}) ⇒ Object
Reload puppetserver, causing it to reread its config without restarting the JVM.
-
#restart_puppet_server(master_host, opts = {}) ⇒ Object
Restart the puppet server and wait for it to come back up or raise an error if the wait times out.
Instance Method Details
#pe_version(master_host) ⇒ String
Return the version of PE installed on the specified Puppet master
96 97 98 99 100 101 102 103 104 |
# File 'lib/master_manipulator/service.rb', line 96 def pe_version(master_host) if on(master_host, 'test -f /opt/puppet/pe_version', :acceptable_exit_codes => [0,1]).exit_code == 0 return on(master_host, 'cat /opt/puppet/pe_version').stdout.chomp elsif on(master_host, 'test -f /opt/puppetlabs/server/pe_version', :acceptable_exit_codes => [0,1]).exit_code == 0 return on(master_host, 'cat /opt/puppetlabs/server/pe_version').stdout.chomp else return 'version unknown' end end |
#reload_puppet_server(master_host, opts = {}) ⇒ Object
Reload puppetserver, causing it to reread its config without restarting the JVM. use this instead of restart_puppet_server unless you absolutely have to stop and restart the server because JVM restarts are very expensive. This implementation relies on puppetserver’s “reload” subcommand, which handles all the waiting for services to refresh. Older code using a forced HUP on the server process should be replaced with this.
18 19 20 21 22 23 24 |
# File 'lib/master_manipulator/service.rb', line 18 def reload_puppet_server(master_host, opts = {}) # 2015.x (Everett) and newer rc = on(master_host, "puppetserver reload", :accept_all_exit_codes => true) if rc.exit_code != 0 raise "'puppetserver reload' failed, returned: #{rc.exit_code}" end end |
#restart_puppet_server(master_host, opts = {}) ⇒ Object
Restart the puppet server and wait for it to come back up or raise an error if the wait times out
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/master_manipulator/service.rb', line 41 def restart_puppet_server(master_host, opts = {}) start_time = Time.now opts[:is_pe?] ||= true opts[:is_pe?] ? service_name = 'pe-puppetserver' : service_name = 'puppetserver' on(master_host, puppet("resource service #{service_name} ensure=stopped")) on(master_host, puppet("resource service #{service_name} ensure=running")) hostname = on(master_host, 'hostname').stdout.chomp opts[:wait_cycles] ||= 10 pe_ver = pe_version(master_host) three_eight_regex = /^3\.8/ # This logic is not ideal refactor in the future # if its PE and not 3.8 use the status endpoint # it its not PE or it is 3.8 use the simple curl call if pe_ver && !pe_ver.match(three_eight_regex) curl_call = "-k -X GET -H 'Content-Type: application/json' https://#{hostname}:8140/status/v1/services?level=debug" else curl_call = "-I -k https://#{hostname}:8140" end (1..opts[:wait_cycles]).each do |i| @result = curl_on(master_host, curl_call, :acceptable_exit_codes => [0,1,7]) # parse body if we are using PE and we are not in PE 3.8 (pe_ver && !pe_ver.match(three_eight_regex)) ? @body = JSON.parse(@result.stdout) : @body = [] case @result.exit_code.to_s when '0' sleep 20 pe_ver.match(/three_eight_regex/) ? return : (return if @body.all? { |k, v| v['state'] == 'running' }) when '1', '7' # Exit code 7 is 'connection refused' sleep (i**(1.2)) end end total_time = Time.now - start_time = "Attempted to restart #{opts[:wait_cycles]} times, waited #{total_time} seconds total." << "\nHere is the status reported by the puppetserver" @body.each do |k,v| << "\n'#{k}' state: #{v['state']} " end raise end |