bmabey-vagrant 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/Gemfile +17 -0
- data/LICENSE +21 -0
- data/README.md +53 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/bin/.gitignore +0 -0
- data/bin/vagrant +15 -0
- data/bin/vagrant-box +34 -0
- data/bin/vagrant-down +27 -0
- data/bin/vagrant-halt +28 -0
- data/bin/vagrant-init +27 -0
- data/bin/vagrant-package +29 -0
- data/bin/vagrant-reload +29 -0
- data/bin/vagrant-resume +27 -0
- data/bin/vagrant-ssh +27 -0
- data/bin/vagrant-status +29 -0
- data/bin/vagrant-suspend +27 -0
- data/bin/vagrant-up +29 -0
- data/config/default.rb +26 -0
- data/keys/README.md +10 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.pub +1 -0
- data/lib/vagrant.rb +19 -0
- data/lib/vagrant/actions/base.rb +118 -0
- data/lib/vagrant/actions/box/add.rb +22 -0
- data/lib/vagrant/actions/box/destroy.rb +14 -0
- data/lib/vagrant/actions/box/download.rb +72 -0
- data/lib/vagrant/actions/box/unpackage.rb +43 -0
- data/lib/vagrant/actions/collection.rb +36 -0
- data/lib/vagrant/actions/runner.rb +132 -0
- data/lib/vagrant/actions/vm/boot.rb +47 -0
- data/lib/vagrant/actions/vm/customize.rb +17 -0
- data/lib/vagrant/actions/vm/destroy.rb +23 -0
- data/lib/vagrant/actions/vm/down.rb +12 -0
- data/lib/vagrant/actions/vm/export.rb +41 -0
- data/lib/vagrant/actions/vm/forward_ports.rb +46 -0
- data/lib/vagrant/actions/vm/halt.rb +14 -0
- data/lib/vagrant/actions/vm/import.rb +18 -0
- data/lib/vagrant/actions/vm/move_hard_drive.rb +51 -0
- data/lib/vagrant/actions/vm/package.rb +65 -0
- data/lib/vagrant/actions/vm/provision.rb +49 -0
- data/lib/vagrant/actions/vm/reload.rb +17 -0
- data/lib/vagrant/actions/vm/resume.rb +16 -0
- data/lib/vagrant/actions/vm/shared_folders.rb +81 -0
- data/lib/vagrant/actions/vm/start.rb +18 -0
- data/lib/vagrant/actions/vm/suspend.rb +16 -0
- data/lib/vagrant/actions/vm/up.rb +40 -0
- data/lib/vagrant/active_list.rb +73 -0
- data/lib/vagrant/box.rb +152 -0
- data/lib/vagrant/busy.rb +73 -0
- data/lib/vagrant/commands.rb +219 -0
- data/lib/vagrant/config.rb +183 -0
- data/lib/vagrant/downloaders/base.rb +16 -0
- data/lib/vagrant/downloaders/file.rb +17 -0
- data/lib/vagrant/downloaders/http.rb +47 -0
- data/lib/vagrant/environment.rb +263 -0
- data/lib/vagrant/provisioners/base.rb +29 -0
- data/lib/vagrant/provisioners/chef.rb +103 -0
- data/lib/vagrant/provisioners/chef_server.rb +84 -0
- data/lib/vagrant/provisioners/chef_solo.rb +97 -0
- data/lib/vagrant/ssh.rb +104 -0
- data/lib/vagrant/util.rb +51 -0
- data/lib/vagrant/util/errors.rb +36 -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 +61 -0
- data/templates/Vagrantfile.erb +8 -0
- data/templates/errors.yml +117 -0
- data/test/test_helper.rb +163 -0
- data/test/vagrant/actions/base_test.rb +32 -0
- data/test/vagrant/actions/box/add_test.rb +37 -0
- data/test/vagrant/actions/box/destroy_test.rb +18 -0
- data/test/vagrant/actions/box/download_test.rb +131 -0
- data/test/vagrant/actions/box/unpackage_test.rb +100 -0
- data/test/vagrant/actions/collection_test.rb +110 -0
- data/test/vagrant/actions/runner_test.rb +265 -0
- data/test/vagrant/actions/vm/boot_test.rb +55 -0
- data/test/vagrant/actions/vm/customize_test.rb +16 -0
- data/test/vagrant/actions/vm/destroy_test.rb +36 -0
- data/test/vagrant/actions/vm/down_test.rb +32 -0
- data/test/vagrant/actions/vm/export_test.rb +88 -0
- data/test/vagrant/actions/vm/forward_ports_test.rb +104 -0
- data/test/vagrant/actions/vm/halt_test.rb +27 -0
- data/test/vagrant/actions/vm/import_test.rb +43 -0
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +108 -0
- data/test/vagrant/actions/vm/package_test.rb +181 -0
- data/test/vagrant/actions/vm/provision_test.rb +108 -0
- data/test/vagrant/actions/vm/reload_test.rb +47 -0
- data/test/vagrant/actions/vm/resume_test.rb +27 -0
- data/test/vagrant/actions/vm/shared_folders_test.rb +176 -0
- data/test/vagrant/actions/vm/start_test.rb +36 -0
- data/test/vagrant/actions/vm/suspend_test.rb +27 -0
- data/test/vagrant/actions/vm/up_test.rb +107 -0
- data/test/vagrant/active_list_test.rb +190 -0
- data/test/vagrant/box_test.rb +151 -0
- data/test/vagrant/busy_test.rb +83 -0
- data/test/vagrant/commands_test.rb +307 -0
- data/test/vagrant/config_test.rb +256 -0
- data/test/vagrant/downloaders/base_test.rb +27 -0
- data/test/vagrant/downloaders/file_test.rb +26 -0
- data/test/vagrant/downloaders/http_test.rb +40 -0
- data/test/vagrant/environment_test.rb +607 -0
- data/test/vagrant/provisioners/base_test.rb +33 -0
- data/test/vagrant/provisioners/chef_server_test.rb +187 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +149 -0
- data/test/vagrant/provisioners/chef_test.rb +117 -0
- data/test/vagrant/ssh_test.rb +222 -0
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/util_test.rb +64 -0
- data/test/vagrant/vm_test.rb +114 -0
- data/vagrant.gemspec +216 -0
- metadata +285 -0
@@ -0,0 +1,33 @@
|
|
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
|
+
@env = mock_environment
|
11
|
+
@base = Vagrant::Provisioners::Base.new(@env)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "set the environment" do
|
15
|
+
base = Vagrant::Provisioners::Base.new(@env)
|
16
|
+
assert_equal @env, base.env
|
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
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ChefServerProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@env = mock_environment
|
6
|
+
@action = Vagrant::Provisioners::ChefServer.new(@env)
|
7
|
+
|
8
|
+
mock_config
|
9
|
+
end
|
10
|
+
|
11
|
+
context "provisioning" do
|
12
|
+
should "run the proper sequence of methods in order" do
|
13
|
+
prov_seq = 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_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
|
+
@env.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
|
+
@env.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
|
+
|
145
|
+
@env.ssh.stubs(:upload!)
|
146
|
+
end
|
147
|
+
|
148
|
+
should "upload properly generate the configuration file using configuration data" do
|
149
|
+
expected_config = <<-config
|
150
|
+
log_level :info
|
151
|
+
log_location STDOUT
|
152
|
+
ssl_verify_mode :verify_none
|
153
|
+
chef_server_url "#{@env.config.chef.chef_server_url}"
|
154
|
+
|
155
|
+
validation_client_name "#{@env.config.chef.validation_client_name}"
|
156
|
+
validation_key "#{@action.guest_validation_key_path}"
|
157
|
+
client_key "#{@env.config.chef.client_key_path}"
|
158
|
+
|
159
|
+
file_store_path "/srv/chef/file_store"
|
160
|
+
file_cache_path "/srv/chef/cache"
|
161
|
+
|
162
|
+
pid_file "/var/run/chef/chef-client.pid"
|
163
|
+
|
164
|
+
Mixlib::Log::Formatter.show_time = true
|
165
|
+
config
|
166
|
+
|
167
|
+
StringIO.expects(:new).with(expected_config).once
|
168
|
+
@action.setup_config
|
169
|
+
end
|
170
|
+
|
171
|
+
should "upload this file as client.rb to the provisioning folder" do
|
172
|
+
StringIO.expects(:new).returns("foo")
|
173
|
+
File.expects(:join).with(@env.config.chef.provisioning_path, "client.rb").once.returns("bar")
|
174
|
+
@env.ssh.expects(:upload!).with("foo", "bar").once
|
175
|
+
@action.setup_config
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "running chef client" do
|
180
|
+
should "cd into the provisioning directory and run chef client" do
|
181
|
+
ssh = mock("ssh")
|
182
|
+
ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
|
183
|
+
@env.ssh.expects(:execute).yields(ssh)
|
184
|
+
@action.run_chef_client
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ChefSoloProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@env = mock_environment
|
6
|
+
@action = Vagrant::Provisioners::ChefSolo.new(@env)
|
7
|
+
|
8
|
+
Vagrant::SSH.stubs(:execute)
|
9
|
+
Vagrant::SSH.stubs(:upload!)
|
10
|
+
|
11
|
+
mock_config
|
12
|
+
end
|
13
|
+
|
14
|
+
context "preparing" do
|
15
|
+
should "share cookbook folders" do
|
16
|
+
@action.expects(:share_cookbook_folders).once
|
17
|
+
@action.prepare
|
18
|
+
end
|
19
|
+
|
20
|
+
should "share the roles folder" do
|
21
|
+
@env.config.chef.provisioning_path = "/provisioning"
|
22
|
+
@env.config.chef.role_path = "/host/roles"
|
23
|
+
|
24
|
+
@env.config.vm.expects(:share_folder).with("vagrant-chef-solo-roles", "/provisioning/roles", "/host/roles")
|
25
|
+
@action.stubs(:share_cookbook_folders)
|
26
|
+
@action.prepare
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "provisioning" do
|
32
|
+
should "run the proper sequence of methods in order" do
|
33
|
+
prov_seq = sequence("prov_seq")
|
34
|
+
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
35
|
+
@action.expects(:setup_json).once.in_sequence(prov_seq)
|
36
|
+
@action.expects(:setup_solo_config).once.in_sequence(prov_seq)
|
37
|
+
@action.expects(:run_chef_solo).once.in_sequence(prov_seq)
|
38
|
+
@action.provision!
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "sharing cookbook folders" do
|
43
|
+
setup do
|
44
|
+
@host_cookbook_paths = ["foo", "bar"]
|
45
|
+
@action.stubs(:host_cookbook_paths).returns(@host_cookbook_paths)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "share each cookbook folder" do
|
49
|
+
share_seq = sequence("share_seq")
|
50
|
+
@host_cookbook_paths.each_with_index do |cookbook, i|
|
51
|
+
@env.config.vm.expects(:share_folder).with("vagrant-chef-solo-#{i}", @action.cookbook_path(i), cookbook).in_sequence(share_seq)
|
52
|
+
end
|
53
|
+
|
54
|
+
@action.share_cookbook_folders
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "host cookbooks paths" do
|
59
|
+
should "return as an array if was originally a string" do
|
60
|
+
File.stubs(:expand_path).returns("foo")
|
61
|
+
@env.config.chef.cookbooks_path = "foo"
|
62
|
+
|
63
|
+
assert_equal ["foo"], @action.host_cookbook_paths
|
64
|
+
end
|
65
|
+
|
66
|
+
should "return the array of cookbooks if its an array" do
|
67
|
+
cookbooks = ["foo", "bar"]
|
68
|
+
@env.config.chef.cookbooks_path = cookbooks
|
69
|
+
|
70
|
+
expand_seq = sequence('expand_seq')
|
71
|
+
cookbooks.collect! { |cookbook| File.expand_path(cookbook, @env.root_path) }
|
72
|
+
|
73
|
+
assert_equal cookbooks, @action.host_cookbook_paths
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "cookbooks path" do
|
78
|
+
should "return a proper path to a single cookbook" do
|
79
|
+
expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
|
80
|
+
assert_equal expected, @action.cookbook_path(5)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "return array-representation of cookbook paths if multiple" do
|
84
|
+
@cookbooks = (0..5).inject([]) do |acc, i|
|
85
|
+
acc << @action.cookbook_path(i)
|
86
|
+
end
|
87
|
+
|
88
|
+
@env.config.chef.cookbooks_path = @cookbooks
|
89
|
+
assert_equal @cookbooks.to_json, @action.cookbooks_path
|
90
|
+
end
|
91
|
+
|
92
|
+
should "return a single string representation if cookbook paths is single" do
|
93
|
+
@cookbooks = @action.cookbook_path(0)
|
94
|
+
|
95
|
+
@env.config.chef.cookbooks_path = @cookbooks
|
96
|
+
assert_equal @cookbooks.to_json, @action.cookbooks_path
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "roles path" do
|
101
|
+
should "return a single string representation containing the provisioning path" do
|
102
|
+
@env.config.chef.provisioning_path = "/stuff"
|
103
|
+
@env.config.chef.role_path = "/host_roles_dir"
|
104
|
+
|
105
|
+
assert_equal "/stuff/roles".to_json, @action.role_path
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
context "generating and uploading chef solo configuration file" do
|
111
|
+
setup do
|
112
|
+
@env.ssh.stubs(:upload!)
|
113
|
+
end
|
114
|
+
|
115
|
+
should "upload properly generate the configuration file using configuration data" do
|
116
|
+
expected_config = <<-config
|
117
|
+
file_cache_path "#{@env.config.chef.provisioning_path}"
|
118
|
+
cookbook_path #{@action.cookbooks_path}
|
119
|
+
config
|
120
|
+
|
121
|
+
StringIO.expects(:new).with(expected_config).once
|
122
|
+
@action.setup_solo_config
|
123
|
+
end
|
124
|
+
|
125
|
+
should "include the role_path in the generated configuration when provided one in the configuration" do
|
126
|
+
@env.config.chef.role_path = "/host_roles_dir"
|
127
|
+
|
128
|
+
StringIO.expects(:new).with() {|config| config =~ /role_path #{@action.role_path}/ }
|
129
|
+
@action.setup_solo_config
|
130
|
+
end
|
131
|
+
|
132
|
+
should "upload this file as solo.rb to the provisioning folder" do
|
133
|
+
@action.expects(:cookbooks_path).returns("cookbooks")
|
134
|
+
StringIO.expects(:new).returns("foo")
|
135
|
+
File.expects(:join).with(@env.config.chef.provisioning_path, "solo.rb").once.returns("bar")
|
136
|
+
@env.ssh.expects(:upload!).with("foo", "bar").once
|
137
|
+
@action.setup_solo_config
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "running chef solo" do
|
142
|
+
should "cd into the provisioning directory and run chef solo" do
|
143
|
+
ssh = mock("ssh")
|
144
|
+
ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
|
145
|
+
@env.ssh.expects(:execute).yields(ssh)
|
146
|
+
@action.run_chef_solo
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ChefProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@env = mock_environment
|
6
|
+
@action = Vagrant::Provisioners::Chef.new(@env)
|
7
|
+
|
8
|
+
Vagrant::SSH.stubs(:execute)
|
9
|
+
Vagrant::SSH.stubs(:upload!)
|
10
|
+
|
11
|
+
mock_config
|
12
|
+
end
|
13
|
+
|
14
|
+
context "preparing" do
|
15
|
+
should "raise an ActionException" do
|
16
|
+
assert_raises(Vagrant::Actions::ActionException) {
|
17
|
+
@action.prepare
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "config" do
|
23
|
+
setup do
|
24
|
+
@config = Vagrant::Provisioners::Chef::ChefConfig.new
|
25
|
+
@config.run_list.clear
|
26
|
+
end
|
27
|
+
|
28
|
+
should "not include the 'json' key in the config dump" do
|
29
|
+
result = JSON.parse(@config.to_json)
|
30
|
+
assert !result.has_key?("json")
|
31
|
+
end
|
32
|
+
|
33
|
+
should "provide accessors to the run list" do
|
34
|
+
@config.run_list << "foo"
|
35
|
+
assert !@config.run_list.empty?
|
36
|
+
assert_equal ["foo"], @config.run_list
|
37
|
+
end
|
38
|
+
|
39
|
+
should "provide a writer for the run list" do
|
40
|
+
data = mock("data")
|
41
|
+
|
42
|
+
assert_nothing_raised {
|
43
|
+
@config.run_list = data
|
44
|
+
assert_equal data, @config.run_list
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
should "add a recipe to the run list" do
|
49
|
+
@config.add_recipe("foo")
|
50
|
+
assert_equal "recipe[foo]", @config.run_list[0]
|
51
|
+
end
|
52
|
+
|
53
|
+
should "not wrap the recipe in 'recipe[]' if it was in the name" do
|
54
|
+
@config.add_recipe("recipe[foo]")
|
55
|
+
assert_equal "recipe[foo]", @config.run_list[0]
|
56
|
+
end
|
57
|
+
|
58
|
+
should "add a role to the run list" do
|
59
|
+
@config.add_role("user")
|
60
|
+
assert_equal "role[user]", @config.run_list[0]
|
61
|
+
end
|
62
|
+
|
63
|
+
should "not wrap the role in 'role[]' if it was in the name" do
|
64
|
+
@config.add_role("role[user]")
|
65
|
+
assert_equal "role[user]", @config.run_list[0]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "permissions on provisioning folder" do
|
70
|
+
should "create and chown the folder to the ssh user" do
|
71
|
+
ssh_seq = sequence("ssh_seq")
|
72
|
+
ssh = mock("ssh")
|
73
|
+
ssh.expects(:exec!).with("sudo mkdir -p #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
|
74
|
+
ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
|
75
|
+
@env.ssh.expects(:execute).yields(ssh)
|
76
|
+
@action.chown_provisioning_folder
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "generating and uploading json" do
|
81
|
+
def assert_json
|
82
|
+
@env.ssh.expects(:upload!).with do |json, path|
|
83
|
+
data = JSON.parse(json.read)
|
84
|
+
yield data
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
@action.setup_json
|
89
|
+
end
|
90
|
+
|
91
|
+
should "merge in the extra json specified in the config" do
|
92
|
+
@env.config.chef.json = { :foo => "BAR" }
|
93
|
+
assert_json do |data|
|
94
|
+
assert_equal "BAR", data["foo"]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
should "add the directory as a special case to the JSON" do
|
99
|
+
assert_json do |data|
|
100
|
+
assert_equal @env.config.vm.project_directory, data["vagrant"]["directory"]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
should "add the config to the JSON" do
|
105
|
+
assert_json do |data|
|
106
|
+
assert_equal @env.config.vm.project_directory, data["vagrant"]["config"]["vm"]["project_directory"]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
should "upload a StringIO to dna.json" do
|
111
|
+
StringIO.expects(:new).with(anything).returns("bar")
|
112
|
+
File.expects(:join).with(@env.config.chef.provisioning_path, "dna.json").once.returns("baz")
|
113
|
+
@env.ssh.expects(:upload!).with("bar", "baz").once
|
114
|
+
@action.setup_json
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|