vagrant-r10k 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/.pullreview.yml +4 -0
- data/.rspec +5 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -1
- data/CHANGES.md +26 -0
- data/Gemfile +7 -2
- data/Gemfile.lock +181 -0
- data/README.md +122 -7
- data/Rakefile +111 -0
- data/lib/vagrant-r10k/action/base.rb +44 -0
- data/lib/vagrant-r10k/action/deploy.rb +91 -0
- data/lib/vagrant-r10k/action/validate.rb +46 -0
- data/lib/vagrant-r10k/config.rb +13 -4
- data/lib/vagrant-r10k/helpers.rb +174 -0
- data/lib/vagrant-r10k/plugin.rb +11 -5
- data/lib/vagrant-r10k/version.rb +2 -1
- data/spec/acceptance/skeletons/correct/Vagrantfile +21 -0
- data/spec/acceptance/skeletons/correct/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/correct/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/correct/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/correct/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/correct/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/Vagrantfile +21 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/Puppetfile +7 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/could_not_resolve_host/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/different_mod_path/Vagrantfile +19 -0
- data/spec/acceptance/skeletons/different_mod_path/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/different_mod_path/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_mod_path/Vagrantfile +17 -0
- data/spec/acceptance/skeletons/no_mod_path/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/no_mod_path/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_puppet_dir/Vagrantfile +18 -0
- data/spec/acceptance/skeletons/no_puppet_dir/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/Vagrantfile +14 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/NOTmodules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/Puppetfile +12 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/Vagrantfile +18 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/gitcheck.sh +20 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/Puppetfile +1 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/manifests/default.pp +1 -0
- data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/modules/.gitkeep +0 -0
- data/spec/acceptance/vagrant-r10k/vagrant-r10k_spec.rb +255 -0
- data/spec/spec_helper.rb +10 -7
- data/spec/unit/action_base_spec.rb +57 -0
- data/spec/unit/action_deploy_spec.rb +550 -0
- data/spec/unit/action_validate_spec.rb +240 -0
- data/spec/unit/helpers_spec.rb +307 -0
- data/spec/unit/plugin_spec.rb +49 -0
- data/support/testrunner.py +189 -0
- data/vagrant-r10k.gemspec +1 -1
- data/vagrant-spec.config.rb +18 -0
- metadata +111 -19
- data/lib/vagrant-r10k/modulegetter.rb +0 -145
- data/spec/unit/modulegetter_spec.rb +0 -369
@@ -0,0 +1,550 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'sharedcontext'
|
3
|
+
require_relative 'shared_expectations'
|
4
|
+
require 'vagrant-r10k/action/base'
|
5
|
+
require 'vagrant-r10k/action/deploy'
|
6
|
+
require 'r10k/task/puppetfile'
|
7
|
+
require 'r10k/git/errors'
|
8
|
+
|
9
|
+
include SharedExpectations
|
10
|
+
|
11
|
+
describe VagrantPlugins::R10k::Action::Deploy do
|
12
|
+
|
13
|
+
subject { described_class.new(app, env) }
|
14
|
+
|
15
|
+
include_context 'vagrant-unit'
|
16
|
+
|
17
|
+
describe '#call' do
|
18
|
+
describe 'r10k not enabled' do
|
19
|
+
let(:pf_dbl) { double }
|
20
|
+
before do
|
21
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(false)
|
22
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(true)
|
23
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return({:puppetfile_path => 'p'})
|
24
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
25
|
+
end
|
26
|
+
include_context 'unit' do
|
27
|
+
let(:vagrantfile) { <<-EOF
|
28
|
+
Vagrant.configure('2') do |config|
|
29
|
+
config.vm.define :test
|
30
|
+
# r10k plugin to deploy puppet modules
|
31
|
+
# config.r10k.puppet_dir = 'puppet'
|
32
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
33
|
+
|
34
|
+
# Provision the machine with the appliction
|
35
|
+
config.vm.provision "puppet" do |puppet|
|
36
|
+
puppet.manifests_path = "puppet/manifests"
|
37
|
+
puppet.manifest_file = "default.pp"
|
38
|
+
puppet.module_path = "puppet/modules"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
EOF
|
42
|
+
}
|
43
|
+
end
|
44
|
+
it 'should send ui info and return' do
|
45
|
+
# positive expectations
|
46
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
47
|
+
expect(ui).to receive(:info).with("vagrant-r10k not configured; skipping").once
|
48
|
+
expect(app).to receive(:call).once.with(env)
|
49
|
+
# negative assetions
|
50
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to_not receive(:provision_enabled?)
|
51
|
+
expect(ui).to_not receive(:info).with(/Beginning r10k deploy/)
|
52
|
+
expect(subject).to receive(:deploy).exactly(0).times
|
53
|
+
# run
|
54
|
+
expect(subject.call(env)).to be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'provisioning not enabled' do
|
59
|
+
let(:pf_dbl) { double }
|
60
|
+
before do
|
61
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(true)
|
62
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(false)
|
63
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return({:puppetfile_path => 'p'})
|
64
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
65
|
+
end
|
66
|
+
include_context 'unit' do
|
67
|
+
let(:vagrantfile) { <<-EOF
|
68
|
+
Vagrant.configure('2') do |config|
|
69
|
+
config.vm.define :test
|
70
|
+
# r10k plugin to deploy puppet modules
|
71
|
+
config.r10k.puppet_dir = 'puppet'
|
72
|
+
config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
73
|
+
|
74
|
+
# Provision the machine with the appliction
|
75
|
+
config.vm.provision "puppet" do |puppet|
|
76
|
+
puppet.manifests_path = "puppet/manifests"
|
77
|
+
puppet.manifest_file = "default.pp"
|
78
|
+
puppet.module_path = "puppet/modules"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
EOF
|
82
|
+
}
|
83
|
+
end
|
84
|
+
it 'should send ui info and return' do
|
85
|
+
# positive expectations
|
86
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
87
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).with(env).once
|
88
|
+
expect(ui).to receive(:info).with("provisioning disabled; skipping vagrant-r10k").once
|
89
|
+
expect(app).to receive(:call).once.with(env)
|
90
|
+
# negative assetions
|
91
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to_not receive(:r10k_config)
|
92
|
+
expect(ui).to_not receive(:info).with(/Beginning r10k deploy/)
|
93
|
+
expect(subject).to receive(:deploy).exactly(0).times
|
94
|
+
# run
|
95
|
+
expect(subject.call(env)).to be_nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'config is nil' do
|
100
|
+
let(:pf_dbl) { double }
|
101
|
+
before do
|
102
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(true)
|
103
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(true)
|
104
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return(nil)
|
105
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
106
|
+
end
|
107
|
+
include_context 'unit' do
|
108
|
+
let(:vagrantfile) { <<-EOF
|
109
|
+
Vagrant.configure('2') do |config|
|
110
|
+
config.vm.define :test
|
111
|
+
# r10k plugin to deploy puppet modules
|
112
|
+
config.r10k.puppet_dir = 'puppet'
|
113
|
+
config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
114
|
+
|
115
|
+
# Provision the machine with the appliction
|
116
|
+
config.vm.provision "puppet" do |puppet|
|
117
|
+
puppet.manifests_path = "puppet/manifests"
|
118
|
+
puppet.manifest_file = "default.pp"
|
119
|
+
puppet.module_path = "puppet/modules"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
EOF
|
123
|
+
}
|
124
|
+
end
|
125
|
+
it 'should raise exception' do
|
126
|
+
# positive expectations
|
127
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
128
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).with(env).once
|
129
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).once
|
130
|
+
logger = subject.instance_variable_get(:@logger)
|
131
|
+
expect(logger).to receive(:info).once.with("vagrant::r10k::deploy got nil configuration")
|
132
|
+
expect(app).to_not receive(:call)
|
133
|
+
# negative assetions
|
134
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to_not receive(:r10k_config)
|
135
|
+
expect(ui).to_not receive(:info).with(/Beginning r10k deploy/)
|
136
|
+
expect(subject).to receive(:deploy).exactly(0).times
|
137
|
+
# run
|
138
|
+
expect { subject.call(env) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /vagrant-r10k configuration error; cannot continue/)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
describe 'config properly set' do
|
142
|
+
let(:config) {{
|
143
|
+
:env_dir_path => 'env/dir/path',
|
144
|
+
:puppetfile_path => 'puppetfile/path',
|
145
|
+
:module_path => 'module/path',
|
146
|
+
:manifests => 'manifests',
|
147
|
+
:manifest_file => 'manifest/file',
|
148
|
+
:puppet_dir => 'puppet/dir',
|
149
|
+
}}
|
150
|
+
let(:pf_dbl) { double }
|
151
|
+
before do
|
152
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).and_return(true)
|
153
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).and_return(true)
|
154
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).and_return(config)
|
155
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(pf_dbl)
|
156
|
+
end
|
157
|
+
include_context 'unit' do
|
158
|
+
let(:vagrantfile) { <<-EOF
|
159
|
+
Vagrant.configure('2') do |config|
|
160
|
+
config.vm.define :test
|
161
|
+
# r10k plugin to deploy puppet modules
|
162
|
+
config.r10k.puppet_dir = 'puppet'
|
163
|
+
config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
164
|
+
|
165
|
+
# Provision the machine with the appliction
|
166
|
+
config.vm.provision "puppet" do |puppet|
|
167
|
+
puppet.manifests_path = "puppet/manifests"
|
168
|
+
puppet.manifest_file = "default.pp"
|
169
|
+
puppet.module_path = "puppet/modules"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
EOF
|
173
|
+
}
|
174
|
+
end
|
175
|
+
it 'should call deploy' do
|
176
|
+
# positive expectations
|
177
|
+
allow(subject).to receive(:deploy).with(env, config).and_return(true).once
|
178
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_enabled?).with(env).once
|
179
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:provision_enabled?).with(env).once
|
180
|
+
expect_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:r10k_config).with(env).once
|
181
|
+
logger = subject.instance_variable_get(:@logger)
|
182
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy called")
|
183
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy: env_dir_path=env/dir/path")
|
184
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy: puppetfile_path=puppetfile/path")
|
185
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy: module_path=module/path")
|
186
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy: manifests=manifests")
|
187
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy: manifest_file=manifest/file")
|
188
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy: puppet_dir=puppet/dir")
|
189
|
+
expect(subject).to receive(:deploy).with(env, config).once
|
190
|
+
expect(app).to receive(:call).once.with(env)
|
191
|
+
# run
|
192
|
+
expect(subject.call(env)).to be_nil
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end # end #call
|
196
|
+
|
197
|
+
describe '#deploy' do
|
198
|
+
let(:config) {{
|
199
|
+
:env_dir_path => 'env/dir/path',
|
200
|
+
:puppetfile_path => 'puppetfile/path',
|
201
|
+
:module_path => 'module/path',
|
202
|
+
:manifests => 'manifests',
|
203
|
+
:manifest_file => 'manifest/file',
|
204
|
+
:puppet_dir => 'puppet/dir',
|
205
|
+
}}
|
206
|
+
describe 'successful run' do
|
207
|
+
include_context 'unit' do
|
208
|
+
let(:vagrantfile) { <<-EOF
|
209
|
+
Vagrant.configure('2') do |config|
|
210
|
+
config.vm.define :test
|
211
|
+
# r10k plugin to deploy puppet modules
|
212
|
+
# config.r10k.puppet_dir = 'puppet'
|
213
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
214
|
+
|
215
|
+
# Provision the machine with the appliction
|
216
|
+
config.vm.provision "puppet" do |puppet|
|
217
|
+
puppet.manifests_path = "puppet/manifests"
|
218
|
+
puppet.manifest_file = "default.pp"
|
219
|
+
puppet.module_path = "puppet/modules"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
EOF
|
223
|
+
}
|
224
|
+
end
|
225
|
+
let(:puppetfile_dbl) { double }
|
226
|
+
before do
|
227
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(puppetfile_dbl)
|
228
|
+
allow_any_instance_of(R10K::Logging).to receive(:level=)
|
229
|
+
end
|
230
|
+
it 'runs' do
|
231
|
+
# stubs and doubles
|
232
|
+
with_temp_env("VAGRANT_LOG" => "foo") do
|
233
|
+
File.stub(:file?).with('puppetfile/path').and_return(true)
|
234
|
+
runner_dbl = double
|
235
|
+
sync_dbl = double
|
236
|
+
allow(runner_dbl).to receive(:append_task).with(sync_dbl)
|
237
|
+
allow(runner_dbl).to receive(:succeeded?).and_return(true)
|
238
|
+
allow(sync_dbl).to receive(:new).with(puppetfile_dbl)
|
239
|
+
R10K::TaskRunner.stub(:new) { runner_dbl }
|
240
|
+
R10K::Task::Puppetfile::Sync.stub(:new) { sync_dbl }
|
241
|
+
# expectations
|
242
|
+
expect(R10K::Logging).to receive(:level=).with(3).twice
|
243
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Beginning r10k deploy of puppet modules into module/path using puppetfile/path")
|
244
|
+
logger = subject.instance_variable_get(:@logger)
|
245
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy.deploy called")
|
246
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: creating Puppetfile::Sync task")
|
247
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: appending task to runner queue")
|
248
|
+
expect(runner_dbl).to receive(:append_task).with(sync_dbl).once
|
249
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: running sync task")
|
250
|
+
expect(runner_dbl).to receive(:run).once
|
251
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: sync task complete")
|
252
|
+
expect(runner_dbl).to receive(:succeeded?).once
|
253
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Deploy finished")
|
254
|
+
expect(app).to receive(:call).once.with(env)
|
255
|
+
# run
|
256
|
+
expect(subject.deploy(env, config)).to be_nil
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe 'successful run with debug' do
|
262
|
+
include_context 'unit' do
|
263
|
+
let(:vagrantfile) { <<-EOF
|
264
|
+
Vagrant.configure('2') do |config|
|
265
|
+
config.vm.define :test
|
266
|
+
# r10k plugin to deploy puppet modules
|
267
|
+
# config.r10k.puppet_dir = 'puppet'
|
268
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
269
|
+
|
270
|
+
# Provision the machine with the appliction
|
271
|
+
config.vm.provision "puppet" do |puppet|
|
272
|
+
puppet.manifests_path = "puppet/manifests"
|
273
|
+
puppet.manifest_file = "default.pp"
|
274
|
+
puppet.module_path = "puppet/modules"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
EOF
|
278
|
+
}
|
279
|
+
end
|
280
|
+
let(:puppetfile_dbl) { double }
|
281
|
+
before do
|
282
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(puppetfile_dbl)
|
283
|
+
allow_any_instance_of(R10K::Logging).to receive(:level=)
|
284
|
+
end
|
285
|
+
it 'runs with r10k logging level to 0' do
|
286
|
+
# stubs and doubles
|
287
|
+
with_temp_env("VAGRANT_LOG" => "debug") do
|
288
|
+
File.stub(:file?).with('puppetfile/path').and_return(true)
|
289
|
+
runner_dbl = double
|
290
|
+
sync_dbl = double
|
291
|
+
allow(runner_dbl).to receive(:append_task).with(sync_dbl)
|
292
|
+
allow(runner_dbl).to receive(:succeeded?).and_return(true)
|
293
|
+
allow(sync_dbl).to receive(:new).with(puppetfile_dbl)
|
294
|
+
R10K::TaskRunner.stub(:new) { runner_dbl }
|
295
|
+
R10K::Task::Puppetfile::Sync.stub(:new) { sync_dbl }
|
296
|
+
# expectations
|
297
|
+
expect(R10K::Logging).to receive(:level=).with(0).twice
|
298
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Beginning r10k deploy of puppet modules into module/path using puppetfile/path")
|
299
|
+
logger = subject.instance_variable_get(:@logger)
|
300
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy.deploy called")
|
301
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: creating Puppetfile::Sync task")
|
302
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: appending task to runner queue")
|
303
|
+
expect(runner_dbl).to receive(:append_task).with(sync_dbl).once
|
304
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: running sync task")
|
305
|
+
expect(runner_dbl).to receive(:run).once
|
306
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: sync task complete")
|
307
|
+
expect(runner_dbl).to receive(:succeeded?).once
|
308
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Deploy finished")
|
309
|
+
expect(app).to receive(:call).once.with(env)
|
310
|
+
# run
|
311
|
+
expect(subject.deploy(env, config)).to be_nil
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe 'puppetfile doesnt exist' do
|
317
|
+
include_context 'unit' do
|
318
|
+
let(:vagrantfile) { <<-EOF
|
319
|
+
Vagrant.configure('2') do |config|
|
320
|
+
config.vm.define :test
|
321
|
+
# r10k plugin to deploy puppet modules
|
322
|
+
# config.r10k.puppet_dir = 'puppet'
|
323
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
324
|
+
|
325
|
+
# Provision the machine with the appliction
|
326
|
+
config.vm.provision "puppet" do |puppet|
|
327
|
+
puppet.manifests_path = "puppet/manifests"
|
328
|
+
puppet.manifest_file = "default.pp"
|
329
|
+
puppet.module_path = "puppet/modules"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
EOF
|
333
|
+
}
|
334
|
+
end
|
335
|
+
let(:puppetfile_dbl) { double }
|
336
|
+
before do
|
337
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(puppetfile_dbl)
|
338
|
+
end
|
339
|
+
it 'raises an error' do
|
340
|
+
# stubs and doubles
|
341
|
+
with_temp_env("VAGRANT_LOG" => "none") do
|
342
|
+
File.stub(:file?).with('puppetfile/path').and_return(false)
|
343
|
+
runner_dbl = double
|
344
|
+
sync_dbl = double
|
345
|
+
allow(runner_dbl).to receive(:append_task).with(sync_dbl)
|
346
|
+
allow(runner_dbl).to receive(:succeeded?).and_return(true)
|
347
|
+
allow(sync_dbl).to receive(:new).with(puppetfile_dbl)
|
348
|
+
R10K::TaskRunner.stub(:new) { runner_dbl }
|
349
|
+
R10K::Task::Puppetfile::Sync.stub(:new) { sync_dbl }
|
350
|
+
# expectations
|
351
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Beginning r10k deploy of puppet modules into module/path using puppetfile/path")
|
352
|
+
logger = subject.instance_variable_get(:@logger)
|
353
|
+
# negative expectations
|
354
|
+
expect(logger).to_not receive(:debug).once.ordered.with("vagrant::r10k::deploy.deploy called")
|
355
|
+
expect(logger).to_not receive(:debug).with("vagrant-r10k: creating Puppetfile::Sync task")
|
356
|
+
expect(logger).to_not receive(:debug).with("vagrant-r10k: appending task to runner queue")
|
357
|
+
expect(runner_dbl).to_not receive(:append_task).with(sync_dbl)
|
358
|
+
expect(logger).to_not receive(:debug).with("vagrant-r10k: running sync task")
|
359
|
+
expect(runner_dbl).to_not receive(:run)
|
360
|
+
expect(logger).to_not receive(:debug).with("vagrant-r10k: sync task complete")
|
361
|
+
expect(runner_dbl).to_not receive(:succeeded?)
|
362
|
+
expect(ui).to_not receive(:info).with("vagrant-r10k: Deploy finished")
|
363
|
+
expect(app).to_not receive(:call).with(env)
|
364
|
+
# run
|
365
|
+
expect { subject.deploy(env, config) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /Puppetfile at puppetfile\/path does not exist/)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
describe 'run failed' do
|
371
|
+
include_context 'unit' do
|
372
|
+
let(:vagrantfile) { <<-EOF
|
373
|
+
Vagrant.configure('2') do |config|
|
374
|
+
config.vm.define :test
|
375
|
+
# r10k plugin to deploy puppet modules
|
376
|
+
# config.r10k.puppet_dir = 'puppet'
|
377
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
378
|
+
|
379
|
+
# Provision the machine with the appliction
|
380
|
+
config.vm.provision "puppet" do |puppet|
|
381
|
+
puppet.manifests_path = "puppet/manifests"
|
382
|
+
puppet.manifest_file = "default.pp"
|
383
|
+
puppet.module_path = "puppet/modules"
|
384
|
+
end
|
385
|
+
end
|
386
|
+
EOF
|
387
|
+
}
|
388
|
+
end
|
389
|
+
let(:puppetfile_dbl) { double }
|
390
|
+
before do
|
391
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(puppetfile_dbl)
|
392
|
+
allow_any_instance_of(R10K::Logging).to receive(:level=)
|
393
|
+
end
|
394
|
+
it 'raises an error' do
|
395
|
+
# stubs and doubles
|
396
|
+
with_temp_env("VAGRANT_LOG" => "foo") do
|
397
|
+
File.stub(:file?).with('puppetfile/path').and_return(true)
|
398
|
+
runner_dbl = double
|
399
|
+
sync_dbl = double
|
400
|
+
allow(runner_dbl).to receive(:append_task).with(sync_dbl)
|
401
|
+
allow(runner_dbl).to receive(:succeeded?).and_return(false)
|
402
|
+
allow(runner_dbl).to receive(:get_errors).and_return(
|
403
|
+
[[
|
404
|
+
sync_dbl,
|
405
|
+
R10K::Git::GitError.new("Couldn't update git cache for https://example.com/foobar.git: \"fatal: repository 'https://example.com/foobar.git/' not found\"")
|
406
|
+
]])
|
407
|
+
allow(sync_dbl).to receive(:new).with(puppetfile_dbl)
|
408
|
+
R10K::TaskRunner.stub(:new) { runner_dbl }
|
409
|
+
R10K::Task::Puppetfile::Sync.stub(:new) { sync_dbl }
|
410
|
+
# expectations
|
411
|
+
expect(R10K::Logging).to receive(:level=).with(3).twice
|
412
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Beginning r10k deploy of puppet modules into module/path using puppetfile/path")
|
413
|
+
logger = subject.instance_variable_get(:@logger)
|
414
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy.deploy called")
|
415
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: creating Puppetfile::Sync task")
|
416
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: appending task to runner queue")
|
417
|
+
expect(runner_dbl).to receive(:append_task).with(sync_dbl).once
|
418
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: running sync task")
|
419
|
+
expect(runner_dbl).to receive(:run).once
|
420
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: sync task complete")
|
421
|
+
expect(runner_dbl).to receive(:succeeded?).once
|
422
|
+
# negative expectations
|
423
|
+
expect(ui).to_not receive(:info).with("vagrant-r10k: Deploy finished")
|
424
|
+
expect(app).to_not receive(:call)
|
425
|
+
# run
|
426
|
+
expect { subject.deploy(env, config) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /Couldn't update git cache for https:\/\/example\.com\/foobar\.git: "fatal: repository 'https:\/\/example\.com\/foobar\.git\/' not found"/)
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe 'Could not resolve host' do
|
432
|
+
include_context 'unit' do
|
433
|
+
let(:vagrantfile) { <<-EOF
|
434
|
+
Vagrant.configure('2') do |config|
|
435
|
+
config.vm.define :test
|
436
|
+
# r10k plugin to deploy puppet modules
|
437
|
+
# config.r10k.puppet_dir = 'puppet'
|
438
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
439
|
+
|
440
|
+
# Provision the machine with the appliction
|
441
|
+
config.vm.provision "puppet" do |puppet|
|
442
|
+
puppet.manifests_path = "puppet/manifests"
|
443
|
+
puppet.manifest_file = "default.pp"
|
444
|
+
puppet.module_path = "puppet/modules"
|
445
|
+
end
|
446
|
+
end
|
447
|
+
EOF
|
448
|
+
}
|
449
|
+
end
|
450
|
+
let(:puppetfile_dbl) { double }
|
451
|
+
before do
|
452
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(puppetfile_dbl)
|
453
|
+
allow_any_instance_of(R10K::Logging).to receive(:level=)
|
454
|
+
end
|
455
|
+
it 'raises an error' do
|
456
|
+
# stubs and doubles
|
457
|
+
with_temp_env("VAGRANT_LOG" => "foo") do
|
458
|
+
File.stub(:file?).with('puppetfile/path').and_return(true)
|
459
|
+
runner_dbl = double
|
460
|
+
sync_dbl = double
|
461
|
+
allow(runner_dbl).to receive(:append_task).with(sync_dbl)
|
462
|
+
allow(runner_dbl).to receive(:succeeded?).and_return(false)
|
463
|
+
allow(runner_dbl).to receive(:get_errors).and_return(
|
464
|
+
[[
|
465
|
+
sync_dbl,
|
466
|
+
R10K::Git::GitError.new("Couldn't update git cache for https://foo.com/jantman/bar.git: \"fatal: unable to access 'https://foo.com/jantman/bar.git/': Could not resolve host: foo.com\"")
|
467
|
+
]])
|
468
|
+
allow(sync_dbl).to receive(:new).with(puppetfile_dbl)
|
469
|
+
R10K::TaskRunner.stub(:new) { runner_dbl }
|
470
|
+
R10K::Task::Puppetfile::Sync.stub(:new) { sync_dbl }
|
471
|
+
# expectations
|
472
|
+
expect(R10K::Logging).to receive(:level=).with(3).twice
|
473
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Beginning r10k deploy of puppet modules into module/path using puppetfile/path")
|
474
|
+
logger = subject.instance_variable_get(:@logger)
|
475
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy.deploy called")
|
476
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: creating Puppetfile::Sync task")
|
477
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: appending task to runner queue")
|
478
|
+
expect(runner_dbl).to receive(:append_task).with(sync_dbl).once
|
479
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: running sync task")
|
480
|
+
expect(runner_dbl).to receive(:run).once
|
481
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: sync task complete")
|
482
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: caught 'Could not resolve host' error")
|
483
|
+
expect(runner_dbl).to receive(:succeeded?).once
|
484
|
+
# negative expectations
|
485
|
+
expect(ui).to_not receive(:info).with("vagrant-r10k: Deploy finished")
|
486
|
+
expect(app).to_not receive(:call)
|
487
|
+
# run
|
488
|
+
expect { subject.deploy(env, config) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /Could not resolve host: foo\.com.*If you don't have connectivity to the host, running 'vagrant up --no-provision' will skip r10k deploy and all provisioning/m)
|
489
|
+
end
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
describe 'puppetfile syntax error' do
|
494
|
+
include_context 'unit' do
|
495
|
+
let(:vagrantfile) { <<-EOF
|
496
|
+
Vagrant.configure('2') do |config|
|
497
|
+
config.vm.define :test
|
498
|
+
# r10k plugin to deploy puppet modules
|
499
|
+
# config.r10k.puppet_dir = 'puppet'
|
500
|
+
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
|
501
|
+
|
502
|
+
# Provision the machine with the appliction
|
503
|
+
config.vm.provision "puppet" do |puppet|
|
504
|
+
puppet.manifests_path = "puppet/manifests"
|
505
|
+
puppet.manifest_file = "default.pp"
|
506
|
+
puppet.module_path = "puppet/modules"
|
507
|
+
end
|
508
|
+
end
|
509
|
+
EOF
|
510
|
+
}
|
511
|
+
end
|
512
|
+
let(:puppetfile_dbl) { double }
|
513
|
+
before do
|
514
|
+
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(puppetfile_dbl)
|
515
|
+
allow_any_instance_of(R10K::Logging).to receive(:level=)
|
516
|
+
end
|
517
|
+
it 'raises an error' do
|
518
|
+
# stubs and doubles
|
519
|
+
with_temp_env("VAGRANT_LOG" => "foo") do
|
520
|
+
File.stub(:file?).with('puppetfile/path').and_return(true)
|
521
|
+
runner_dbl = double
|
522
|
+
sync_dbl = double
|
523
|
+
allow(runner_dbl).to receive(:append_task).with(sync_dbl)
|
524
|
+
allow(runner_dbl).to receive(:succeeded?).and_return(false)
|
525
|
+
allow(runner_dbl).to receive(:run).and_raise(SyntaxError.new("some syntax error"))
|
526
|
+
allow(sync_dbl).to receive(:new).with(puppetfile_dbl)
|
527
|
+
R10K::TaskRunner.stub(:new) { runner_dbl }
|
528
|
+
R10K::Task::Puppetfile::Sync.stub(:new) { sync_dbl }
|
529
|
+
# expectations
|
530
|
+
expect(R10K::Logging).to receive(:level=).with(3).twice
|
531
|
+
expect(ui).to receive(:info).with("vagrant-r10k: Beginning r10k deploy of puppet modules into module/path using puppetfile/path")
|
532
|
+
logger = subject.instance_variable_get(:@logger)
|
533
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy.deploy called")
|
534
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: creating Puppetfile::Sync task")
|
535
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: appending task to runner queue")
|
536
|
+
expect(runner_dbl).to receive(:append_task).with(sync_dbl).once
|
537
|
+
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: running sync task")
|
538
|
+
expect(runner_dbl).to receive(:run).once
|
539
|
+
# negative expectations
|
540
|
+
expect(logger).to_not receive(:debug).with("vagrant-r10k: sync task complete")
|
541
|
+
expect(runner_dbl).to_not receive(:succeeded?)
|
542
|
+
expect(ui).to_not receive(:info).with("vagrant-r10k: Deploy finished")
|
543
|
+
expect(app).to_not receive(:call)
|
544
|
+
# run
|
545
|
+
expect { subject.deploy(env, config) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /SyntaxError: some syntax error/)
|
546
|
+
end
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end
|
550
|
+
end
|