vagrantup 0.4.3.dev → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,33 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
-
|
3
|
-
class BaseProvisionerTest < Test::Unit::TestCase
|
4
|
-
should "include the util class so subclasses have access to it" do
|
5
|
-
assert Vagrant::Provisioners::Base.include?(Vagrant::Util)
|
6
|
-
end
|
7
|
-
|
8
|
-
context "base instance" do
|
9
|
-
setup do
|
10
|
-
@vm = mock("vm")
|
11
|
-
@base = Vagrant::Provisioners::Base.new(@vm)
|
12
|
-
end
|
13
|
-
|
14
|
-
should "set the environment" do
|
15
|
-
base = Vagrant::Provisioners::Base.new(@vm)
|
16
|
-
assert_equal @vm, base.vm
|
17
|
-
end
|
18
|
-
|
19
|
-
should "implement provision! which does nothing" do
|
20
|
-
assert_nothing_raised do
|
21
|
-
assert @base.respond_to?(:provision!)
|
22
|
-
@base.provision!
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
should "implement prepare which does nothing" do
|
27
|
-
assert_nothing_raised do
|
28
|
-
assert @base.respond_to?(:prepare)
|
29
|
-
@base.prepare
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
-
|
3
|
-
class ChefServerProvisionerTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@vm = mock_vm
|
6
|
-
@env = @vm.env
|
7
|
-
@action = Vagrant::Provisioners::ChefServer.new(@vm)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "provisioning" do
|
11
|
-
should "run the proper sequence of methods in order" do
|
12
|
-
prov_seq = sequence("prov_seq")
|
13
|
-
@action.expects(:verify_binary).with("chef-client").once.in_sequence(prov_seq)
|
14
|
-
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
15
|
-
@action.expects(:create_client_key_folder).once.in_sequence(prov_seq)
|
16
|
-
@action.expects(:upload_validation_key).once.in_sequence(prov_seq)
|
17
|
-
@action.expects(:setup_json).once.in_sequence(prov_seq)
|
18
|
-
@action.expects(:setup_server_config).once.in_sequence(prov_seq)
|
19
|
-
@action.expects(:run_chef_client).once.in_sequence(prov_seq)
|
20
|
-
@action.provision!
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "preparing" do
|
25
|
-
setup do
|
26
|
-
File.stubs(:file?).returns(true)
|
27
|
-
end
|
28
|
-
|
29
|
-
should "not raise an exception if validation_key_path is set" do
|
30
|
-
@env = mock_environment do |config|
|
31
|
-
config.chef.validation_key_path = "7"
|
32
|
-
end
|
33
|
-
|
34
|
-
@action.stubs(:env).returns(@env)
|
35
|
-
|
36
|
-
assert_nothing_raised { @action.prepare }
|
37
|
-
end
|
38
|
-
|
39
|
-
should "raise an exception if validation_key_path is nil" do
|
40
|
-
@env = mock_environment do |config|
|
41
|
-
config.chef.validation_key_path = nil
|
42
|
-
end
|
43
|
-
|
44
|
-
@action.stubs(:env).returns(@env)
|
45
|
-
|
46
|
-
assert_raises(Vagrant::Actions::ActionException) {
|
47
|
-
@action.prepare
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
should "not raise an exception if validation_key_path does exist" do
|
52
|
-
@env = mock_environment do |config|
|
53
|
-
config.chef.validation_key_path = "7"
|
54
|
-
end
|
55
|
-
|
56
|
-
@action.stubs(:env).returns(@env)
|
57
|
-
@action.stubs(:validation_key_path).returns("9")
|
58
|
-
|
59
|
-
File.expects(:file?).with(@action.validation_key_path).returns(true)
|
60
|
-
assert_nothing_raised { @action.prepare }
|
61
|
-
end
|
62
|
-
|
63
|
-
should "raise an exception if validation_key_path doesn't exist" do
|
64
|
-
@env = mock_environment do |config|
|
65
|
-
config.chef.validation_key_path = "7"
|
66
|
-
end
|
67
|
-
|
68
|
-
@action.stubs(:env).returns(@env)
|
69
|
-
@action.stubs(:validation_key_path).returns("9")
|
70
|
-
|
71
|
-
File.expects(:file?).with(@action.validation_key_path).returns(false)
|
72
|
-
assert_raises(Vagrant::Actions::ActionException) {
|
73
|
-
@action.prepare
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
should "not raise an exception if chef_server_url is set" do
|
78
|
-
@env = mock_environment do |config|
|
79
|
-
config.chef.chef_server_url = "7"
|
80
|
-
end
|
81
|
-
|
82
|
-
@action.stubs(:env).returns(@env)
|
83
|
-
|
84
|
-
assert_nothing_raised { @action.prepare }
|
85
|
-
end
|
86
|
-
|
87
|
-
should "raise an exception if chef_server_url is nil" do
|
88
|
-
@env = mock_environment do |config|
|
89
|
-
config.chef.chef_server_url = nil
|
90
|
-
end
|
91
|
-
|
92
|
-
@action.stubs(:env).returns(@env)
|
93
|
-
|
94
|
-
assert_raises(Vagrant::Actions::ActionException) {
|
95
|
-
@action.prepare
|
96
|
-
}
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "creating the client key folder" do
|
101
|
-
setup do
|
102
|
-
@raw_path = "/foo/bar/baz.pem"
|
103
|
-
@env.config.chef.client_key_path = @raw_path
|
104
|
-
|
105
|
-
@path = Pathname.new(@raw_path)
|
106
|
-
end
|
107
|
-
|
108
|
-
should "create the folder using the dirname of the path" do
|
109
|
-
ssh = mock("ssh")
|
110
|
-
ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
|
111
|
-
@vm.ssh.expects(:execute).yields(ssh)
|
112
|
-
@action.create_client_key_folder
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "uploading the validation key" do
|
117
|
-
should "upload the validation key to the provisioning path" do
|
118
|
-
@action.expects(:validation_key_path).once.returns("foo")
|
119
|
-
@action.expects(:guest_validation_key_path).once.returns("bar")
|
120
|
-
@vm.ssh.expects(:upload!).with("foo", "bar").once
|
121
|
-
@action.upload_validation_key
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "the validation key path" do
|
126
|
-
should "expand the configured key path" do
|
127
|
-
result = mock("result")
|
128
|
-
File.expects(:expand_path).with(@env.config.chef.validation_key_path, @env.root_path).once.returns(result)
|
129
|
-
assert_equal result, @action.validation_key_path
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "the guest validation key path" do
|
134
|
-
should "be the provisioning path joined with validation.pem" do
|
135
|
-
result = mock("result")
|
136
|
-
File.expects(:join).with(@env.config.chef.provisioning_path, "validation.pem").once.returns(result)
|
137
|
-
assert_equal result, @action.guest_validation_key_path
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "generating and uploading chef client configuration file" do
|
142
|
-
setup do
|
143
|
-
@action.stubs(:guest_validation_key_path).returns("foo")
|
144
|
-
end
|
145
|
-
|
146
|
-
should "call setup_config with proper variables" do
|
147
|
-
@action.expects(:setup_config).with("chef_server_client", "client.rb", {
|
148
|
-
:node_name => @env.config.chef.node_name,
|
149
|
-
:chef_server_url => @env.config.chef.chef_server_url,
|
150
|
-
:validation_client_name => @env.config.chef.validation_client_name,
|
151
|
-
:validation_key => @action.guest_validation_key_path,
|
152
|
-
:client_key => @env.config.chef.client_key_path
|
153
|
-
})
|
154
|
-
|
155
|
-
@action.setup_server_config
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context "running chef client" do
|
160
|
-
setup do
|
161
|
-
@ssh = mock("ssh")
|
162
|
-
@vm.ssh.stubs(:execute).yields(@ssh)
|
163
|
-
end
|
164
|
-
|
165
|
-
should "cd into the provisioning directory and run chef client" do
|
166
|
-
@ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
|
167
|
-
@action.run_chef_client
|
168
|
-
end
|
169
|
-
|
170
|
-
should "check the exit status if that is given" do
|
171
|
-
@ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
|
172
|
-
@ssh.expects(:check_exit_status).with(:foo, anything).once
|
173
|
-
@action.run_chef_client
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
@@ -1,183 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
-
|
3
|
-
class ChefSoloProvisionerTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@vm = mock_vm
|
6
|
-
@env = @vm.env
|
7
|
-
@action = Vagrant::Provisioners::ChefSolo.new(@vm)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "preparing" do
|
11
|
-
should "share cookbook folders" do
|
12
|
-
@action.expects(:share_cookbook_folders).once
|
13
|
-
@action.prepare
|
14
|
-
end
|
15
|
-
|
16
|
-
should "share role folders" do
|
17
|
-
@action.expects(:share_role_folders).once
|
18
|
-
@action.prepare
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "provisioning" do
|
23
|
-
should "run the proper sequence of methods in order" do
|
24
|
-
prov_seq = sequence("prov_seq")
|
25
|
-
@action.expects(:verify_binary).with("chef-solo").once.in_sequence(prov_seq)
|
26
|
-
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
27
|
-
@action.expects(:setup_json).once.in_sequence(prov_seq)
|
28
|
-
@action.expects(:setup_solo_config).once.in_sequence(prov_seq)
|
29
|
-
@action.expects(:run_chef_solo).once.in_sequence(prov_seq)
|
30
|
-
@action.provision!
|
31
|
-
end
|
32
|
-
end
|
33
|
-
context "sharing cookbook folders" do
|
34
|
-
setup do
|
35
|
-
@host_cookbook_paths = ["foo", "bar"]
|
36
|
-
@action.stubs(:host_cookbook_paths).returns(@host_cookbook_paths)
|
37
|
-
end
|
38
|
-
|
39
|
-
should "share each cookbook folder" do
|
40
|
-
share_seq = sequence("share_seq")
|
41
|
-
@host_cookbook_paths.each_with_index do |cookbook, i|
|
42
|
-
@env.config.vm.expects(:share_folder).with("v-csc-#{i}", @action.cookbook_path(i), cookbook).in_sequence(share_seq)
|
43
|
-
end
|
44
|
-
|
45
|
-
@action.share_cookbook_folders
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "sharing role folders" do
|
50
|
-
setup do
|
51
|
-
@host_role_paths = ["foo", "bar"]
|
52
|
-
@action.stubs(:host_role_paths).returns(@host_role_paths)
|
53
|
-
end
|
54
|
-
|
55
|
-
should "share each role folder" do
|
56
|
-
share_seq = sequence("share_seq")
|
57
|
-
@host_role_paths.each_with_index do |role, i|
|
58
|
-
@env.config.vm.expects(:share_folder).with("v-csr-#{i}", @action.role_path(i), role).in_sequence(share_seq)
|
59
|
-
end
|
60
|
-
|
61
|
-
@action.share_role_folders
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "host folder paths" do
|
66
|
-
should "return as an array if was originally a string" do
|
67
|
-
folder = "foo"
|
68
|
-
File.stubs(:expand_path).returns("bar")
|
69
|
-
assert_equal ["bar"], @action.host_folder_paths(folder)
|
70
|
-
end
|
71
|
-
|
72
|
-
should "return the array of folders if its an array" do
|
73
|
-
folders = ["foo", "bar"]
|
74
|
-
expand_seq = sequence('expand_seq')
|
75
|
-
folders.collect! { |folder| File.expand_path(folder, @env.root_path) }
|
76
|
-
|
77
|
-
assert_equal folders, @action.host_folder_paths(folders)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "host cookbooks paths" do
|
82
|
-
should "get folders path for configured cookbooks path" do
|
83
|
-
result = mock("result")
|
84
|
-
@env.config.chef.stubs(:cookbooks_path).returns("foo")
|
85
|
-
@action.expects(:host_folder_paths).with(@env.config.chef.cookbooks_path).returns(result)
|
86
|
-
assert_equal result, @action.host_cookbook_paths
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "host roles paths" do
|
91
|
-
should "get folders path for configured roles path" do
|
92
|
-
result = mock("result")
|
93
|
-
@env.config.chef.stubs(:roles_path).returns("foo")
|
94
|
-
@action.expects(:host_folder_paths).with(@env.config.chef.roles_path).returns(result)
|
95
|
-
assert_equal result, @action.host_role_paths
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "folder path" do
|
100
|
-
should "return a proper path to a single folder" do
|
101
|
-
expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
|
102
|
-
assert_equal expected, @action.folder_path("cookbooks", 5)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "return array-representation of folder paths if multiple" do
|
106
|
-
@folders = (0..5).to_a
|
107
|
-
@cookbooks = @folders.inject([]) do |acc, i|
|
108
|
-
acc << @action.cookbook_path(i)
|
109
|
-
end
|
110
|
-
|
111
|
-
assert_equal @cookbooks.to_json, @action.folders_path(@folders, "cookbooks")
|
112
|
-
end
|
113
|
-
|
114
|
-
should "return a single string representation if folder paths is single" do
|
115
|
-
@folder = "cookbooks"
|
116
|
-
@cookbooks = @action.folder_path(@folder, 0)
|
117
|
-
|
118
|
-
assert_equal @cookbooks.to_json, @action.folders_path([0], @folder)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "cookbooks path" do
|
123
|
-
should "return a proper path to a single cookbook" do
|
124
|
-
expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
|
125
|
-
assert_equal expected, @action.cookbook_path(5)
|
126
|
-
end
|
127
|
-
|
128
|
-
should "properly call folders path and return result" do
|
129
|
-
result = mock("result")
|
130
|
-
@action.stubs(:host_cookbook_paths).returns([])
|
131
|
-
@action.expects(:folders_path).with(@action.host_cookbook_paths, "cookbooks").once.returns(result)
|
132
|
-
assert_equal result, @action.cookbooks_path
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "roles path" do
|
137
|
-
should "return a proper path to a single role" do
|
138
|
-
expected = File.join(@env.config.chef.provisioning_path, "roles-5")
|
139
|
-
assert_equal expected, @action.role_path(5)
|
140
|
-
end
|
141
|
-
|
142
|
-
should "properly call folders path and return result" do
|
143
|
-
result = mock("result")
|
144
|
-
@action.stubs(:host_role_paths).returns([])
|
145
|
-
@action.expects(:folders_path).with(@action.host_role_paths, "roles").once.returns(result)
|
146
|
-
assert_equal result, @action.roles_path
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "generating and uploading chef solo configuration file" do
|
151
|
-
setup do
|
152
|
-
@vm.ssh.stubs(:upload!)
|
153
|
-
end
|
154
|
-
|
155
|
-
should "call setup_config with proper variables" do
|
156
|
-
@action.expects(:setup_config).with("chef_solo_solo", "solo.rb", {
|
157
|
-
:provisioning_path => @env.config.chef.provisioning_path,
|
158
|
-
:cookbooks_path => @action.cookbooks_path,
|
159
|
-
:roles_path => @action.roles_path
|
160
|
-
})
|
161
|
-
|
162
|
-
@action.setup_solo_config
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context "running chef solo" do
|
167
|
-
setup do
|
168
|
-
@ssh = mock("ssh")
|
169
|
-
@vm.ssh.stubs(:execute).yields(@ssh)
|
170
|
-
end
|
171
|
-
|
172
|
-
should "cd into the provisioning directory and run chef solo" do
|
173
|
-
@ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
|
174
|
-
@action.run_chef_solo
|
175
|
-
end
|
176
|
-
|
177
|
-
should "check the exit status if that is given" do
|
178
|
-
@ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
|
179
|
-
@ssh.expects(:check_exit_status).with(:foo, anything).once
|
180
|
-
@action.run_chef_solo
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
@@ -1,175 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
-
|
3
|
-
class ChefProvisionerTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@vm = mock_vm
|
6
|
-
@env = @vm.env
|
7
|
-
@action = Vagrant::Provisioners::Chef.new(@vm)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "preparing" do
|
11
|
-
should "raise an ActionException" do
|
12
|
-
assert_raises(Vagrant::Actions::ActionException) {
|
13
|
-
@action.prepare
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "config" do
|
19
|
-
setup do
|
20
|
-
@config = Vagrant::Provisioners::Chef::ChefConfig.new
|
21
|
-
@config.run_list.clear
|
22
|
-
end
|
23
|
-
|
24
|
-
should "not include the 'json' key in the config dump" do
|
25
|
-
result = JSON.parse(@config.to_json)
|
26
|
-
assert !result.has_key?("json")
|
27
|
-
end
|
28
|
-
|
29
|
-
should "provide accessors to the run list" do
|
30
|
-
@config.run_list << "foo"
|
31
|
-
assert !@config.run_list.empty?
|
32
|
-
assert_equal ["foo"], @config.run_list
|
33
|
-
end
|
34
|
-
|
35
|
-
should "provide a writer for the run list" do
|
36
|
-
data = mock("data")
|
37
|
-
|
38
|
-
assert_nothing_raised {
|
39
|
-
@config.run_list = data
|
40
|
-
assert_equal data, @config.run_list
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
should "add a recipe to the run list" do
|
45
|
-
@config.add_recipe("foo")
|
46
|
-
assert_equal "recipe[foo]", @config.run_list[0]
|
47
|
-
end
|
48
|
-
|
49
|
-
should "not wrap the recipe in 'recipe[]' if it was in the name" do
|
50
|
-
@config.add_recipe("recipe[foo]")
|
51
|
-
assert_equal "recipe[foo]", @config.run_list[0]
|
52
|
-
end
|
53
|
-
|
54
|
-
should "add a role to the run list" do
|
55
|
-
@config.add_role("user")
|
56
|
-
assert_equal "role[user]", @config.run_list[0]
|
57
|
-
end
|
58
|
-
|
59
|
-
should "not wrap the role in 'role[]' if it was in the name" do
|
60
|
-
@config.add_role("role[user]")
|
61
|
-
assert_equal "role[user]", @config.run_list[0]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "verifying binary" do
|
66
|
-
setup do
|
67
|
-
@ssh = mock("ssh")
|
68
|
-
@vm.ssh.stubs(:execute).yields(@ssh)
|
69
|
-
end
|
70
|
-
|
71
|
-
should "verify binary exists" do
|
72
|
-
binary = "foo"
|
73
|
-
@ssh.expects(:exec!).with("which #{binary}", :error_key => :chef_not_detected, :error_data => { :binary => binary }).once
|
74
|
-
@action.verify_binary(binary)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
context "permissions on provisioning folder" do
|
78
|
-
should "create and chown the folder to the ssh user" do
|
79
|
-
ssh_seq = sequence("ssh_seq")
|
80
|
-
ssh = mock("ssh")
|
81
|
-
ssh.expects(:exec!).with("sudo mkdir -p #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
|
82
|
-
ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
|
83
|
-
@vm.ssh.expects(:execute).yields(ssh)
|
84
|
-
@action.chown_provisioning_folder
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "generating and uploading chef configuration file" do
|
89
|
-
setup do
|
90
|
-
@vm.ssh.stubs(:upload!)
|
91
|
-
|
92
|
-
@template = "template"
|
93
|
-
@filename = "foo.rb"
|
94
|
-
|
95
|
-
Vagrant::Util::TemplateRenderer.stubs(:render).returns("foo")
|
96
|
-
end
|
97
|
-
|
98
|
-
should "render and upload file" do
|
99
|
-
template_data = mock("data")
|
100
|
-
string_io = mock("string_io")
|
101
|
-
Vagrant::Util::TemplateRenderer.expects(:render).with(@template, anything).returns(template_data)
|
102
|
-
StringIO.expects(:new).with(template_data).returns(string_io)
|
103
|
-
File.expects(:join).with(@env.config.chef.provisioning_path, @filename).once.returns("bar")
|
104
|
-
@vm.ssh.expects(:upload!).with(string_io, "bar")
|
105
|
-
|
106
|
-
@action.setup_config(@template, @filename, {})
|
107
|
-
end
|
108
|
-
|
109
|
-
should "provide log level by default" do
|
110
|
-
Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars|
|
111
|
-
assert vars.has_key?(:log_level)
|
112
|
-
assert_equal @env.config.chef.log_level.to_sym, vars[:log_level]
|
113
|
-
true
|
114
|
-
end
|
115
|
-
|
116
|
-
@action.setup_config(@template, @filename, {})
|
117
|
-
end
|
118
|
-
|
119
|
-
should "allow custom template variables" do
|
120
|
-
custom = {
|
121
|
-
:foo => "bar",
|
122
|
-
:int => 7
|
123
|
-
}
|
124
|
-
|
125
|
-
Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars|
|
126
|
-
custom.each do |key, value|
|
127
|
-
assert vars.has_key?(key)
|
128
|
-
assert_equal value, vars[key]
|
129
|
-
end
|
130
|
-
|
131
|
-
true
|
132
|
-
end
|
133
|
-
|
134
|
-
@action.setup_config(@template, @filename, custom)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "generating and uploading json" do
|
139
|
-
def assert_json
|
140
|
-
@vm.ssh.expects(:upload!).with do |json, path|
|
141
|
-
data = JSON.parse(json.read)
|
142
|
-
yield data
|
143
|
-
true
|
144
|
-
end
|
145
|
-
|
146
|
-
@action.setup_json
|
147
|
-
end
|
148
|
-
|
149
|
-
should "merge in the extra json specified in the config" do
|
150
|
-
@env.config.chef.json = { :foo => "BAR" }
|
151
|
-
assert_json do |data|
|
152
|
-
assert_equal "BAR", data["foo"]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
should "add the directory as a special case to the JSON" do
|
157
|
-
assert_json do |data|
|
158
|
-
assert_equal @env.config.vm.shared_folders["v-root"][:guestpath], data["vagrant"]["directory"]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
should "add the config to the JSON" do
|
163
|
-
assert_json do |data|
|
164
|
-
assert_equal @env.config.ssh.username, data["vagrant"]["config"]["ssh"]["username"]
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
should "upload a StringIO to dna.json" do
|
169
|
-
StringIO.expects(:new).with(anything).returns("bar")
|
170
|
-
File.expects(:join).with(@env.config.chef.provisioning_path, "dna.json").once.returns("baz")
|
171
|
-
@vm.ssh.expects(:upload!).with("bar", "baz").once
|
172
|
-
@action.setup_json
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|