From 60293244c07a546cf22bed66b2f217b3a3cd8093 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Mon, 30 Sep 2013 10:01:16 -0700 Subject: [PATCH] add rspec-system-puppet infrastructure + basic system tests --- .gitignore | 1 + .nodeset.yml | 11 ++++++++++ Gemfile | 4 ++++ Rakefile | 1 + spec/spec_helper_system.rb | 28 +++++++++++++++++++++++++ spec/system/smartd_spec.rb | 42 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 .nodeset.yml create mode 100644 spec/spec_helper_system.rb create mode 100644 spec/system/smartd_spec.rb diff --git a/.gitignore b/.gitignore index b7a885f..6e64147 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ Gemfile.lock *.orig *.rej *.patch +.rspec_system/ diff --git a/.nodeset.yml b/.nodeset.yml new file mode 100644 index 0000000..b802983 --- /dev/null +++ b/.nodeset.yml @@ -0,0 +1,11 @@ +--- +default_set: 'centos-64-x64' +sets: + 'centos-64-x64': + nodes: + 'main.vm': + prefab: 'centos-64-x64' + 'debian-607-x64': + nodes: + 'main.vm': + prefab: 'debian-607-x64' diff --git a/Gemfile b/Gemfile index af9879b..2f03508 100644 --- a/Gemfile +++ b/Gemfile @@ -10,5 +10,9 @@ gem 'rake' gem 'puppetlabs_spec_helper' gem 'puppet-lint' gem 'puppet-syntax' +gem 'rspec-system', :require => false +gem 'rspec-system-puppet', :require => false +gem 'rspec-system-serverspec', :require => false +gem 'serverspec', :require => false # vim:ft=ruby diff --git a/Rakefile b/Rakefile index 992421b..a4c4fbd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ require 'puppetlabs_spec_helper/rake_tasks' +require 'rspec-system/rake_task' require 'puppet-syntax/tasks/puppet-syntax' require 'puppet-lint/tasks/puppet-lint' diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb new file mode 100644 index 0000000..ecb7a4b --- /dev/null +++ b/spec/spec_helper_system.rb @@ -0,0 +1,28 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' + +include RSpecSystemPuppet::Helpers + +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + # This is where we 'setup' the nodes before running our tests + c.before :suite do + # Install puppet + puppet_install + + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'smartd') + shell('puppet module install puppetlabs-stdlib') + end +end diff --git a/spec/system/smartd_spec.rb b/spec/system/smartd_spec.rb new file mode 100644 index 0000000..697c622 --- /dev/null +++ b/spec/system/smartd_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper_system' + +describe 'smartd class' do + case node.facts['osfamily'] + when 'RedHat', 'Debian' + package_name = 'smartmontools' + service_name = 'smartd' + end + + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'smartd': } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + + describe package(package_name) do + it { should be_installed } + end + + describe service(service_name) do + it { should be_running } + it { should be_enabled } + end + + describe file('/etc/smartd.conf') do + it { should be_file } + it { should contain([ + 'DEFAULT -m root -M daily', + 'DEVICESCAN', + ]) } + end +end