fix #7489 preventing winrm connection leakage

This commit is contained in:
Matt Wrock 2016-08-13 07:49:08 -07:00
parent c5438675ea
commit 64828f1ed3
2 changed files with 9 additions and 7 deletions

View File

@ -56,12 +56,16 @@ module VagrantPlugins
def powershell(command, &block) def powershell(command, &block)
# Ensure an exit code # Ensure an exit code
command += "\r\nif ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }" command += "\r\nif ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }"
session.create_executor do |executor|
execute_with_rescue(executor.method("run_powershell_script"), command, &block) execute_with_rescue(executor.method("run_powershell_script"), command, &block)
end end
end
def cmd(command, &block) def cmd(command, &block)
session.create_executor do |executor|
execute_with_rescue(executor.method("run_cmd"), command, &block) execute_with_rescue(executor.method("run_cmd"), command, &block)
end end
end
def wql(query, &block) def wql(query, &block)
retryable(tries: @config.max_tries, on: @@exceptions_to_retry_on, sleep: @config.retry_delay) do retryable(tries: @config.max_tries, on: @@exceptions_to_retry_on, sleep: @config.retry_delay) do
@ -172,10 +176,6 @@ module VagrantPlugins
@session ||= new_session @session ||= new_session
end end
def executor
@executor ||= session.create_executor
end
def endpoint def endpoint
case @config.transport.to_sym case @config.transport.to_sym
when :ssl when :ssl

View File

@ -6,7 +6,7 @@ require Vagrant.source_root.join("plugins/communicators/winrm/config")
describe VagrantPlugins::CommunicatorWinRM::WinRMShell do describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
include_context "unit" include_context "unit"
let(:session) { double("winrm_session", create_executor: executor) } let(:session) { double("winrm_session") }
let(:executor) { double("command_executor") } let(:executor) { double("command_executor") }
let(:port) { config.transport == :ssl ? 5986 : 5985 } let(:port) { config.transport == :ssl ? 5986 : 5985 }
let(:config) { let(:config) {
@ -22,6 +22,8 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
end end
} }
before { allow(session).to receive(:create_executor).and_yield(executor) }
subject do subject do
described_class.new('localhost', port, config).tap do |comm| described_class.new('localhost', port, config).tap do |comm|
allow(comm).to receive(:new_session).and_return(session) allow(comm).to receive(:new_session).and_return(session)