diff --git a/.gitignore b/.gitignore index fa05440..ba372e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ files/server_test.crt files/server_test.pem pkg/ -pkg/ +log/ Gemfile.lock spec/fixtures/modules spec/fixtures/manifests vendor .ruby-version +.vagrant/ diff --git a/.nodeset.yml b/.nodeset.yml deleted file mode 100644 index 767f9cd..0000000 --- a/.nodeset.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -default_set: 'centos-64-x64' -sets: - 'centos-59-x64': - nodes: - "main.foo.vm": - prefab: 'centos-59-x64' - 'centos-64-x64': - nodes: - "main.foo.vm": - prefab: 'centos-64-x64' - 'fedora-18-x64': - nodes: - "main.foo.vm": - prefab: 'fedora-18-x64' - 'debian-607-x64': - nodes: - "main.foo.vm": - prefab: 'debian-607-x64' - 'debian-70rc1-x64': - nodes: - "main.foo.vm": - prefab: 'debian-70rc1-x64' - 'ubuntu-server-10044-x64': - nodes: - "main.foo.vm": - prefab: 'ubuntu-server-10044-x64' - 'ubuntu-server-12042-x64': - nodes: - "main.foo.vm": - prefab: 'ubuntu-server-12042-x64' diff --git a/Gemfile b/Gemfile index 5f402a0..d6373ba 100644 --- a/Gemfile +++ b/Gemfile @@ -7,14 +7,14 @@ end group :rake, :test do gem 'puppetlabs_spec_helper', '>=0.8.2', :require => false gem 'puppet-blacksmith', :require => false - gem 'rspec-system-puppet', :require => false + gem 'beaker', :require => false + gem 'beaker-rspec', :require => false end group :rake do gem 'rspec-puppet', '>=2', :require => false gem 'rake', '>=0.9.2.2' gem 'puppet-lint', '>=1.0.1' - gem 'rspec-system-serverspec', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 1878335..de87c4c 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,6 @@ CLOBBER.include('.tmp', '.librarian') require 'puppetlabs_spec_helper/rake_tasks' require 'puppet_blacksmith/rake_tasks' -require 'rspec-system/rake_task' task :default => [:clean, :spec] diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb new file mode 100644 index 0000000..f35d5c8 --- /dev/null +++ b/spec/acceptance/class_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper_acceptance' + +describe "nginx class:" do + + context 'default parameters' do + it 'should run successfully' do + pp = "class { 'nginx': }" + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + end + end + + describe package('nginx') do + it { is_expected.to be_installed } + end + + describe service('nginx') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + +end diff --git a/spec/acceptance/nginx_mail_spec.rb b/spec/acceptance/nginx_mail_spec.rb new file mode 100644 index 0000000..df4c342 --- /dev/null +++ b/spec/acceptance/nginx_mail_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper_acceptance' + +describe "nginx::resource::mailhost define:" do + it 'should run successfully' do + + pp = " + class { 'nginx': + mail => true, + } + nginx::resource::mailhost { 'domain1.example': + ensure => present, + auth_http => 'localhost/cgi-bin/auth', + protocol => 'smtp', + listen_port => 587, + ssl => true, + ssl_port => 465, + ssl_cert => '/tmp/blah.cert', + ssl_key => '/tmp/blah.key', + xclient => 'off', + } + " + + apply_manifest(pp, :catch_failures => true) + end + + describe file('/etc/nginx/conf.mail.d/domain1.example.conf') do + it { is_expected.to be_file } + it { is_expected.to contain "auth_http localhost/cgi-bin/auth;" } + end + + describe port(587) do + it { is_expected.to be_listening } + end + + describe port(465) do + it { is_expected.to be_listening } + end + +end diff --git a/spec/system/nginx_proxy_spec.rb b/spec/acceptance/nginx_proxy_spec.rb similarity index 53% rename from spec/system/nginx_proxy_spec.rb rename to spec/acceptance/nginx_proxy_spec.rb index 09b1885..27cd906 100644 --- a/spec/system/nginx_proxy_spec.rb +++ b/spec/acceptance/nginx_proxy_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe "nginx::resource::upstream define:" do it 'should run successfully' do @@ -19,25 +19,20 @@ describe "nginx::resource::upstream define:" do } " - puppet_apply(pp) do |r| - [0,2].should include r.exit_code - r.refresh - r.stderr.should be_empty - r.exit_code.should be_zero - end + apply_manifest(pp, :catch_failures => true) end describe file('/etc/nginx/conf.d/puppet_rack_app-upstream.conf') do - it { should be_file } - it { should contain "server localhost:3000" } - it { should contain "server localhost:3001" } - it { should contain "server localhost:3002" } - it { should_not contain "server localhost:3003" } + it { is_expected.to be_file } + it { is_expected.to contain "server localhost:3000" } + it { is_expected.to contain "server localhost:3001" } + it { is_expected.to contain "server localhost:3002" } + it { is_expected.not_to contain "server localhost:3003" } end describe file('/etc/nginx/sites-available/rack.puppetlabs.com.conf') do - it { should be_file } - it { should contain "proxy_pass http://puppet_rack_app;" } + it { is_expected.to be_file } + it { is_expected.to contain "proxy_pass http://puppet_rack_app;" } end end diff --git a/spec/system/nginx_vhost_spec.rb b/spec/acceptance/nginx_vhost_spec.rb similarity index 67% rename from spec/system/nginx_vhost_spec.rb rename to spec/acceptance/nginx_vhost_spec.rb index d4f3446..287621d 100644 --- a/spec/system/nginx_vhost_spec.rb +++ b/spec/acceptance/nginx_vhost_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe "nginx::resource::vhost define:" do context 'new vhost on port 80' do @@ -15,31 +15,30 @@ describe "nginx::resource::vhost define:" do file { '/var/www/www.puppetlabs.com/index.html': ensure => file, content => 'Hello from www\n', } " - puppet_apply(pp) do |r| - [0,2].should include r.exit_code - r.refresh - r.stderr.should be_empty - r.exit_code.should be_zero - end + apply_manifest(pp, :catch_failures => true) end describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do - it { should be_file } - it { should contain "www.puppetlabs.com" } + it { is_expected.to be_file } + it { is_expected.to contain "www.puppetlabs.com" } end describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do - it { should be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' } + it { is_expected.to be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' } end describe service('nginx') do - it { should be_running } + it { is_expected.to be_running } + end + + describe port(80) do + it { is_expected.to be_listening } end it 'should answer to www.puppetlabs.com' do shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r| - r.stdout.should == "Hello from www\n" - r.exit_code.should be_zero + expect(r.stdout).to eq("Hello from www\n") + expect(r.exit_code).to be_zero end end end @@ -61,39 +60,38 @@ describe "nginx::resource::vhost define:" do file { '/var/www/www.puppetlabs.com/index.html': ensure => file, content => 'Hello from www\n', } " - puppet_apply(pp) do |r| - [0,2].should include r.exit_code - r.refresh - r.stderr.should be_empty - r.exit_code.should be_zero - end + apply_manifest(pp, :catch_failures => true) end describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do - it { should be_file } - it { should contain "ssl on;" } + it { is_expected.to be_file } + it { is_expected.to contain "ssl on;" } end describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do - it { should be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' } + it { is_expected.to be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' } end describe service('nginx') do - it { should be_running } + it { is_expected.to be_running } + end + + describe port(443) do + it { is_expected.to be_listening } end it 'should answer to http://www.puppetlabs.com' do shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r| - r.stdout.should == "Hello from www\n" - r.exit_code.should == 0 + expect(r.stdout).to eq("Hello from www\n") + expect(r.exit_code).to eq(0) end end it 'should answer to https://www.puppetlabs.com' do # use --insecure because it's a self-signed cert shell("/usr/bin/curl --insecure https://www.puppetlabs.com:443") do |r| - r.stdout.should == "Hello from www\n" - r.exit_code.should == 0 + expect(r.stdout).to eq("Hello from www\n") + expect(r.exit_code).to eq(0) end end end diff --git a/spec/acceptance/nodesets/centos-5-x64.yml b/spec/acceptance/nodesets/centos-5-x64.yml new file mode 100644 index 0000000..3b48f36 --- /dev/null +++ b/spec/acceptance/nodesets/centos-5-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-5-x64: + roles: + - master + platform: el-5-x86_64 + box : puppetlabs/centos-5.11-64-nocm + box_url : https://vagrantcloud.com/puppetlabs/boxes/centos-5.11-64-nocm + hypervisor : vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/centos-6-x64.yml b/spec/acceptance/nodesets/centos-6-x64.yml new file mode 100644 index 0000000..ad1d123 --- /dev/null +++ b/spec/acceptance/nodesets/centos-6-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-6-x64: + roles: + - master + platform: el-6-x86_64 + box : puppetlabs/centos-6.6-64-nocm + box_url : https://vagrantcloud.com/puppetlabs/boxes/centos-6.6-64-nocm + hypervisor : vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml new file mode 100644 index 0000000..8a5ff92 --- /dev/null +++ b/spec/acceptance/nodesets/centos-7-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-7-x64: + roles: + - master + platform: el-7-x86_64 + box : puppetlabs/centos-7.0-64-nocm + box_url : https://vagrantcloud.com/puppetlabs/boxes/centos-7.0-64-nocm + hypervisor : vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/debian-6-x64.yml b/spec/acceptance/nodesets/debian-6-x64.yml new file mode 100644 index 0000000..00de3cb --- /dev/null +++ b/spec/acceptance/nodesets/debian-6-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + debian-6-x64: + roles: + - master + platform: debian-6-amd64 + box : puppetlabs/debian-6.0.10-64-nocm + box_url : http://vagrantcloud.com/puppetlabs/debian-6.0.10-64-nocm + hypervisor : vagrant +CONFIG: + log_level: debug + type: git diff --git a/spec/acceptance/nodesets/debian-7-x64.yml b/spec/acceptance/nodesets/debian-7-x64.yml new file mode 100644 index 0000000..e06c450 --- /dev/null +++ b/spec/acceptance/nodesets/debian-7-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + debian-7-x64: + roles: + - master + platform: debian-7-amd64 + box : puppetlabs/debian-7.8-64-nocm + box_url : http://vagrantcloud.com/puppetlabs/debian-7.8-64-nocm + hypervisor : vagrant +CONFIG: + log_level: debug + type: git diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..3bb3e62 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: git diff --git a/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml new file mode 100644 index 0000000..d6b4b28 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-1204-x64: + roles: + - master + platform: ubuntu-12.04-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-12.04-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: git diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..3bb3e62 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: git diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_acceptance.rb similarity index 73% rename from spec/spec_helper_system.rb rename to spec/spec_helper_acceptance.rb index bfb7271..24e7075 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,30 +1,31 @@ -require 'rspec-system/spec_helper' -require 'rspec-system-puppet/helpers' -require 'rspec-system-serverspec/helpers' -include RSpecSystemPuppet::Helpers +require 'beaker-rspec' + +hosts.each do |host| + # Install Puppet + on host, install_puppet +end RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - # Enable colour - c.tty = true + c.formatter = :documentation # This is where we 'setup' the nodes before running our tests c.before :suite do - # Install puppet - puppet_install + hosts.each do |host| + # Install module + copy_module_to(host, :source => proj_root, :module_name => 'nginx') + if fact('osfamily') == 'Debian' + on host, puppet('module','install','puppetlabs-apt'), { :acceptable_exit_codes => [0,1] } + end + on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module','install','puppetlabs-concat'), { :acceptable_exit_codes => [0,1] } - # Install modules and dependencies - puppet_module_install(:source => proj_root, :module_name => 'nginx') - shell('puppet module install puppetlabs-apt') - shell('puppet module install puppetlabs-stdlib') - shell('puppet module install puppetlabs-concat') - - # Fake keys. - # Valid self-signed SSL key with 10 year expiry. - # Required for nginx to start when SSL enabled - shell('echo "-----BEGIN PRIVATE KEY----- + # Fake keys. + # Valid self-signed SSL key with 10 year expiry. + # Required for nginx to start when SSL enabled + on host, shell('echo "-----BEGIN PRIVATE KEY----- MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAOPchwRZRF4KmU6E g7C6Pq9zhdLiQt9owdcLZNiZS+UVRQjeDHSy3titzh5YwSoQonlnSqd0g/PJ6kNA O3CNOMVuzAddnAaHzW1J4Rt6sZwOuidtJC4t/hFCgz5NqOMgYOOfratQx00A7ZXK @@ -40,7 +41,7 @@ J9lmX7GV9nUCM7lKVD2ckFOQNlMwCURs8ukJh7H/MfQ8Dt5xoQAMjQJBAOWpK6k6 b0fTREZFZRGZBJcSu959YyMzhpSFA+lXkLNTWX8j1/D88H731oMSImoQNWcYx2dH sCwOCDqu1nZ2LJ8= -----END PRIVATE KEY-----" > /tmp/blah.key') - shell('echo "-----BEGIN CERTIFICATE----- + on host, shell('echo "-----BEGIN CERTIFICATE----- MIIDRjCCAq+gAwIBAgIJAL9m0V4sHW2tMA0GCSqGSIb3DQEBBQUAMIG7MQswCQYD VQQGEwItLTESMBAGA1UECAwJU29tZVN0YXRlMREwDwYDVQQHDAhTb21lQ2l0eTEZ MBcGA1UECgwQU29tZU9yZ2FuaXphdGlvbjEfMB0GA1UECwwWU29tZU9yZ2FuaXph @@ -60,5 +61,6 @@ HaHIWGMBuXApE7t4PNdYWZ5Y56tI+HT59yVoDjc1YSnuzkKlWUPibVYoLpX/ROKr aIZ8kxsBjLvpi9KQTHi7Wl6Sw3ecoYdKy+2P8S5xOIpWjs8XVmOWf7Tq1+9KPv3z HLw/FDCzntkdq3G4em15CdFlO9BTY4HXiHU= -----END CERTIFICATE-----" > /tmp/blah.cert') + end end end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb deleted file mode 100644 index 775c8b6..0000000 --- a/spec/system/basic_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper_system' - -# Here we put the more basic fundamental tests, ultra obvious stuff. -describe "basic tests:" do - context 'make sure we have copied the module across' do - # No point diagnosing any more if the module wasn't copied properly - context shell 'ls /etc/puppet/modules/nginx' do - its(:stdout) { should =~ /Modulefile/ } - its(:stderr) { should be_empty } - its(:exit_code) { should be_zero } - end - end - - #puppet smoke test - context puppet_apply 'notice("foo")' do - its(:stdout) { should =~ /foo/ } - its(:stderr) { should be_empty } - its(:exit_code) { should be_zero } - end - - it 'nginx class should work with no errors' do - pp = <<-EOS - class { 'nginx': } - EOS - - # Run it twice and test for idempotency - puppet_apply(pp) do |r| - [0,2].should include(r.exit_code) - r.refresh - r.exit_code.should be_zero - end - end -end diff --git a/spec/system/class_spec.rb b/spec/system/class_spec.rb deleted file mode 100644 index d8eff7c..0000000 --- a/spec/system/class_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper_system' - -describe "nginx class:" do - case node.facts['osfamily'] - when 'RedHat' - package_name = 'nginx' - when 'Debian' - package_name = 'nginx' - when 'Suse' - package_name = 'nginx-0.8' - end - - context 'should run successfully' do - it 'should run successfully' do - pp = "class { 'nginx': }" - - puppet_apply(pp) do |r| - #r.stderr.should be_empty - [0,2].should include r.exit_code - r.refresh - #r.stderr.should be_empty - r.exit_code.should be_zero - end - end - end - - describe package(package_name) do - it { should be_installed } - end - - describe service('nginx') do - it { should be_running } - end - -end diff --git a/spec/system/nginx_mail_spec.rb b/spec/system/nginx_mail_spec.rb deleted file mode 100644 index e8cce6c..0000000 --- a/spec/system/nginx_mail_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'spec_helper_system' - -describe "nginx::resource::mailhost define:" do - it 'should run successfully' do - - pp = " - class { 'nginx': - mail => true, - } - nginx::resource::vhost { 'www.puppetlabs.com': - ensure => present, - www_root => '/var/www/www.puppetlabs.com', - } - nginx::resource::mailhost { 'domain1.example': - ensure => present, - auth_http => 'localhost/cgi-bin/auth', - protocol => 'smtp', - listen_port => 587, - ssl_port => 465, - xclient => 'off', - } - " - - puppet_apply(pp) do |r| - [0,2].should include r.exit_code - r.refresh - # Not until deprecated variables fixed. - #r.stderr.should be_empty - r.exit_code.should be_zero - end - end - - describe file('/etc/nginx/conf.mail.d/domain1.example.conf') do - it { should be_file } - it { should contain "auth_http localhost/cgi-bin/auth;" } - end - - describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do - it { should be_file } - end - -end