module Dopi::CommandParser::PuppetRun
Public Instance Methods
check_run_lock_wrapper()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 94 def check_run_lock_wrapper cmd_stdout, cmd_stderr, cmd_exitcode = check_run_lock return true if cmd_exitcode == 0 return false end
max_rerun()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 35 def max_rerun @max_rerun ||= max_rerun_valid? ? hash[:max_rerun] : 1 end
parse_output_defaults()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 112 def parse_output_defaults { :error => [ '^Error:' ], :warning => [ '^Warning:' ] } end
puppet_bin()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 43 def puppet_bin @puppet_bin ||= puppet_bin_valid? ? hash[:puppet_bin] : 'puppet' end
puppet_run_wrapper()
click to toggle source
puppet run wrapper method this will return :done, :change or :error
# File lib/dopi/command_parser/puppet_run.rb, line 102 def puppet_run_wrapper cmd_stdout, cmd_stderr, cmd_exitcode = puppet_run return :error unless (check_output(cmd_stdout) && check_output(cmd_stderr)) case cmd_exitcode when 0 then return :done when 2 then return :change else return :error end end
rerun_on_change()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 27 def rerun_on_change @rerun_on_change ||= rerun_on_change_valid? ? hash[:rerun_on_change] : false end
rerun_on_error()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 31 def rerun_on_error @rerun_on_error ||= rerun_on_error_valid? ? hash[:rerun_on_error] : false end
run()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 47 def run runs = 0 loop do raise GracefulExit if signals[:stop] if check_run_lock_wrapper if wait_if_already_running log(:info, "Puppet run already in progress, waiting 10s to check again if finished") sleep(10) else log(:error, "Puppet run already in progress and wait_if_already_running = false") return false end else runs += 1 if runs < 2 log(:info, "Starting Puppet Run") else log(:info, "Starting Puppet Rerun #{runs - 1} of #{max_rerun}") end case puppet_run_wrapper when :done then return true when :change if rerun_on_change if runs < 2 log(:info, "Puppet had changes and rerun_on_change = true") else log(:warn, "Puppet had still changes after multiple reruns. Please fix your Puppet manifests") end return true if max_rerun < runs else return true end else if rerun_on_error log(:warn, "Puppet had ERRORS during the run and rerun_on_errors = true. Please fix your Puppet manifests") if max_rerun < runs log(:error, "Puppet had ERRORS during the run! max_reruns (#{max_rerun}) reached!") return false end else return false end end end end end
validate_puppet_run()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 16 def validate_puppet_run validate_env validate_arguments validate_output log_validation_method('rerun_on_change_valid?', CommandParsingError) log_validation_method('rerun_on_error_valid?', CommandParsingError) log_validation_method('max_rerun_valid?', CommandParsingError) log_validation_method('wait_if_already_running_valid?', CommandParsingError) log_validation_method('puppet_bin_valid?', CommandParsingError) end
wait_if_already_running()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 39 def wait_if_already_running @wait_if_already_running ||= wait_if_already_running_valid? ? hash[:wait_if_already_running] : true end
Private Instance Methods
max_rerun_valid?()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 138 def max_rerun_valid? return false unless hash.kind_of?(Hash) return false if hash[:max_rerun].nil? # is optional hash[:max_rerun].kind_of?(Fixnum) or raise CommandParsingError, "Plugin #{name}: The value for 'max_rerun' has to be a number" hash[:max_rerun] > 0 or raise CommandParsingError, "Plugin #{name}: The value for 'max_rerun' has to be > 0" end
puppet_bin_valid?()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 154 def puppet_bin_valid? return false unless hash.kind_of?(Hash) return false if hash[:puppet_bin].nil? # is optional begin Pathname.new(hash[:puppet_bin]).absolute? or hash[:puppet_bin][/[a-zA-Z]+:\\/] or hash[:puppet_bin][/\\\\\w+/] or raise CommandParsingError, "Plugin #{name}: The path for 'puppet_bin' has to be absolute" rescue ArgumentError => e raise CommandParsingError, "Plugin #{name}: The value in 'puppet_bin' is not a valid file path: #{e.message}" end end
rerun_on_change_valid?()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 124 def rerun_on_change_valid? return false unless hash.kind_of?(Hash) return false if hash[:rerun_on_change].nil? # is optional hash[:rerun_on_change].kind_of?(TrueClass) or hash[:rerun_on_change].kind_of?(FalseClass) or raise CommandParsingError, "Plugin #{name}: The value for 'rerun_on_change' must be boolean" end
rerun_on_error_valid?()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 131 def rerun_on_error_valid? return false unless hash.kind_of?(Hash) return false if hash[:rerun_on_error].nil? # is optional hash[:rerun_on_error].kind_of?(TrueClass) or hash[:rerun_on_error].kind_of?(FalseClass) or raise CommandParsingError, "Plugin #{name}: The value for 'rerun_on_error' must be boolean" end
wait_if_already_running_valid?()
click to toggle source
# File lib/dopi/command_parser/puppet_run.rb, line 147 def wait_if_already_running_valid? return false unless hash.kind_of?(Hash) return false if hash[:wait_if_already_running].nil? # is optional hash[:wait_if_already_running].kind_of?(TrueClass) or hash[:wait_if_already_running].kind_of?(FalseClass) or raise CommandParsingError, "Plugin #{name}: The value for 'wait_if_already_running' must be boolean" end