vagrant 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/vagrant +5 -13
- data/config/default.rb +1 -0
- data/keys/README.md +8 -1
- data/keys/vagrant.ppk +26 -0
- data/lib/vagrant.rb +3 -3
- data/lib/vagrant/actions/base.rb +15 -4
- data/lib/vagrant/actions/box/add.rb +1 -1
- data/lib/vagrant/actions/box/download.rb +72 -66
- data/lib/vagrant/actions/box/unpackage.rb +1 -4
- data/lib/vagrant/actions/runner.rb +1 -1
- data/lib/vagrant/actions/vm/boot.rb +5 -7
- data/lib/vagrant/actions/vm/customize.rb +2 -2
- data/lib/vagrant/actions/vm/destroy.rb +2 -2
- data/lib/vagrant/actions/vm/down.rb +7 -0
- data/lib/vagrant/actions/vm/export.rb +10 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
- data/lib/vagrant/actions/vm/halt.rb +5 -3
- data/lib/vagrant/actions/vm/import.rb +10 -3
- data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
- data/lib/vagrant/actions/vm/package.rb +33 -10
- data/lib/vagrant/actions/vm/provision.rb +4 -4
- data/lib/vagrant/actions/vm/reload.rb +1 -1
- data/lib/vagrant/actions/vm/resume.rb +1 -1
- data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
- data/lib/vagrant/actions/vm/start.rb +3 -2
- data/lib/vagrant/actions/vm/suspend.rb +2 -2
- data/lib/vagrant/actions/vm/up.rb +7 -17
- data/lib/vagrant/active_list.rb +52 -45
- data/lib/vagrant/box.rb +18 -11
- data/lib/vagrant/busy.rb +7 -0
- data/lib/vagrant/command.rb +27 -0
- data/lib/vagrant/commands/base.rb +163 -0
- data/lib/vagrant/commands/box.rb +16 -0
- data/lib/vagrant/commands/box/add.rb +24 -0
- data/lib/vagrant/commands/box/list.rb +30 -0
- data/lib/vagrant/commands/box/remove.rb +31 -0
- data/lib/vagrant/commands/destroy.rb +23 -0
- data/lib/vagrant/commands/down.rb +16 -0
- data/lib/vagrant/commands/halt.rb +23 -0
- data/lib/vagrant/commands/init.rb +32 -0
- data/lib/vagrant/commands/package.rb +46 -0
- data/lib/vagrant/commands/reload.rb +22 -0
- data/lib/vagrant/commands/resume.rb +22 -0
- data/lib/vagrant/commands/ssh.rb +22 -0
- data/lib/vagrant/commands/ssh_config.rb +30 -0
- data/lib/vagrant/commands/status.rb +58 -0
- data/lib/vagrant/commands/suspend.rb +23 -0
- data/lib/vagrant/commands/up.rb +26 -0
- data/lib/vagrant/config.rb +21 -11
- data/lib/vagrant/downloaders/file.rb +5 -5
- data/lib/vagrant/downloaders/http.rb +10 -15
- data/lib/vagrant/environment.rb +259 -0
- data/lib/vagrant/provisioners/base.rb +7 -0
- data/lib/vagrant/provisioners/chef.rb +24 -9
- data/lib/vagrant/provisioners/chef_server.rb +23 -48
- data/lib/vagrant/provisioners/chef_solo.rb +48 -22
- data/lib/vagrant/ssh.rb +95 -46
- data/lib/vagrant/util.rb +2 -2
- data/lib/vagrant/util/errors.rb +36 -0
- data/lib/vagrant/util/platform.rb +12 -0
- data/lib/vagrant/util/progress_meter.rb +33 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/vm.rb +1 -0
- data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
- data/templates/chef_server_client.erb +16 -0
- data/templates/chef_solo_solo.erb +4 -0
- data/templates/errors.yml +157 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +7 -0
- data/test/test_helper.rb +12 -15
- data/test/vagrant/actions/box/add_test.rb +1 -2
- data/test/vagrant/actions/box/destroy_test.rb +0 -1
- data/test/vagrant/actions/box/download_test.rb +40 -15
- data/test/vagrant/actions/box/unpackage_test.rb +2 -3
- data/test/vagrant/actions/collection_test.rb +8 -5
- data/test/vagrant/actions/runner_test.rb +8 -6
- data/test/vagrant/actions/vm/boot_test.rb +12 -11
- data/test/vagrant/actions/vm/customize_test.rb +2 -3
- data/test/vagrant/actions/vm/destroy_test.rb +2 -3
- data/test/vagrant/actions/vm/down_test.rb +16 -3
- data/test/vagrant/actions/vm/export_test.rb +4 -5
- data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
- data/test/vagrant/actions/vm/halt_test.rb +8 -2
- data/test/vagrant/actions/vm/import_test.rb +5 -5
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
- data/test/vagrant/actions/vm/package_test.rb +60 -22
- data/test/vagrant/actions/vm/provision_test.rb +7 -16
- data/test/vagrant/actions/vm/reload_test.rb +3 -2
- data/test/vagrant/actions/vm/resume_test.rb +0 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
- data/test/vagrant/actions/vm/start_test.rb +10 -3
- data/test/vagrant/actions/vm/suspend_test.rb +1 -2
- data/test/vagrant/actions/vm/up_test.rb +19 -11
- data/test/vagrant/active_list_test.rb +148 -129
- data/test/vagrant/box_test.rb +26 -14
- data/test/vagrant/busy_test.rb +15 -6
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +118 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/destroy_test.rb +32 -0
- data/test/vagrant/commands/down_test.rb +17 -0
- data/test/vagrant/commands/halt_test.rb +28 -0
- data/test/vagrant/commands/init_test.rb +55 -0
- data/test/vagrant/commands/package_test.rb +84 -0
- data/test/vagrant/commands/reload_test.rb +28 -0
- data/test/vagrant/commands/resume_test.rb +33 -0
- data/test/vagrant/commands/ssh_config_test.rb +54 -0
- data/test/vagrant/commands/ssh_test.rb +32 -0
- data/test/vagrant/commands/status_test.rb +20 -0
- data/test/vagrant/commands/suspend_test.rb +33 -0
- data/test/vagrant/commands/up_test.rb +41 -0
- data/test/vagrant/config_test.rb +42 -17
- data/test/vagrant/downloaders/file_test.rb +7 -0
- data/test/vagrant/downloaders/http_test.rb +12 -0
- data/test/vagrant/environment_test.rb +595 -0
- data/test/vagrant/provisioners/base_test.rb +7 -1
- data/test/vagrant/provisioners/chef_server_test.rb +41 -51
- data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
- data/test/vagrant/provisioners/chef_test.rb +61 -15
- data/test/vagrant/ssh_test.rb +166 -38
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/progress_meter_test.rb +33 -0
- data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/vm_test.rb +3 -2
- data/vagrant.gemspec +88 -33
- metadata +94 -51
- data/bin/vagrant-box +0 -34
- data/bin/vagrant-down +0 -27
- data/bin/vagrant-halt +0 -28
- data/bin/vagrant-init +0 -27
- data/bin/vagrant-package +0 -29
- data/bin/vagrant-reload +0 -29
- data/bin/vagrant-resume +0 -27
- data/bin/vagrant-ssh +0 -27
- data/bin/vagrant-status +0 -29
- data/bin/vagrant-suspend +0 -27
- data/bin/vagrant-up +0 -29
- data/lib/vagrant/commands.rb +0 -234
- data/lib/vagrant/env.rb +0 -189
- data/lib/vagrant/stacked_proc_runner.rb +0 -33
- data/test/vagrant/commands_test.rb +0 -269
- data/test/vagrant/env_test.rb +0 -418
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class ProvisionActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Provision)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "initialization" do
|
@@ -29,9 +28,7 @@ class ProvisionActionTest < Test::Unit::TestCase
|
|
29
28
|
context "preparing" do
|
30
29
|
context "with a nil provisioner" do
|
31
30
|
setup do
|
32
|
-
|
33
|
-
config.vm.provisioner = nil
|
34
|
-
end
|
31
|
+
@runner.env.config.vm.provisioner = nil
|
35
32
|
end
|
36
33
|
|
37
34
|
should "not set a provisioner if set to nil" do
|
@@ -47,15 +44,13 @@ class ProvisionActionTest < Test::Unit::TestCase
|
|
47
44
|
@instance.stubs(:prepare)
|
48
45
|
@klass = mock("klass")
|
49
46
|
@klass.stubs(:is_a?).with(Class).returns(true)
|
50
|
-
@klass.stubs(:new).returns(@instance)
|
47
|
+
@klass.stubs(:new).with(@runner.env).returns(@instance)
|
51
48
|
|
52
|
-
|
53
|
-
config.vm.provisioner = @klass
|
54
|
-
end
|
49
|
+
@runner.env.config.vm.provisioner = @klass
|
55
50
|
end
|
56
51
|
|
57
52
|
should "set the provisioner to an instantiation of the class" do
|
58
|
-
@klass.expects(:new).once.returns(@instance)
|
53
|
+
@klass.expects(:new).with(@runner.env).once.returns(@instance)
|
59
54
|
assert_nothing_raised { @action.prepare }
|
60
55
|
assert_equal @instance, @action.provisioner
|
61
56
|
end
|
@@ -75,21 +70,17 @@ class ProvisionActionTest < Test::Unit::TestCase
|
|
75
70
|
|
76
71
|
context "with a Symbol provisioner" do
|
77
72
|
def provisioner_expectation(symbol, provisioner)
|
78
|
-
|
79
|
-
config.vm.provisioner = symbol
|
80
|
-
end
|
73
|
+
@runner.env.config.vm.provisioner = symbol
|
81
74
|
|
82
75
|
instance = mock("instance")
|
83
76
|
instance.expects(:prepare).once
|
84
|
-
provisioner.expects(:new).returns(instance)
|
77
|
+
provisioner.expects(:new).with(@runner.env).returns(instance)
|
85
78
|
assert_nothing_raised { @action.prepare }
|
86
79
|
assert_equal instance, @action.provisioner
|
87
80
|
end
|
88
81
|
|
89
82
|
should "raise an ActionException if its an unknown symbol" do
|
90
|
-
|
91
|
-
config.vm.provisioner = :this_will_never_exist
|
92
|
-
end
|
83
|
+
@runner.env.config.vm.provisioner = :this_will_never_exist
|
93
84
|
|
94
85
|
assert_raises(Vagrant::Actions::ActionException) {
|
95
86
|
@action.prepare
|
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class ReloadActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Reload)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "sub-actions" do
|
@@ -32,11 +31,13 @@ class ReloadActionTest < Test::Unit::TestCase
|
|
32
31
|
end
|
33
32
|
|
34
33
|
should "add in the provisioning step if enabled" do
|
35
|
-
|
34
|
+
env = mock_environment do |config|
|
36
35
|
# Dummy provisioner to test
|
37
36
|
config.vm.provisioner = "foo"
|
38
37
|
end
|
39
38
|
|
39
|
+
@runner.stubs(:env).returns(env)
|
40
|
+
|
40
41
|
@default_order.push(Vagrant::Actions::VM::Provision)
|
41
42
|
setup_action_expectations
|
42
43
|
@action.prepare
|
@@ -2,8 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class SharedFoldersActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
6
|
-
mock_config
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
|
7
6
|
end
|
8
7
|
|
9
8
|
def stub_shared_folders
|
@@ -27,11 +26,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
27
26
|
end
|
28
27
|
|
29
28
|
should "convert the vagrant config values into an array" do
|
30
|
-
|
29
|
+
env = mock_environment do |config|
|
31
30
|
config.vm.shared_folders.clear
|
32
31
|
config.vm.share_folder("foo", "bar", "baz")
|
33
32
|
end
|
34
33
|
|
34
|
+
@runner.expects(:env).returns(env)
|
35
|
+
|
35
36
|
result = [["foo", "baz", "bar"]]
|
36
37
|
assert_equal result, @action.shared_folders
|
37
38
|
end
|
@@ -39,11 +40,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
39
40
|
should "expand the path of the host folder" do
|
40
41
|
File.expects(:expand_path).with("baz").once.returns("expanded_baz")
|
41
42
|
|
42
|
-
|
43
|
+
env = mock_environment do |config|
|
43
44
|
config.vm.shared_folders.clear
|
44
45
|
config.vm.share_folder("foo", "bar", "baz")
|
45
46
|
end
|
46
47
|
|
48
|
+
@runner.expects(:env).returns(env)
|
49
|
+
|
47
50
|
result = [["foo", "expanded_baz", "bar"]]
|
48
51
|
assert_equal result, @action.shared_folders
|
49
52
|
end
|
@@ -62,7 +65,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
62
65
|
sf.expects(:destroy).once.in_sequence(destroy_seq)
|
63
66
|
end
|
64
67
|
|
65
|
-
@
|
68
|
+
@runner.expects(:reload!).once.in_sequence(destroy_seq)
|
66
69
|
@action.clear_shared_folders
|
67
70
|
end
|
68
71
|
end
|
@@ -75,10 +78,10 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
75
78
|
should "add all shared folders to the VM" do
|
76
79
|
share_seq = sequence("share_seq")
|
77
80
|
shared_folders = mock("shared_folders")
|
78
|
-
shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "foo" && sf.
|
79
|
-
shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "bar" && sf.
|
81
|
+
shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "foo" && sf.host_path == "from" }
|
82
|
+
shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "bar" && sf.host_path == "bfrom" }
|
80
83
|
@vm.stubs(:shared_folders).returns(shared_folders)
|
81
|
-
@vm.expects(:save).
|
84
|
+
@vm.expects(:save).once
|
82
85
|
|
83
86
|
@action.create_metadata
|
84
87
|
end
|
@@ -95,9 +98,9 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
95
98
|
@folders.each do |name, hostpath, guestpath|
|
96
99
|
ssh.expects(:exec!).with("sudo mkdir -p #{guestpath}").in_sequence(mount_seq)
|
97
100
|
@action.expects(:mount_folder).with(ssh, name, guestpath).in_sequence(mount_seq)
|
98
|
-
ssh.expects(:exec!).with("sudo chown #{
|
101
|
+
ssh.expects(:exec!).with("sudo chown #{@runner.env.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
|
99
102
|
end
|
100
|
-
|
103
|
+
@runner.env.ssh.expects(:execute).yields(ssh)
|
101
104
|
|
102
105
|
@action.after_boot
|
103
106
|
end
|
@@ -119,7 +122,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
119
122
|
end
|
120
123
|
|
121
124
|
should "execute the proper mount command" do
|
122
|
-
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{
|
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)
|
123
126
|
mount_folder
|
124
127
|
end
|
125
128
|
|
@@ -158,11 +161,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|
158
161
|
should "add uid AND gid to mount" do
|
159
162
|
uid = "foo"
|
160
163
|
gid = "bar"
|
161
|
-
|
164
|
+
env = mock_environment do |config|
|
162
165
|
config.vm.shared_folder_uid = uid
|
163
166
|
config.vm.shared_folder_gid = gid
|
164
167
|
end
|
165
168
|
|
169
|
+
@runner.expects(:env).twice.returns(env)
|
170
|
+
|
166
171
|
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
|
167
172
|
mount_folder
|
168
173
|
end
|
@@ -3,19 +3,19 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class StartActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Start)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "sub-actions" do
|
10
9
|
setup do
|
10
|
+
@vm.stubs(:saved?).returns(true)
|
11
11
|
File.stubs(:file?).returns(true)
|
12
12
|
File.stubs(:exist?).returns(true)
|
13
|
-
@default_order = [Vagrant::Actions::VM::
|
13
|
+
@default_order = [Vagrant::Actions::VM::Boot]
|
14
14
|
end
|
15
15
|
|
16
16
|
def setup_action_expectations
|
17
17
|
default_seq = sequence("default_seq")
|
18
|
-
@default_order.each do |action|
|
18
|
+
@default_order.flatten.each do |action|
|
19
19
|
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
|
20
20
|
end
|
21
21
|
end
|
@@ -24,5 +24,12 @@ class StartActionTest < Test::Unit::TestCase
|
|
24
24
|
setup_action_expectations
|
25
25
|
@action.prepare
|
26
26
|
end
|
27
|
+
|
28
|
+
should "add customize to the beginning if its not saved" do
|
29
|
+
@vm.expects(:saved?).returns(false)
|
30
|
+
@default_order.unshift([Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders])
|
31
|
+
setup_action_expectations
|
32
|
+
@action.prepare
|
33
|
+
end
|
27
34
|
end
|
28
35
|
end
|
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class SuspendActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Suspend)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "executing" do
|
@@ -12,7 +11,7 @@ class SuspendActionTest < Test::Unit::TestCase
|
|
12
11
|
end
|
13
12
|
|
14
13
|
should "save the state of the VM" do
|
15
|
-
@vm.expects(:save_state).
|
14
|
+
@vm.expects(:save_state).once
|
16
15
|
@action.execute!
|
17
16
|
end
|
18
17
|
|
@@ -2,8 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class UpActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
6
|
-
mock_config
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Up)
|
7
6
|
end
|
8
7
|
|
9
8
|
context "sub-actions" do
|
@@ -11,17 +10,20 @@ class UpActionTest < Test::Unit::TestCase
|
|
11
10
|
File.stubs(:file?).returns(true)
|
12
11
|
File.stubs(:exist?).returns(true)
|
13
12
|
@default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
13
|
+
|
14
|
+
@dotfile_path = "foo"
|
15
|
+
@runner.env.stubs(:dotfile_path).returns(@dotfile_path)
|
14
16
|
end
|
15
17
|
|
16
18
|
def setup_action_expectations
|
17
19
|
default_seq = sequence("default_seq")
|
18
20
|
@default_order.each do |action|
|
19
|
-
@
|
21
|
+
@runner.expects(:add_action).with(action).once.in_sequence(default_seq)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
should "raise an ActionException if a dotfile exists but is not a file" do
|
24
|
-
File.expects(:file?).with(
|
26
|
+
File.expects(:file?).with(@runner.env.dotfile_path).returns(false)
|
25
27
|
assert_raises(Vagrant::Actions::ActionException) {
|
26
28
|
@action.prepare
|
27
29
|
}
|
@@ -46,21 +48,27 @@ class UpActionTest < Test::Unit::TestCase
|
|
46
48
|
end
|
47
49
|
|
48
50
|
should "add in the provisioning step if enabled" do
|
49
|
-
|
51
|
+
env = mock_environment do |config|
|
50
52
|
config.vm.provisioner = "foo"
|
51
53
|
end
|
52
54
|
|
55
|
+
@runner.stubs(:env).returns(env)
|
56
|
+
env.stubs(:dotfile_path).returns(@dotfile_path)
|
57
|
+
|
53
58
|
@default_order.push(Vagrant::Actions::VM::Provision)
|
54
59
|
setup_action_expectations
|
55
60
|
@action.prepare
|
56
61
|
end
|
57
62
|
|
58
63
|
should "add in the action to move hard drive if config is set" do
|
59
|
-
|
64
|
+
env = mock_environment do |config|
|
60
65
|
File.expects(:directory?).with("foo").returns(true)
|
61
66
|
config.vm.hd_location = "foo"
|
62
67
|
end
|
63
68
|
|
69
|
+
@runner.stubs(:env).returns(env)
|
70
|
+
env.stubs(:dotfile_path).returns(@dotfile_path)
|
71
|
+
|
64
72
|
@default_order.insert(0, Vagrant::Actions::VM::MoveHardDrive)
|
65
73
|
setup_action_expectations
|
66
74
|
@action.prepare
|
@@ -78,8 +86,8 @@ class UpActionTest < Test::Unit::TestCase
|
|
78
86
|
|
79
87
|
context "persisting" do
|
80
88
|
should "persist the VM with Env" do
|
81
|
-
@
|
82
|
-
|
89
|
+
@runner.stubs(:uuid)
|
90
|
+
@runner.env.expects(:persist_vm).once
|
83
91
|
@action.persist
|
84
92
|
end
|
85
93
|
end
|
@@ -87,10 +95,10 @@ class UpActionTest < Test::Unit::TestCase
|
|
87
95
|
context "setting up MAC address" do
|
88
96
|
should "match the mac address with the base" do
|
89
97
|
nic = mock("nic")
|
90
|
-
nic.expects(:
|
98
|
+
nic.expects(:mac_address=).once
|
91
99
|
|
92
|
-
@vm.expects(:
|
93
|
-
@vm.expects(:save).
|
100
|
+
@vm.expects(:network_adapters).returns([nic]).once
|
101
|
+
@vm.expects(:save).once
|
94
102
|
|
95
103
|
@action.setup_mac_address
|
96
104
|
end
|
@@ -2,168 +2,187 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class ActiveListTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
|
5
|
+
@env = mock_environment
|
6
|
+
@list = Vagrant::ActiveList.new(@env)
|
6
7
|
end
|
7
8
|
|
8
|
-
context "
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
context "initializing" do
|
10
|
+
should "set the environment to nil if not specified" do
|
11
|
+
assert_nothing_raised {
|
12
|
+
list = Vagrant::ActiveList.new
|
13
|
+
assert list.env.nil?
|
14
|
+
}
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
should "set the environment to the given parameter if specified" do
|
18
|
+
env = mock("env")
|
19
|
+
list = Vagrant::ActiveList.new(env)
|
20
|
+
assert_equal env, list.env
|
21
|
+
end
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
File.expects(:open).with(Vagrant::ActiveList.path, 'r').once.yields(file)
|
28
|
-
file.expects(:read).returns(data)
|
29
|
-
JSON.expects(:parse).with(data).returns(result)
|
30
|
-
assert_equal result, Vagrant::ActiveList.list(true)
|
31
|
-
end
|
24
|
+
context "listing" do
|
25
|
+
setup do
|
26
|
+
@path = "foo"
|
27
|
+
@list.stubs(:path).returns(@path)
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
assert result.equal?(Vagrant::ActiveList.list)
|
38
|
-
assert result.equal?(Vagrant::ActiveList.list)
|
39
|
-
end
|
30
|
+
should "load if reload is given" do
|
31
|
+
File.stubs(:file?).returns(true)
|
32
|
+
File.expects(:open).once
|
33
|
+
@list.list(true)
|
40
34
|
end
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
should "not load if the active json file doesn't exist" do
|
37
|
+
File.expects(:file?).with(@list.path).returns(false)
|
38
|
+
File.expects(:open).never
|
39
|
+
assert_equal [], @list.list(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "parse the JSON by reading the file" do
|
43
|
+
file = mock("file")
|
44
|
+
data = mock("data")
|
45
|
+
result = mock("result")
|
46
|
+
File.expects(:file?).returns(true)
|
47
|
+
File.expects(:open).with(@list.path, 'r').once.yields(file)
|
48
|
+
file.expects(:read).returns(data)
|
49
|
+
JSON.expects(:parse).with(data).returns(result)
|
50
|
+
assert_equal result, @list.list(true)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "not load if reload flag is false and already loaded" do
|
54
|
+
File.expects(:file?).once.returns(false)
|
55
|
+
result = @list.list(true)
|
56
|
+
assert result.equal?(@list.list)
|
57
|
+
assert result.equal?(@list.list)
|
58
|
+
assert result.equal?(@list.list)
|
59
|
+
end
|
60
|
+
end
|
47
61
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
Vagrant::VM.expects(:find).with(item).returns(result).in_sequence(new_seq)
|
54
|
-
results << result
|
55
|
-
end
|
62
|
+
context "vms" do
|
63
|
+
setup do
|
64
|
+
@the_list = ["foo", "bar"]
|
65
|
+
@list.stubs(:list).returns(@the_list)
|
66
|
+
end
|
56
67
|
|
57
|
-
|
68
|
+
should "return the list, but with each value as a VM" do
|
69
|
+
new_seq = sequence("new")
|
70
|
+
results = []
|
71
|
+
@the_list.each do |item|
|
72
|
+
result = mock("result-#{item}")
|
73
|
+
Vagrant::VM.expects(:find).with(item).returns(result).in_sequence(new_seq)
|
74
|
+
results << result
|
58
75
|
end
|
59
76
|
|
60
|
-
|
61
|
-
Vagrant::VM.stubs(:find).returns(nil)
|
62
|
-
results = Vagrant::ActiveList.vms
|
63
|
-
assert results.empty?
|
64
|
-
end
|
77
|
+
assert_equal results, @list.vms
|
65
78
|
end
|
66
79
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
vm.expects(:uuid).returns(i)
|
74
|
-
result << i
|
75
|
-
vms << vm
|
76
|
-
end
|
80
|
+
should "compact out the nil values" do
|
81
|
+
Vagrant::VM.stubs(:find).returns(nil)
|
82
|
+
results = @list.vms
|
83
|
+
assert results.empty?
|
84
|
+
end
|
85
|
+
end
|
77
86
|
|
78
|
-
|
79
|
-
|
87
|
+
context "filtered list" do
|
88
|
+
should "return a list of UUIDs from the VMs" do
|
89
|
+
vms = []
|
90
|
+
result = []
|
91
|
+
5.times do |i|
|
92
|
+
vm = mock("vm#{i}")
|
93
|
+
vm.expects(:uuid).returns(i)
|
94
|
+
result << i
|
95
|
+
vms << vm
|
80
96
|
end
|
97
|
+
|
98
|
+
@list.stubs(:vms).returns(vms)
|
99
|
+
assert_equal result, @list.filtered_list
|
81
100
|
end
|
101
|
+
end
|
82
102
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
103
|
+
context "adding a VM to the list" do
|
104
|
+
setup do
|
105
|
+
@the_list = []
|
106
|
+
@list.stubs(:list).returns(@the_list)
|
107
|
+
@list.stubs(:save)
|
88
108
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
109
|
+
@uuid = "foo"
|
110
|
+
@vm = mock("vm")
|
111
|
+
@vm.stubs(:uuid).returns(@uuid)
|
112
|
+
end
|
93
113
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
114
|
+
should "add the VMs UUID to the list" do
|
115
|
+
@list.add(@vm)
|
116
|
+
assert_equal [@uuid], @the_list
|
117
|
+
end
|
98
118
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
119
|
+
should "uniq the array so multiples never exist" do
|
120
|
+
@the_list << @uuid
|
121
|
+
assert_equal 1, @the_list.length
|
122
|
+
@list.add(@vm)
|
123
|
+
assert_equal 1, @the_list.length
|
124
|
+
end
|
105
125
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
126
|
+
should "save after adding" do
|
127
|
+
save_seq = sequence('save')
|
128
|
+
@the_list.expects(:<<).in_sequence(save_seq)
|
129
|
+
@list.expects(:save).in_sequence(save_seq)
|
130
|
+
@list.add(@vm)
|
112
131
|
end
|
132
|
+
end
|
113
133
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
134
|
+
context "deleting a VM from the list" do
|
135
|
+
setup do
|
136
|
+
@the_list = ["bar"]
|
137
|
+
@list.stubs(:list).returns(@the_list)
|
138
|
+
@list.stubs(:save)
|
119
139
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
140
|
+
@uuid = "bar"
|
141
|
+
@vm = mock("vm")
|
142
|
+
@vm.stubs(:uuid).returns(@uuid)
|
143
|
+
@vm.stubs(:is_a?).with(Vagrant::VM).returns(true)
|
144
|
+
end
|
125
145
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
146
|
+
should "delete the uuid from the list of a VM" do
|
147
|
+
@list.remove(@vm)
|
148
|
+
assert @the_list.empty?
|
149
|
+
end
|
130
150
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
151
|
+
should "delete just the string if a string is given" do
|
152
|
+
@the_list << "zoo"
|
153
|
+
@list.remove("zoo")
|
154
|
+
assert !@the_list.include?("zoo")
|
155
|
+
end
|
136
156
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
157
|
+
should "save after removing" do
|
158
|
+
save_seq = sequence('save')
|
159
|
+
@the_list.expects(:delete).in_sequence(save_seq)
|
160
|
+
@list.expects(:save).in_sequence(save_seq)
|
161
|
+
@list.remove(@vm)
|
143
162
|
end
|
163
|
+
end
|
144
164
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
165
|
+
context "saving" do
|
166
|
+
setup do
|
167
|
+
@filtered = ["zoo"]
|
168
|
+
@list.stubs(:filtered_list).returns(@filtered)
|
169
|
+
end
|
150
170
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
171
|
+
should "open the JSON path and save to it" do
|
172
|
+
file = mock("file")
|
173
|
+
File.expects(:open).with(@list.path, "w+").yields(file)
|
174
|
+
file.expects(:write).with(@filtered.to_json)
|
175
|
+
@list.save
|
157
176
|
end
|
177
|
+
end
|
158
178
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
179
|
+
context "path" do
|
180
|
+
setup do
|
181
|
+
@env.stubs(:home_path).returns("foo")
|
182
|
+
end
|
163
183
|
|
164
|
-
|
165
|
-
|
166
|
-
end
|
184
|
+
should "return the active file within the home path" do
|
185
|
+
assert_equal File.join(@env.home_path, Vagrant::ActiveList::FILENAME), @list.path
|
167
186
|
end
|
168
187
|
end
|
169
188
|
end
|