2017-07-04 22:02:58 -04:00
|
|
|
require "open3"
|
2016-03-01 10:51:47 -05:00
|
|
|
|
2014-04-22 11:36:44 -04:00
|
|
|
module VagrantHelpers
|
|
|
|
extend self
|
|
|
|
|
|
|
|
class VagrantSSHCommandError < RuntimeError; end
|
|
|
|
|
|
|
|
at_exit do
|
2016-02-28 18:16:11 -05:00
|
|
|
if ENV["KEEP_RUNNING"]
|
2014-04-22 11:36:44 -04:00
|
|
|
puts "Vagrant vm will be left up because KEEP_RUNNING is set."
|
|
|
|
puts "Rerun without KEEP_RUNNING set to cleanup the vm."
|
|
|
|
else
|
|
|
|
vagrant_cli_command("destroy -f")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def vagrant_cli_command(command)
|
|
|
|
puts "[vagrant] #{command}"
|
2017-07-04 22:02:58 -04:00
|
|
|
stdout, stderr, status = Dir.chdir(VAGRANT_ROOT) do
|
|
|
|
Open3.capture3("#{VAGRANT_BIN} #{command}")
|
2014-04-22 11:36:44 -04:00
|
|
|
end
|
2017-07-04 22:02:58 -04:00
|
|
|
|
|
|
|
(stdout + stderr).each_line { |line| puts "[vagrant] #{line}" }
|
|
|
|
|
|
|
|
[stdout, stderr, status]
|
2014-04-22 11:36:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_vagrant_command(command)
|
2017-07-04 22:02:58 -04:00
|
|
|
stdout, stderr, status = vagrant_cli_command("ssh -c #{command.inspect}")
|
|
|
|
return [stdout, stderr] if status.success?
|
2016-09-19 12:59:57 -04:00
|
|
|
raise VagrantSSHCommandError, status
|
2014-04-22 11:36:44 -04:00
|
|
|
end
|
2021-01-18 11:24:12 -05:00
|
|
|
|
|
|
|
def puts(message)
|
|
|
|
# Attach log messages to the current cucumber feature (`log`),
|
|
|
|
# or simply puts to the console (`super`) if we are outside of cucumber.
|
|
|
|
respond_to?(:log) ? log(message) : super(message)
|
|
|
|
end
|
2014-04-22 11:36:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
World(VagrantHelpers)
|