vagrant-r10k 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.pullreview.yml +4 -0
  4. data/.rspec +5 -0
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +3 -1
  7. data/CHANGES.md +26 -0
  8. data/Gemfile +7 -2
  9. data/Gemfile.lock +181 -0
  10. data/README.md +122 -7
  11. data/Rakefile +111 -0
  12. data/lib/vagrant-r10k/action/base.rb +44 -0
  13. data/lib/vagrant-r10k/action/deploy.rb +91 -0
  14. data/lib/vagrant-r10k/action/validate.rb +46 -0
  15. data/lib/vagrant-r10k/config.rb +13 -4
  16. data/lib/vagrant-r10k/helpers.rb +174 -0
  17. data/lib/vagrant-r10k/plugin.rb +11 -5
  18. data/lib/vagrant-r10k/version.rb +2 -1
  19. data/spec/acceptance/skeletons/correct/Vagrantfile +21 -0
  20. data/spec/acceptance/skeletons/correct/gitcheck.sh +20 -0
  21. data/spec/acceptance/skeletons/correct/puppet/NOTmodules/.gitkeep +0 -0
  22. data/spec/acceptance/skeletons/correct/puppet/Puppetfile +12 -0
  23. data/spec/acceptance/skeletons/correct/puppet/manifests/default.pp +1 -0
  24. data/spec/acceptance/skeletons/correct/puppet/modules/.gitkeep +0 -0
  25. data/spec/acceptance/skeletons/could_not_resolve_host/Vagrantfile +21 -0
  26. data/spec/acceptance/skeletons/could_not_resolve_host/gitcheck.sh +20 -0
  27. data/spec/acceptance/skeletons/could_not_resolve_host/puppet/NOTmodules/.gitkeep +0 -0
  28. data/spec/acceptance/skeletons/could_not_resolve_host/puppet/Puppetfile +7 -0
  29. data/spec/acceptance/skeletons/could_not_resolve_host/puppet/manifests/default.pp +1 -0
  30. data/spec/acceptance/skeletons/could_not_resolve_host/puppet/modules/.gitkeep +0 -0
  31. data/spec/acceptance/skeletons/different_mod_path/Vagrantfile +19 -0
  32. data/spec/acceptance/skeletons/different_mod_path/gitcheck.sh +20 -0
  33. data/spec/acceptance/skeletons/different_mod_path/puppet/NOTmodules/.gitkeep +0 -0
  34. data/spec/acceptance/skeletons/different_mod_path/puppet/Puppetfile +12 -0
  35. data/spec/acceptance/skeletons/different_mod_path/puppet/manifests/default.pp +1 -0
  36. data/spec/acceptance/skeletons/different_mod_path/puppet/modules/.gitkeep +0 -0
  37. data/spec/acceptance/skeletons/no_mod_path/Vagrantfile +17 -0
  38. data/spec/acceptance/skeletons/no_mod_path/gitcheck.sh +20 -0
  39. data/spec/acceptance/skeletons/no_mod_path/puppet/NOTmodules/.gitkeep +0 -0
  40. data/spec/acceptance/skeletons/no_mod_path/puppet/Puppetfile +12 -0
  41. data/spec/acceptance/skeletons/no_mod_path/puppet/manifests/default.pp +1 -0
  42. data/spec/acceptance/skeletons/no_mod_path/puppet/modules/.gitkeep +0 -0
  43. data/spec/acceptance/skeletons/no_puppet_dir/Vagrantfile +18 -0
  44. data/spec/acceptance/skeletons/no_puppet_dir/gitcheck.sh +20 -0
  45. data/spec/acceptance/skeletons/no_vagrant_r10k/Vagrantfile +14 -0
  46. data/spec/acceptance/skeletons/no_vagrant_r10k/gitcheck.sh +20 -0
  47. data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/NOTmodules/.gitkeep +0 -0
  48. data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/Puppetfile +12 -0
  49. data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/manifests/default.pp +1 -0
  50. data/spec/acceptance/skeletons/no_vagrant_r10k/puppet/modules/.gitkeep +0 -0
  51. data/spec/acceptance/skeletons/puppetfile_syntax_error/Vagrantfile +18 -0
  52. data/spec/acceptance/skeletons/puppetfile_syntax_error/gitcheck.sh +20 -0
  53. data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/Puppetfile +1 -0
  54. data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/manifests/default.pp +1 -0
  55. data/spec/acceptance/skeletons/puppetfile_syntax_error/puppet/modules/.gitkeep +0 -0
  56. data/spec/acceptance/vagrant-r10k/vagrant-r10k_spec.rb +255 -0
  57. data/spec/spec_helper.rb +10 -7
  58. data/spec/unit/action_base_spec.rb +57 -0
  59. data/spec/unit/action_deploy_spec.rb +550 -0
  60. data/spec/unit/action_validate_spec.rb +240 -0
  61. data/spec/unit/helpers_spec.rb +307 -0
  62. data/spec/unit/plugin_spec.rb +49 -0
  63. data/support/testrunner.py +189 -0
  64. data/vagrant-r10k.gemspec +1 -1
  65. data/vagrant-spec.config.rb +18 -0
  66. metadata +111 -19
  67. data/lib/vagrant-r10k/modulegetter.rb +0 -145
  68. data/spec/unit/modulegetter_spec.rb +0 -369
@@ -0,0 +1,18 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "vagrantr10kspec"
6
+ config.vm.network "private_network", type: "dhcp"
7
+
8
+ # r10k plugin to deploy puppet modules
9
+ config.r10k.puppet_dir = "puppet"
10
+ config.r10k.puppetfile_path = "puppet/Puppetfile"
11
+
12
+ # Provision the machine with the appliction
13
+ config.vm.provision "puppet" do |puppet|
14
+ puppet.manifests_path = "puppet/manifests"
15
+ puppet.manifest_file = "default.pp"
16
+ puppet.module_path = "puppet/modules"
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+ # helper script to determine if a git clone is checked out to a
3
+ # PR, tag, or branch, and then output some information about the status
4
+ if [ $# -gt 0 ]; then
5
+ cd $1
6
+ fi
7
+ origin=$(git remote show -n origin | grep 'Fetch URL:' | awk '{print $3}')
8
+ if tmp=$(git status | grep "refs/pull/origin"); then
9
+ foo=$(echo "$tmp" | awk '{print $4}' | awk -F / '{print $4}')
10
+ echo "PR: ${foo} @ $(git rev-parse HEAD) (origin: ${origin})"
11
+ elif tagname=$(git describe --exact-match --tags $(git log -n1 --pretty='%h') 2>/dev/null); then
12
+ echo "tag: ${tagname} @ $(git rev-parse HEAD) (origin: ${origin})"
13
+ elif git symbolic-ref -q HEAD &>/dev/null; then
14
+ branch_name=$(git symbolic-ref -q HEAD)
15
+ branch_name=${branch_name##refs/heads/}
16
+ branch_name=${branch_name:-HEAD}
17
+ echo "branch: ${branch_name} @ $(git rev-parse HEAD) (origin: ${origin})"
18
+ else
19
+ echo "sha: $(git rev-parse HEAD) (origin: ${origin})"
20
+ fi
@@ -0,0 +1,14 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "vagrantr10kspec"
6
+ config.vm.network "private_network", type: "dhcp"
7
+
8
+ # Provision the machine with the appliction
9
+ config.vm.provision "puppet" do |puppet|
10
+ puppet.manifests_path = "puppet/manifests"
11
+ puppet.manifest_file = "default.pp"
12
+ puppet.module_path = "puppet/modules"
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+ # helper script to determine if a git clone is checked out to a
3
+ # PR, tag, or branch, and then output some information about the status
4
+ if [ $# -gt 0 ]; then
5
+ cd $1
6
+ fi
7
+ origin=$(git remote show -n origin | grep 'Fetch URL:' | awk '{print $3}')
8
+ if tmp=$(git status | grep "refs/pull/origin"); then
9
+ foo=$(echo "$tmp" | awk '{print $4}' | awk -F / '{print $4}')
10
+ echo "PR: ${foo} @ $(git rev-parse HEAD) (origin: ${origin})"
11
+ elif tagname=$(git describe --exact-match --tags $(git log -n1 --pretty='%h') 2>/dev/null); then
12
+ echo "tag: ${tagname} @ $(git rev-parse HEAD) (origin: ${origin})"
13
+ elif git symbolic-ref -q HEAD &>/dev/null; then
14
+ branch_name=$(git symbolic-ref -q HEAD)
15
+ branch_name=${branch_name##refs/heads/}
16
+ branch_name=${branch_name:-HEAD}
17
+ echo "branch: ${branch_name} @ $(git rev-parse HEAD) (origin: ${origin})"
18
+ else
19
+ echo "sha: $(git rev-parse HEAD) (origin: ${origin})"
20
+ fi
@@ -0,0 +1,12 @@
1
+ # This is currently a noop but will be supported in the future.
2
+ forge 'forge.puppetlabs.com'
3
+
4
+ # v1.0.1 -> cdb8d7a186846b49326cec1cfb4623bd77529b04
5
+ mod 'reviewboard',
6
+ :git => 'https://github.com/jantman/puppet-reviewboard.git',
7
+ :ref => 'v1.0.1'
8
+
9
+ # 0.1.0 -> 3a504b5f66ebe1853bda4ee065fce18118958d84
10
+ mod 'nodemeister',
11
+ :git => 'https://github.com/jantman/puppet-nodemeister.git',
12
+ :ref => '0.1.0'
@@ -0,0 +1 @@
1
+ notify {'vagrant-r10k puppet run': }
@@ -0,0 +1,18 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "vagrantr10kspec"
6
+ config.vm.network "private_network", type: "dhcp"
7
+
8
+ # r10k plugin to deploy puppet modules
9
+ config.r10k.puppet_dir = "puppet"
10
+ config.r10k.puppetfile_path = "puppet/Puppetfile"
11
+
12
+ # Provision the machine with the appliction
13
+ config.vm.provision "puppet" do |puppet|
14
+ puppet.manifests_path = "puppet/manifests"
15
+ puppet.manifest_file = "default.pp"
16
+ puppet.module_path = "puppet/modules"
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+ # helper script to determine if a git clone is checked out to a
3
+ # PR, tag, or branch, and then output some information about the status
4
+ if [ $# -gt 0 ]; then
5
+ cd $1
6
+ fi
7
+ origin=$(git remote show -n origin | grep 'Fetch URL:' | awk '{print $3}')
8
+ if tmp=$(git status | grep "refs/pull/origin"); then
9
+ foo=$(echo "$tmp" | awk '{print $4}' | awk -F / '{print $4}')
10
+ echo "PR: ${foo} @ $(git rev-parse HEAD) (origin: ${origin})"
11
+ elif tagname=$(git describe --exact-match --tags $(git log -n1 --pretty='%h') 2>/dev/null); then
12
+ echo "tag: ${tagname} @ $(git rev-parse HEAD) (origin: ${origin})"
13
+ elif git symbolic-ref -q HEAD &>/dev/null; then
14
+ branch_name=$(git symbolic-ref -q HEAD)
15
+ branch_name=${branch_name##refs/heads/}
16
+ branch_name=${branch_name:-HEAD}
17
+ echo "branch: ${branch_name} @ $(git rev-parse HEAD) (origin: ${origin})"
18
+ else
19
+ echo "sha: $(git rev-parse HEAD) (origin: ${origin})"
20
+ fi
@@ -0,0 +1 @@
1
+ this is not a valid puppetfile
@@ -0,0 +1 @@
1
+ notify {'vagrant-r10k puppet run': }
@@ -0,0 +1,255 @@
1
+ include VagrantPlugins::R10k
2
+ shared_examples 'provider/vagrant-r10k' do |provider, options|
3
+ # NOTE: vagrant-spec's acceptance framework (specifically IsolatedEnvironment)
4
+ # creates an isolated environment for each 'it' block and tears it down afterwards.
5
+ # This *only* works with the layout below. As such, quite unfortunately, we have a
6
+ # bunch of assertions in each 'it' block; they're not isolated the way they should be.
7
+ # The alternative is to run a complete up/provision/assert/destroy cycle for each
8
+ # assertion we want to make, and also therefore lose the ability to make multiple
9
+ # assertions about one provisioning run.
10
+
11
+ if !File.file?(options[:box])
12
+ raise ArgumentError,
13
+ "A box file #{options[:box]} must be downloaded for provider: #{provider}. The rake task should have done this."
14
+ end
15
+
16
+ include_context 'acceptance'
17
+
18
+ let(:box_ip) { '10.10.10.29' }
19
+ let(:name) { 'single.testbox.spec' }
20
+
21
+ before do
22
+ ENV['VAGRANT_DEFAULT_PROVIDER'] = provider
23
+ end
24
+
25
+ describe 'configured correctly' do
26
+ before do
27
+ setup_before('correct', options)
28
+ end
29
+ after do
30
+ assert_execute("vagrant", "destroy", "--force")
31
+ end
32
+
33
+ it 'deploys Puppetfile modules' do
34
+ status("Test: vagrant up")
35
+ up_result = assert_execute('vagrant', 'up', "--provider=#{provider}", '--debug')
36
+ ensure_successful_run(up_result, environment.workdir)
37
+ status("Test: reviewboard module")
38
+ rb_dir = File.join(environment.workdir, 'puppet', 'modules', 'reviewboard')
39
+ expect(File.directory?(rb_dir)).to be_truthy
40
+ rb_result = assert_execute('bash', 'gitcheck.sh', 'puppet/modules/reviewboard')
41
+ expect(rb_result).to exit_with(0)
42
+ expect(rb_result.stdout).to match(/tag: v1\.0\.1 @ cdb8d7a186846b49326cec1cfb4623bd77529b04 \(origin: https:\/\/github\.com\/jantman\/puppet-reviewboard\.git\)/)
43
+
44
+ status("Test: nodemeister module")
45
+ nm_dir = File.join(environment.workdir, 'puppet', 'modules', 'nodemeister')
46
+ expect(File.directory?(nm_dir)).to be_truthy
47
+ nm_result = assert_execute('bash', 'gitcheck.sh', 'puppet/modules/nodemeister')
48
+ expect(nm_result).to exit_with(0)
49
+ expect(nm_result.stdout).to match(/tag: 0\.1\.0 @ 3a504b5f66ebe1853bda4ee065fce18118958d84 \(origin: https:\/\/github\.com\/jantman\/puppet-nodemeister\.git\)/)
50
+ end
51
+ end
52
+
53
+ describe 'destroy when configured correctly' do
54
+ before do
55
+ setup_before('correct', options)
56
+ end
57
+ after do
58
+ assert_execute("vagrant", "destroy", "--force")
59
+ end
60
+
61
+ it 'does not deploy modules' do
62
+ status("Test: vagrant up destroy")
63
+ assert_execute('vagrant', 'up', "--provider=#{provider}", '--debug')
64
+ destroy_result = assert_execute("vagrant", "destroy", "--force", '--debug')
65
+ expect(destroy_result.stdout).to_not include("vagrant-r10k: Beginning r10k deploy of puppet modules")
66
+ expect(destroy_result.stdout).to_not include('vagrant-r10k: Building the r10k module path')
67
+ expect(destroy_result.stdout).to_not include('vagrant-r10k: Deploy finished')
68
+ expect(destroy_result.stderr).to_not include("vagrant-r10k: Beginning r10k deploy of puppet modules")
69
+ expect(destroy_result.stderr).to_not include('vagrant-r10k: Building the r10k module path')
70
+ expect(destroy_result.stderr).to_not include('vagrant-r10k: Deploy finished')
71
+ end
72
+ end
73
+
74
+ describe 'puppet directory missing' do
75
+ # this is a complete failure
76
+ before do
77
+ setup_before('no_puppet_dir', options)
78
+ end
79
+ after do
80
+ assert_execute("vagrant", "destroy", "--force")
81
+ end
82
+
83
+ it 'errors during config validation' do
84
+ status("Test: vagrant up")
85
+ up_result = execute('vagrant', 'up', "--provider=#{provider}", '--debug')
86
+ ensure_r10k_didnt_run(up_result, environment.workdir)
87
+ expect(up_result).to exit_with(1)
88
+ expect(up_result.stderr).to match(/puppetfile '[^']+' does not exist/)
89
+ ensure_puppet_didnt_run(up_result)
90
+ end
91
+ end
92
+
93
+ describe 'module path different from Puppet provisioner' do
94
+ # this just doesn't run the r10k portion
95
+ before do
96
+ setup_before('different_mod_path', options)
97
+ end
98
+ after do
99
+ assert_execute("vagrant", "destroy", "--force")
100
+ end
101
+
102
+ it 'throws RuntimeError' do
103
+ status("Test: vagrant up")
104
+ up_result = execute('vagrant', 'up', "--provider=#{provider}")
105
+ expect(up_result).to exit_with(1)
106
+ expect(up_result.stderr).to match('RuntimeError: vagrant-r10k: module_path "puppet/NOTmodules" is not the same as in puppet provisioner; please correct this condition')
107
+ ensure_r10k_didnt_run(up_result, environment.workdir)
108
+ ensure_puppet_didnt_run(up_result)
109
+ end
110
+ end
111
+
112
+ describe 'no module path set' do
113
+ # this just doesn't run the r10k portion
114
+ before do
115
+ setup_before('no_mod_path', options)
116
+ end
117
+ after do
118
+ assert_execute("vagrant", "destroy", "--force")
119
+ end
120
+
121
+ it 'skips r10k deploy' do
122
+ status("Test: vagrant up")
123
+ up_result = execute('vagrant', 'up', "--provider=#{provider}", '--debug')
124
+ expect(up_result).to exit_with(1)
125
+ ensure_r10k_didnt_run(up_result, environment.workdir)
126
+ ensure_puppet_didnt_run(up_result)
127
+ end
128
+ end
129
+
130
+ describe 'no r10k configuration' do
131
+ # this just doesn't run the r10k portion
132
+ before do
133
+ setup_before('no_vagrant_r10k', options)
134
+ end
135
+ after do
136
+ assert_execute("vagrant", "destroy", "--force")
137
+ end
138
+
139
+ it 'skips r10k deploy' do
140
+ status("Test: vagrant up")
141
+ up_result = execute('vagrant', 'up', "--provider=#{provider}")
142
+ expect(up_result).to exit_with(0)
143
+ expect(up_result.stdout).to include("vagrant-r10k not configured; skipping")
144
+ ensure_r10k_didnt_run(up_result, environment.workdir)
145
+ ensure_puppet_ran(up_result)
146
+ end
147
+ end
148
+
149
+ describe 'Puppetfile syntax error' do
150
+ # r10k runtime failure
151
+ before do
152
+ setup_before('puppetfile_syntax_error', options)
153
+ end
154
+ after do
155
+ assert_execute("vagrant", "destroy", "--force")
156
+ end
157
+
158
+ it 'fails during module deploy' do
159
+ status("Test: vagrant up")
160
+ up_result = execute('vagrant', 'up', "--provider=#{provider}")
161
+ expect(up_result).to exit_with(1)
162
+ expect(up_result.stderr).to match(%r"SyntaxError: .*puppet/Puppetfile:1: syntax error, unexpected tIDENTIFIER, expecting '\('\s+this is not a valid puppetfile\s+\^")
163
+ ensure_r10k_didnt_run(up_result, environment.workdir)
164
+ ensure_puppet_didnt_run(up_result)
165
+ end
166
+ end
167
+
168
+ describe 'could not resolve git host' do
169
+ before do
170
+ setup_before('could_not_resolve_host', options)
171
+ end
172
+ after do
173
+ assert_execute("vagrant", "destroy", "--force")
174
+ end
175
+
176
+ it 'fails with error including how to skip provisioning' do
177
+ status("Test: vagrant up")
178
+ up_result = execute('vagrant', 'up', "--provider=#{provider}", '--debug')
179
+ expect(up_result).to exit_with(1)
180
+ expect(up_result.stderr).to match(%r"RuntimeError: Couldn't update git cache for https://invalidhost\.jasonantman\.com/jantman/puppet-reviewboard\.git: \"fatal: unable to access 'https://invalidhost\.jasonantman\.com/jantman/puppet-reviewboard\.git/': Could not resolve host: invalidhost\.jasonantman\.com\"\n\nIf you don't have connectivity to the host, running 'vagrant up --no-provision' will skip r10k deploy and all provisioning")
181
+ ensure_puppet_didnt_run(up_result)
182
+ end
183
+ end
184
+
185
+ # setup skeleton, add box
186
+ def setup_before(skel_name, options)
187
+ environment.skeleton(skel_name)
188
+ environment.env['VBOX_USER_HOME'] = environment.homedir.to_s
189
+ assert_execute('vagrant', 'box', 'add', "vagrantr10kspec", options[:box])
190
+ end
191
+
192
+ # checks for a successful up run with r10k deployment and puppet provisioning
193
+ def ensure_successful_run(up_result, workdir)
194
+ expect(up_result).to exit_with(0)
195
+ # version checks
196
+ expect(up_result.stderr).to include('global: - r10k = 1.2.1')
197
+ expect(up_result.stderr).to include("global: - vagrant-r10k = #{VagrantPlugins::R10k::VERSION}")
198
+ expect(up_result.stderr).to include('Registered plugin: vagrant-r10k')
199
+ expect(up_result.stderr).to include('vagrant::r10k::validate called')
200
+ expect(up_result.stderr).to include('vagrant::r10k::deploy called')
201
+ expect(up_result.stderr).to match_num_times(1, %r"DEBUG config: vagrant-r10k-config: validate.*DEBUG validate: vagrant::r10k::validate called.*Running action: provisioner_run"m), "config and validate run before provisioner"
202
+ expect(up_result.stderr).to match_num_times(1, %r"DEBUG deploy: vagrant::r10k::deploy called.*Running action: provisioner_run"m), "deploy runs before provisioners"
203
+ # provisioning runs
204
+ expect(up_result.stdout).to include_num_times(1, '==> default: vagrant-r10k: Beginning r10k deploy of puppet modules into'), "provisioning runs once"
205
+ # modulegetter runs before provisioning
206
+ expect(up_result.stdout).to match_num_times(1, %r"vagrant-r10k: Deploy finished.*\s+Running provisioner: puppet"m), "deploy runs before puppet provisioner"
207
+ # modulegetter BEFORE ConfigValidate
208
+ expect(up_result.stderr).to match(%r"(?!ConfigValidate)+default: vagrant-r10k: Deploy finished.*Vagrant::Action::Builtin::ConfigValidate"m), "modulegetter runs before ConfigValidate"
209
+ # other checks
210
+ expect(up_result.stdout).to include('vagrant-r10k: Building the r10k module path with puppet provisioner module_path "puppet/modules"')
211
+ expect(up_result.stdout).to include("vagrant-r10k: Beginning r10k deploy of puppet modules into #{workdir}/puppet/modules using #{workdir}/puppet/Puppetfile")
212
+ expect(up_result.stdout).to include('vagrant-r10k: Deploy finished')
213
+ # file tests
214
+ expect(File).to exist("#{workdir}/puppet/modules/reviewboard/Modulefile")
215
+ expect(File).to exist("#{workdir}/puppet/modules/nodemeister/Modulefile")
216
+ expect(File).to exist("#{workdir}/puppet/modules/nodemeister/manifests/init.pp")
217
+
218
+ # ensure puppet ran
219
+ ensure_puppet_ran(up_result)
220
+ end
221
+
222
+ # ensure that r10k didnt run
223
+ def ensure_r10k_didnt_run(up_result, workdir)
224
+ expect(up_result.stdout).to_not include("vagrant-r10k: Beginning r10k deploy of puppet modules")
225
+ expect(up_result.stdout).to_not include('vagrant-r10k: Deploy finished')
226
+
227
+ # file tests
228
+ expect(File).to_not exist("#{workdir}/puppet/modules/reviewboard/Modulefile")
229
+ expect(File).to_not exist("#{workdir}/puppet/modules/nodemeister/Modulefile")
230
+ expect(File).to_not exist("#{workdir}/puppet/modules/nodemeister/manifests/init.pp")
231
+ end
232
+
233
+ # ensure that the puppet provisioner ran with default.pp
234
+ def ensure_puppet_ran(up_result)
235
+ expect(up_result.stdout).to include('Running provisioner: puppet')
236
+ expect(up_result.stdout).to include('Running Puppet with default.pp')
237
+ expect(up_result.stdout).to include('vagrant-r10k puppet run')
238
+ end
239
+
240
+ # ensure that the puppet provisioner DIDNT run
241
+ def ensure_puppet_didnt_run(up_result)
242
+ expect(up_result.stdout).to_not include('Running provisioner: puppet')
243
+ expect(up_result.stdout).to_not include('Running Puppet with default.pp')
244
+ expect(up_result.stdout).to_not include('vagrant-r10k puppet run')
245
+ end
246
+
247
+ # method to print output
248
+ def print_output(up_result)
249
+ puts "################# STDOUT #####################"
250
+ puts up_result.stdout
251
+ puts "################# STDERR #####################"
252
+ puts up_result.stderr
253
+ puts "################# END #####################"
254
+ end
255
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,9 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/vendor/"
4
+ add_filter "/spec/"
5
+ end
6
+
1
7
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
8
 
3
9
  # Disable Vagrant autoloading so that other plugins defined in the Gemfile for
@@ -5,14 +11,11 @@ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
5
11
  ENV['VAGRANT_NO_PLUGINS'] = '1'
6
12
 
7
13
  require 'vagrant-spec/unit'
14
+ require 'rspec_matcher_num_times'
8
15
 
9
- require 'simplecov'
10
- SimpleCov.start do
11
- add_filter "/vendor/"
12
- if ENV['CI']=='true'
13
- require 'codecov'
14
- formatter = SimpleCov::Formatter::Codecov
15
- end
16
+ require 'codecov'
17
+ if ENV['CI']=='true'
18
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
16
19
  end
17
20
 
18
21
  require 'vagrant-r10k'
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require_relative 'sharedcontext'
3
+ require_relative 'shared_expectations'
4
+ require 'vagrant-r10k/action/base'
5
+
6
+ include SharedExpectations
7
+
8
+ describe VagrantPlugins::R10k::Action::Base do
9
+ include_context 'vagrant-unit'
10
+ context 'instantiation' do
11
+
12
+ it 'has app and env instance variables' do
13
+ x = described_class.new(:app, :env)
14
+ expect(x.instance_variable_get(:@app)).to equal(:app)
15
+ expect(x.instance_variable_get(:@env)).to equal(:env)
16
+ end
17
+
18
+ it 'has a logger' do
19
+ x = described_class.new(:app, :env)
20
+ expect(x.instance_variable_get(:@logger)).to be_a_kind_of(Log4r::Logger)
21
+ expect(x.instance_variable_get(:@logger).fullname).to eq('vagrant::r10k::base')
22
+ end
23
+
24
+ it 'sets logging levels to 3 when not running in debug mode' do
25
+ allow(ENV).to receive(:[]).with("VAGRANT_LOG").and_return('no')
26
+ x = described_class.new(:app, :env)
27
+ expect(R10K::Logging.level).to eq(3)
28
+ end
29
+
30
+ it 'sets logging levels to 0 when running in debug mode' do
31
+ allow(ENV).to receive(:[]).with("VAGRANT_LOG").and_return('debug')
32
+ x = described_class.new(:app, :env)
33
+ expect(R10K::Logging.level).to eq(0)
34
+ expect(x.instance_variable_get(:@logger).level).to eq(0)
35
+ end
36
+ end
37
+
38
+ context 'validate' do
39
+ it 'returns Vagrant::Action::Builder with Action::Validate' do
40
+ res = described_class.validate
41
+ expect(res).to be_a_kind_of(Vagrant::Action::Builder)
42
+ expect(res.stack).to eq([[VagrantPlugins::R10k::Action::Validate, [], nil]])
43
+ end
44
+ end
45
+
46
+ context 'deploy' do
47
+ it 'returns Vagrant::Action::Builder with Action::Validate and Action::Deploy' do
48
+ res = described_class.deploy
49
+ expect(res).to be_a_kind_of(Vagrant::Action::Builder)
50
+ expect(res.stack).to eq([
51
+ [VagrantPlugins::R10k::Action::Validate, [], nil],
52
+ [VagrantPlugins::R10k::Action::Deploy, [], nil]
53
+ ])
54
+ end
55
+
56
+ end
57
+ end