forked from matschaffer/knife-solo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matschaffer#450 rsync command doesn't work in windows with cygwin due…
… to broken ControlMaster support
- Loading branch information
Showing
3 changed files
with
70 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
module KnifeSolo | ||
module Tools | ||
def system!(*command) | ||
raise "Failed to launch command #{command}" unless system(*command) | ||
end | ||
|
||
def windows_client? | ||
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ | ||
end | ||
|
||
def config_value(key, default = nil) | ||
Tools.config_value(config, key, default) | ||
end | ||
|
||
# Chef 10 compatible way of getting correct precedence for command line | ||
# and configuration file options. Adds correct handling of `false` values | ||
# to the original example in | ||
# http://docs.opscode.com/breaking_changes_chef_11.html#knife-configuration-parameter-changes | ||
def self.config_value(config, key, default = nil) | ||
key = key.to_sym | ||
if !config[key].nil? | ||
config[key] | ||
elsif !Chef::Config[:knife][key].nil? | ||
# when Chef 10 support is dropped, this branch can be removed | ||
# as Chef 11 automatically merges the values to the `config` hash | ||
Chef::Config[:knife][key] | ||
else | ||
default | ||
end | ||
end | ||
|
||
end | ||
end | ||
module KnifeSolo | ||
module Tools | ||
def system!(*command) | ||
raise "Failed to launch command #{command}" unless system(*command) | ||
end | ||
|
||
def windows_client? | ||
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ | ||
end | ||
|
||
def self.cygwin_client? | ||
RbConfig::CONFIG['host_os'] =~ /cygwin/ | ||
end | ||
|
||
def config_value(key, default = nil) | ||
Tools.config_value(config, key, default) | ||
end | ||
|
||
# Chef 10 compatible way of getting correct precedence for command line | ||
# and configuration file options. Adds correct handling of `false` values | ||
# to the original example in | ||
# http://docs.opscode.com/breaking_changes_chef_11.html#knife-configuration-parameter-changes | ||
def self.config_value(config, key, default = nil) | ||
key = key.to_sym | ||
if !config[key].nil? | ||
config[key] | ||
elsif !Chef::Config[:knife][key].nil? | ||
# when Chef 10 support is dropped, this branch can be removed | ||
# as Chef 11 automatically merges the values to the `config` hash | ||
Chef::Config[:knife][key] | ||
else | ||
default | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
require 'test_helper' | ||
|
||
require 'knife-solo/ssh_command' | ||
require 'knife-solo/tools' | ||
require 'chef/knife' | ||
require 'net/ssh' | ||
|
||
|
@@ -9,6 +10,11 @@ class DummySshCommand < Chef::Knife | |
end | ||
|
||
class SshCommandTest < TestCase | ||
|
||
def setup | ||
KnifeSolo::Tools.stubs(:cygwin_client?).returns(false) | ||
end | ||
|
||
def test_separates_user_and_host | ||
assert_equal "ubuntu", command("[email protected]").user | ||
assert_equal "10.0.0.1", command("[email protected]").host | ||
|
@@ -69,7 +75,7 @@ def test_try_connection_with_gateway_connects_using_ssh_gateway | |
cmd = command("10.0.0.1", "--ssh-gateway=user@gateway") | ||
ssh_mock = mock 'ssh_mock' | ||
Net::SSH::Gateway.expects(:new).with('gateway', 'user').returns(ssh_mock) | ||
ssh_mock.expects(:ssh).with(cmd.host, cmd.user, cmd.connection_options.except(:gateway)) | ||
ssh_mock.expects(:ssh).with(cmd.host, cmd.user, cmd.connection_options.select{|o| o != :gateway}) | ||
|
||
Net::SSH.expects(:start).never | ||
|
||
|
@@ -164,6 +170,26 @@ def test_builds_cli_ssh_args | |
assert_equal "[email protected] -o ControlMaster=auto -o ControlPath=#{cmd.ssh_control_path} -o ControlPersist=3600", cmd.ssh_args | ||
end | ||
|
||
def test_no_control_master_by_default_in_cygwin | ||
DummySshCommand.any_instance.stubs(:try_connection) | ||
DummySshCommand.any_instance.stubs(:ssh_control_path).returns('/path') | ||
KnifeSolo::Tools.stubs(:cygwin_client?).returns(false) | ||
cmd = command_internal('[email protected]') | ||
cmd.validate_ssh_options! | ||
assert_equal '[email protected] -o ControlMaster=auto -o ControlPath=/path -o ControlPersist=3600', cmd.ssh_args | ||
|
||
# if knife-solo runs in cygwin, disable ssh ControlMaster by default | ||
KnifeSolo::Tools.stubs(:cygwin_client?).returns(true) | ||
cmd = command_internal('[email protected]') | ||
cmd.validate_ssh_options! | ||
assert_equal '[email protected]', cmd.ssh_args | ||
|
||
KnifeSolo::Tools.stubs(:cygwin_client?).returns(true) | ||
cmd = command_internal('[email protected]', '--ssh-control-master=auto') | ||
cmd.validate_ssh_options! | ||
assert_equal '[email protected] -o ControlMaster=auto -o ControlPath=/path -o ControlPersist=3600', cmd.ssh_args | ||
end | ||
|
||
def test_barks_without_atleast_a_hostname | ||
cmd = command | ||
cmd.ui.expects(:fatal).with(regexp_matches(/hostname.*argument/)) | ||
|