providers/hyperv: clean up driver error handling quite a bit
This commit is contained in:
parent
fb7dd73d95
commit
ab4390eb67
|
@ -7,6 +7,9 @@ require_relative "plugin"
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module HyperV
|
module HyperV
|
||||||
class Driver
|
class Driver
|
||||||
|
ERROR_REGEXP = /===Begin-Error===(.+?)===End-Error===/m
|
||||||
|
OUTPUT_REGEXP = /===Begin-Output===(.+?)===End-Output===/m
|
||||||
|
|
||||||
attr_reader :vmid
|
attr_reader :vmid
|
||||||
|
|
||||||
def initialize(id=nil)
|
def initialize(id=nil)
|
||||||
|
@ -15,29 +18,32 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(path, options)
|
def execute(path, options)
|
||||||
r = execute_powershell(path, options) do |type, data|
|
r = execute_powershell(path, options)
|
||||||
process_output(type, data)
|
|
||||||
end
|
|
||||||
if r.exit_code != 0
|
if r.exit_code != 0
|
||||||
raise Errors::PowerShellError,
|
raise Errors::PowerShellError,
|
||||||
script: path,
|
script: path,
|
||||||
stderr: r.stderr
|
stderr: r.stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
if success?
|
# We only want unix-style line endings within Vagrant
|
||||||
JSON.parse(json_output[:success].join) unless json_output[:success].empty?
|
r.stdout.gsub!("\r\n", "\n")
|
||||||
else
|
r.stderr.gsub!("\r\n", "\n")
|
||||||
message = json_output[:error].join unless json_output[:error].empty?
|
|
||||||
raise Error::SubprocessError, message if message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def raw_execute(command)
|
error_match = ERROR_REGEXP.match(r.stdout)
|
||||||
command = [command , {notify: [:stdout, :stderr, :stdin]}].flatten
|
output_match = OUTPUT_REGEXP.match(r.stdout)
|
||||||
clear_output_buffer
|
|
||||||
Vagrant::Util::Subprocess.execute(*command) do |type, data|
|
if error_match
|
||||||
process_output(type, data)
|
data = JSON.parse(error_match[1])
|
||||||
|
|
||||||
|
# We have some error data.
|
||||||
|
raise Errors::PowerShellError,
|
||||||
|
script: path,
|
||||||
|
stderr: data["error"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Nothing
|
||||||
|
return nil if !output_match
|
||||||
|
return JSON.parse(output_match[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -86,7 +92,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_powershell(path, options, &block)
|
def execute_powershell(path, options, &block)
|
||||||
lib_path = Pathname.new(File.expand_path("../../scripts", __FILE__))
|
lib_path = Pathname.new(File.expand_path("../scripts", __FILE__))
|
||||||
path = lib_path.join(path).to_s.gsub("/", "\\")
|
path = lib_path.join(path).to_s.gsub("/", "\\")
|
||||||
options = options || {}
|
options = options || {}
|
||||||
ps_options = []
|
ps_options = []
|
||||||
|
|
Loading…
Reference in New Issue