Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
Add the idea of a debug flag to make the vagrant commands output expl…
Browse files Browse the repository at this point in the history
…icit to the end user. Also does the changes necessaries to make the vagrant command runner fetch the stdout and stdin on demand and not waiting till the end of it to report.

Fixes elastic#5566
  • Loading branch information
Pere Urbon-Bayes authored and jsvd committed Aug 23, 2016
1 parent 32e2cae commit 688adca
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
8 changes: 5 additions & 3 deletions qa/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace :qa do

puts user_feedback_string_for("bootstraping", args[:platform], machines, {"experimental" => experimental})

LogStash::VagrantHelpers.destroy(machines)
LogStash::VagrantHelpers.bootstrap(machines)
options = {:debug => ENV['LS_QA_DEBUG']}
LogStash::VagrantHelpers.destroy(machines, options)
LogStash::VagrantHelpers.bootstrap(machines, options)
end

desc "Halt all VM's involved in the acceptance test round"
Expand All @@ -46,8 +47,9 @@ namespace :qa do
machines = config.select_names_for(args[:platform], {"experimental" => experimental})

puts user_feedback_string_for("halting", args[:platform], machines, {"experimental" => experimental})
options = {:debug => ENV['LS_QA_DEBUG']}

LogStash::VagrantHelpers.halt(machines)
LogStash::VagrantHelpers.halt(machines, options)
end
end

Expand Down
36 changes: 31 additions & 5 deletions qa/vagrant/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,51 @@ def success?
end
end

def self.run(cmd)
def self.run(cmd, debug=false)
# This block is require to be able to launch a ruby subprocess
# that use bundler.
Bundler.with_clean_env do
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
CommandResponse.new(stdin, stdout.read.chomp, stderr.read.chomp, wait_thr.value.exitstatus)
stdin, stdout, stderr, wait_thr = Open3.popen3(cmd)
stdout_acc, stderr_acc = "", ""
stdout_reporter = reporter(stdout, wait_thr) do |c|
stdout_acc << c
print c if debug
end
reporter(stderr, wait_thr) do |c|
stderr_acc << c;
print c if debug
end
stdout_reporter.join
CommandResponse.new(stdin, stdout_acc, stderr_acc, wait_thr.value.exitstatus)
end
end

# This method will raise an exception if the `CMD`
# was not run successfully and will display the content of STDERR
def self.run!(cmd)
response = run(cmd)
def self.run!(cmd, debug=false)
response = run(cmd, debug)

unless response.success?
raise CommandError, "CMD: #{cmd} STDERR: #{response.stderr}"
end
response
end

private

def self.reporter(io, wait_thr, &block)
Thread.new(io, wait_thr) do |_io, _wait_thr|
while (_wait_thr.status == "run")
begin
c = _io.read(1)
block.call(c) if c
rescue IO::WaitReadable
IO.select([_io])
retry
end
end
end
end

end
end
15 changes: 9 additions & 6 deletions qa/vagrant/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
module LogStash
class VagrantHelpers

def self.halt(machines="")
CommandExecutor.run!("vagrant halt #{machines.join(' ')}")
def self.halt(machines="", options={})
debug = options.fetch(:debug, false)
CommandExecutor.run!("vagrant halt #{machines.join(' ')}", debug)
end

def self.destroy(machines="")
CommandExecutor.run!("vagrant destroy --force #{machines.join(' ')}")
def self.destroy(machines="", options={})
debug = options.fetch(:debug, false)
CommandExecutor.run!("vagrant destroy --force #{machines.join(' ')}", debug)
end

def self.bootstrap(machines="")
CommandExecutor.run!("vagrant up #{machines.join(' ')}")
def self.bootstrap(machines="", options={})
debug = options.fetch(:debug, false)
CommandExecutor.run!("vagrant up #{machines.join(' ')}", debug)
end

def self.save_snapshot(machine="")
Expand Down

0 comments on commit 688adca

Please sign in to comment.