Module: Dopi::CommandParser::PuppetRun
Instance Method Summary
collapse
Methods included from Output
#check_output, #error_patterns, #fail_on_warning, #lines_with_matches, #parse_output, #validate_output, #warning_patterns
Methods included from Arguments
#arguments, #validate_arguments
Methods included from Env
#env, #validate_env
Instance Method Details
#check_run_lock_wrapper ⇒ Object
94
95
96
97
98
|
# 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 ⇒ Object
35
36
37
|
# 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 ⇒ Object
112
113
114
115
116
117
118
119
120
|
# File 'lib/dopi/command_parser/puppet_run.rb', line 112
def parse_output_defaults
{ :error => [
'^Error:'
],
:warning => [
'^Warning:'
]
}
end
|
#puppet_bin ⇒ Object
43
44
45
|
# 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 ⇒ Object
puppet run wrapper method this will return :done, :change or :error
102
103
104
105
106
107
108
109
110
|
# 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 ⇒ Object
27
28
29
|
# 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 ⇒ Object
31
32
33
|
# 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 ⇒ Object
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
90
91
92
|
# 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 ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# 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 ⇒ Object
39
40
41
|
# 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
|