Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit 1c8e133

Browse files
author
Daniel Dreier
committed
Separate out server acceptance tests
passenger, thin, unicorn, and webrick can be tested independently This implies differences to how tests are run, so documentation was updated The advantage here is no chance of bleed-over between test cases, whereas the previous way required imperfect automated cleanup between test cases. This also permits testing one thing at a time to save a little bit of time. Unfortunately, it also means that testing all cases requires considerably longer because a new VM must be provisioned for each case.
1 parent da3426a commit 1c8e133

File tree

8 files changed

+178
-173
lines changed

8 files changed

+178
-173
lines changed

CONTRIBUTING.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
11
Testing
22
=======
33

4-
Tests on the puppet-puppet module can be run via `rake`.
4+
Puppet-puppet is tested via beaker and rspec-puppet. Rspec-puppet tests are run
5+
automatically for pull requests via travis-ci, or can be triggered manually
6+
by running `rake spec` after doing a `bundle install`.
57

6-
#### Beaker acceptance tests
7-
```
8-
BEAKER_destroy=no BEAKER_provision=onpass rake acceptance
8+
Beaker tests are run slightly differently for puppet-puppet than for other
9+
beaker-tested projects because the test suite should be run independently for
10+
each test case to prevent contamination between environments. For example,
11+
running the apache-passenger based puppet master test case will cause obvious
12+
conflicts if the nginx-unicorn puppet master is subsequently built on the same
13+
virtual machine. Rspec tags are used to accomplish this in the test cases.
14+
15+
Running beaker tests for unicorn puppetmaster on the default nodeset (debian 7):
16+
```bash
17+
rspec . --tag servertype:unicorn --pattern "spec/acceptance/**/*_spec.rb"
918
```
1019

11-
Run beaker acceptance tests on debian 7:
20+
Same as above, but only only destroying the VM if the build is successful, to
21+
help troubleshooting:
1222
```
13-
BEAKER_set=debian-73-x64 BEAKER_destroy=onpass BEAKER_provision=no rake acceptance
23+
BEAKER_destroy=onpass BEAKER_provision=yes rspec . --tag servertype:unicorn --pattern "spec/acceptance/**/*_spec.rb"
1424
```
15-
See spec/acceptance/nodesets for a list of possible node names; use the filename without .yml.
25+
26+
Same as above, but on a different nodeset (see `spec/acceptance/nodesets` for
27+
options):
28+
```bash
29+
BEAKER_set=sles-11sp1-x64 BEAKER_destroy=onpass BEAKER_provision=yes rspec . --tag servertype:unicorn --pattern "spec/acceptance/**/*_spec.rb"
30+
```
31+
32+
The presence of an OS/distro in the nodeset list does not imply support. The
33+
SLES example above is expected to fail most test cases but is included to lower
34+
the bar for future contributors who want to add support for additional distros.
35+
36+
The rake command includes acceptance testing tasks, but these should not be
37+
used because they will run all of the acceptance tests on the same VM, which
38+
is expected to fail.
1639

1740
If a beaker test fails, you can SSH into the environment if you use BEAKER_PROVISION=onpass.
1841
The path of the vagrantfile will be `.vagrant/beaker_vagrant_files/debian-73-x64.yml`
1942
if you followed the above instructions, and slightly different if you used a
2043
different nodeset. `cd` to that directory and `vagrant ssh` to access the VM.
2144
The tests that ran are in /tmp with randomly generated filenames.
22-
```
2345

2446
#### rspec-puppet tests
2547
(note that these are run automatically by travis CI on pull requests)

spec/acceptance/agent_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe 'agent', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
44
context 'with default parameters' do
5-
it 'should run with no errors' do
5+
it 'should run with no errors', :agent do
66
pp = <<-EOS
77
class { 'puppet::agent': }
88
EOS
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'passenger server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
context 'running on passenger' do
5+
it 'should run with no errors', :servertype => 'passenger', :webserver => 'apache' do
6+
pp = <<-EOS
7+
class { "puppet::server":
8+
servertype => 'passenger',
9+
ca => true,
10+
servername => $::hostname,
11+
}
12+
EOS
13+
14+
# Run it twice and test for idempotency
15+
apply_manifest(pp, :catch_failures => true)
16+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
17+
end
18+
19+
describe port(8140) do
20+
it {
21+
should be_listening
22+
}
23+
end
24+
end
25+
end

spec/acceptance/server_spec.rb

Lines changed: 0 additions & 164 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'thin server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
5+
context 'running on thin' do
6+
it 'should run with no errors', :servertype => 'thin', :webserver => 'nginx' do
7+
pp = <<-EOS
8+
class { "puppet::server":
9+
servertype => 'thin',
10+
ca => true,
11+
}
12+
EOS
13+
14+
# Run it twice and test for idempotency
15+
apply_manifest(pp, :catch_failures => true)
16+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
17+
end
18+
19+
describe package('thin') do
20+
it {
21+
should be_installed.by('gem')
22+
}
23+
end
24+
25+
describe service('thin-puppetmaster') do
26+
it {
27+
should be_enabled
28+
}
29+
it {
30+
should be_running
31+
}
32+
end
33+
34+
describe port(8140) do
35+
it {
36+
should be_listening
37+
}
38+
end
39+
end
40+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
context 'running on unicorn' do
5+
it 'should run with no errors', :servertype => 'unicorn', :webserver => 'nginx' do
6+
pp = <<-EOS
7+
class { "puppet::server":
8+
servertype => 'unicorn',
9+
ca => true,
10+
}
11+
EOS
12+
13+
# Run it twice and test for idempotency
14+
apply_manifest(pp, :catch_failures => true)
15+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
16+
end
17+
describe command('puppet agent --test --server puppet') do
18+
its(:exit_status) { should eq 0 }
19+
its(:stderr) { should_not match /Forbidden request:/ }
20+
its(:stderr) { should_not match /Error:/ }
21+
end
22+
23+
describe package('nginx') do
24+
it {
25+
should be_installed
26+
}
27+
end
28+
29+
describe service('nginx') do
30+
it {
31+
should be_enabled
32+
}
33+
it {
34+
should be_running
35+
}
36+
end
37+
38+
describe port(8140) do
39+
it {
40+
should be_listening
41+
}
42+
end
43+
end
44+
45+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4+
context 'running on webrick/standalone' do
5+
it 'should run with no errors', :server => 'webrick', :webserver => 'builtin' do
6+
pp = <<-EOS
7+
class { "puppet::server":
8+
servertype => 'standalone',
9+
ca => true,
10+
}
11+
EOS
12+
13+
# Run it twice and test for idempotency
14+
apply_manifest(pp, :catch_failures => true)
15+
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
16+
end
17+
18+
describe service('puppetmaster') do
19+
it {
20+
should be_enabled
21+
}
22+
it {
23+
should be_running
24+
}
25+
end
26+
27+
describe port(8140) do
28+
it {
29+
should be_listening
30+
}
31+
end
32+
end
33+
34+
end

spec/spec_helper_acceptance.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
EOS
5959
on host, "echo \"#{puppetfile}\" > /etc/puppet/Puppetfile"
6060
on host, "cd /etc/puppet; r10k puppetfile install"
61+
on host, "mkdir -p /etc/puppet/environments/production/modules"
62+
on host, "puppet config set --section master environmentpath '$confdir/environments'"
63+
on host, "puppet config set --section master basemodulepath '$confdir/modules'"
6164

6265
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
6366
puppet_module_install(:source => proj_root, :module_name => 'puppet')

0 commit comments

Comments
 (0)