Commit 21ac37ba authored by Volker Hilsheimer's avatar Volker Hilsheimer

Fix handling of LoadError when winrm is not installed

LoadError is not a StandardError in ruby, and has to be handled explicitly.
Add mocking for winssh.

Be silent about the fallback for info calls, and handle winssh
correctly when running jobs.
parent 91a1d8d1
......@@ -145,9 +145,10 @@ Vagrant.configure("2") do |config|
# Test if winrm is available
begin
$has_winrm = require 'winrm' unless $has_winrm
rescue => e
puts "==> #{name}: WinRM gem not installed, falling back to winssh!"
puts " #{name}: Shared folder support and file provisioning might fail"
rescue LoadError => e
if ARGV[0] != "info"
puts "==> #{name}: WinRM gem not installed, falling back to winssh!"
end
end
if $has_winrm
......
# Mocking classes for testing Vagrant
# THe hierarchy is MockVagrant -> MockConfig -> MockVM -> MockBox
class MockVagrant
def initialize()
@config = MockConfig.new()
@config.vagrant = self
@plugin = MockPlugin.new()
@sensitive = Array.new
end
def require_version(expr)
end
def configure(version)
yield @config
end
def config()
return @config
end
def plugin(a, b="default")
MockPlugin
end
def sensitive
@sensitive
end
def sensitive=(sensitive)
@sensitive << sensitive
end
end
class MockConfig
def initialize()
@vm = MockVm.new(nil)
@vagrant = nil
end
def vm()
return @vm
end
def vagrant
@vagrant
end
def vagrant=(vagrant)
@vagrant = vagrant
end
end
class MockPlugin
def initialize()
end
def self.name(n)
end
def self.config(a, b)
end
def self.provisioner(a)
end
end
class MockVm
def initialize(type)
@guest = type
@box = ""
@url = ""
@box_url = ""
@communicator = :ssh
@boxes = {}
end
def vm()
return self
end
def define(a, b=nil)
vm = MockVm.new(nil)
@boxes[a] = vm
yield vm
end
def box()
return @box
end
def box=(box)
@box = box
end
def box_url()
@box_url
end
def box_url=(box_url)
@box_url = box_url
end
def communicator()
@communicator
end
def communicator=(communicator)
@communicator = communicator
end
def hostname=(hostname)
end
def guest()
return @guest
end
def guest=(guest)
@guest = guest
end
def network(a, b)
end
def provider(a)
end
def synced_folder(a, b, c=nil)
end
def provision(a, b)
end
def trigger()
return MockTrigger.new()
end
def boxes()
return @boxes
end
end
class MockTrigger
def before(a)
end
def after(a)
end
end
\ No newline at end of file
def initialize()
@config = MockConfig.new()
@config.vagrant = self
@plugin = MockPlugin.new()
@sensitive = Array.new
end
def require_version(expr)
end
def configure(version)
yield @config
end
def config()
return @config
end
def plugin(a, b="default")
MockPlugin
end
def sensitive
@sensitive
end
def sensitive=(sensitive)
@sensitive << sensitive
end
end
class MockConfig
def initialize()
@vm = MockVm.new(nil)
@vagrant = nil
end
def vm()
return @vm
end
def vagrant
@vagrant
end
def vagrant=(vagrant)
@vagrant = vagrant
end
end
class MockPlugin
def initialize()
end
def self.name(n)
end
def self.config(a, b)
end
def self.provisioner(a)
end
end
class MockWinssh
def insert_key=(a)
end
end
class MockVm
def initialize(type)
@guest = type
@box = ""
@url = ""
@box_url = ""
@communicator = :ssh
@boxes = {}
end
def vm()
return self
end
def define(a, b=nil)
vm = MockVm.new(nil)
@boxes[a] = vm
yield vm
end
def box()
return @box
end
def box=(box)
@box = box
end
def box_url()
@box_url
end
def box_url=(box_url)
@box_url = box_url
end
def communicator()
@communicator
end
def communicator=(communicator)
@communicator = communicator
end
def hostname=(hostname)
end
def guest()
return @guest
end
def guest=(guest)
@guest = guest
end
def network(a, b)
end
def provider(a)
end
def synced_folder(a, b, c=nil)
end
def provision(a, b)
end
def trigger()
return MockTrigger.new()
end
def boxes()
return @boxes
end
def winssh()
MockWinssh.new
end
end
class MockTrigger
def before(a)
end
def after(a)
end
end
\ No newline at end of file
......@@ -136,8 +136,9 @@ function run_on_machine() {
upload_source="$jobroot/$job"
communicator=$(minicoin info $machine | awk {'print $3'})
if [ $communicator == "winrm" ]
if [[ $communicator == "winrm" || $communicator == "winssh" ]]
then
[ $communicator == "winssh" ] && communicator="ssh"
ext="cmd"
if [ ! -f "$upload_source/main.cmd" ]; then
ext="ps1"
......@@ -218,7 +219,8 @@ function run_on_machine() {
cleanup_command="rm -rf"
if [[ $ext == "cmd" || $ext == "ps1" ]];
then
command="c:\\minicoin\\util\\run_helper.ps1 Documents\\"
command="c:\\minicoin\\util\\run_helper.ps1 "
[ $communicator=="winrm" ] && command="${command}Documents\\"
cleanup_command="Remove-Item -Recurse -Force"
scriptfile=${scriptfile//\//\\}
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment