fixed-vagrant 0.7.4.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +272 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/README.md +75 -0
- data/Rakefile +22 -0
- data/bin/vagrant +22 -0
- data/config/default.rb +39 -0
- data/contrib/README.md +12 -0
- data/contrib/emacs/vagrant.el +8 -0
- data/contrib/vim/vagrantfile.vim +9 -0
- data/keys/README.md +17 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.ppk +26 -0
- data/keys/vagrant.pub +1 -0
- data/lib/vagrant.rb +42 -0
- data/lib/vagrant/action.rb +134 -0
- data/lib/vagrant/action/box.rb +11 -0
- data/lib/vagrant/action/box/destroy.rb +21 -0
- data/lib/vagrant/action/box/download.rb +72 -0
- data/lib/vagrant/action/box/package.rb +19 -0
- data/lib/vagrant/action/box/unpackage.rb +55 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +124 -0
- data/lib/vagrant/action/builtin.rb +104 -0
- data/lib/vagrant/action/env.rb +7 -0
- data/lib/vagrant/action/env/set.rb +18 -0
- data/lib/vagrant/action/environment.rb +50 -0
- data/lib/vagrant/action/general.rb +8 -0
- data/lib/vagrant/action/general/package.rb +109 -0
- data/lib/vagrant/action/general/validate.rb +19 -0
- data/lib/vagrant/action/vm.rb +31 -0
- data/lib/vagrant/action/vm/boot.rb +48 -0
- data/lib/vagrant/action/vm/check_box.rb +28 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +30 -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 +19 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +30 -0
- data/lib/vagrant/action/vm/discard_state.rb +22 -0
- data/lib/vagrant/action/vm/export.rb +52 -0
- data/lib/vagrant/action/vm/forward_ports.rb +134 -0
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
- data/lib/vagrant/action/vm/halt.rb +29 -0
- data/lib/vagrant/action/vm/host_name.rb +21 -0
- data/lib/vagrant/action/vm/import.rb +35 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
- data/lib/vagrant/action/vm/network.rb +139 -0
- data/lib/vagrant/action/vm/nfs.rb +159 -0
- data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
- data/lib/vagrant/action/vm/package.rb +23 -0
- data/lib/vagrant/action/vm/package_vagrantfile.rb +33 -0
- data/lib/vagrant/action/vm/provision.rb +41 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/share_folders.rb +70 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +79 -0
- data/lib/vagrant/box.rb +90 -0
- data/lib/vagrant/box_collection.rb +53 -0
- data/lib/vagrant/cli.rb +55 -0
- data/lib/vagrant/command.rb +25 -0
- data/lib/vagrant/command/base.rb +106 -0
- data/lib/vagrant/command/box.rb +33 -0
- data/lib/vagrant/command/destroy.rb +17 -0
- data/lib/vagrant/command/group_base.rb +107 -0
- data/lib/vagrant/command/halt.rb +18 -0
- data/lib/vagrant/command/helpers.rb +33 -0
- data/lib/vagrant/command/init.rb +14 -0
- data/lib/vagrant/command/named_base.rb +14 -0
- data/lib/vagrant/command/package.rb +41 -0
- data/lib/vagrant/command/provision.rb +17 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +42 -0
- data/lib/vagrant/command/ssh_config.rb +26 -0
- data/lib/vagrant/command/status.rb +22 -0
- data/lib/vagrant/command/suspend.rb +17 -0
- data/lib/vagrant/command/up.rb +19 -0
- data/lib/vagrant/command/upgrade_to_060.rb +45 -0
- data/lib/vagrant/command/version.rb +13 -0
- data/lib/vagrant/config.rb +123 -0
- data/lib/vagrant/config/base.rb +85 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/nfs.rb +10 -0
- data/lib/vagrant/config/package.rb +9 -0
- data/lib/vagrant/config/ssh.rb +33 -0
- data/lib/vagrant/config/top.rb +61 -0
- data/lib/vagrant/config/vagrant.rb +16 -0
- data/lib/vagrant/config/vm.rb +137 -0
- data/lib/vagrant/config/vm/provisioner.rb +56 -0
- data/lib/vagrant/config/vm/sub_vm.rb +17 -0
- data/lib/vagrant/data_store.rb +70 -0
- data/lib/vagrant/downloaders.rb +7 -0
- data/lib/vagrant/downloaders/base.rb +23 -0
- data/lib/vagrant/downloaders/file.rb +22 -0
- data/lib/vagrant/downloaders/http.rb +64 -0
- data/lib/vagrant/environment.rb +392 -0
- data/lib/vagrant/errors.rb +332 -0
- data/lib/vagrant/hosts.rb +8 -0
- data/lib/vagrant/hosts/arch.rb +27 -0
- data/lib/vagrant/hosts/base.rb +78 -0
- data/lib/vagrant/hosts/bsd.rb +52 -0
- data/lib/vagrant/hosts/linux.rb +47 -0
- data/lib/vagrant/plugin.rb +57 -0
- data/lib/vagrant/provisioners.rb +9 -0
- data/lib/vagrant/provisioners/base.rb +63 -0
- data/lib/vagrant/provisioners/chef.rb +130 -0
- data/lib/vagrant/provisioners/chef_server.rb +103 -0
- data/lib/vagrant/provisioners/chef_solo.rb +142 -0
- data/lib/vagrant/provisioners/puppet.rb +137 -0
- data/lib/vagrant/provisioners/puppet_server.rb +55 -0
- data/lib/vagrant/provisioners/shell.rb +52 -0
- data/lib/vagrant/ssh.rb +173 -0
- data/lib/vagrant/ssh/session.rb +125 -0
- data/lib/vagrant/systems.rb +11 -0
- data/lib/vagrant/systems/base.rb +87 -0
- data/lib/vagrant/systems/debian.rb +36 -0
- data/lib/vagrant/systems/freebsd.rb +84 -0
- data/lib/vagrant/systems/gentoo.rb +27 -0
- data/lib/vagrant/systems/linux.rb +83 -0
- data/lib/vagrant/systems/linux/config.rb +21 -0
- data/lib/vagrant/systems/linux/error.rb +9 -0
- data/lib/vagrant/systems/redhat.rb +39 -0
- data/lib/vagrant/systems/solaris.rb +62 -0
- data/lib/vagrant/systems/ubuntu.rb +17 -0
- data/lib/vagrant/test_helpers.rb +128 -0
- data/lib/vagrant/ui.rb +69 -0
- data/lib/vagrant/util.rb +13 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/plain_logger.rb +25 -0
- data/lib/vagrant/util/platform.rb +65 -0
- data/lib/vagrant/util/resource_logger.rb +63 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/version.rb +6 -0
- data/lib/vagrant/vm.rb +177 -0
- data/templates/chef_server_client.erb +18 -0
- data/templates/chef_solo_solo.erb +19 -0
- data/templates/commands/init/Vagrantfile.erb +82 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +535 -0
- data/templates/network_entry_debian.erb +8 -0
- data/templates/network_entry_gentoo.erb +5 -0
- data/templates/network_entry_redhat.erb +8 -0
- data/templates/nfs/exports.erb +5 -0
- data/templates/nfs/exports_linux.erb +5 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +9 -0
- data/test/locales/en.yml +8 -0
- data/test/test_helper.rb +26 -0
- data/test/vagrant/action/box/destroy_test.rb +18 -0
- data/test/vagrant/action/box/download_test.rb +125 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/vagrant/action/box/verify_test.rb +30 -0
- data/test/vagrant/action/builder_test.rb +203 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +27 -0
- data/test/vagrant/action/general/package_test.rb +268 -0
- data/test/vagrant/action/general/validate_test.rb +31 -0
- data/test/vagrant/action/vm/boot_test.rb +66 -0
- data/test/vagrant/action/vm/check_box_test.rb +56 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
- data/test/vagrant/action/vm/customize_test.rb +30 -0
- data/test/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/vagrant/action/vm/export_test.rb +107 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +194 -0
- data/test/vagrant/action/vm/halt_test.rb +79 -0
- data/test/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/vagrant/action/vm/import_test.rb +66 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +36 -0
- data/test/vagrant/action/vm/network_test.rb +286 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/vagrant/action/vm/package_test.rb +25 -0
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/vagrant/action/vm/provision_test.rb +90 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +139 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action/warden_test.rb +119 -0
- data/test/vagrant/action_test.rb +89 -0
- data/test/vagrant/box_collection_test.rb +45 -0
- data/test/vagrant/box_test.rb +74 -0
- data/test/vagrant/cli_test.rb +35 -0
- data/test/vagrant/command/base_test.rb +23 -0
- data/test/vagrant/command/group_base_test.rb +15 -0
- data/test/vagrant/command/helpers_test.rb +88 -0
- data/test/vagrant/command/package_test.rb +27 -0
- data/test/vagrant/config/base_test.rb +52 -0
- data/test/vagrant/config/error_recorder_test.rb +18 -0
- data/test/vagrant/config/ssh_test.rb +12 -0
- data/test/vagrant/config/vagrant_test.rb +35 -0
- data/test/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/vagrant/config/vm_test.rb +86 -0
- data/test/vagrant/config_test.rb +162 -0
- data/test/vagrant/data_store_test.rb +77 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +48 -0
- data/test/vagrant/downloaders/http_test.rb +80 -0
- data/test/vagrant/environment_test.rb +508 -0
- data/test/vagrant/errors_test.rb +42 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +53 -0
- data/test/vagrant/hosts/linux_test.rb +54 -0
- data/test/vagrant/plugin_test.rb +9 -0
- data/test/vagrant/provisioners/base_test.rb +63 -0
- data/test/vagrant/provisioners/chef_server_test.rb +188 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +219 -0
- data/test/vagrant/provisioners/chef_test.rb +179 -0
- data/test/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/vagrant/provisioners/shell_test.rb +68 -0
- data/test/vagrant/ssh/session_test.rb +40 -0
- data/test/vagrant/ssh_test.rb +342 -0
- data/test/vagrant/systems/base_test.rb +18 -0
- data/test/vagrant/systems/linux_test.rb +114 -0
- data/test/vagrant/ui_test.rb +29 -0
- data/test/vagrant/util/busy_test.rb +106 -0
- data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/resource_logger_test.rb +78 -0
- data/test/vagrant/util/retryable_test.rb +50 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +145 -0
- data/test/vagrant/vm_test.rb +291 -0
- data/vagrant.gemspec +36 -0
- metadata +514 -0
@@ -0,0 +1,219 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ChefSoloProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Provisioners::ChefSolo
|
6
|
+
|
7
|
+
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
8
|
+
|
9
|
+
@config = @klass::Config.new
|
10
|
+
@action = @klass.new(@action_env, @config)
|
11
|
+
@env = @action.env
|
12
|
+
@vm = @action.vm
|
13
|
+
end
|
14
|
+
|
15
|
+
context "config validation" do
|
16
|
+
setup do
|
17
|
+
@errors = Vagrant::Config::ErrorRecorder.new
|
18
|
+
@config.run_list = ["foo"]
|
19
|
+
@config.cookbooks_path = "cookbooks"
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be invalid if run list is empty" do
|
23
|
+
@config.run_list = []
|
24
|
+
@config.validate(@errors)
|
25
|
+
assert !@errors.errors.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
should "be invalid if cookbooks path is empty" do
|
29
|
+
@config.cookbooks_path = nil
|
30
|
+
@config.validate(@errors)
|
31
|
+
assert !@errors.errors.empty?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "preparing" do
|
36
|
+
should "share cookbook folders" do
|
37
|
+
@action.expects(:share_cookbook_folders).once
|
38
|
+
@action.prepare
|
39
|
+
end
|
40
|
+
|
41
|
+
should "share role folders" do
|
42
|
+
@action.expects(:share_role_folders).once
|
43
|
+
@action.prepare
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "provisioning" do
|
48
|
+
should "run the proper sequence of methods in order" do
|
49
|
+
prov_seq = sequence("prov_seq")
|
50
|
+
@action.expects(:verify_binary).with("chef-solo").once.in_sequence(prov_seq)
|
51
|
+
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
52
|
+
@action.expects(:setup_json).once.in_sequence(prov_seq)
|
53
|
+
@action.expects(:setup_solo_config).once.in_sequence(prov_seq)
|
54
|
+
@action.expects(:run_chef_solo).once.in_sequence(prov_seq)
|
55
|
+
@action.provision!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context "sharing cookbook folders" do
|
59
|
+
setup do
|
60
|
+
@host_cookbook_paths = ["foo", "bar"]
|
61
|
+
@action.stubs(:host_cookbook_paths).returns(@host_cookbook_paths)
|
62
|
+
end
|
63
|
+
|
64
|
+
should "share each cookbook folder" do
|
65
|
+
share_seq = sequence("share_seq")
|
66
|
+
@host_cookbook_paths.each_with_index do |cookbook, i|
|
67
|
+
@env.config.vm.expects(:share_folder).with("v-csc-#{i}", @action.cookbook_path(i), cookbook).in_sequence(share_seq)
|
68
|
+
end
|
69
|
+
|
70
|
+
@action.share_cookbook_folders
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "sharing role folders" do
|
75
|
+
setup do
|
76
|
+
@host_role_paths = ["foo", "bar"]
|
77
|
+
@action.stubs(:host_role_paths).returns(@host_role_paths)
|
78
|
+
end
|
79
|
+
|
80
|
+
should "share each role folder" do
|
81
|
+
share_seq = sequence("share_seq")
|
82
|
+
@host_role_paths.each_with_index do |role, i|
|
83
|
+
@env.config.vm.expects(:share_folder).with("v-csr-#{i}", @action.role_path(i), role).in_sequence(share_seq)
|
84
|
+
end
|
85
|
+
|
86
|
+
@action.share_role_folders
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "host folder paths" do
|
91
|
+
should "ignore VM paths" do
|
92
|
+
assert @action.host_folder_paths([:vm, "foo"]).empty?
|
93
|
+
end
|
94
|
+
|
95
|
+
should "return as an array if was originally a string" do
|
96
|
+
folder = "foo"
|
97
|
+
File.stubs(:expand_path).returns("bar")
|
98
|
+
assert_equal ["bar"], @action.host_folder_paths(folder)
|
99
|
+
end
|
100
|
+
|
101
|
+
should "return the array of folders if its an array" do
|
102
|
+
folders = ["foo", "bar"]
|
103
|
+
expand_seq = sequence('expand_seq')
|
104
|
+
folders.collect! { |folder| File.expand_path(folder, @env.root_path) }
|
105
|
+
|
106
|
+
assert_equal folders, @action.host_folder_paths(folders)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "host cookbooks paths" do
|
111
|
+
should "get folders path for configured cookbooks path" do
|
112
|
+
result = mock("result")
|
113
|
+
@config.stubs(:cookbooks_path).returns("foo")
|
114
|
+
@action.expects(:host_folder_paths).with(@config.cookbooks_path).returns(result)
|
115
|
+
assert_equal result, @action.host_cookbook_paths
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "host roles paths" do
|
120
|
+
should "get folders path for configured roles path" do
|
121
|
+
result = mock("result")
|
122
|
+
@config.stubs(:roles_path).returns("foo")
|
123
|
+
@action.expects(:host_folder_paths).with(@config.roles_path).returns(result)
|
124
|
+
assert_equal result, @action.host_role_paths
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "folder path" do
|
129
|
+
should "return a proper path to a single folder" do
|
130
|
+
expected = File.join(@config.provisioning_path, "cookbooks-5")
|
131
|
+
assert_equal expected, @action.folder_path("cookbooks", 5)
|
132
|
+
end
|
133
|
+
|
134
|
+
should "return array-representation of folder paths if multiple" do
|
135
|
+
@folders = (0..5).to_a
|
136
|
+
@cookbooks = @folders.inject([]) do |acc, i|
|
137
|
+
acc << @action.cookbook_path(i)
|
138
|
+
end
|
139
|
+
|
140
|
+
assert_equal @cookbooks, @action.folders_path(@folders, "cookbooks")
|
141
|
+
end
|
142
|
+
|
143
|
+
should "return a single string representation if folder paths is single" do
|
144
|
+
@folder = "cookbooks"
|
145
|
+
@cookbooks = @action.folder_path(@folder, 0)
|
146
|
+
|
147
|
+
assert_equal @cookbooks, @action.folders_path([0], @folder)
|
148
|
+
end
|
149
|
+
|
150
|
+
should "properly format VM folder paths" do
|
151
|
+
@config.provisioning_path = "/foo"
|
152
|
+
assert_equal "/foo/bar", @action.folders_path([:vm, "bar"], nil)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "cookbooks path" do
|
157
|
+
should "return a proper path to a single cookbook" do
|
158
|
+
expected = File.join(@config.provisioning_path, "cookbooks-5")
|
159
|
+
assert_equal expected, @action.cookbook_path(5)
|
160
|
+
end
|
161
|
+
|
162
|
+
should "properly call folders path and return result" do
|
163
|
+
result = [:a, :b, :c]
|
164
|
+
@action.expects(:folders_path).with(@config.cookbooks_path, "cookbooks").once.returns(result)
|
165
|
+
assert_equal result.to_json, @action.cookbooks_path
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "roles path" do
|
170
|
+
should "return a proper path to a single role" do
|
171
|
+
expected = File.join(@config.provisioning_path, "roles-5")
|
172
|
+
assert_equal expected, @action.role_path(5)
|
173
|
+
end
|
174
|
+
|
175
|
+
should "properly call folders path and return result" do
|
176
|
+
result = [:a, :b, :c]
|
177
|
+
@action.expects(:folders_path).with(@config.roles_path, "roles").once.returns(result)
|
178
|
+
assert_equal result.to_json, @action.roles_path
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "generating and uploading chef solo configuration file" do
|
183
|
+
setup do
|
184
|
+
@vm.ssh.stubs(:upload!)
|
185
|
+
|
186
|
+
@config.recipe_url = "foo/bar/baz"
|
187
|
+
end
|
188
|
+
|
189
|
+
should "call setup_config with proper variables" do
|
190
|
+
@action.expects(:setup_config).with("chef_solo_solo", "solo.rb", {
|
191
|
+
:node_name => @config.node_name,
|
192
|
+
:provisioning_path => @config.provisioning_path,
|
193
|
+
:cookbooks_path => @action.cookbooks_path,
|
194
|
+
:recipe_url => @config.recipe_url,
|
195
|
+
:roles_path => @action.roles_path
|
196
|
+
})
|
197
|
+
|
198
|
+
@action.setup_solo_config
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "running chef solo" do
|
203
|
+
setup do
|
204
|
+
@ssh = mock("ssh")
|
205
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
206
|
+
end
|
207
|
+
|
208
|
+
should "cd into the provisioning directory and run chef solo" do
|
209
|
+
@ssh.expects(:sudo!).with(["cd #{@config.provisioning_path}", "chef-solo -c solo.rb -j dna.json"]).once
|
210
|
+
@action.run_chef_solo
|
211
|
+
end
|
212
|
+
|
213
|
+
should "check the exit status if that is given" do
|
214
|
+
@ssh.stubs(:sudo!).yields(nil, :exit_status, :foo)
|
215
|
+
@ssh.expects(:check_exit_status).with(:foo, anything).once
|
216
|
+
@action.run_chef_solo
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ChefProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
6
|
+
|
7
|
+
@klass = Vagrant::Provisioners::Chef
|
8
|
+
@config = @klass::Config.new
|
9
|
+
@action = @klass.new(@action_env, @config)
|
10
|
+
@env = @action.env
|
11
|
+
@vm = @action.vm
|
12
|
+
end
|
13
|
+
|
14
|
+
context "preparing" do
|
15
|
+
should "error the environment" do
|
16
|
+
assert_raises(@klass::ChefError) {
|
17
|
+
@action.prepare
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "config" do
|
23
|
+
should "not include the 'json' key in the config dump" do
|
24
|
+
result = @config.to_json
|
25
|
+
assert result !~ /"json":/
|
26
|
+
end
|
27
|
+
|
28
|
+
should "provide accessors to the run list" do
|
29
|
+
@config.run_list << "foo"
|
30
|
+
assert !@config.run_list.empty?
|
31
|
+
assert_equal ["foo"], @config.run_list
|
32
|
+
end
|
33
|
+
|
34
|
+
should "provide a writer for the run list" do
|
35
|
+
data = mock("data")
|
36
|
+
|
37
|
+
assert_nothing_raised {
|
38
|
+
@config.run_list = data
|
39
|
+
assert_equal data, @config.run_list
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
should "have an empty run list to begin with" do
|
44
|
+
assert @config.run_list.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
should "add a recipe to the run list" do
|
48
|
+
@config.add_recipe("foo")
|
49
|
+
assert_equal "recipe[foo]", @config.run_list[0]
|
50
|
+
end
|
51
|
+
|
52
|
+
should "not wrap the recipe in 'recipe[]' if it was in the name" do
|
53
|
+
@config.add_recipe("recipe[foo]")
|
54
|
+
assert_equal "recipe[foo]", @config.run_list[0]
|
55
|
+
end
|
56
|
+
|
57
|
+
should "add a role to the run list" do
|
58
|
+
@config.add_role("user")
|
59
|
+
assert_equal "role[user]", @config.run_list[0]
|
60
|
+
end
|
61
|
+
|
62
|
+
should "not wrap the role in 'role[]' if it was in the name" do
|
63
|
+
@config.add_role("role[user]")
|
64
|
+
assert_equal "role[user]", @config.run_list[0]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "verifying binary" do
|
69
|
+
setup do
|
70
|
+
@ssh = mock("ssh")
|
71
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
72
|
+
end
|
73
|
+
|
74
|
+
should "verify binary exists" do
|
75
|
+
binary = "foo"
|
76
|
+
@ssh.expects(:sudo!).with("which #{binary}", anything)
|
77
|
+
@action.verify_binary(binary)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "permissions on provisioning folder" do
|
82
|
+
should "create and chown the folder to the ssh user" do
|
83
|
+
ssh_seq = sequence("ssh_seq")
|
84
|
+
ssh = mock("ssh")
|
85
|
+
ssh.expects(:sudo!).with("mkdir -p #{@config.provisioning_path}").once.in_sequence(ssh_seq)
|
86
|
+
ssh.expects(:sudo!).with("chown #{@env.config.ssh.username} #{@config.provisioning_path}").once.in_sequence(ssh_seq)
|
87
|
+
@vm.ssh.expects(:execute).yields(ssh)
|
88
|
+
@action.chown_provisioning_folder
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "generating and uploading chef configuration file" do
|
93
|
+
setup do
|
94
|
+
@vm.ssh.stubs(:upload!)
|
95
|
+
|
96
|
+
@template = "template"
|
97
|
+
@filename = "foo.rb"
|
98
|
+
|
99
|
+
Vagrant::Util::TemplateRenderer.stubs(:render).returns("foo")
|
100
|
+
end
|
101
|
+
|
102
|
+
should "render and upload file" do
|
103
|
+
template_data = mock("data")
|
104
|
+
string_io = mock("string_io")
|
105
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with(@template, anything).returns(template_data)
|
106
|
+
StringIO.expects(:new).with(template_data).returns(string_io)
|
107
|
+
File.expects(:join).with(@config.provisioning_path, @filename).once.returns("bar")
|
108
|
+
@vm.ssh.expects(:upload!).with(string_io, "bar")
|
109
|
+
|
110
|
+
@action.setup_config(@template, @filename, {})
|
111
|
+
end
|
112
|
+
|
113
|
+
should "provide log level by default" do
|
114
|
+
Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars|
|
115
|
+
assert vars.has_key?(:log_level)
|
116
|
+
assert_equal @config.log_level.to_sym, vars[:log_level]
|
117
|
+
true
|
118
|
+
end
|
119
|
+
|
120
|
+
@action.setup_config(@template, @filename, {})
|
121
|
+
end
|
122
|
+
|
123
|
+
should "allow custom template variables" do
|
124
|
+
custom = {
|
125
|
+
:foo => "bar",
|
126
|
+
:int => 7
|
127
|
+
}
|
128
|
+
|
129
|
+
Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars|
|
130
|
+
custom.each do |key, value|
|
131
|
+
assert vars.has_key?(key)
|
132
|
+
assert_equal value, vars[key]
|
133
|
+
end
|
134
|
+
|
135
|
+
true
|
136
|
+
end
|
137
|
+
|
138
|
+
@action.setup_config(@template, @filename, custom)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "generating and uploading json" do
|
143
|
+
def assert_json
|
144
|
+
@vm.ssh.expects(:upload!).with do |json, path|
|
145
|
+
data = JSON.parse(json.read)
|
146
|
+
yield data
|
147
|
+
true
|
148
|
+
end
|
149
|
+
|
150
|
+
@action.setup_json
|
151
|
+
end
|
152
|
+
|
153
|
+
should "merge in the extra json specified in the config" do
|
154
|
+
@config.json = { :foo => "BAR" }
|
155
|
+
assert_json do |data|
|
156
|
+
assert_equal "BAR", data["foo"]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
should "add the directory as a special case to the JSON" do
|
161
|
+
assert_json do |data|
|
162
|
+
assert_equal @env.config.vm.shared_folders["v-root"][:guestpath], data["vagrant"]["directory"]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
should "add the config to the JSON" do
|
167
|
+
assert_json do |data|
|
168
|
+
assert_equal @env.config.ssh.username, data["vagrant"]["config"]["ssh"]["username"]
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
should "upload a StringIO to dna.json" do
|
173
|
+
StringIO.expects(:new).with(anything).returns("bar")
|
174
|
+
File.expects(:join).with(@config.provisioning_path, "dna.json").once.returns("baz")
|
175
|
+
@vm.ssh.expects(:upload!).with("bar", "baz").once
|
176
|
+
@action.setup_json
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PuppetServerProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Provisioners::PuppetServer
|
6
|
+
|
7
|
+
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
8
|
+
|
9
|
+
@config = @klass::Config.new
|
10
|
+
@action = @klass.new(@action_env, @config)
|
11
|
+
@env = @action.env
|
12
|
+
@vm = @action.vm
|
13
|
+
end
|
14
|
+
|
15
|
+
context "provisioning" do
|
16
|
+
should "run the proper sequence of methods in order" do
|
17
|
+
prov_seq = sequence("prov_seq")
|
18
|
+
@action.expects(:verify_binary).with("puppetd").once.in_sequence(prov_seq)
|
19
|
+
@action.expects(:run_puppetd_client).once.in_sequence(prov_seq)
|
20
|
+
@action.provision!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "verifying binary" do
|
25
|
+
setup do
|
26
|
+
@ssh = mock("ssh")
|
27
|
+
@shell = mock("shell")
|
28
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "verify binary exists" do
|
32
|
+
binary = "foo"
|
33
|
+
@ssh.expects(:sudo!).with("which #{binary}", anything)
|
34
|
+
@action.verify_binary(binary)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "running puppetd client" do
|
39
|
+
setup do
|
40
|
+
@cn = "puppet_node"
|
41
|
+
@ssh = mock("ssh")
|
42
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "run the puppetd client" do
|
46
|
+
@ssh.expects(:sudo!).with("puppetd --server #{@config.puppet_server} --certname #{@cn}").once
|
47
|
+
@action.run_puppetd_client
|
48
|
+
end
|
49
|
+
|
50
|
+
should "run puppetd with given options when given as an array" do
|
51
|
+
@config.options = ["--modulepath", "modules", "--verbose"]
|
52
|
+
@ssh.expects(:sudo!).with("puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
|
53
|
+
@action.run_puppetd_client
|
54
|
+
end
|
55
|
+
|
56
|
+
should "run puppetd with the options when given as a string" do
|
57
|
+
@config.options = "--modulepath modules --verbose"
|
58
|
+
@ssh.expects(:sudo!).with("puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
|
59
|
+
@action.run_puppetd_client
|
60
|
+
end
|
61
|
+
|
62
|
+
should "check the exit status if that is given" do
|
63
|
+
@ssh.stubs(:sudo!).yields(nil, :exit_status, :foo)
|
64
|
+
@ssh.expects(:check_exit_status).with(:foo, anything).once
|
65
|
+
@action.run_puppetd_client
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|