]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Initial start on rspec-system tests
authorKen Barber <ken@bob.sh>
Fri, 29 Mar 2013 20:35:04 +0000 (20:35 +0000)
committerKen Barber <ken@bob.sh>
Sat, 30 Mar 2013 22:05:25 +0000 (22:05 +0000)
This patch includes system tests using rspec-system. You can try these out
with:

    rake spec:system

Consult the docs in the README.md for details on how to run tests on
different OS variants.

Signed-off-by: Ken Barber <ken@bob.sh>
.nodeset.yml [new file with mode: 0644]
Gemfile
README.markdown
Rakefile
spec/spec_helper_system.rb [new file with mode: 0644]
spec/system/basic_spec.rb [new file with mode: 0644]
spec/unit/classes/firewall_linux_debian_spec.rb [moved from spec/classes/firewall_linux_debian_spec.rb with 83% similarity]
spec/unit/classes/firewall_linux_redhat_spec.rb [moved from spec/classes/firewall_linux_redhat_spec.rb with 69% similarity]
spec/unit/classes/firewall_linux_spec.rb [moved from spec/classes/firewall_linux_spec.rb with 94% similarity]
spec/unit/classes/firewall_spec.rb [moved from spec/classes/firewall_spec.rb with 79% similarity]

diff --git a/.nodeset.yml b/.nodeset.yml
new file mode 100644 (file)
index 0000000..857a3c2
--- /dev/null
@@ -0,0 +1,23 @@
+---
+default_set: 'centos-63-x64'
+sets:
+  'centos-58-x64':
+    nodes:
+      "main":
+        prefab: 'centos-58-x64'
+  'centos-63-x64':
+    nodes:
+      "main":
+        prefab: 'centos-63-x64'
+  'debian-606-x64':
+    nodes:
+      "main":
+        prefab: 'debian-606-x64'
+  'ubuntu-server-1004-x64':
+    nodes:
+      "main":
+        prefab: 'ubuntu-server-1004-x64'
+  'ubuntu-server-1204-x64':
+    nodes:
+      "main":
+        prefab: 'ubuntu-server-1204-x64'
diff --git a/Gemfile b/Gemfile
index 7dde5a977ec81e77827ee5528189017b91b9dc60..ba5693040bf045aadb687f452876db7b57891ec6 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
 
 group :development, :test do
   gem 'puppetlabs_spec_helper', :require => false
+  gem 'rspec-system', '0.1.3'
 end
 
 if puppetversion = ENV['PUPPET_GEM_VERSION']
index c31dad49cc00735ddc25df42f486916988c0983b..0c9b181537bd2b72443d4dda77f739a900311c84 100644 (file)
@@ -381,3 +381,10 @@ Install the necessary gems:
 And run the tests from the root of the source code:
 
     rake test
+
+If you have a copy of Vagrant 1.1.0 you can also run the system tests:
+
+    RSPEC_SET=debian-606-x64 rake spec:system
+    RSPEC_SET=centos-58-x64 rake spec:system
+
+*Note:* system testing is fairly alpha at this point, your mileage may vary.
index 79d29df89fac3d5ba487df68d3a7c3a05730c139..4847ddd2044f49a5c4d0c69edea83efe427d8c96 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -5,6 +5,7 @@ Bundler.require :default
 
 require 'rspec/core/rake_task'
 require 'puppetlabs_spec_helper/rake_tasks'
+require 'rspec-system/rake_task'
 
 task :default do
   sh %{rake -T}
diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb
new file mode 100644 (file)
index 0000000..f4b91e3
--- /dev/null
@@ -0,0 +1,51 @@
+# This helper file is specific to the system tests for puppetlabs-firewall
+# and should be included by all tests under spec/system
+require 'rspec-system/spec_helper'
+
+RSpec.configure do |c|
+  # Project root for the firewall code
+  proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+  # This is where we 'setup' the nodes before running our tests
+  c.system_setup_block = proc do
+    # TODO: find a better way of importing these into this namespace
+    include RSpecSystem::Helpers
+    include RSpecSystem::Log
+
+    # TODO: this setup stuff is fairly generic, should move this into a plugin
+    # for rspec-system.
+
+    # Grab facts from node
+    facts = system_node.facts
+
+    # Remove annoying mesg n from profile, otherwise on Debian we get:
+    # stdin: is not a tty which messes with our tests later on.
+    if facts['osfamily'] == 'Debian'
+      log.info("Remove 'mesg n' from profile to stop noise")
+      system_run("sed -i 's/^mesg n/# mesg n/' /root/.profile")
+    end
+
+    # Grab PL repository and install PL copy of puppet
+    log.info "Starting installation of puppet from PL repos"
+    if facts['osfamily'] == 'RedHat'
+      system_run('rpm -ivh http://yum.puppetlabs.com/el/5/products/i386/puppetlabs-release-5-6.noarch.rpm')
+      system_run('yum install -y puppet')
+    elsif facts['osfamily'] == 'Debian'
+      system_run("wget http://apt.puppetlabs.com/puppetlabs-release-#{facts['lsbdistcodename']}.deb")
+      system_run("dpkg -i puppetlabs-release-#{facts['lsbdistcodename']}.deb")
+      system_run('apt-get update')
+      system_run('apt-get install -y puppet')
+    end
+
+    # Prep modules dir
+    log.info("Preparing modules dir")
+    system_run('mkdir -p /etc/puppet/modules')
+
+    # Copy the current code into appropriate module dir
+    # TODO: we could always use the build process, copy tarball across etc.
+    # just a shame the puppet module tool doesn't handle standalone tarballs
+    # yet.
+    log.info("Now transferring module onto node")
+    system_rcp(:sp => proj_root, :dp => '/etc/puppet/modules/firewall')
+  end
+end
diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb
new file mode 100644 (file)
index 0000000..a412417
--- /dev/null
@@ -0,0 +1,49 @@
+require 'spec_helper_system'
+
+# TODO: we probably wanna break this into pieces
+describe "basic tests:" do
+  # This helper flushes all tables on the default machine.
+  #
+  # It checks that the flush command returns with no errors.
+  def iptables_flush_all_tables
+    ['filter', 'nat', 'mangle', 'raw'].each do |t|
+      system_run("iptables -t #{t} -F") do |s, o, e|
+        s.exitstatus.should == 0
+        e.should == ''
+      end
+    end
+  end
+
+  context 'prelim:' do
+    it 'make sure we have copied the module across' do
+      # No point diagnosing any more if the module wasn't copied properly
+      system_run("ls /etc/puppet/modules/firewall") do |s, o, e|
+        s.exitstatus.should == 0
+        o.should =~ /Modulefile/
+        e.should == ''
+      end
+    end
+  end
+
+  context 'puppet resource firewall command:' do
+    it 'make sure it returns no errors when executed on a clean machine' do
+      # Except for the absence of iptables, it should run perfectly usually
+      # most hosts have iptables at least.
+      system_run('puppet resource firewall') do |s, o, e|
+        s.exitstatus.should == 0
+        # don't check stdout, some boxes come with rules, that is normal
+        e.should == ''
+      end
+    end
+
+    it 'flush iptables and make sure it returns nothing afterwards' do
+      iptables_flush_all_tables
+      # No rules, means no output thanks. And no errors as well.
+      system_run('puppet resource firewall') do |s, o, e|
+        s.exitstatus.should == 0
+        e.should == ''
+        o.should == "\n"
+      end
+    end
+  end
+end
similarity index 83%
rename from spec/classes/firewall_linux_debian_spec.rb
rename to spec/unit/classes/firewall_linux_debian_spec.rb
index 3215ce78c61b2fbb8785bd3241283ed0c03772fa..ed468f55ab4205b9511b854045ae8e6041794fc4 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper'
 
-describe 'firewall::linux::debian' do
+describe 'firewall::linux::debian', :type => :class do
   it { should contain_package('iptables-persistent').with(
     :ensure => 'present'
   )}
similarity index 69%
rename from spec/classes/firewall_linux_redhat_spec.rb
rename to spec/unit/classes/firewall_linux_redhat_spec.rb
index a4a307bb73d49d6369ff5190c1ce87dad8c4559e..f61e7815a9dd9efd1883327163ee9c91b93cb8de 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper'
 
-describe 'firewall::linux::redhat' do
+describe 'firewall::linux::redhat', :type => :class do
   it { should contain_service('iptables').with(
     :ensure => 'running',
     :enable => 'true'
similarity index 94%
rename from spec/classes/firewall_linux_spec.rb
rename to spec/unit/classes/firewall_linux_spec.rb
index 61a1b64c4a48483b1fbb0f3c45b62153bbd09ad9..8245915a9fd9722471a300d3ae1e39e4044ff23a 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper'
 
-describe 'firewall::linux' do
+describe 'firewall::linux', :type => :class do
   let(:facts_default) {{ :kernel => 'Linux' }}
   it { should contain_package('iptables').with_ensure('present') }
 
similarity index 79%
rename from spec/classes/firewall_spec.rb
rename to spec/unit/classes/firewall_spec.rb
index d97443fa7ebd7be4388de6f70f54be2afba6ac0f..8d1b7c25cca239d44c75145346ef931957f98f10 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper'
 
-describe 'firewall' do
+describe 'firewall', :type => :class do
   context 'kernel => Linux' do
     let(:facts) {{ :kernel => 'Linux' }}
     it { should include_class('firewall::linux') }