324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
# File 'lib/beaker/host.rb', line 324
def exec command, options={}
result = nil
cmdline = command.cmd_line(self)
options[:dry_run] ||= @options[:dry_run]
if options[:dry_run]
@logger.debug "\n Running in :dry_run mode. Command #{cmdline} not executed."
result = Beaker::NullResult.new(self, command)
return result
end
if options[:silent]
output_callback = nil
else
@logger.debug "\n#{log_prefix} #{Time.new.strftime('%H:%M:%S')}$ #{cmdline}"
if @options[:color_host_output]
output_callback = logger.method(:color_host_output)
else
output_callback = logger.method(:host_output)
end
end
unless options[:dry_run]
seconds = Benchmark.realtime {
@logger.with_indent do
result = connection.execute(cmdline, options, output_callback)
end
}
if not options[:silent]
@logger.debug "\n#{log_prefix} executed in %0.2f seconds" % seconds
end
if options[:reset_connection]
close
return result
end
unless options[:silent]
result.log(@logger)
if !options[:expect_connection_failure] && !result.exit_code
raise CommandFailure, "Host '#{self}' connection failure running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}"
end
if options[:expect_connection_failure] && result.exit_code
if not connection.wait_for_connection_failure(options, output_callback)
raise CommandFailure, "Host '#{self}' should have resulted in a connection failure running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}"
end
end
if options[:accept_all_exit_codes] && options[:acceptable_exit_codes]
@logger.warn ":accept_all_exit_codes & :acceptable_exit_codes set. :acceptable_exit_codes overrides, but they shouldn't both be set at once"
options[:accept_all_exit_codes] = false
end
if !options[:accept_all_exit_codes] && !result.exit_code_in?(Array(options[:acceptable_exit_codes] || [0, nil]))
raise CommandFailure, "Host '#{self}' exited with #{result.exit_code} running:\n #{cmdline}\nLast #{@options[:trace_limit]} lines of output were:\n#{result.formatted_output(@options[:trace_limit])}"
end
end
end
result
end
|