Module: MasterManipulator::Service
- Included in:
- Beaker::TestCase
- Defined in:
- lib/master_manipulator/service.rb
Instance Method Summary collapse
-
#restart_puppet_server(host, opts = {}) ⇒ Object
Restart the puppet server and wait for it to come back up ==== Attributes *
host
- the host that this should operate on *opts
- an options hash - not required *:wait_cycle
- the number of cycles to attempt retry *:is_pe?
- Boolean : if the SUT is PE, defaults to true.
Instance Method Details
#restart_puppet_server(host, opts = {}) ⇒ Object
Restart the puppet server and wait for it to come back up
Attributes
*host
- the host that this should operate on *opts
- an options hash - not required
*+:wait_cycle+ - the number of cycles to attempt retry
*+:is_pe?+ - Boolean : if the SUT is PE, defaults to true
Raises a standard error if the wait is unsuccessful
Example
restart_puppet_server(master) restart_puppet_server(master, => 20)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/master_manipulator/service.rb', line 18 def restart_puppet_server(host, opts = {}) start_time = Time.now opts[:is_pe?] ||= true opts[:is_pe?] ? service_name = 'pe-puppetserver' : service_name = 'puppetserver' on(host, puppet("resource service #{service_name} ensure=stopped")) on(host, puppet("resource service #{service_name} ensure=running")) hostname = on(host, 'hostname').stdout.chomp opts[:wait_cycles] ||= 10 # -k to ignore HTTPS error that isn't relevant to us curl_call = "-k -X GET -H 'Content-Type: application/json' https://#{hostname}:8140/status/v1/services?level=debug" (1..opts[:wait_cycles]).each do |i| @result = curl_on(host, curl_call, :acceptable_exit_codes => [0,1,7]) @body = JSON.parse(@result.stdout) case @result.exit_code.to_s when '0' sleep 20 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 |