From e5085f39e6516c916f512e6ee5ba8478135db34b Mon Sep 17 00:00:00 2001 From: Matthew Haughton Date: Sun, 5 Apr 2015 22:53:52 -0400 Subject: [PATCH] switch to beaker-rspec from rspec-system-puppet --- .gitignore | 3 +- .nodeset.yml | 31 -------------- Gemfile | 4 +- Rakefile | 1 - spec/acceptance/class_spec.rb | 31 ++++++++++++++ .../{system => acceptance}/nginx_mail_spec.rb | 18 +-------- .../nginx_proxy_spec.rb | 11 ++--- .../nginx_vhost_spec.rb | 16 ++------ spec/acceptance/nodesets/default.yml | 11 +++++ .../nodesets/ubuntu-server-1404-x64.yml | 11 +++++ ...er_system.rb => spec_helper_acceptance.rb} | 40 ++++++++++--------- spec/system/basic_spec.rb | 33 --------------- spec/system/class_spec.rb | 35 ---------------- 13 files changed, 86 insertions(+), 159 deletions(-) delete mode 100644 .nodeset.yml create mode 100644 spec/acceptance/class_spec.rb rename spec/{system => acceptance}/nginx_mail_spec.rb (54%) rename spec/{system => acceptance}/nginx_proxy_spec.rb (77%) rename spec/{system => acceptance}/nginx_vhost_spec.rb (88%) create mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1404-x64.yml rename spec/{spec_helper_system.rb => spec_helper_acceptance.rb} (73%) delete mode 100644 spec/system/basic_spec.rb delete mode 100644 spec/system/class_spec.rb 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..f8fbcd2 --- /dev/null +++ b/spec/acceptance/class_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper_acceptance' + +describe "nginx class:" do + case fact('osfamily') + when 'RedHat' + package_name = 'nginx' + when 'Debian' + package_name = 'nginx' + when 'Suse' + package_name = 'nginx-0.8' + end + + 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(package_name) do + it { is_expected.to be_installed } + end + + describe service('nginx') do + it { is_expected.to be_running } + end + +end diff --git a/spec/system/nginx_mail_spec.rb b/spec/acceptance/nginx_mail_spec.rb similarity index 54% rename from spec/system/nginx_mail_spec.rb rename to spec/acceptance/nginx_mail_spec.rb index e8cce6c..0094a10 100644 --- a/spec/system/nginx_mail_spec.rb +++ b/spec/acceptance/nginx_mail_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper_system' +require 'spec_helper_acceptance' describe "nginx::resource::mailhost define:" do it 'should run successfully' do @@ -7,10 +7,6 @@ describe "nginx::resource::mailhost define:" do 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', @@ -21,13 +17,7 @@ describe "nginx::resource::mailhost define:" do } " - 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 + apply_manifest(pp, :catch_failures => true) end describe file('/etc/nginx/conf.mail.d/domain1.example.conf') do @@ -35,8 +25,4 @@ describe "nginx::resource::mailhost define:" do 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 diff --git a/spec/system/nginx_proxy_spec.rb b/spec/acceptance/nginx_proxy_spec.rb similarity index 77% rename from spec/system/nginx_proxy_spec.rb rename to spec/acceptance/nginx_proxy_spec.rb index 09b1885..9460bea 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,12 +19,7 @@ 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 @@ -37,7 +32,7 @@ describe "nginx::resource::upstream define:" do 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 { should 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 88% rename from spec/system/nginx_vhost_spec.rb rename to spec/acceptance/nginx_vhost_spec.rb index d4f3446..bb58089 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,12 +15,7 @@ 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 @@ -61,12 +56,7 @@ 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 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-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