fix #7489 preventing winrm connection leakage
This commit is contained in:
parent
c5438675ea
commit
64828f1ed3
|
@ -56,11 +56,15 @@ 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 } }"
|
||||||
execute_with_rescue(executor.method("run_powershell_script"), command, &block)
|
session.create_executor do |executor|
|
||||||
|
execute_with_rescue(executor.method("run_powershell_script"), command, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cmd(command, &block)
|
def cmd(command, &block)
|
||||||
execute_with_rescue(executor.method("run_cmd"), command, &block)
|
session.create_executor do |executor|
|
||||||
|
execute_with_rescue(executor.method("run_cmd"), command, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def wql(query, &block)
|
def wql(query, &block)
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue