Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests and fix forwarder bug #7

Merged
merged 1 commit into from
Dec 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .nodeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
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'
26 changes: 26 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
source 'https://rubygems.org'

group :development, :test do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'rspec-system', :require => false
gem 'rspec-system-puppet', :require => false
gem 'rspec-system-serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'pry', :require => false
end

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
gem 'facter', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end

# vim:ft=ruby
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'rspec-system/rake_task'
2 changes: 1 addition & 1 deletion manifests/forwarder.pp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
# to the agnostic resources declared here.
case $::kernel {
default: { } # no special configuration needed
'Linux': { include splunk::platform::posix }
'Linux': { class { 'splunk::platform::posix': splunkd_port => $splunkd_port, } }
'SunOS': { include splunk::platform::solaris }
}

Expand Down
6 changes: 4 additions & 2 deletions manifests/platform/posix.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#
# Requires: nothing
#
class splunk::platform::posix inherits splunk::virtual {
class splunk::platform::posix (
$splunkd_port = $splunk::splunkd_port,
) inherits splunk::virtual {

# Many of the resources declared here are virtual. They will be realized by
# the appropriate including class if required.
Expand Down Expand Up @@ -67,7 +69,7 @@
restart => '/opt/splunk/bin/splunk restart splunkd',
start => '/opt/splunk/bin/splunk start splunkd',
stop => '/opt/splunk/bin/splunk stop splunkd',
pattern => "splunkd -p ${splunk::splunkd_port} (restart|start)",
pattern => "splunkd -p ${splunkd_port} (restart|start)",
require => Service['splunk'],
}
Service['splunkweb'] {
Expand Down
4 changes: 4 additions & 0 deletions spec/spec.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--format s
--colour
--loadby mtime
--backtrace
27 changes: 27 additions & 0 deletions spec/spec_helper_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rspec-system/spec_helper'
require 'rspec-system-puppet/helpers'
require 'rspec-system-serverspec/helpers'
include RSpecSystemPuppet::Helpers

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 => 'splunk')
shell('puppet module install nanliu-staging --version 0.3.1')
shell('puppet module install puppetlabs-stdlib --version 3.0.0')
shell('puppet module install puppetlabs-inifile --version 1.0.0')
end
end

52 changes: 52 additions & 0 deletions spec/system/forwarder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'spec_helper_system'
require 'pry'

describe 'setting up the forwarder' do

it 'should be able to set up a forwarder' do
pp = <<-EOS
class { 'splunk::params':
version => '6.0',
build => '182037',
}
class { 'splunk::forwarder': }
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

describe service('splunk') do
it { should be_running }
end

it 'changes the transforms settings for the forwarder' do
pp = <<-EOS
splunkforwarder_transforms { 'hadoop severity regex':
section => 'hadoop_severity',
setting => 'REGEX',
value => '\\d',
}
splunkforwarder_transforms { 'hadoop severity format':
section => 'hadoop_severity',
setting => 'FORMAT',
value => 'severity::$1',
}
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

describe file('/opt/splunkforwarder/etc/system/local/transforms.conf') do
its(:content) { should match(/\[hadoop_severity\]\nREGEX=\\d\nFORMAT=severity/) }
end
end