vagrantup 0.4.3.dev → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/config/default.rb +6 -6
- data/lib/vagrant.rb +6 -3
- data/lib/vagrant/action.rb +77 -0
- data/lib/vagrant/action/action_exception.rb +16 -0
- data/lib/vagrant/action/box/destroy.rb +19 -0
- data/lib/vagrant/action/box/download.rb +78 -0
- data/lib/vagrant/action/box/unpackage.rb +58 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +151 -0
- data/lib/vagrant/action/builtin.rb +114 -0
- data/lib/vagrant/action/env/error_halt.rb +16 -0
- data/lib/vagrant/action/env/set.rb +18 -0
- data/lib/vagrant/action/environment.rb +98 -0
- data/lib/vagrant/action/exception_catcher.rb +14 -0
- data/lib/vagrant/action/vm/boot.rb +54 -0
- data/lib/vagrant/action/vm/check_box.rb +27 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
- data/lib/vagrant/action/vm/customize.rb +21 -0
- data/lib/vagrant/action/vm/destroy.rb +20 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
- data/lib/vagrant/action/vm/disable_networks.rb +26 -0
- data/lib/vagrant/action/vm/export.rb +53 -0
- data/lib/vagrant/action/vm/forward_ports.rb +121 -0
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
- data/lib/vagrant/action/vm/halt.rb +34 -0
- data/lib/vagrant/action/vm/import.rb +33 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
- data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
- data/lib/vagrant/action/vm/nfs.rb +161 -0
- data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
- data/lib/vagrant/action/vm/package.rb +99 -0
- data/lib/vagrant/action/vm/persist.rb +22 -0
- data/lib/vagrant/action/vm/provision.rb +50 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/box.rb +3 -7
- data/lib/vagrant/commands/base.rb +1 -3
- data/lib/vagrant/commands/package.rb +4 -9
- data/lib/vagrant/commands/up.rb +0 -2
- data/lib/vagrant/config.rb +15 -1
- data/lib/vagrant/downloaders/file.rb +1 -1
- data/lib/vagrant/downloaders/http.rb +2 -1
- data/lib/vagrant/environment.rb +18 -14
- data/lib/vagrant/hosts/base.rb +77 -0
- data/lib/vagrant/hosts/bsd.rb +53 -0
- data/lib/vagrant/hosts/linux.rb +52 -0
- data/lib/vagrant/provisioners/base.rb +17 -9
- data/lib/vagrant/provisioners/chef.rb +1 -1
- data/lib/vagrant/provisioners/chef_server.rb +4 -8
- data/lib/vagrant/provisioners/chef_solo.rb +1 -2
- data/lib/vagrant/ssh.rb +12 -4
- data/lib/vagrant/systems/base.rb +4 -0
- data/lib/vagrant/systems/linux.rb +12 -1
- data/lib/vagrant/util.rb +16 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/plain_logger.rb +11 -0
- data/lib/vagrant/util/platform.rb +18 -0
- data/lib/vagrant/util/resource_logger.rb +128 -0
- data/lib/vagrant/version.rb +6 -0
- data/lib/vagrant/vm.rb +10 -12
- data/templates/chef_solo_solo.erb +2 -1
- data/templates/nfs/exports.erb +3 -0
- data/templates/nfs/exports_linux.erb +3 -0
- data/templates/strings.yml +23 -3
- metadata +121 -196
- data/.gitignore +0 -11
- data/Gemfile +0 -18
- data/Rakefile +0 -41
- data/VERSION +0 -1
- data/bin/.gitignore +0 -0
- data/lib/vagrant/actions/base.rb +0 -130
- data/lib/vagrant/actions/box/add.rb +0 -23
- data/lib/vagrant/actions/box/destroy.rb +0 -14
- data/lib/vagrant/actions/box/download.rb +0 -67
- data/lib/vagrant/actions/box/unpackage.rb +0 -42
- data/lib/vagrant/actions/box/verify.rb +0 -32
- data/lib/vagrant/actions/collection.rb +0 -36
- data/lib/vagrant/actions/runner.rb +0 -131
- data/lib/vagrant/actions/vm/boot.rb +0 -43
- data/lib/vagrant/actions/vm/customize.rb +0 -19
- data/lib/vagrant/actions/vm/destroy.rb +0 -24
- data/lib/vagrant/actions/vm/down.rb +0 -22
- data/lib/vagrant/actions/vm/export.rb +0 -45
- data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
- data/lib/vagrant/actions/vm/halt.rb +0 -24
- data/lib/vagrant/actions/vm/import.rb +0 -23
- data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
- data/lib/vagrant/actions/vm/package.rb +0 -94
- data/lib/vagrant/actions/vm/provision.rb +0 -49
- data/lib/vagrant/actions/vm/reload.rb +0 -17
- data/lib/vagrant/actions/vm/resume.rb +0 -16
- data/lib/vagrant/actions/vm/start.rb +0 -26
- data/lib/vagrant/actions/vm/suspend.rb +0 -16
- data/lib/vagrant/actions/vm/up.rb +0 -53
- data/lib/vagrant/busy.rb +0 -79
- data/lib/vagrant/resource_logger.rb +0 -126
- data/lib/vagrant/util/error_helper.rb +0 -13
- data/lib/vagrant/util/output_helper.rb +0 -9
- data/test/test_helper.rb +0 -149
- data/test/vagrant/actions/base_test.rb +0 -32
- data/test/vagrant/actions/box/add_test.rb +0 -36
- data/test/vagrant/actions/box/destroy_test.rb +0 -17
- data/test/vagrant/actions/box/download_test.rb +0 -137
- data/test/vagrant/actions/box/unpackage_test.rb +0 -99
- data/test/vagrant/actions/box/verify_test.rb +0 -44
- data/test/vagrant/actions/collection_test.rb +0 -113
- data/test/vagrant/actions/runner_test.rb +0 -268
- data/test/vagrant/actions/vm/boot_test.rb +0 -49
- data/test/vagrant/actions/vm/customize_test.rb +0 -21
- data/test/vagrant/actions/vm/destroy_test.rb +0 -37
- data/test/vagrant/actions/vm/down_test.rb +0 -39
- data/test/vagrant/actions/vm/export_test.rb +0 -88
- data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
- data/test/vagrant/actions/vm/halt_test.rb +0 -65
- data/test/vagrant/actions/vm/import_test.rb +0 -45
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
- data/test/vagrant/actions/vm/network_test.rb +0 -291
- data/test/vagrant/actions/vm/package_test.rb +0 -254
- data/test/vagrant/actions/vm/provision_test.rb +0 -99
- data/test/vagrant/actions/vm/reload_test.rb +0 -46
- data/test/vagrant/actions/vm/resume_test.rb +0 -26
- data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
- data/test/vagrant/actions/vm/start_test.rb +0 -73
- data/test/vagrant/actions/vm/suspend_test.rb +0 -26
- data/test/vagrant/actions/vm/up_test.rb +0 -96
- data/test/vagrant/active_list_test.rb +0 -173
- data/test/vagrant/box_test.rb +0 -154
- data/test/vagrant/busy_test.rb +0 -78
- data/test/vagrant/command_test.rb +0 -53
- data/test/vagrant/commands/base_test.rb +0 -139
- data/test/vagrant/commands/box/add_test.rb +0 -34
- data/test/vagrant/commands/box/list_test.rb +0 -32
- data/test/vagrant/commands/box/remove_test.rb +0 -41
- data/test/vagrant/commands/destroy_test.rb +0 -44
- data/test/vagrant/commands/halt_test.rb +0 -50
- data/test/vagrant/commands/init_test.rb +0 -55
- data/test/vagrant/commands/package_test.rb +0 -104
- data/test/vagrant/commands/provision_test.rb +0 -60
- data/test/vagrant/commands/reload_test.rb +0 -44
- data/test/vagrant/commands/resume_test.rb +0 -44
- data/test/vagrant/commands/ssh_config_test.rb +0 -77
- data/test/vagrant/commands/ssh_test.rb +0 -129
- data/test/vagrant/commands/status_test.rb +0 -40
- data/test/vagrant/commands/suspend_test.rb +0 -44
- data/test/vagrant/commands/up_test.rb +0 -47
- data/test/vagrant/config_test.rb +0 -287
- data/test/vagrant/downloaders/base_test.rb +0 -28
- data/test/vagrant/downloaders/file_test.rb +0 -33
- data/test/vagrant/downloaders/http_test.rb +0 -62
- data/test/vagrant/environment_test.rb +0 -770
- data/test/vagrant/provisioners/base_test.rb +0 -33
- data/test/vagrant/provisioners/chef_server_test.rb +0 -176
- data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
- data/test/vagrant/provisioners/chef_test.rb +0 -175
- data/test/vagrant/resource_logger_test.rb +0 -145
- data/test/vagrant/ssh_session_test.rb +0 -46
- data/test/vagrant/ssh_test.rb +0 -296
- data/test/vagrant/systems/linux_test.rb +0 -179
- data/test/vagrant/util/error_helper_test.rb +0 -5
- data/test/vagrant/util/output_helper_test.rb +0 -5
- data/test/vagrant/util/plain_logger_test.rb +0 -17
- data/test/vagrant/util/platform_test.rb +0 -18
- data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
- data/test/vagrant/util/template_renderer_test.rb +0 -144
- data/test/vagrant/util/translator_test.rb +0 -61
- data/test/vagrant/util_test.rb +0 -27
- data/test/vagrant/vm_test.rb +0 -235
- data/vagrant.gemspec +0 -291
@@ -1,145 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class ResourceLoggerTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@klass = Vagrant::ResourceLogger
|
6
|
-
end
|
7
|
-
|
8
|
-
context "singleton logger" do
|
9
|
-
setup do
|
10
|
-
@klass.reset_singleton_logger!
|
11
|
-
|
12
|
-
@result = mock("result")
|
13
|
-
end
|
14
|
-
|
15
|
-
should "return a nil plain logger if no environment is given" do
|
16
|
-
Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
|
17
|
-
assert_equal @result, @klass.singleton_logger
|
18
|
-
end
|
19
|
-
|
20
|
-
should "return a nil plain logger if the config is not loaded" do
|
21
|
-
env = mock_environment
|
22
|
-
env.config.stubs(:loaded?).returns(false)
|
23
|
-
|
24
|
-
Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
|
25
|
-
assert_equal @result, @klass.singleton_logger(env)
|
26
|
-
end
|
27
|
-
|
28
|
-
should "return a logger with the specified output if environment is ready" do
|
29
|
-
output = mock("output")
|
30
|
-
env = mock_environment
|
31
|
-
env.config.vagrant.log_output = output
|
32
|
-
|
33
|
-
Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
|
34
|
-
assert_equal @result, @klass.singleton_logger(env)
|
35
|
-
end
|
36
|
-
|
37
|
-
should "only load the logger once" do
|
38
|
-
output = mock("output")
|
39
|
-
env = mock_environment
|
40
|
-
env.config.vagrant.log_output = output
|
41
|
-
|
42
|
-
Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
|
43
|
-
assert_equal @result, @klass.singleton_logger(env)
|
44
|
-
assert_equal @result, @klass.singleton_logger(env)
|
45
|
-
assert_equal @result, @klass.singleton_logger(env)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "initialization" do
|
50
|
-
should "setup the logger and attributes" do
|
51
|
-
env = mock_environment
|
52
|
-
resource = mock("resource")
|
53
|
-
result = mock("result")
|
54
|
-
|
55
|
-
@klass.expects(:singleton_logger).with(env).returns(result)
|
56
|
-
instance = @klass.new(resource, env)
|
57
|
-
assert_equal resource, instance.resource
|
58
|
-
assert_equal env, instance.env
|
59
|
-
assert_equal result, instance.logger
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "with an instance" do
|
64
|
-
setup do
|
65
|
-
@resource = "foo"
|
66
|
-
@env = mock_environment
|
67
|
-
@logger = mock("logger")
|
68
|
-
|
69
|
-
@klass.stubs(:singleton_logger).returns(@logger)
|
70
|
-
@instance = @klass.new(@resource, @env)
|
71
|
-
end
|
72
|
-
|
73
|
-
context "logging methods" do
|
74
|
-
setup do
|
75
|
-
@instance.stubs(:flush_progress)
|
76
|
-
@instance.stubs(:cl_reset).returns("")
|
77
|
-
end
|
78
|
-
|
79
|
-
[:debug, :info, :error, :fatal].each do |method|
|
80
|
-
should "log with the proper format on #{method}" do
|
81
|
-
message = "bar"
|
82
|
-
@logger.expects(method).with("[#{@resource}] #{message}").once
|
83
|
-
@instance.send(method, message)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "reporting progress" do
|
89
|
-
setup do
|
90
|
-
@instance.stubs(:flush_progress)
|
91
|
-
end
|
92
|
-
|
93
|
-
should "flush progress" do
|
94
|
-
@instance.expects(:flush_progress).once
|
95
|
-
@instance.report_progress(72, 100)
|
96
|
-
end
|
97
|
-
|
98
|
-
should "add the reporter to the progress reporters" do
|
99
|
-
@instance.report_progress(72, 100)
|
100
|
-
assert @klass.progress_reporters.has_key?(@instance.resource)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "clearing progress" do
|
105
|
-
setup do
|
106
|
-
@instance.stubs(:flush_progress)
|
107
|
-
|
108
|
-
@klass.progress_reporters.clear
|
109
|
-
@instance.report_progress(72, 100)
|
110
|
-
end
|
111
|
-
|
112
|
-
should "remove the key from the reporters" do
|
113
|
-
assert @klass.progress_reporters.has_key?(@instance.resource)
|
114
|
-
@instance.clear_progress
|
115
|
-
assert !@klass.progress_reporters.has_key?(@instance.resource)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "command line reset" do
|
120
|
-
setup do
|
121
|
-
Mario::Platform.logger(nil)
|
122
|
-
end
|
123
|
-
|
124
|
-
context "on windows" do
|
125
|
-
setup do
|
126
|
-
Mario::Platform.forced = Mario::Platform::Windows7
|
127
|
-
end
|
128
|
-
|
129
|
-
should "just return \\r for the clear screen" do
|
130
|
-
assert_equal "\r", @instance.cl_reset
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context "on other platforms" do
|
135
|
-
setup do
|
136
|
-
Mario::Platform.forced = Mario::Platform::Linux
|
137
|
-
end
|
138
|
-
|
139
|
-
should "return the full clear screen" do
|
140
|
-
assert_equal "\r\e[0K", @instance.cl_reset
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class SshSessionTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@session = mock("session")
|
6
|
-
|
7
|
-
@klass = Vagrant::SSH::Session
|
8
|
-
@instance = @klass.new(@session)
|
9
|
-
end
|
10
|
-
|
11
|
-
context "exec!" do
|
12
|
-
should "retry 5 times" do
|
13
|
-
@session.expects(:open_channel).times(5).raises(IOError)
|
14
|
-
assert_raises(IOError) {
|
15
|
-
@instance.exec!("foo")
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "checking exit status" do
|
21
|
-
should "raise an ActionException if its non-zero" do
|
22
|
-
assert_raises(Vagrant::Actions::ActionException) {
|
23
|
-
@instance.check_exit_status(1, "foo")
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
should "raise the given exception if specified" do
|
28
|
-
options = {
|
29
|
-
:error_key => :foo,
|
30
|
-
:error_data => {}
|
31
|
-
}
|
32
|
-
result = Exception.new
|
33
|
-
Vagrant::Actions::ActionException.expects(:new).with(options[:error_key], options[:error_data]).once.returns(result)
|
34
|
-
|
35
|
-
assert_raises(Exception) {
|
36
|
-
@instance.check_exit_status(1, "foo", options)
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
should "raise nothing if its zero" do
|
41
|
-
assert_nothing_raised {
|
42
|
-
@instance.check_exit_status(0, "foo")
|
43
|
-
}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/test/vagrant/ssh_test.rb
DELETED
@@ -1,296 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class SshTest < Test::Unit::TestCase
|
4
|
-
def mock_ssh
|
5
|
-
@env = mock_environment do |config|
|
6
|
-
yield config if block_given?
|
7
|
-
end
|
8
|
-
|
9
|
-
@forwarded_ports = []
|
10
|
-
@network_adapters = []
|
11
|
-
@vm = mock("vm")
|
12
|
-
@vm.stubs(:network_adapters).returns(@network_adapters)
|
13
|
-
|
14
|
-
@env.stubs(:vm).returns(mock_vm(@env))
|
15
|
-
@env.vm.stubs(:vm).returns(@vm)
|
16
|
-
|
17
|
-
@ssh = Vagrant::SSH.new(@env)
|
18
|
-
end
|
19
|
-
|
20
|
-
setup do
|
21
|
-
VirtualBox.stubs(:version).returns("3.1.4")
|
22
|
-
end
|
23
|
-
|
24
|
-
context "connecting to external SSH" do
|
25
|
-
setup do
|
26
|
-
mock_ssh
|
27
|
-
@ssh.stubs(:check_key_permissions)
|
28
|
-
@ssh.stubs(:error_and_exit)
|
29
|
-
Kernel.stubs(:exec)
|
30
|
-
|
31
|
-
Vagrant::Util::Platform.stubs(:leopard?).returns(false)
|
32
|
-
end
|
33
|
-
|
34
|
-
should "check key permissions prior to exec" do
|
35
|
-
exec_seq = sequence("exec_seq")
|
36
|
-
@ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(exec_seq)
|
37
|
-
Kernel.expects(:exec).in_sequence(exec_seq)
|
38
|
-
@ssh.connect
|
39
|
-
end
|
40
|
-
|
41
|
-
should "call exec with defaults when no options are supplied" do
|
42
|
-
ssh_exec_expect(@ssh.port,
|
43
|
-
@env.config.ssh.private_key_path,
|
44
|
-
@env.config.ssh.username,
|
45
|
-
@env.config.ssh.host)
|
46
|
-
@ssh.connect
|
47
|
-
end
|
48
|
-
|
49
|
-
should "call exec with supplied params" do
|
50
|
-
args = {:username => 'bar', :private_key_path => 'baz', :host => 'bak', :port => 'bag'}
|
51
|
-
ssh_exec_expect(args[:port], args[:private_key_path], args[:username], args[:host])
|
52
|
-
@ssh.connect(args)
|
53
|
-
end
|
54
|
-
|
55
|
-
context "on leopard" do
|
56
|
-
setup do
|
57
|
-
Vagrant::Util::Platform.stubs(:leopard?).returns(true)
|
58
|
-
end
|
59
|
-
|
60
|
-
should "fork, exec, and wait" do
|
61
|
-
pid = mock("pid")
|
62
|
-
@ssh.expects(:fork).once.returns(pid)
|
63
|
-
Process.expects(:wait).with(pid)
|
64
|
-
|
65
|
-
@ssh.connect
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "checking windows" do
|
70
|
-
should "error and exit if the platform is windows" do
|
71
|
-
Mario::Platform.expects(:windows?).returns(true)
|
72
|
-
@ssh.expects(:error_and_exit).with do |error_name, opts|
|
73
|
-
opts[:key_path] && opts[:ssh_port]
|
74
|
-
end
|
75
|
-
@ssh.connect
|
76
|
-
end
|
77
|
-
|
78
|
-
should "not error and exit if the platform is anything other that windows" do
|
79
|
-
Mario::Platform.expects(:windows?).returns(false)
|
80
|
-
@ssh.expects(:error_and_exit).never
|
81
|
-
@ssh.connect
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def ssh_exec_expect(port, key_path, uname, host)
|
86
|
-
Kernel.expects(:exec).with() do |arg|
|
87
|
-
assert arg =~ /^ssh/
|
88
|
-
assert arg =~ /-p #{port}/
|
89
|
-
assert arg =~ /-i #{key_path}/
|
90
|
-
assert arg =~ /#{uname}@#{host}/
|
91
|
-
# TODO options not tested for as they may be removed
|
92
|
-
true
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "executing ssh commands" do
|
98
|
-
setup do
|
99
|
-
mock_ssh
|
100
|
-
@ssh.stubs(:check_key_permissions)
|
101
|
-
@ssh.stubs(:port).returns(80)
|
102
|
-
end
|
103
|
-
|
104
|
-
should "check key permissions then attempt to start connection" do
|
105
|
-
seq = sequence("seq")
|
106
|
-
@ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(seq)
|
107
|
-
Net::SSH.expects(:start).once.in_sequence(seq)
|
108
|
-
@ssh.execute
|
109
|
-
end
|
110
|
-
|
111
|
-
should "call net::ssh.start with the proper names" do
|
112
|
-
Net::SSH.expects(:start).once.with() do |host, username, opts|
|
113
|
-
assert_equal @env.config.ssh.host, host
|
114
|
-
assert_equal @env.config.ssh.username, username
|
115
|
-
assert_equal @ssh.port, opts[:port]
|
116
|
-
assert_equal [@env.config.ssh.private_key_path], opts[:keys]
|
117
|
-
true
|
118
|
-
end
|
119
|
-
@ssh.execute
|
120
|
-
end
|
121
|
-
|
122
|
-
should "use custom host if set" do
|
123
|
-
@env.config.ssh.host = "foo"
|
124
|
-
Net::SSH.expects(:start).with(@env.config.ssh.host, @env.config.ssh.username, anything).once
|
125
|
-
@ssh.execute
|
126
|
-
end
|
127
|
-
|
128
|
-
should "yield an SSH session object" do
|
129
|
-
raw = mock("raw")
|
130
|
-
Net::SSH.expects(:start).yields(raw)
|
131
|
-
@ssh.execute do |ssh|
|
132
|
-
assert ssh.is_a?(Vagrant::SSH::Session)
|
133
|
-
assert_equal raw, ssh.session
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "SCPing files to the remote host" do
|
139
|
-
setup do
|
140
|
-
mock_ssh
|
141
|
-
end
|
142
|
-
|
143
|
-
should "use Vagrant::SSH execute to setup an SCP connection and upload" do
|
144
|
-
scp = mock("scp")
|
145
|
-
ssh = mock("ssh")
|
146
|
-
sess = mock("session")
|
147
|
-
ssh.stubs(:session).returns(sess)
|
148
|
-
scp.expects(:upload!).with("foo", "bar").once
|
149
|
-
Net::SCP.expects(:new).with(ssh.session).returns(scp).once
|
150
|
-
@ssh.expects(:execute).yields(ssh).once
|
151
|
-
@ssh.upload!("foo", "bar")
|
152
|
-
end
|
153
|
-
|
154
|
-
should "retry 5 times" do
|
155
|
-
@ssh.expects(:execute).times(5).raises(IOError)
|
156
|
-
assert_raises(IOError) {
|
157
|
-
@ssh.upload!("foo", "bar")
|
158
|
-
}
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "checking if host is up" do
|
163
|
-
setup do
|
164
|
-
mock_ssh
|
165
|
-
@ssh.stubs(:check_key_permissions)
|
166
|
-
end
|
167
|
-
|
168
|
-
should "return true if SSH connection works" do
|
169
|
-
Net::SSH.expects(:start).yields("success")
|
170
|
-
assert @ssh.up?
|
171
|
-
end
|
172
|
-
|
173
|
-
should "return false if SSH connection times out" do
|
174
|
-
Net::SSH.expects(:start)
|
175
|
-
assert !@ssh.up?
|
176
|
-
end
|
177
|
-
|
178
|
-
should "allow the thread the configured timeout time" do
|
179
|
-
@thread = mock("thread")
|
180
|
-
@thread.stubs(:[])
|
181
|
-
Thread.expects(:new).returns(@thread)
|
182
|
-
@thread.expects(:join).with(@env.config.ssh.timeout).once
|
183
|
-
@ssh.up?
|
184
|
-
end
|
185
|
-
|
186
|
-
should "return false if the connection is refused" do
|
187
|
-
Net::SSH.expects(:start).raises(Errno::ECONNREFUSED)
|
188
|
-
assert_nothing_raised {
|
189
|
-
assert !@ssh.up?
|
190
|
-
}
|
191
|
-
end
|
192
|
-
|
193
|
-
should "return false if the connection is dropped" do
|
194
|
-
Net::SSH.expects(:start).raises(Net::SSH::Disconnect)
|
195
|
-
assert_nothing_raised {
|
196
|
-
assert !@ssh.up?
|
197
|
-
}
|
198
|
-
end
|
199
|
-
|
200
|
-
should "specifity the timeout as an option to execute" do
|
201
|
-
@ssh.expects(:execute).with(:timeout => @env.config.ssh.timeout).yields(true)
|
202
|
-
assert @ssh.up?
|
203
|
-
end
|
204
|
-
|
205
|
-
should "error and exit if a Net::SSH::AuthenticationFailed is raised" do
|
206
|
-
@ssh.expects(:execute).raises(Net::SSH::AuthenticationFailed)
|
207
|
-
@ssh.expects(:error_and_exit).with(:vm_ssh_auth_failed).once
|
208
|
-
@ssh.up?
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context "getting the ssh port" do
|
213
|
-
setup do
|
214
|
-
mock_ssh
|
215
|
-
end
|
216
|
-
|
217
|
-
should "return the port given in options if it exists" do
|
218
|
-
assert_equal "47", @ssh.port({ :port => "47" })
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context "checking key permissions" do
|
223
|
-
setup do
|
224
|
-
mock_ssh
|
225
|
-
@ssh.stubs(:file_perms)
|
226
|
-
|
227
|
-
@key_path = "foo"
|
228
|
-
|
229
|
-
|
230
|
-
@stat = mock("stat")
|
231
|
-
@stat.stubs(:owned?).returns(true)
|
232
|
-
File.stubs(:stat).returns(@stat)
|
233
|
-
|
234
|
-
Mario::Platform.stubs(:windows?).returns(false)
|
235
|
-
end
|
236
|
-
|
237
|
-
should "do nothing if on windows" do
|
238
|
-
Mario::Platform.stubs(:windows?).returns(true)
|
239
|
-
File.expects(:stat).never
|
240
|
-
@ssh.check_key_permissions(@key_path)
|
241
|
-
end
|
242
|
-
|
243
|
-
should "do nothing if the user is not the owner" do
|
244
|
-
@stat.expects(:owned?).returns(false)
|
245
|
-
File.expects(:chmod).never
|
246
|
-
@ssh.check_key_permissions(@key_path)
|
247
|
-
end
|
248
|
-
|
249
|
-
should "do nothing if the file perms equal 600" do
|
250
|
-
@ssh.expects(:file_perms).with(@key_path).returns("600")
|
251
|
-
File.expects(:chmod).never
|
252
|
-
@ssh.check_key_permissions(@key_path)
|
253
|
-
end
|
254
|
-
|
255
|
-
should "chmod the file if the file perms aren't 600" do
|
256
|
-
perm_sequence = sequence("perm_seq")
|
257
|
-
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
258
|
-
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
259
|
-
@ssh.expects(:file_perms).returns("600").in_sequence(perm_sequence)
|
260
|
-
@ssh.expects(:error_and_exit).never
|
261
|
-
@ssh.check_key_permissions(@key_path)
|
262
|
-
end
|
263
|
-
|
264
|
-
should "error and exit if the resulting chmod doesn't work" do
|
265
|
-
perm_sequence = sequence("perm_seq")
|
266
|
-
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
267
|
-
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
268
|
-
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
269
|
-
@ssh.expects(:error_and_exit).once.with(:ssh_bad_permissions, :key_path => @key_path).in_sequence(perm_sequence)
|
270
|
-
@ssh.check_key_permissions(@key_path)
|
271
|
-
end
|
272
|
-
|
273
|
-
should "error and exit if a bad file perm is raised" do
|
274
|
-
@ssh.expects(:file_perms).with(@key_path).returns("900")
|
275
|
-
File.expects(:chmod).raises(Errno::EPERM)
|
276
|
-
@ssh.expects(:error_and_exit).once.with(:ssh_bad_permissions, :key_path => @key_path)
|
277
|
-
@ssh.check_key_permissions(@key_path)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
context "getting file permissions" do
|
282
|
-
setup do
|
283
|
-
mock_ssh
|
284
|
-
end
|
285
|
-
|
286
|
-
should "return the last 3 characters of the file mode" do
|
287
|
-
path = "foo"
|
288
|
-
mode = "10000foo"
|
289
|
-
stat = mock("stat")
|
290
|
-
File.expects(:stat).with(path).returns(stat)
|
291
|
-
stat.expects(:mode).returns(mode)
|
292
|
-
@ssh.expects(:sprintf).with("%o", mode).returns(mode)
|
293
|
-
assert_equal path, @ssh.file_perms(path)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|