Module: Kitchen::Command::RunAction
Overview
Common module to execute a Kitchen action such as create, converge, etc.
Instance Method Summary collapse
- #concurrency_setting(instances) ⇒ Object
-
#report_errors ⇒ Object
private.
-
#run_action(action, instances, *args) ⇒ Object
Run an instance action (create, converge, setup, verify, destroy) on a collection of instances.
- #run_action_in_thread(action, instance, *args) ⇒ Object
Instance Method Details
#concurrency_setting(instances) ⇒ Object
191 192 193 194 195 196 197 198 |
# File 'lib/kitchen/command.rb', line 191 def concurrency_setting(instances) concurrency = 1 if [:concurrency] concurrency = [:concurrency] || instances.size concurrency = instances.size if concurrency > instances.size end concurrency end |
#report_errors ⇒ Object
private
183 184 185 186 187 188 189 |
# File 'lib/kitchen/command.rb', line 183 def report_errors unless @action_errors.empty? msg = ["#{@action_errors.length} actions failed.", @action_errors.map { |e| ">>>>>> #{e.}" }].join("\n") raise ActionFailed.new(msg, @action_errors) end end |
#run_action(action, instances, *args) ⇒ Object
Run an instance action (create, converge, setup, verify, destroy) on a collection of instances. The instance actions will take place in a seperate thread of execution which may or may not be running concurrently.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/kitchen/command.rb', line 161 def run_action(action, instances, *args) concurrency = concurrency_setting(instances) queue = Queue.new instances.each { |i| queue << i } concurrency.times { queue << nil } threads = [] @action_errors = [] concurrency.times do threads << Thread.new do while instance = queue.pop run_action_in_thread(action, instance, *args) end end end threads.map(&:join) report_errors end |
#run_action_in_thread(action, instance, *args) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/kitchen/command.rb', line 200 def run_action_in_thread(action, instance, *args) instance.public_send(action, *args) rescue Kitchen::InstanceFailure => e @action_errors << e rescue Kitchen::ActionFailed => e new_error = Kitchen::ActionFailed.new("#{e.} on #{instance.name}") new_error.set_backtrace(e.backtrace) @action_errors << new_error ensure instance.cleanup! end |