vagrantup 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/config/default.rb +13 -3
- data/lib/vagrant.rb +10 -13
- data/lib/vagrant/actions/base.rb +14 -2
- data/lib/vagrant/actions/box/download.rb +2 -7
- data/lib/vagrant/actions/box/verify.rb +1 -1
- data/lib/vagrant/actions/runner.rb +0 -1
- data/lib/vagrant/actions/vm/boot.rb +2 -6
- data/lib/vagrant/actions/vm/customize.rb +7 -5
- data/lib/vagrant/actions/vm/destroy.rb +4 -3
- data/lib/vagrant/actions/vm/down.rb +6 -3
- data/lib/vagrant/actions/vm/export.rb +2 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +77 -16
- data/lib/vagrant/actions/vm/halt.rb +10 -2
- data/lib/vagrant/actions/vm/import.rb +2 -4
- data/lib/vagrant/actions/vm/move_hard_drive.rb +2 -2
- data/lib/vagrant/actions/vm/network.rb +120 -0
- data/lib/vagrant/actions/vm/package.rb +11 -7
- data/lib/vagrant/actions/vm/provision.rb +3 -3
- data/lib/vagrant/actions/vm/reload.rb +2 -9
- data/lib/vagrant/actions/vm/shared_folders.rb +19 -39
- data/lib/vagrant/actions/vm/start.rb +10 -2
- data/lib/vagrant/actions/vm/up.rb +5 -6
- data/lib/vagrant/active_list.rb +23 -13
- data/lib/vagrant/box.rb +2 -2
- data/lib/vagrant/busy.rb +3 -3
- data/lib/vagrant/command.rb +2 -2
- data/lib/vagrant/commands/base.rb +40 -20
- data/lib/vagrant/commands/destroy.rb +17 -3
- data/lib/vagrant/commands/halt.rb +23 -3
- data/lib/vagrant/commands/package.rb +54 -14
- data/lib/vagrant/commands/provision.rb +31 -0
- data/lib/vagrant/commands/reload.rb +16 -3
- data/lib/vagrant/commands/resume.rb +16 -3
- data/lib/vagrant/commands/ssh.rb +25 -3
- data/lib/vagrant/commands/ssh_config.rb +20 -5
- data/lib/vagrant/commands/status.rb +107 -40
- data/lib/vagrant/commands/suspend.rb +16 -3
- data/lib/vagrant/commands/up.rb +26 -7
- data/lib/vagrant/config.rb +82 -12
- data/lib/vagrant/downloaders/base.rb +8 -1
- data/lib/vagrant/downloaders/http.rb +31 -19
- data/lib/vagrant/environment.rb +146 -49
- data/lib/vagrant/provisioners/base.rb +19 -5
- data/lib/vagrant/provisioners/chef.rb +12 -4
- data/lib/vagrant/provisioners/chef_server.rb +13 -6
- data/lib/vagrant/provisioners/chef_solo.rb +7 -3
- data/lib/vagrant/resource_logger.rb +126 -0
- data/lib/vagrant/ssh.rb +109 -8
- data/lib/vagrant/systems/base.rb +70 -0
- data/lib/vagrant/systems/linux.rb +137 -0
- data/lib/vagrant/util.rb +1 -45
- data/lib/vagrant/util/error_helper.rb +13 -0
- data/lib/vagrant/util/glob_loader.rb +22 -0
- data/lib/vagrant/util/output_helper.rb +9 -0
- data/lib/vagrant/util/plain_logger.rb +12 -0
- data/lib/vagrant/util/platform.rb +7 -2
- data/lib/vagrant/util/template_renderer.rb +2 -2
- data/lib/vagrant/util/translator.rb +35 -0
- data/lib/vagrant/vm.rb +91 -10
- data/templates/crontab_entry.erb +1 -0
- data/templates/network_entry.erb +8 -0
- data/templates/ssh_config.erb +1 -0
- data/templates/{errors.yml → strings.yml} +111 -3
- data/templates/sync.erb +14 -0
- data/test/test_helper.rb +46 -3
- data/test/vagrant/actions/box/download_test.rb +0 -17
- data/test/vagrant/actions/vm/boot_test.rb +3 -10
- data/test/vagrant/actions/vm/customize_test.rb +6 -0
- data/test/vagrant/actions/vm/destroy_test.rb +6 -5
- data/test/vagrant/actions/vm/down_test.rb +5 -11
- data/test/vagrant/actions/vm/export_test.rb +1 -0
- data/test/vagrant/actions/vm/forward_ports_test.rb +92 -15
- data/test/vagrant/actions/vm/halt_test.rb +36 -4
- data/test/vagrant/actions/vm/import_test.rb +2 -0
- data/test/vagrant/actions/vm/network_test.rb +237 -0
- data/test/vagrant/actions/vm/package_test.rb +35 -5
- data/test/vagrant/actions/vm/provision_test.rb +3 -3
- data/test/vagrant/actions/vm/reload_test.rb +1 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +41 -74
- data/test/vagrant/actions/vm/start_test.rb +41 -3
- data/test/vagrant/actions/vm/up_test.rb +10 -21
- data/test/vagrant/active_list_test.rb +28 -43
- data/test/vagrant/commands/base_test.rb +25 -4
- data/test/vagrant/commands/destroy_test.rb +24 -12
- data/test/vagrant/commands/halt_test.rb +33 -11
- data/test/vagrant/commands/package_test.rb +77 -57
- data/test/vagrant/commands/provision_test.rb +50 -0
- data/test/vagrant/commands/reload_test.rb +27 -11
- data/test/vagrant/commands/resume_test.rb +25 -14
- data/test/vagrant/commands/ssh_config_test.rb +40 -17
- data/test/vagrant/commands/ssh_test.rb +52 -13
- data/test/vagrant/commands/status_test.rb +21 -1
- data/test/vagrant/commands/suspend_test.rb +25 -14
- data/test/vagrant/commands/up_test.rb +25 -19
- data/test/vagrant/config_test.rb +74 -18
- data/test/vagrant/downloaders/base_test.rb +2 -1
- data/test/vagrant/downloaders/http_test.rb +18 -8
- data/test/vagrant/environment_test.rb +245 -77
- data/test/vagrant/provisioners/base_test.rb +4 -4
- data/test/vagrant/provisioners/chef_server_test.rb +18 -7
- data/test/vagrant/provisioners/chef_solo_test.rb +17 -7
- data/test/vagrant/provisioners/chef_test.rb +22 -9
- data/test/vagrant/resource_logger_test.rb +144 -0
- data/test/vagrant/ssh_session_test.rb +46 -0
- data/test/vagrant/ssh_test.rb +42 -2
- data/test/vagrant/systems/linux_test.rb +174 -0
- data/test/vagrant/util/error_helper_test.rb +5 -0
- data/test/vagrant/util/output_helper_test.rb +5 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/{errors_test.rb → translator_test.rb} +25 -21
- data/test/vagrant/util_test.rb +12 -49
- data/test/vagrant/vm_test.rb +133 -11
- data/vagrant.gemspec +39 -15
- metadata +38 -14
- data/lib/vagrant/commands/down.rb +0 -16
- data/lib/vagrant/util/errors.rb +0 -36
- data/lib/vagrant/util/progress_meter.rb +0 -33
- data/test/vagrant/commands/down_test.rb +0 -17
- data/test/vagrant/util/progress_meter_test.rb +0 -33
@@ -3,25 +3,57 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class HaltActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Halt)
|
6
|
+
@runner.stubs(:system).returns(linux_system(@vm))
|
7
|
+
end
|
8
|
+
|
9
|
+
context "force?" do
|
10
|
+
should "not force by default" do
|
11
|
+
@action.options[:force] = nil
|
12
|
+
assert !@action.force?
|
13
|
+
end
|
14
|
+
|
15
|
+
should "force if specified" do
|
16
|
+
@action.options[:force] = true
|
17
|
+
assert @action.force?
|
18
|
+
end
|
6
19
|
end
|
7
20
|
|
8
21
|
context "executing" do
|
9
22
|
setup do
|
10
23
|
@vm.stubs(:running?).returns(true)
|
24
|
+
|
25
|
+
@runner.system.stubs(:halt)
|
26
|
+
@vm.stubs(:stop)
|
27
|
+
@vm.stubs(:state).returns(:powered_off)
|
11
28
|
end
|
12
29
|
|
13
30
|
should "invoke the 'halt' around callback" do
|
14
|
-
|
15
|
-
@runner.expects(:invoke_around_callback).with(:halt).once.in_sequence(halt_seq).yields
|
16
|
-
@vm.expects(:stop).in_sequence(halt_seq)
|
31
|
+
@runner.expects(:invoke_around_callback).with(:halt).once
|
17
32
|
@action.execute!
|
18
33
|
end
|
19
34
|
|
20
|
-
should "
|
35
|
+
should "halt with the system and NOT force VM to stop if powered off" do
|
36
|
+
@vm.expects(:state).with(true).returns(:powered_off)
|
37
|
+
|
38
|
+
@runner.system.expects(:halt).once
|
39
|
+
@vm.expects(:stop).never
|
40
|
+
@action.execute!
|
41
|
+
end
|
42
|
+
|
43
|
+
should "halt with the system and force VM to stop if NOT powered off" do
|
44
|
+
@vm.expects(:state).with(true).returns(:running)
|
45
|
+
|
46
|
+
@runner.system.expects(:halt).once
|
21
47
|
@vm.expects(:stop).once
|
22
48
|
@action.execute!
|
23
49
|
end
|
24
50
|
|
51
|
+
should "not call halt on the system if forcing" do
|
52
|
+
@action.stubs(:force).returns(true)
|
53
|
+
@runner.system.expects(:halt).never
|
54
|
+
@action.execute!
|
55
|
+
end
|
56
|
+
|
25
57
|
should "raise an ActionException if VM is not running" do
|
26
58
|
@vm.stubs(:running?).returns(false)
|
27
59
|
@vm.expects(:stop).never
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class NetworkTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Network)
|
6
|
+
@runner.stubs(:system).returns(linux_system(@vm))
|
7
|
+
end
|
8
|
+
|
9
|
+
context "before destroy" do
|
10
|
+
setup do
|
11
|
+
@network_adapters = []
|
12
|
+
@vm.stubs(:network_adapters).returns(@network_adapters)
|
13
|
+
end
|
14
|
+
|
15
|
+
def stub_interface(length=5)
|
16
|
+
interface = mock("interface")
|
17
|
+
adapter = mock("adapter")
|
18
|
+
adapter.stubs(:host_interface_object).returns(interface)
|
19
|
+
interface.stubs(:attached_vms).returns(Array.new(length))
|
20
|
+
|
21
|
+
@network_adapters << adapter
|
22
|
+
interface
|
23
|
+
end
|
24
|
+
|
25
|
+
should "destroy only the unused network interfaces" do
|
26
|
+
stub_interface(5)
|
27
|
+
stub_interface(7)
|
28
|
+
results = [stub_interface(1), stub_interface(1)]
|
29
|
+
|
30
|
+
results.each do |result|
|
31
|
+
result.expects(:destroy).once
|
32
|
+
end
|
33
|
+
|
34
|
+
@action.before_destroy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "before boot" do
|
39
|
+
setup do
|
40
|
+
@action.stubs(:enable_network?).returns(false)
|
41
|
+
end
|
42
|
+
|
43
|
+
should "do nothing if network should not be enabled" do
|
44
|
+
@action.expects(:assign_network).never
|
45
|
+
@action.before_boot
|
46
|
+
end
|
47
|
+
|
48
|
+
should "assign the network if host only networking is enabled" do
|
49
|
+
@action.stubs(:enable_network?).returns(true)
|
50
|
+
@action.expects(:assign_network).once
|
51
|
+
@action.before_boot
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "after boot" do
|
56
|
+
setup do
|
57
|
+
@runner.env.config.vm.network("foo")
|
58
|
+
@action.stubs(:enable_network?).returns(true)
|
59
|
+
end
|
60
|
+
|
61
|
+
should "prepare the host only network, then enable them" do
|
62
|
+
run_seq = sequence("run")
|
63
|
+
@runner.system.expects(:prepare_host_only_network).once.in_sequence(run_seq)
|
64
|
+
@runner.system.expects(:enable_host_only_network).once.in_sequence(run_seq)
|
65
|
+
@action.after_boot
|
66
|
+
end
|
67
|
+
|
68
|
+
should "do nothing if network is not enabled" do
|
69
|
+
@action.stubs(:enable_network?).returns(false)
|
70
|
+
@runner.system.expects(:prepare_host_only_network).never
|
71
|
+
@action.after_boot
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "checking if network is enabled" do
|
76
|
+
should "return true if the network options are set" do
|
77
|
+
@runner.env.config.vm.network("foo")
|
78
|
+
assert @action.enable_network?
|
79
|
+
end
|
80
|
+
|
81
|
+
should "return false if the network was not set" do
|
82
|
+
assert !@action.enable_network?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "assigning the network" do
|
87
|
+
setup do
|
88
|
+
@network_name = "foo"
|
89
|
+
@action.stubs(:network_name).returns(@network_name)
|
90
|
+
|
91
|
+
@network_adapters = []
|
92
|
+
@vm.stubs(:network_adapters).returns(@network_adapters)
|
93
|
+
|
94
|
+
@options = {
|
95
|
+
:ip => "foo",
|
96
|
+
:adapter => 7
|
97
|
+
}
|
98
|
+
|
99
|
+
@runner.env.config.vm.network(@options[:ip], @options)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "setup the specified network adapter" do
|
103
|
+
adapter = mock("adapter")
|
104
|
+
@network_adapters[@options[:adapter]] = adapter
|
105
|
+
|
106
|
+
adapter.expects(:enabled=).with(true).once
|
107
|
+
adapter.expects(:attachment_type=).with(:host_only).once
|
108
|
+
adapter.expects(:host_interface=).with(@network_name).once
|
109
|
+
adapter.expects(:save).once
|
110
|
+
|
111
|
+
@action.assign_network
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "network name" do
|
116
|
+
setup do
|
117
|
+
@interfaces = []
|
118
|
+
VirtualBox::Global.global.host.stubs(:network_interfaces).returns(@interfaces)
|
119
|
+
|
120
|
+
@action.stubs(:matching_network?).returns(false)
|
121
|
+
|
122
|
+
@options = { :ip => :foo, :netmask => :bar, :name => nil }
|
123
|
+
end
|
124
|
+
|
125
|
+
should "return the network which matches" do
|
126
|
+
result = mock("result")
|
127
|
+
interface = mock("interface")
|
128
|
+
interface.stubs(:name).returns(result)
|
129
|
+
@interfaces << interface
|
130
|
+
|
131
|
+
@action.expects(:matching_network?).with(interface, @options).returns(true)
|
132
|
+
assert_equal result, @action.network_name(@options)
|
133
|
+
end
|
134
|
+
|
135
|
+
should "return the network which matches the name if given" do
|
136
|
+
@options[:name] = "foo"
|
137
|
+
|
138
|
+
interface = mock("interface")
|
139
|
+
interface.stubs(:name).returns(@options[:name])
|
140
|
+
@interfaces << interface
|
141
|
+
|
142
|
+
assert_equal @options[:name], @action.network_name(@options)
|
143
|
+
end
|
144
|
+
|
145
|
+
should "error and exit if the given network name is not found" do
|
146
|
+
@options[:name] = "foo"
|
147
|
+
|
148
|
+
@interfaces.expects(:create).never
|
149
|
+
|
150
|
+
assert_raises(Vagrant::Actions::ActionException) {
|
151
|
+
@action.network_name(@options)
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
should "create a network for the IP and netmask" do
|
156
|
+
result = mock("result")
|
157
|
+
interface = mock("interface")
|
158
|
+
network_ip = :foo
|
159
|
+
@interfaces.expects(:create).returns(interface)
|
160
|
+
@action.expects(:network_ip).with(@options[:ip], @options[:netmask]).once.returns(network_ip)
|
161
|
+
interface.expects(:enable_static).with(network_ip, @options[:netmask])
|
162
|
+
interface.expects(:name).returns(result)
|
163
|
+
|
164
|
+
assert_equal result, @action.network_name(@options)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "checking for a matching network" do
|
169
|
+
setup do
|
170
|
+
@interface = mock("interface")
|
171
|
+
@interface.stubs(:network_mask).returns("foo")
|
172
|
+
@interface.stubs(:ip_address).returns("192.168.0.1")
|
173
|
+
|
174
|
+
@options = {
|
175
|
+
:netmask => "foo",
|
176
|
+
:ip => "baz"
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
should "return false if the netmasks don't match" do
|
181
|
+
@options[:netmask] = "bar"
|
182
|
+
assert @interface.network_mask != @options[:netmask] # sanity
|
183
|
+
assert !@action.matching_network?(@interface, @options)
|
184
|
+
end
|
185
|
+
|
186
|
+
should "return true if the netmasks yield the same IP" do
|
187
|
+
tests = [["255.255.255.0", "192.168.0.1", "192.168.0.45"],
|
188
|
+
["255.255.0.0", "192.168.45.1", "192.168.28.7"]]
|
189
|
+
|
190
|
+
tests.each do |netmask, interface_ip, guest_ip|
|
191
|
+
@options[:netmask] = netmask
|
192
|
+
@options[:ip] = guest_ip
|
193
|
+
@interface.stubs(:network_mask).returns(netmask)
|
194
|
+
@interface.stubs(:ip_address).returns(interface_ip)
|
195
|
+
|
196
|
+
assert @action.matching_network?(@interface, @options)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "applying the netmask" do
|
202
|
+
should "return the proper result" do
|
203
|
+
tests = {
|
204
|
+
["192.168.0.1","255.255.255.0"] => [192,168,0,0],
|
205
|
+
["192.168.45.10","255.255.255.0"] => [192,168,45,0]
|
206
|
+
}
|
207
|
+
|
208
|
+
tests.each do |k,v|
|
209
|
+
assert_equal v, @action.apply_netmask(*k)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "splitting an IP" do
|
215
|
+
should "return the proper result" do
|
216
|
+
tests = {
|
217
|
+
"192.168.0.1" => [192,168,0,1]
|
218
|
+
}
|
219
|
+
|
220
|
+
tests.each do |k,v|
|
221
|
+
assert_equal v, @action.split_ip(k)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context "network IP" do
|
227
|
+
should "return the proper result" do
|
228
|
+
tests = {
|
229
|
+
["192.168.0.45", "255.255.255.0"] => "192.168.0.1"
|
230
|
+
}
|
231
|
+
|
232
|
+
tests.each do |args, result|
|
233
|
+
assert_equal result, @action.network_ip(*args)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -2,12 +2,15 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class PackageActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package)
|
6
6
|
end
|
7
7
|
|
8
8
|
context "initialization" do
|
9
|
-
def get_action(
|
10
|
-
runner, vm, action = mock_action(Vagrant::Actions::VM::Package,
|
9
|
+
def get_action(output, include_files)
|
10
|
+
runner, vm, action = mock_action(Vagrant::Actions::VM::Package, {
|
11
|
+
:output => output,
|
12
|
+
:include => include_files
|
13
|
+
})
|
11
14
|
return action
|
12
15
|
end
|
13
16
|
|
@@ -35,6 +38,31 @@ class PackageActionTest < Test::Unit::TestCase
|
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
41
|
+
context "out path" do
|
42
|
+
should "be the specified output file if given" do
|
43
|
+
result = mock("result")
|
44
|
+
@action.options[:output] = result
|
45
|
+
assert_equal result, @action.out_path
|
46
|
+
end
|
47
|
+
|
48
|
+
should "default to 'package'" do
|
49
|
+
@action.options[:output] = nil
|
50
|
+
assert_equal "package", @action.out_path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "include files" do
|
55
|
+
should "specified array if given" do
|
56
|
+
@action.options[:include] = [1,2,3]
|
57
|
+
assert_equal @action.options[:include], @action.include_files
|
58
|
+
end
|
59
|
+
|
60
|
+
should "be an empty array by default" do
|
61
|
+
@action.options[:include] = nil
|
62
|
+
assert_equal [], @action.include_files
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
38
66
|
context "tar path" do
|
39
67
|
should "be the temporary directory with the name and extension attached" do
|
40
68
|
pwd = "foo"
|
@@ -138,7 +166,7 @@ class PackageActionTest < Test::Unit::TestCase
|
|
138
166
|
end
|
139
167
|
|
140
168
|
should "open the tar file with the tar path properly" do
|
141
|
-
File.expects(:open).with(@tar_path,
|
169
|
+
File.expects(:open).with(@tar_path, Vagrant::Util::Platform.tar_file_options).once
|
142
170
|
@action.compress
|
143
171
|
end
|
144
172
|
|
@@ -185,7 +213,9 @@ class PackageActionTest < Test::Unit::TestCase
|
|
185
213
|
context "checking include files" do
|
186
214
|
setup do
|
187
215
|
@include_files = ['fooiest', 'booiest']
|
188
|
-
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package,
|
216
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, {
|
217
|
+
:include => @include_files
|
218
|
+
})
|
189
219
|
@runner.stubs(:find_action).returns("foo")
|
190
220
|
end
|
191
221
|
|
@@ -44,13 +44,13 @@ class ProvisionActionTest < Test::Unit::TestCase
|
|
44
44
|
@instance.stubs(:prepare)
|
45
45
|
@klass = mock("klass")
|
46
46
|
@klass.stubs(:is_a?).with(Class).returns(true)
|
47
|
-
@klass.stubs(:new).with(@runner
|
47
|
+
@klass.stubs(:new).with(@runner).returns(@instance)
|
48
48
|
|
49
49
|
@runner.env.config.vm.provisioner = @klass
|
50
50
|
end
|
51
51
|
|
52
52
|
should "set the provisioner to an instantiation of the class" do
|
53
|
-
@klass.expects(:new).with(@runner
|
53
|
+
@klass.expects(:new).with(@runner).once.returns(@instance)
|
54
54
|
assert_nothing_raised { @action.prepare }
|
55
55
|
assert_equal @instance, @action.provisioner
|
56
56
|
end
|
@@ -74,7 +74,7 @@ class ProvisionActionTest < Test::Unit::TestCase
|
|
74
74
|
|
75
75
|
instance = mock("instance")
|
76
76
|
instance.expects(:prepare).once
|
77
|
-
provisioner.expects(:new).with(@runner
|
77
|
+
provisioner.expects(:new).with(@runner).returns(instance)
|
78
78
|
assert_nothing_raised { @action.prepare }
|
79
79
|
assert_equal instance, @action.provisioner
|
80
80
|
end
|
@@ -7,7 +7,7 @@ class ReloadActionTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
context "sub-actions" do
|
9
9
|
setup do
|
10
|
-
@default_order = [Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
10
|
+
@default_order = [Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Network, Vagrant::Actions::VM::Boot]
|
11
11
|
@vm.stubs(:running?).returns(false)
|
12
12
|
end
|
13
13
|
|
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class SharedFoldersActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
|
6
|
+
@runner.stubs(:system).returns(linux_system(@vm))
|
6
7
|
end
|
7
8
|
|
8
9
|
def stub_shared_folders
|
@@ -26,19 +27,14 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
26
27
|
end
|
27
28
|
|
28
29
|
should "convert the vagrant config values into an array" do
|
29
|
-
|
30
|
-
config.vm.shared_folders.clear
|
31
|
-
config.vm.share_folder("foo", "bar", "baz")
|
32
|
-
end
|
33
|
-
|
34
|
-
@runner.expects(:env).returns(env)
|
30
|
+
mock_env_shared_folders
|
35
31
|
|
36
32
|
result = [["foo", "baz", "bar"]]
|
37
33
|
assert_equal result, @action.shared_folders
|
38
34
|
end
|
39
35
|
|
40
36
|
should "expand the path of the host folder" do
|
41
|
-
File.expects(:expand_path).with("baz").once.returns("expanded_baz")
|
37
|
+
File.expects(:expand_path).with("baz", @runner.env.root_path).once.returns("expanded_baz")
|
42
38
|
|
43
39
|
env = mock_environment do |config|
|
44
40
|
config.vm.shared_folders.clear
|
@@ -50,6 +46,23 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
50
46
|
result = [["foo", "expanded_baz", "bar"]]
|
51
47
|
assert_equal result, @action.shared_folders
|
52
48
|
end
|
49
|
+
|
50
|
+
context "with sync" do
|
51
|
+
should "append the sync value to the other config values" do
|
52
|
+
mock_env_shared_folders(:sync => true)
|
53
|
+
|
54
|
+
assert_equal [["foo", "baz", "bar-sync", "bar"]], @action.shared_folders
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def mock_env_shared_folders(opts={})
|
59
|
+
env = mock_environment do |config|
|
60
|
+
config.vm.shared_folders.clear
|
61
|
+
config.vm.share_folder("foo", "bar", "baz", opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
@runner.expects(:env).returns(env)
|
65
|
+
end
|
53
66
|
end
|
54
67
|
|
55
68
|
context "clearing shared folders" do
|
@@ -68,6 +81,12 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
68
81
|
@runner.expects(:reload!).once.in_sequence(destroy_seq)
|
69
82
|
@action.clear_shared_folders
|
70
83
|
end
|
84
|
+
|
85
|
+
should "do nothing if no shared folders existed" do
|
86
|
+
@shared_folders.clear
|
87
|
+
@runner.expects(:reload!).never
|
88
|
+
@action.clear_shared_folders
|
89
|
+
end
|
71
90
|
end
|
72
91
|
|
73
92
|
context "setting up shared folder metadata" do
|
@@ -90,86 +109,34 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
90
109
|
context "mounting the shared folders" do
|
91
110
|
setup do
|
92
111
|
@folders = stub_shared_folders
|
112
|
+
@ssh = mock("ssh")
|
113
|
+
@runner.ssh.stubs(:execute).yields(@ssh)
|
114
|
+
@runner.system.stubs(:mount_shared_folder)
|
93
115
|
end
|
94
116
|
|
95
117
|
should "mount all shared folders to the VM" do
|
96
118
|
mount_seq = sequence("mount_seq")
|
97
|
-
ssh = mock("ssh")
|
98
119
|
@folders.each do |name, hostpath, guestpath|
|
99
|
-
|
100
|
-
@action.expects(:mount_folder).with(ssh, name, guestpath).in_sequence(mount_seq)
|
101
|
-
ssh.expects(:exec!).with("sudo chown #{@runner.env.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
|
120
|
+
@runner.system.expects(:mount_shared_folder).with(@ssh, name, guestpath).in_sequence(mount_seq)
|
102
121
|
end
|
103
|
-
@runner.env.ssh.expects(:execute).yields(ssh)
|
104
122
|
|
105
123
|
@action.after_boot
|
106
124
|
end
|
107
|
-
end
|
108
125
|
|
109
|
-
|
110
|
-
|
111
|
-
@
|
112
|
-
|
113
|
-
@guestpath = "bar"
|
114
|
-
@sleeptime = 0
|
115
|
-
@limit = 10
|
116
|
-
|
117
|
-
@success_return = false
|
118
|
-
end
|
119
|
-
|
120
|
-
def mount_folder
|
121
|
-
@action.mount_folder(@ssh, @name, @guestpath, @sleeptime)
|
122
|
-
end
|
123
|
-
|
124
|
-
should "execute the proper mount command" do
|
125
|
-
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{@runner.env.config.ssh.username},gid=#{@runner.env.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
|
126
|
-
mount_folder
|
127
|
-
end
|
128
|
-
|
129
|
-
should "test type of text and text string to detect error" do
|
130
|
-
data = mock("data")
|
131
|
-
data.expects(:[]=).with(:result, !@success_return)
|
132
|
-
|
133
|
-
@ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return)
|
134
|
-
mount_folder
|
135
|
-
end
|
136
|
-
|
137
|
-
should "test type of text and test string to detect success" do
|
138
|
-
data = mock("data")
|
139
|
-
data.expects(:[]=).with(:result, @success_return)
|
140
|
-
|
141
|
-
@ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return)
|
142
|
-
mount_folder
|
143
|
-
end
|
144
|
-
|
145
|
-
should "raise an ActionException if the command fails constantly" do
|
146
|
-
@ssh.expects(:exec!).times(@limit).returns(!@success_return)
|
147
|
-
|
148
|
-
assert_raises(Vagrant::Actions::ActionException) {
|
149
|
-
mount_folder
|
150
|
-
}
|
151
|
-
end
|
152
|
-
|
153
|
-
should "not raise any exception if the command succeeded" do
|
154
|
-
@ssh.expects(:exec!).once.returns(@success_return)
|
155
|
-
|
156
|
-
assert_nothing_raised {
|
157
|
-
mount_folder
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
|
-
should "add uid AND gid to mount" do
|
162
|
-
uid = "foo"
|
163
|
-
gid = "bar"
|
164
|
-
env = mock_environment do |config|
|
165
|
-
config.vm.shared_folder_uid = uid
|
166
|
-
config.vm.shared_folder_gid = gid
|
126
|
+
should "execute the necessary rysnc commands for each sync folder" do
|
127
|
+
@folders.map { |f| f << 'sync' }
|
128
|
+
@folders.each do |name, hostpath, guestpath, syncd|
|
129
|
+
@runner.system.expects(:create_sync).with(@ssh, :syncpath => syncd, :guestpath => guestpath)
|
167
130
|
end
|
131
|
+
@runner.ssh.expects(:execute).yields(@ssh)
|
168
132
|
|
169
|
-
@
|
133
|
+
@action.after_boot
|
134
|
+
end
|
135
|
+
end
|
170
136
|
|
171
|
-
|
172
|
-
|
137
|
+
context "with syncd folders" do
|
138
|
+
# TODO prevented by odd configuration swapping when stubbing ssh.execute
|
139
|
+
should "prepare the system for sync if necessary" do
|
173
140
|
end
|
174
141
|
end
|
175
142
|
end
|