vagrant 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG.md +48 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +49 -0
- data/README.md +2 -2
- data/Rakefile +22 -0
- data/bin/.gitignore +0 -0
- data/lib/vagrant/provisioners/chef_solo.rb +1 -1
- data/lib/vagrant/util/template_renderer.rb +2 -2
- data/lib/vagrant/version.rb +1 -1
- data/templates/Vagrantfile.erb +1 -1
- data/templates/nfs/exports.erb +4 -2
- data/test/test_helper.rb +128 -0
- data/test/vagrant/action/box/destroy_test.rb +30 -0
- data/test/vagrant/action/box/download_test.rb +141 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +103 -0
- data/test/vagrant/action/box/verify_test.rb +39 -0
- data/test/vagrant/action/builder_test.rb +218 -0
- data/test/vagrant/action/env/error_halt_test.rb +21 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +45 -0
- data/test/vagrant/action/exception_catcher_test.rb +30 -0
- data/test/vagrant/action/general/package_test.rb +254 -0
- data/test/vagrant/action/vm/boot_test.rb +83 -0
- data/test/vagrant/action/vm/check_box_test.rb +48 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -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 +29 -0
- data/test/vagrant/action/vm/destroy_test.rb +26 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
- data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
- data/test/vagrant/action/vm/discard_state_test.rb +36 -0
- data/test/vagrant/action/vm/export_test.rb +135 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
- data/test/vagrant/action/vm/halt_test.rb +69 -0
- data/test/vagrant/action/vm/import_test.rb +50 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
- data/test/vagrant/action/vm/network_test.rb +246 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
- data/test/vagrant/action/vm/nfs_test.rb +269 -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/persist_test.rb +50 -0
- data/test/vagrant/action/vm/provision_test.rb +134 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +215 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action_test.rb +111 -0
- data/test/vagrant/active_list_test.rb +173 -0
- data/test/vagrant/box_test.rb +166 -0
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +139 -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/box/repackage_test.rb +52 -0
- data/test/vagrant/commands/destroy_test.rb +44 -0
- data/test/vagrant/commands/halt_test.rb +50 -0
- data/test/vagrant/commands/init_test.rb +71 -0
- data/test/vagrant/commands/package_test.rb +97 -0
- data/test/vagrant/commands/provision_test.rb +60 -0
- data/test/vagrant/commands/reload_test.rb +47 -0
- data/test/vagrant/commands/resume_test.rb +44 -0
- data/test/vagrant/commands/ssh_config_test.rb +77 -0
- data/test/vagrant/commands/ssh_test.rb +129 -0
- data/test/vagrant/commands/status_test.rb +40 -0
- data/test/vagrant/commands/suspend_test.rb +44 -0
- data/test/vagrant/commands/up_test.rb +49 -0
- data/test/vagrant/config_test.rb +307 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +33 -0
- data/test/vagrant/downloaders/http_test.rb +70 -0
- data/test/vagrant/environment_test.rb +770 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +56 -0
- data/test/vagrant/hosts/linux_test.rb +56 -0
- data/test/vagrant/provisioners/base_test.rb +36 -0
- data/test/vagrant/provisioners/chef_server_test.rb +182 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
- data/test/vagrant/provisioners/chef_test.rb +178 -0
- data/test/vagrant/ssh_session_test.rb +46 -0
- data/test/vagrant/ssh_test.rb +317 -0
- data/test/vagrant/systems/linux_test.rb +179 -0
- data/test/vagrant/util/busy_test.rb +106 -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 +145 -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/util/translator_test.rb +61 -0
- data/test/vagrant/util_test.rb +27 -0
- data/test/vagrant/vm_test.rb +228 -0
- data/vagrant.gemspec +34 -0
- metadata +158 -43
@@ -0,0 +1,46 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BaseHostTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Hosts::Base
|
6
|
+
end
|
7
|
+
|
8
|
+
context "class methods" do
|
9
|
+
context "loading" do
|
10
|
+
setup do
|
11
|
+
@env = mock_environment
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return detected class if klass is nil" do
|
15
|
+
Vagrant::Util::Platform.stubs(:platform).returns("darwin")
|
16
|
+
result = @klass.load(@env, nil)
|
17
|
+
assert result.is_a?(Vagrant::Hosts::BSD)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "instantiate the given class" do
|
21
|
+
result = @klass.load(@env, Vagrant::Hosts::BSD)
|
22
|
+
assert result.is_a?(Vagrant::Hosts::BSD)
|
23
|
+
assert_equal @env, result.env
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "detecting class" do
|
28
|
+
should "return the proper class" do
|
29
|
+
Vagrant::Util::Platform.stubs(:platform).returns("darwin10")
|
30
|
+
assert_equal Vagrant::Hosts::BSD, @klass.detect
|
31
|
+
end
|
32
|
+
|
33
|
+
should "return nil if no class is detected" do
|
34
|
+
Vagrant::Util::Platform.stubs(:platform).returns("boo")
|
35
|
+
assert_nil @klass.detect
|
36
|
+
end
|
37
|
+
|
38
|
+
should "return nil if an exception is raised" do
|
39
|
+
Vagrant::Util::Platform.stubs(:platform).returns("boo")
|
40
|
+
assert_nothing_raised {
|
41
|
+
assert_nil @klass.detect
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BSDHostTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Hosts::BSD
|
6
|
+
@env = mock_environment
|
7
|
+
@env.stubs(:vm).returns(Vagrant::VM.new(:env => @env))
|
8
|
+
@env.logger.stubs(:info)
|
9
|
+
|
10
|
+
@instance = @klass.new(@env)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "supporting nfs check" do
|
14
|
+
should "support NFS" do
|
15
|
+
@instance.expects(:system).returns(true)
|
16
|
+
assert @instance.nfs?
|
17
|
+
end
|
18
|
+
|
19
|
+
should "not support NFS if nfsd is not found" do
|
20
|
+
@instance.expects(:system).returns(false)
|
21
|
+
assert !@instance.nfs?
|
22
|
+
end
|
23
|
+
|
24
|
+
should "retry until a boolean is returned" do
|
25
|
+
seq = sequence("seq")
|
26
|
+
@instance.expects(:system).in_sequence(seq).raises(TypeError.new("foo"))
|
27
|
+
@instance.expects(:system).in_sequence(seq).returns(true)
|
28
|
+
assert @instance.nfs?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "nfs export" do
|
33
|
+
setup do
|
34
|
+
@instance.stubs(:system)
|
35
|
+
|
36
|
+
@ip = "foo"
|
37
|
+
@folders = "bar"
|
38
|
+
end
|
39
|
+
|
40
|
+
should "output the lines of the rendered template" do
|
41
|
+
output = %W[foo bar baz].join("\n")
|
42
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with("nfs/exports",
|
43
|
+
:uuid => @env.vm.uuid,
|
44
|
+
:ip => @ip,
|
45
|
+
:folders => @folders).returns(output)
|
46
|
+
|
47
|
+
@instance.expects(:system).times(output.split("\n").length)
|
48
|
+
@instance.expects(:system).with("sudo nfsd restart")
|
49
|
+
@instance.nfs_export(@ip, @folders)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "nfs cleanup" do
|
54
|
+
# TODO: How to test all the system calls?
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class LinuxHostTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Hosts::Linux
|
6
|
+
@env = mock_environment
|
7
|
+
@env.stubs(:vm).returns(Vagrant::VM.new(:env => @env))
|
8
|
+
@env.logger.stubs(:info)
|
9
|
+
|
10
|
+
@instance = @klass.new(@env)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "supporting nfs check" do
|
14
|
+
should "support NFS" do
|
15
|
+
@instance.expects(:system).returns(true)
|
16
|
+
assert @instance.nfs?
|
17
|
+
end
|
18
|
+
|
19
|
+
should "not support NFS if nfsd is not found" do
|
20
|
+
@instance.expects(:system).returns(false)
|
21
|
+
assert !@instance.nfs?
|
22
|
+
end
|
23
|
+
|
24
|
+
should "retry until a boolean is returned" do
|
25
|
+
seq = sequence("seq")
|
26
|
+
@instance.expects(:system).in_sequence(seq).raises(TypeError.new("foo"))
|
27
|
+
@instance.expects(:system).in_sequence(seq).returns(true)
|
28
|
+
assert @instance.nfs?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "nfs export" do
|
33
|
+
setup do
|
34
|
+
@instance.stubs(:system)
|
35
|
+
|
36
|
+
@ip = "foo"
|
37
|
+
@folders = "bar"
|
38
|
+
end
|
39
|
+
|
40
|
+
should "output the lines of the rendered template" do
|
41
|
+
output = %W[foo bar baz].join("\n")
|
42
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with("nfs/exports_linux",
|
43
|
+
:uuid => @env.vm.uuid,
|
44
|
+
:ip => @ip,
|
45
|
+
:folders => @folders).returns(output)
|
46
|
+
|
47
|
+
@instance.expects(:system).times(output.split("\n").length)
|
48
|
+
@instance.expects(:system).with("sudo /etc/init.d/nfs-kernel-server restart")
|
49
|
+
@instance.nfs_export(@ip, @folders)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "nfs cleanup" do
|
54
|
+
# TODO: How to test all the system calls?
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "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 = Vagrant::Action::Environment.new(mock_environment)
|
11
|
+
@base = Vagrant::Provisioners::Base.new(@env)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "set the environment" do
|
15
|
+
assert_equal @env.env, @base.env
|
16
|
+
end
|
17
|
+
|
18
|
+
should "return the VM which the provisioner is acting on" do
|
19
|
+
assert_equal @env.env.vm, @base.vm
|
20
|
+
end
|
21
|
+
|
22
|
+
should "implement provision! which does nothing" do
|
23
|
+
assert_nothing_raised do
|
24
|
+
assert @base.respond_to?(:provision!)
|
25
|
+
@base.provision!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
should "implement prepare which does nothing" do
|
30
|
+
assert_nothing_raised do
|
31
|
+
assert @base.respond_to?(:prepare)
|
32
|
+
@base.prepare
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ChefServerProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@action_env = Vagrant::Action::Environment.new(mock_environment)
|
6
|
+
@action_env.env.vm = mock_vm
|
7
|
+
|
8
|
+
@action = Vagrant::Provisioners::ChefServer.new(@action_env)
|
9
|
+
@env = @action.env
|
10
|
+
@vm = @action.vm
|
11
|
+
end
|
12
|
+
|
13
|
+
context "provisioning" do
|
14
|
+
should "run the proper sequence of methods in order" do
|
15
|
+
prov_seq = sequence("prov_seq")
|
16
|
+
@action.expects(:verify_binary).with("chef-client").once.in_sequence(prov_seq)
|
17
|
+
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
18
|
+
@action.expects(:create_client_key_folder).once.in_sequence(prov_seq)
|
19
|
+
@action.expects(:upload_validation_key).once.in_sequence(prov_seq)
|
20
|
+
@action.expects(:setup_json).once.in_sequence(prov_seq)
|
21
|
+
@action.expects(:setup_server_config).once.in_sequence(prov_seq)
|
22
|
+
@action.expects(:run_chef_client).once.in_sequence(prov_seq)
|
23
|
+
@action.provision!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "preparing" do
|
28
|
+
setup do
|
29
|
+
File.stubs(:file?).returns(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "not raise an exception if validation_key_path is set" do
|
33
|
+
@env = mock_environment do |config|
|
34
|
+
config.chef.validation_key_path = "7"
|
35
|
+
end
|
36
|
+
|
37
|
+
@action.stubs(:env).returns(@env)
|
38
|
+
|
39
|
+
@action.prepare
|
40
|
+
assert !@action_env.error?
|
41
|
+
end
|
42
|
+
|
43
|
+
should "eraise an exception if validation_key_path is nil" do
|
44
|
+
@env = mock_environment do |config|
|
45
|
+
config.chef.validation_key_path = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
@action.stubs(:env).returns(@env)
|
49
|
+
|
50
|
+
@action.prepare
|
51
|
+
assert @action_env.error?
|
52
|
+
assert_equal :chef_server_validation_key_required, @action_env.error.first
|
53
|
+
end
|
54
|
+
|
55
|
+
should "not raise an exception if validation_key_path does exist" do
|
56
|
+
@env = mock_environment do |config|
|
57
|
+
config.chef.validation_key_path = "7"
|
58
|
+
end
|
59
|
+
|
60
|
+
@action.stubs(:env).returns(@env)
|
61
|
+
@action.stubs(:validation_key_path).returns("9")
|
62
|
+
|
63
|
+
File.expects(:file?).with(@action.validation_key_path).returns(true)
|
64
|
+
@action.prepare
|
65
|
+
assert !@action_env.error?
|
66
|
+
end
|
67
|
+
|
68
|
+
should "raise an exception if validation_key_path doesn't exist" do
|
69
|
+
@env = mock_environment do |config|
|
70
|
+
config.chef.validation_key_path = "7"
|
71
|
+
end
|
72
|
+
|
73
|
+
@action.stubs(:env).returns(@env)
|
74
|
+
@action.stubs(:validation_key_path).returns("9")
|
75
|
+
|
76
|
+
File.expects(:file?).with(@action.validation_key_path).returns(false)
|
77
|
+
@action.prepare
|
78
|
+
assert @action_env.error?
|
79
|
+
assert_equal :chef_server_validation_key_doesnt_exist, @action_env.error.first
|
80
|
+
end
|
81
|
+
|
82
|
+
should "not raise an exception if chef_server_url is set" do
|
83
|
+
@env = mock_environment do |config|
|
84
|
+
config.chef.chef_server_url = "7"
|
85
|
+
end
|
86
|
+
|
87
|
+
@action.stubs(:env).returns(@env)
|
88
|
+
|
89
|
+
@action.prepare
|
90
|
+
assert !@action_env.error?
|
91
|
+
end
|
92
|
+
|
93
|
+
should "raise an exception if chef_server_url is nil" do
|
94
|
+
@env = mock_environment do |config|
|
95
|
+
config.chef.chef_server_url = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
@action.stubs(:env).returns(@env)
|
99
|
+
|
100
|
+
@action.prepare
|
101
|
+
assert @action_env.error?
|
102
|
+
assert_equal :chef_server_url_required, @action_env.error.first
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "creating the client key folder" do
|
107
|
+
setup do
|
108
|
+
@raw_path = "/foo/bar/baz.pem"
|
109
|
+
@env.config.chef.client_key_path = @raw_path
|
110
|
+
|
111
|
+
@path = Pathname.new(@raw_path)
|
112
|
+
end
|
113
|
+
|
114
|
+
should "create the folder using the dirname of the path" do
|
115
|
+
ssh = mock("ssh")
|
116
|
+
ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
|
117
|
+
@vm.ssh.expects(:execute).yields(ssh)
|
118
|
+
@action.create_client_key_folder
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "uploading the validation key" do
|
123
|
+
should "upload the validation key to the provisioning path" do
|
124
|
+
@action.expects(:validation_key_path).once.returns("foo")
|
125
|
+
@action.expects(:guest_validation_key_path).once.returns("bar")
|
126
|
+
@vm.ssh.expects(:upload!).with("foo", "bar").once
|
127
|
+
@action.upload_validation_key
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "the validation key path" do
|
132
|
+
should "expand the configured key path" do
|
133
|
+
result = mock("result")
|
134
|
+
File.expects(:expand_path).with(@env.config.chef.validation_key_path, @env.root_path).once.returns(result)
|
135
|
+
assert_equal result, @action.validation_key_path
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "the guest validation key path" do
|
140
|
+
should "be the provisioning path joined with validation.pem" do
|
141
|
+
result = mock("result")
|
142
|
+
File.expects(:join).with(@env.config.chef.provisioning_path, "validation.pem").once.returns(result)
|
143
|
+
assert_equal result, @action.guest_validation_key_path
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "generating and uploading chef client configuration file" do
|
148
|
+
setup do
|
149
|
+
@action.stubs(:guest_validation_key_path).returns("foo")
|
150
|
+
end
|
151
|
+
|
152
|
+
should "call setup_config with proper variables" do
|
153
|
+
@action.expects(:setup_config).with("chef_server_client", "client.rb", {
|
154
|
+
:node_name => @env.config.chef.node_name,
|
155
|
+
:chef_server_url => @env.config.chef.chef_server_url,
|
156
|
+
:validation_client_name => @env.config.chef.validation_client_name,
|
157
|
+
:validation_key => @action.guest_validation_key_path,
|
158
|
+
:client_key => @env.config.chef.client_key_path
|
159
|
+
})
|
160
|
+
|
161
|
+
@action.setup_server_config
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "running chef client" do
|
166
|
+
setup do
|
167
|
+
@ssh = mock("ssh")
|
168
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
169
|
+
end
|
170
|
+
|
171
|
+
should "cd into the provisioning directory and run chef client" do
|
172
|
+
@ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json").once
|
173
|
+
@action.run_chef_client
|
174
|
+
end
|
175
|
+
|
176
|
+
should "check the exit status if that is given" do
|
177
|
+
@ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
|
178
|
+
@ssh.expects(:check_exit_status).with(:foo, anything).once
|
179
|
+
@action.run_chef_client
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ChefSoloProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@action_env = Vagrant::Action::Environment.new(mock_environment)
|
6
|
+
@action_env.env.vm = mock_vm
|
7
|
+
|
8
|
+
@action = Vagrant::Provisioners::ChefSolo.new(@action_env)
|
9
|
+
@env = @action.env
|
10
|
+
@vm = @action.vm
|
11
|
+
end
|
12
|
+
|
13
|
+
context "preparing" do
|
14
|
+
should "share cookbook folders" do
|
15
|
+
@action.expects(:share_cookbook_folders).once
|
16
|
+
@action.prepare
|
17
|
+
end
|
18
|
+
|
19
|
+
should "share role folders" do
|
20
|
+
@action.expects(:share_role_folders).once
|
21
|
+
@action.prepare
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "provisioning" do
|
26
|
+
should "run the proper sequence of methods in order" do
|
27
|
+
prov_seq = sequence("prov_seq")
|
28
|
+
@action.expects(:verify_binary).with("chef-solo").once.in_sequence(prov_seq)
|
29
|
+
@action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
|
30
|
+
@action.expects(:setup_json).once.in_sequence(prov_seq)
|
31
|
+
@action.expects(:setup_solo_config).once.in_sequence(prov_seq)
|
32
|
+
@action.expects(:run_chef_solo).once.in_sequence(prov_seq)
|
33
|
+
@action.provision!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
context "sharing cookbook folders" do
|
37
|
+
setup do
|
38
|
+
@host_cookbook_paths = ["foo", "bar"]
|
39
|
+
@action.stubs(:host_cookbook_paths).returns(@host_cookbook_paths)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "share each cookbook folder" do
|
43
|
+
share_seq = sequence("share_seq")
|
44
|
+
@host_cookbook_paths.each_with_index do |cookbook, i|
|
45
|
+
@env.config.vm.expects(:share_folder).with("v-csc-#{i}", @action.cookbook_path(i), cookbook).in_sequence(share_seq)
|
46
|
+
end
|
47
|
+
|
48
|
+
@action.share_cookbook_folders
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "sharing role folders" do
|
53
|
+
setup do
|
54
|
+
@host_role_paths = ["foo", "bar"]
|
55
|
+
@action.stubs(:host_role_paths).returns(@host_role_paths)
|
56
|
+
end
|
57
|
+
|
58
|
+
should "share each role folder" do
|
59
|
+
share_seq = sequence("share_seq")
|
60
|
+
@host_role_paths.each_with_index do |role, i|
|
61
|
+
@env.config.vm.expects(:share_folder).with("v-csr-#{i}", @action.role_path(i), role).in_sequence(share_seq)
|
62
|
+
end
|
63
|
+
|
64
|
+
@action.share_role_folders
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "host folder paths" do
|
69
|
+
should "ignore VM paths" do
|
70
|
+
assert @action.host_folder_paths([:vm, "foo"]).empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
should "return as an array if was originally a string" do
|
74
|
+
folder = "foo"
|
75
|
+
File.stubs(:expand_path).returns("bar")
|
76
|
+
assert_equal ["bar"], @action.host_folder_paths(folder)
|
77
|
+
end
|
78
|
+
|
79
|
+
should "return the array of folders if its an array" do
|
80
|
+
folders = ["foo", "bar"]
|
81
|
+
expand_seq = sequence('expand_seq')
|
82
|
+
folders.collect! { |folder| File.expand_path(folder, @env.root_path) }
|
83
|
+
|
84
|
+
assert_equal folders, @action.host_folder_paths(folders)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "host cookbooks paths" do
|
89
|
+
should "get folders path for configured cookbooks path" do
|
90
|
+
result = mock("result")
|
91
|
+
@env.config.chef.stubs(:cookbooks_path).returns("foo")
|
92
|
+
@action.expects(:host_folder_paths).with(@env.config.chef.cookbooks_path).returns(result)
|
93
|
+
assert_equal result, @action.host_cookbook_paths
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "host roles paths" do
|
98
|
+
should "get folders path for configured roles path" do
|
99
|
+
result = mock("result")
|
100
|
+
@env.config.chef.stubs(:roles_path).returns("foo")
|
101
|
+
@action.expects(:host_folder_paths).with(@env.config.chef.roles_path).returns(result)
|
102
|
+
assert_equal result, @action.host_role_paths
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "folder path" do
|
107
|
+
should "return a proper path to a single folder" do
|
108
|
+
expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
|
109
|
+
assert_equal expected, @action.folder_path("cookbooks", 5)
|
110
|
+
end
|
111
|
+
|
112
|
+
should "return array-representation of folder paths if multiple" do
|
113
|
+
@folders = (0..5).to_a
|
114
|
+
@cookbooks = @folders.inject([]) do |acc, i|
|
115
|
+
acc << @action.cookbook_path(i)
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_equal @cookbooks, @action.folders_path(@folders, "cookbooks")
|
119
|
+
end
|
120
|
+
|
121
|
+
should "return a single string representation if folder paths is single" do
|
122
|
+
@folder = "cookbooks"
|
123
|
+
@cookbooks = @action.folder_path(@folder, 0)
|
124
|
+
|
125
|
+
assert_equal @cookbooks, @action.folders_path([0], @folder)
|
126
|
+
end
|
127
|
+
|
128
|
+
should "properly format VM folder paths" do
|
129
|
+
@env.config.chef.provisioning_path = "/foo"
|
130
|
+
assert_equal "/foo/bar", @action.folders_path([:vm, "bar"], nil)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "cookbooks path" do
|
135
|
+
should "return a proper path to a single cookbook" do
|
136
|
+
expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
|
137
|
+
assert_equal expected, @action.cookbook_path(5)
|
138
|
+
end
|
139
|
+
|
140
|
+
should "properly call folders path and return result" do
|
141
|
+
result = [:a, :b, :c]
|
142
|
+
@action.expects(:folders_path).with(@env.config.chef.cookbooks_path, "cookbooks").once.returns(result)
|
143
|
+
assert_equal result.to_json, @action.cookbooks_path
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "roles path" do
|
148
|
+
should "return a proper path to a single role" do
|
149
|
+
expected = File.join(@env.config.chef.provisioning_path, "roles-5")
|
150
|
+
assert_equal expected, @action.role_path(5)
|
151
|
+
end
|
152
|
+
|
153
|
+
should "properly call folders path and return result" do
|
154
|
+
result = [:a, :b, :c]
|
155
|
+
@action.expects(:folders_path).with(@env.config.chef.roles_path, "roles").once.returns(result)
|
156
|
+
assert_equal result.to_json, @action.roles_path
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "generating and uploading chef solo configuration file" do
|
161
|
+
setup do
|
162
|
+
@vm.ssh.stubs(:upload!)
|
163
|
+
|
164
|
+
@env.config.chef.recipe_url = "foo/bar/baz"
|
165
|
+
end
|
166
|
+
|
167
|
+
should "call setup_config with proper variables" do
|
168
|
+
@action.expects(:setup_config).with("chef_solo_solo", "solo.rb", {
|
169
|
+
:node_name => @env.config.chef.node_name,
|
170
|
+
:provisioning_path => @env.config.chef.provisioning_path,
|
171
|
+
:cookbooks_path => @action.cookbooks_path,
|
172
|
+
:recipe_url => @env.config.chef.recipe_url,
|
173
|
+
:roles_path => @action.roles_path
|
174
|
+
})
|
175
|
+
|
176
|
+
@action.setup_solo_config
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "running chef solo" do
|
181
|
+
setup do
|
182
|
+
@ssh = mock("ssh")
|
183
|
+
@vm.ssh.stubs(:execute).yields(@ssh)
|
184
|
+
end
|
185
|
+
|
186
|
+
should "cd into the provisioning directory and run chef solo" do
|
187
|
+
@ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json").once
|
188
|
+
@action.run_chef_solo
|
189
|
+
end
|
190
|
+
|
191
|
+
should "check the exit status if that is given" do
|
192
|
+
@ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
|
193
|
+
@ssh.expects(:check_exit_status).with(:foo, anything).once
|
194
|
+
@action.run_chef_solo
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|