vagrant 0.3.4 → 0.4.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.
- 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 +64 -40
- 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
data/templates/sync.erb
ADDED
data/test/test_helper.rb
CHANGED
@@ -24,10 +24,11 @@ class Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
Vagrant::Config.run do |config|
|
26
26
|
config.vagrant.dotfile_name = ".vagrant"
|
27
|
+
config.vagrant.log_output = nil
|
27
28
|
|
28
29
|
config.ssh.username = "foo"
|
29
|
-
config.ssh.password = "bar"
|
30
30
|
config.ssh.host = "baz"
|
31
|
+
config.ssh.port = 22
|
31
32
|
config.ssh.forwarded_port_key = "ssh"
|
32
33
|
config.ssh.max_tries = 10
|
33
34
|
config.ssh.timeout = 10
|
@@ -36,11 +37,14 @@ class Test::Unit::TestCase
|
|
36
37
|
config.vm.box = "foo"
|
37
38
|
config.vm.box_ovf = "box.ovf"
|
38
39
|
config.vm.base_mac = "42"
|
39
|
-
config.vm.project_directory = "/vagrant"
|
40
40
|
config.vm.disk_image_format = 'VMDK'
|
41
41
|
config.vm.forward_port("ssh", 22, 2222)
|
42
42
|
config.vm.shared_folder_uid = nil
|
43
43
|
config.vm.shared_folder_gid = nil
|
44
|
+
config.vm.system = :linux
|
45
|
+
config.vm.sync_script = "/foo"
|
46
|
+
config.vm.sync_crontab_entry_file = "/tmp/foo"
|
47
|
+
config.vm.share_folder("v-root", "/vagrant", ".")
|
44
48
|
|
45
49
|
config.package.name = 'vagrant'
|
46
50
|
config.package.extension = '.box'
|
@@ -69,9 +73,26 @@ class Test::Unit::TestCase
|
|
69
73
|
config = Vagrant::Config.execute!
|
70
74
|
|
71
75
|
environment.instance_variable_set(:@config, config)
|
76
|
+
|
77
|
+
# Setup the logger. We create it then reset it so that subsequent
|
78
|
+
# calls will recreate it for us.
|
79
|
+
environment.load_logger!
|
80
|
+
environment.logger.class.reset_singleton_logger!
|
81
|
+
environment.logger.stubs(:flush_progress)
|
82
|
+
environment.logger.stubs(:cl_reset).returns("")
|
83
|
+
|
72
84
|
environment
|
73
85
|
end
|
74
86
|
|
87
|
+
# Sets up the mocks for a VM
|
88
|
+
def mock_vm(env=nil)
|
89
|
+
env ||= mock_environment
|
90
|
+
vm = Vagrant::VM.new
|
91
|
+
vm.stubs(:env).returns(env)
|
92
|
+
vm.stubs(:ssh).returns(Vagrant::SSH.new(vm.env))
|
93
|
+
vm
|
94
|
+
end
|
95
|
+
|
75
96
|
# Sets up the mocks and instantiates an action for testing
|
76
97
|
def mock_action(action_klass, *args)
|
77
98
|
vm = mock("vboxvm")
|
@@ -79,16 +100,38 @@ class Test::Unit::TestCase
|
|
79
100
|
action = action_klass.new(mock_vm, *args)
|
80
101
|
stub_default_action_dependecies(action)
|
81
102
|
|
103
|
+
mock_vm.stubs(:name).returns("foo")
|
82
104
|
mock_vm.stubs(:vm).returns(vm)
|
83
105
|
mock_vm.stubs(:vm=)
|
84
106
|
mock_vm.stubs(:invoke_callback)
|
85
107
|
mock_vm.stubs(:invoke_around_callback).yields
|
86
108
|
mock_vm.stubs(:actions).returns([action])
|
87
109
|
mock_vm.stubs(:env).returns(mock_environment)
|
110
|
+
mock_vm.env.stubs(:logger).returns(quiet_logger("mock"))
|
111
|
+
|
112
|
+
mock_ssh = Vagrant::SSH.new(mock_vm.env)
|
113
|
+
mock_ssh.stubs(:execute)
|
114
|
+
|
115
|
+
mock_vm.stubs(:ssh).returns(mock_ssh)
|
116
|
+
|
117
|
+
vm.stubs(:env).returns(mock_vm.env)
|
88
118
|
|
89
119
|
[mock_vm, vm, action]
|
90
120
|
end
|
91
121
|
|
122
|
+
# Returns a resource logger which is safe for tests
|
123
|
+
def quiet_logger(resource, env=nil)
|
124
|
+
logger = Vagrant::ResourceLogger.new(resource, env)
|
125
|
+
logger.stubs(:flush_progress)
|
126
|
+
logger.stubs(:cl_reset).returns("")
|
127
|
+
logger
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns a linux system
|
131
|
+
def linux_system(vm)
|
132
|
+
Vagrant::Systems::Linux.new(vm)
|
133
|
+
end
|
134
|
+
|
92
135
|
def stub_default_action_dependecies(mock)
|
93
136
|
mock.stubs(:precedes).returns([])
|
94
137
|
mock.stubs(:follows).returns([])
|
@@ -99,7 +142,7 @@ class Test::Unit::TestCase
|
|
99
142
|
tempfile = mock("tempfile")
|
100
143
|
tempfile.stubs(:write)
|
101
144
|
|
102
|
-
[downloader_klass.new, tempfile]
|
145
|
+
[downloader_klass.new(mock_environment), tempfile]
|
103
146
|
end
|
104
147
|
end
|
105
148
|
|
@@ -93,7 +93,6 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
|
93
93
|
@action.with_tempfile
|
94
94
|
end
|
95
95
|
|
96
|
-
|
97
96
|
should "yield the tempfile object" do
|
98
97
|
@tempfile = mock("tempfile")
|
99
98
|
File.expects(:open).yields(@tempfile)
|
@@ -104,22 +103,6 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
107
|
-
context "file options" do
|
108
|
-
should "include add binary bit to options on windows platform" do
|
109
|
-
# This constant is not defined on non-windows platforms, so define it here
|
110
|
-
File::BINARY = 4096 unless defined?(File::BINARY)
|
111
|
-
|
112
|
-
Mario::Platform.expects(:windows?).returns(true)
|
113
|
-
assert_equal @action.file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY
|
114
|
-
end
|
115
|
-
|
116
|
-
should "not include binary bit on other platforms" do
|
117
|
-
Mario::Platform.expects(:windows?).returns(false)
|
118
|
-
assert_equal @action.file_options, File::CREAT|File::EXCL|File::WRONLY
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
106
|
context "cleaning up" do
|
124
107
|
setup do
|
125
108
|
@temp_path = "foo"
|
@@ -6,13 +6,6 @@ class BootActionTest < Test::Unit::TestCase
|
|
6
6
|
@runner.stubs(:invoke_callback)
|
7
7
|
end
|
8
8
|
|
9
|
-
context "preparing" do
|
10
|
-
should "add the root shared folder" do
|
11
|
-
@runner.env.config.vm.expects(:share_folder).with("v-root", @runner.env.config.vm.project_directory, @runner.env.root_path).once
|
12
|
-
@action.prepare
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
9
|
context "execution" do
|
17
10
|
should "invoke the 'boot' around callback" do
|
18
11
|
boot_seq = sequence("boot_seq")
|
@@ -43,13 +36,13 @@ class BootActionTest < Test::Unit::TestCase
|
|
43
36
|
context "waiting for boot" do
|
44
37
|
should "repeatedly ping the SSH port and return false with no response" do
|
45
38
|
seq = sequence('pings')
|
46
|
-
@runner.
|
47
|
-
@runner.
|
39
|
+
@runner.ssh.expects(:up?).times(@runner.env.config.ssh.max_tries.to_i - 1).returns(false).in_sequence(seq)
|
40
|
+
@runner.ssh.expects(:up?).once.returns(true).in_sequence(seq)
|
48
41
|
assert @action.wait_for_boot(0)
|
49
42
|
end
|
50
43
|
|
51
44
|
should "ping the max number of times then just return" do
|
52
|
-
@runner.
|
45
|
+
@runner.ssh.expects(:up?).times(@runner.env.config.ssh.max_tries.to_i).returns(false)
|
53
46
|
assert !@action.wait_for_boot(0)
|
54
47
|
end
|
55
48
|
end
|
@@ -7,9 +7,15 @@ class CustomizeActionTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
context "executing" do
|
9
9
|
should "run the VM customization procs then save the VM" do
|
10
|
+
@runner.env.config.vm.customize { |vm| }
|
10
11
|
@runner.env.config.vm.expects(:run_procs!).with(@vm)
|
11
12
|
@vm.expects(:save).once
|
12
13
|
@action.execute!
|
13
14
|
end
|
15
|
+
|
16
|
+
should "not run anything if no customize blocks exist" do
|
17
|
+
@vm.expects(:save).never
|
18
|
+
@action.execute!
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
@@ -15,7 +15,7 @@ class DestroyActionTest < Test::Unit::TestCase
|
|
15
15
|
@runner.stubs(:invoke_around_callback).yields
|
16
16
|
clear_seq = sequence("clear")
|
17
17
|
@action.expects(:destroy_vm).in_sequence(clear_seq)
|
18
|
-
@action.expects(:
|
18
|
+
@action.expects(:update_dotfile).in_sequence(clear_seq)
|
19
19
|
@action.execute!
|
20
20
|
end
|
21
21
|
end
|
@@ -23,14 +23,15 @@ class DestroyActionTest < Test::Unit::TestCase
|
|
23
23
|
context "destroying the VM" do
|
24
24
|
should "destroy VM and attached images" do
|
25
25
|
@vm.expects(:destroy).with(:destroy_medium => :delete).once
|
26
|
+
@runner.expects(:vm=).with(nil).once
|
26
27
|
@action.destroy_vm
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
context "
|
31
|
-
should "
|
32
|
-
@runner.env.expects(:
|
33
|
-
@action.
|
31
|
+
context "updating the dotfile" do
|
32
|
+
should "update the environment dotfile" do
|
33
|
+
@runner.env.expects(:update_dotfile).once
|
34
|
+
@action.update_dotfile
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -13,33 +13,27 @@ class DownActionTest < Test::Unit::TestCase
|
|
13
13
|
def setup_action_expectations(order)
|
14
14
|
default_seq = sequence("default_seq")
|
15
15
|
order.each do |action|
|
16
|
-
|
16
|
+
action = [action] unless action.is_a?(Array)
|
17
|
+
@runner.expects(:add_action).with(action.shift, *action).once.in_sequence(default_seq)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
should "add the destroy action alone if VM is not running" do
|
21
|
-
setup_action_expectations([Vagrant::Actions::VM::Destroy])
|
22
|
+
setup_action_expectations([Vagrant::Actions::VM::Network, Vagrant::Actions::VM::Destroy])
|
22
23
|
@action.prepare
|
23
24
|
end
|
24
25
|
|
25
26
|
should "add the halt action if the VM is running" do
|
26
27
|
@vm.expects(:running?).returns(true)
|
27
|
-
setup_action_expectations([Vagrant::Actions::VM::Halt, Vagrant::Actions::VM::Destroy])
|
28
|
+
setup_action_expectations([[Vagrant::Actions::VM::Halt, {:force => true}], Vagrant::Actions::VM::Network, Vagrant::Actions::VM::Destroy])
|
28
29
|
@action.prepare
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
context "after halting" do
|
33
|
-
should "sleep
|
34
|
-
@runner.env.config.vm.boot_mode = "gui"
|
34
|
+
should "sleep" do
|
35
35
|
Kernel.expects(:sleep).once
|
36
36
|
@action.after_halt
|
37
37
|
end
|
38
|
-
|
39
|
-
should "not sleep if boot mode is anything else" do
|
40
|
-
@runner.env.config.vm.boot_mode = "vrdp"
|
41
|
-
Kernel.expects(:sleep).never
|
42
|
-
@action.after_halt
|
43
|
-
end
|
44
38
|
end
|
45
39
|
end
|
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class ExportActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Export)
|
6
|
+
@action.stubs(:complete_progress)
|
6
7
|
end
|
7
8
|
|
8
9
|
context "executing" do
|
@@ -2,10 +2,18 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class ForwardPortsActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::ForwardPorts)
|
6
6
|
end
|
7
7
|
|
8
|
-
context "
|
8
|
+
context "preparing" do
|
9
|
+
should "call proper sequence" do
|
10
|
+
prep_seq = sequence("prepare")
|
11
|
+
@action.expects(:external_collision_check).in_sequence(prep_seq)
|
12
|
+
@action.prepare
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "checking for colliding external ports" do
|
9
17
|
setup do
|
10
18
|
@forwarded_port = mock("forwarded_port")
|
11
19
|
@forwarded_port.stubs(:hostport)
|
@@ -15,7 +23,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
15
23
|
@vm.stubs(:forwarded_ports).returns(@forwarded_ports)
|
16
24
|
@vm.stubs(:running?).returns(true)
|
17
25
|
@vm.stubs(:uuid).returns("foo")
|
18
|
-
@
|
26
|
+
@runner.stubs(:uuid).returns("bar")
|
19
27
|
vms = [@vm]
|
20
28
|
VirtualBox::VM.stubs(:all).returns(vms)
|
21
29
|
|
@@ -24,37 +32,80 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
24
32
|
config.vm.forward_port("ssh", 22, 2222)
|
25
33
|
end
|
26
34
|
|
27
|
-
@
|
35
|
+
@runner.stubs(:env).returns(@env)
|
36
|
+
|
37
|
+
# So no exceptions are raised
|
38
|
+
@action.stubs(:handle_collision)
|
28
39
|
end
|
29
40
|
|
30
41
|
should "ignore vms which aren't running" do
|
31
42
|
@vm.expects(:running?).returns(false)
|
32
43
|
@vm.expects(:forwarded_ports).never
|
33
|
-
@action.
|
44
|
+
@action.external_collision_check
|
34
45
|
end
|
35
46
|
|
36
47
|
should "ignore vms which are equivalent to ours" do
|
37
|
-
@
|
48
|
+
@runner.expects(:uuid).returns(@vm.uuid)
|
38
49
|
@vm.expects(:forwarded_ports).never
|
39
|
-
@action.
|
50
|
+
@action.external_collision_check
|
40
51
|
end
|
41
52
|
|
42
53
|
should "not raise any errors if no forwarded ports collide" do
|
43
54
|
@forwarded_port.expects(:hostport).returns(80)
|
44
|
-
assert_nothing_raised { @action.
|
55
|
+
assert_nothing_raised { @action.external_collision_check }
|
45
56
|
end
|
46
57
|
|
47
|
-
should "
|
58
|
+
should "handle the collision if it happens" do
|
48
59
|
@forwarded_port.expects(:hostport).returns(2222)
|
60
|
+
@action.expects(:handle_collision).with("ssh", anything, anything).once
|
61
|
+
@action.external_collision_check
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "handling collisions" do
|
66
|
+
setup do
|
67
|
+
@name = :foo
|
68
|
+
@options = {
|
69
|
+
:hostport => 0,
|
70
|
+
:auto => true
|
71
|
+
}
|
72
|
+
@used_ports = [1,2,3]
|
73
|
+
|
74
|
+
@runner.env.config.vm.auto_port_range = (1..5)
|
75
|
+
end
|
76
|
+
|
77
|
+
should "raise an exception if auto forwarding is disabled" do
|
78
|
+
@options[:auto] = false
|
79
|
+
|
49
80
|
assert_raises(Vagrant::Actions::ActionException) {
|
50
|
-
@action.
|
81
|
+
@action.handle_collision(@name, @options, @used_ports)
|
51
82
|
}
|
52
83
|
end
|
53
84
|
|
54
|
-
should "
|
55
|
-
@
|
85
|
+
should "set the host port to the first available port" do
|
86
|
+
assert_equal 0, @options[:hostport]
|
87
|
+
@action.handle_collision(@name, @options, @used_ports)
|
88
|
+
assert_equal 4, @options[:hostport]
|
89
|
+
end
|
90
|
+
|
91
|
+
should "add the newly used port to the list of used ports" do
|
92
|
+
assert !@used_ports.include?(4)
|
93
|
+
@action.handle_collision(@name, @options, @used_ports)
|
94
|
+
assert @used_ports.include?(4)
|
95
|
+
end
|
96
|
+
|
97
|
+
should "not use a host port which is being forwarded later" do
|
98
|
+
@runner.env.config.vm.forward_port("http", 80, 4)
|
99
|
+
|
100
|
+
assert_equal 0, @options[:hostport]
|
101
|
+
@action.handle_collision(@name, @options, @used_ports)
|
102
|
+
assert_equal 5, @options[:hostport]
|
103
|
+
end
|
104
|
+
|
105
|
+
should "raise an exception if there are no auto ports available" do
|
106
|
+
@runner.env.config.vm.auto_port_range = (1..3)
|
56
107
|
assert_raises(Vagrant::Actions::ActionException) {
|
57
|
-
@action.
|
108
|
+
@action.handle_collision(@name, @options, @used_ports)
|
58
109
|
}
|
59
110
|
end
|
60
111
|
end
|
@@ -71,18 +122,37 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
71
122
|
context "forwarding ports" do
|
72
123
|
should "create a port forwarding for the VM" do
|
73
124
|
forwarded_ports = mock("forwarded_ports")
|
125
|
+
network_adapter = mock("network_adapter")
|
74
126
|
|
75
|
-
@
|
127
|
+
@vm.expects(:network_adapters).returns([network_adapter])
|
128
|
+
network_adapter.expects(:attachment_type).returns(:nat)
|
129
|
+
|
130
|
+
@runner.env.config.vm.forwarded_ports.each do |name, opts|
|
76
131
|
forwarded_ports.expects(:<<).with do |port|
|
77
132
|
assert_equal name, port.name
|
78
133
|
assert_equal opts[:hostport], port.hostport
|
79
134
|
assert_equal opts[:guestport], port.guestport
|
135
|
+
assert_equal opts[:adapter], port.instance
|
80
136
|
true
|
81
137
|
end
|
82
138
|
end
|
83
139
|
|
84
140
|
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
85
141
|
@vm.expects(:save).once
|
142
|
+
@runner.expects(:reload!).once
|
143
|
+
@action.forward_ports
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "Not forwarding ports" do
|
148
|
+
should "No port forwarding for non NAT interfaces" do
|
149
|
+
forwarded_ports = mock("forwarded_ports")
|
150
|
+
network_adapter = mock("network_adapter")
|
151
|
+
|
152
|
+
@vm.expects(:network_adapters).returns([network_adapter])
|
153
|
+
network_adapter.expects(:attachment_type).returns(:host_only)
|
154
|
+
@vm.expects(:save).once
|
155
|
+
@runner.expects(:reload!).once
|
86
156
|
@action.forward_ports
|
87
157
|
end
|
88
158
|
end
|
@@ -96,7 +166,14 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
96
166
|
forwarded_ports << port
|
97
167
|
end
|
98
168
|
|
99
|
-
@vm.
|
169
|
+
@vm.stubs(:forwarded_ports).returns(forwarded_ports)
|
170
|
+
@runner.expects(:reload!)
|
171
|
+
@action.clear
|
172
|
+
end
|
173
|
+
|
174
|
+
should "do nothing if there are no forwarded ports" do
|
175
|
+
@vm.stubs(:forwarded_ports).returns([])
|
176
|
+
@runner.expects(:reload!).never
|
100
177
|
@action.clear
|
101
178
|
end
|
102
179
|
end
|
@@ -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
|