Commit 6c1f805b authored by Jonathan Gazeley's avatar Jonathan Gazeley
Browse files

Add auto generated spec tests

parent 7e33cb49
---
BUNDLE_DISABLE_SHARED_GEMS: '1'
fixtures:
symlinks:
freeradius: "#{source_dir}"
repositories:
stdlib:
repo: https://github.com/puppetlabs/puppetlabs-stdlib.git
ref: 4.3.2
forge_modules:
# Use this file to instruct puppet-lint to ignore certain checks.
# For the complete list of checks and flags to disable them,
# refer to <http://puppet-lint.com/checks/>.
# Examples (uncomment before use):
#--no-80chars-check
#--no-class_inherits_from_params_class-check
#--no-inherits_across_namespaces-check
branches:
script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
bundler_args: --without development
rvm:
- 1.9.3
- 2.0.0
- 2.1.5
- 2.2.0
env:
matrix:
- PUPPET_GEM_VERSION="~> 3.2"
- PUPPET_GEM_VERSION="~> 3.7"
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
require 'puppet-syntax/tasks/puppet-syntax'
desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
# These two gems aren't always present, for instance
# on Travis with --without development
begin
require 'puppet_blacksmith/rake_tasks'
Blacksmith::RakeTask.new do |t|
t.tag_pattern = "v%s" # Use a custom pattern with git tag. %s is replaced with the version number.
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
rescue LoadError
end
PuppetLint.configuration.relative = true
PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
PuppetLint.configuration.fail_on_warnings = true
# Forsake support for Puppet 2.6.2 for the benefit of cleaner code.
# http://puppet-lint.com/checks/class_parameter_defaults/
PuppetLint.configuration.send('disable_class_parameter_defaults')
# http://puppet-lint.com/checks/class_inherits_from_params_class/
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
exclude_paths = [
"pkg/**/*",
"vendor/**/*",
"spec/**/*",
]
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths
task :metadata do
sh "metadata-json-lint metadata.json"
end
desc "Run syntax, lint, and spec tests."
task :test => [
:syntax,
:lint,
:spec,
:metadata,
]
def io_popen(command)
IO.popen(command) do |io|
io.each do |line|
print line
yield line if block_given?
end
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
desc 'Vagrant VM power up and provision'
task :vagrant_up, [:manifest, :hostname] do |t, args|
args.with_defaults(:manifest => 'init.pp', :hostname => '')
Rake::Task['spec_prep'].execute
ENV['VAGRANT_MANIFEST'] = args[:manifest]
provision = false
io_popen("vagrant up #{args[:hostname]}") do |line|
provision = true if line =~ /is already running./
end
io_popen("vagrant provision #{args[:hostname]}") if provision
end
# Cleanup vagrant environment
desc 'Vagrant VM shutdown and fixtures cleanup'
task :vagrant_destroy do
Rake::Task['spec_prep'].execute
`vagrant destroy -f`
Rake::Task['spec_clean'].execute
end
def vm(opt)
module_name = opt.fetch(:module).to_s || raise(ArgumentError, 'Must provide puppet module name')
hostname = opt.fetch(:hostname, module_name).to_s
memory = opt.fetch(:memory, 512)
cpu = opt.fetch(:cpu, 1)
box = opt.fetch(:box).to_s || raise(ArgumentError, 'Must provide box type.')
url = opt.fetch(:url, '').to_s
os_type = opt[:os_type] || opt[:type] || :linux
gui = opt.fetch(:gui, false)
ports = Array(opt.fetch(:port, []))
iso = opt.fetch(:iso, nil)
proj_root = File.expand_path(File.join(File.dirname(__FILE__)))
fixture_modules = File.join(proj_root, 'spec', 'fixtures', 'modules')
Vagrant.configure('2') do |conf|
# forward all the ports
ports.each do |p|
conf.vm.network(:forwarded_port, guest: p, host: p, auto_correct: true)
end
if os_type == :windows
conf.ssh.username = 'vagrant'
conf.winrm.username = 'vagrant'
conf.winrm.password = 'vagrant'
end
conf.vm.define hostname.to_sym do |mod|
mod.vm.box = box
mod.vm.box_url = url
if os_type == :windows
mod.vm.guest = :windows
mod.vm.communicator = 'winrm'
mod.vm.synced_folder './' , "/ProgramData/PuppetLabs/puppet/etc/modules/#{module_name}"
mod.vm.synced_folder 'spec/fixtures/modules' , '/temp/modules'
else
mod.vm.synced_folder './', "/etc/puppet/modules/#{module_name}"
mod.vm.synced_folder 'spec/fixtures/modules', '/tmp/puppet/modules'
end
mod.vm.hostname = hostname
mod.vm.provider :vmware_fusion do |f|
f.gui = gui
f.vmx['displayName'] = hostname
f.vmx['memsize'] = memory
f.vmx['numvcpus'] = cpu
if iso
f.vmx['ide1:0.devicetype'] = "cdrom-image"
f.vmx['ide1:0.filename'] = iso
end
end
mod.vm.provider :vmware_workstation do |f|
f.gui = gui
f.vmx['displayName'] = hostname
f.vmx['memsize'] = memory
f.vmx['numvcpus'] = cpu
if iso
f.vmx['ide1:0.devicetype'] = "cdrom-image"
f.vmx['ide1:0.filename'] = iso
end
end
mod.vm.provider :virtualbox do |v|
v.gui = gui
v.name = hostname
v.memory = memory
v.cpus = cpu
end
if os_type == :windows
manifest = ENV['VAGRANT_MANIFEST'] || 'init.pp'
#mod.vm.provision :shell, :inline => "@powershell -NoProfile -ExecutionPolicy Bypass -Command \"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))\" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
#mod.vm.provision :shell, :inline => "choco install puppet"
mod.vm.provision :shell, :inline => "puppet apply --modulepath 'C:/ProgramData/PuppetLabs/puppet/etc/modules;C:/temp/modules' --verbose C:/ProgramData/PuppetLabs/puppet/etc/modules/#{module_name}/tests/#{manifest}"
else
mod.vm.provision :puppet do |p|
p.manifests_path = 'tests'
# p.hiera_config_path = File.join(fixture_modules, 'hieradata', 'hiera.yaml')
p.manifest_file = ENV['VAGRANT_MANIFEST'] || 'init.pp'
#p.module_path = fixture_modules
# because of how symlinks are handled via the spec_helper we are forced to mount the modules is different locations
# otherwise we could just use the above option
p.options = '--modulepath="/etc/puppet/modules:/tmp/puppet/modules"'
end
end
end
end
end
module_name = File.basename(File.expand_path(File.join(File.dirname(__FILE__))))
vm :hostname => 'win2012r2', :module => module_name, :box => 'opentable/win-2012r2-standard-amd64-nocm', :url => 'opentable/win-2012r2-standard-amd64-nocm', :os_type => :windows, :cpu => 1, :memory => 4096, :gui => true
vm :hostname => 'win2008r2', :module => module_name, :box => 'opentable/win-2008r2-standard-amd64-nocm', :url => 'opentable/win-2008r2-standard-amd64-nocm', :os_type => :windows, :cpu => 1, :memory => 4096, :gui => true
vm :hostname => 'centos6', :module => module_name, :box => 'puppetlabs/centos-6.6-64-puppet', :url => 'puppetlabs/centos-6.6-64-puppet', :cpu => 1, :memory => 2048, :gui => false
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius::control_socket' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
#:mode => "ro",
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_freeradius__site('control-socket')
.with(
'content' => 'template(freeradius/sites-enabled/control-socket.erb)'
)
end
end
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
#:control_socket => false,
#:max_servers => "4096",
#:max_requests => "4096",
#:mysql_support => false,
#:perl_support => false,
#:utils_support => false,
#:ldap_support => false,
#:wpa_supplicant => false,
#:winbind_support => false,
#:syslog => false,
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_file('radiusd.conf')
.with(
'content' => 'template(freeradius/radiusd.conf.fr$freeradius::fr_version.erb)',
'group' => '$freeradius::fr_group',
'mode' => '0640',
'name' => '$freeradius::fr_basepath/radiusd.conf',
'notify' => 'Service[$freeradius::fr_service]',
'owner' => 'root',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_file('[$freeradius::fr_basepath/statusclients.d, $freeradius::fr_basepath, $freeradius::fr_basepath/conf.d, $freeradius::fr_basepath/attr.d, $freeradius::fr_basepath/users.d, $freeradius::fr_basepath/policy.d, $freeradius::fr_basepath/dictionary.d, $freeradius::fr_basepath/scripts]')
.with(
'ensure' => 'directory',
'group' => '$freeradius::fr_group',
'mode' => '0750',
'notify' => 'Service[$freeradius::fr_service]',
'owner' => 'root',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_file('[$freeradius::fr_basepath/certs, $freeradius::fr_basepath/clients.d, $freeradius::fr_basepath/sites-enabled, $freeradius::fr_basepath/sites-available, $freeradius::fr_basepath/instantiate]')
.with(
'ensure' => 'directory',
'group' => '$freeradius::fr_group',
'mode' => '0750',
'notify' => 'Service[$freeradius::fr_service]',
'owner' => 'root',
'purge' => 'true',
'recurse' => 'true',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_freeradius__module('eap')
.with(
'ensure' => 'absent'
)
end
it do
is_expected.to contain_concat('$freeradius::fr_basepath/policy.conf')
.with(
'group' => '$freeradius::fr_group',
'mode' => '0640',
'notify' => 'Service[$freeradius::fr_service]',
'owner' => 'root',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_concat__fragment('policy_header')
.with(
'content' => 'policy {\\n',
'order' => '10',
'target' => '$freeradius::fr_basepath/policy.conf'
)
end
it do
is_expected.to contain_concat__fragment('policy_footer')
.with(
'content' => '}\\n',
'order' => '99',
'target' => '$freeradius::fr_basepath/policy.conf'
)
end
it do
is_expected.to contain_concat('$freeradius::fr_basepath/proxy.conf')
.with(
'group' => '$freeradius::fr_group',
'mode' => '0640',
'notify' => 'Service[$freeradius::fr_service]',
'owner' => 'root',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_concat__fragment('proxy_header')
.with(
'content' => '# Proxy config\\n\\n',
'order' => '05',
'target' => '$freeradius::fr_basepath/proxy.conf'
)
end
it do
is_expected.to contain_concat('$freeradius::fr_modulepath/attr_filter')
.with(
'group' => '$freeradius::fr_group',
'mode' => '0640',
'notify' => 'Service[$freeradius::fr_service]',
'owner' => 'root',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_concat__fragment('attr-default')
.with(
'content' => 'template(freeradius/attr_default.fr$freeradius::fr_version.erb)',
'order' => '10',
'target' => '$freeradius::fr_modulepath/attr_filter'
)
end
it do
is_expected.to contain_concat('$freeradius::fr_basepath/dictionary')
.with(
'group' => '$freeradius::fr_group',
'mode' => '0640',
'owner' => 'root',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_concat__fragment('dictionary_header')
.with(
'order' => '10',
'source' => 'puppet:///modules/freeradius/dictionary.header',
'target' => '$freeradius::fr_basepath/dictionary'
)
end
it do
is_expected.to contain_concat__fragment('dictionary_footer')
.with(
'order' => '90',
'source' => 'puppet:///modules/freeradius/dictionary.footer',
'target' => '$freeradius::fr_basepath/dictionary'
)
end
it do
is_expected.to contain_package('freeradius')
.with(
'ensure' => 'installed',
'name' => '$freeradius::fr_package'
)
end
it do
is_expected.to contain_service('$freeradius::fr_service')
.with(
'enable' => 'true',
'ensure' => 'running',
'hasrestart' => 'true',
'hasstatus' => '$freeradius::fr_service_has_status',
'name' => '$freeradius::fr_service',
'require' => '[Exec[radiusd-config-test], File[radiusd.conf], User[$freeradius::fr_user], Package[$freeradius::fr_package]]'
)
end
it do
is_expected.to contain_user('$freeradius::fr_user')
.with(
'ensure' => 'present',
'groups' => '$winbind_support ? { true => $freeradius::fr_wbpriv_user, default => undef }',
'require' => 'Package[$freeradius::fr_package]'
)
end
it do
is_expected.to contain_group('$freeradius::fr_group')
.with(
'ensure' => 'present',
'require' => 'Package[$freeradius::fr_package]'
)
end
it do
is_expected.to contain_freeradius__module('always')
.with( )
end
it do
is_expected.to contain_freeradius__module('detail')
.with( )
end
it do
is_expected.to contain_freeradius__module('detail.log')
.with( )
end
it do
is_expected.to contain_file('[$freeradius::fr_logpath, $freeradius::fr_logpath/radacct]')
.with(
'mode' => '0750',
'require' => 'Package[$freeradius::fr_package]'
)
end
it do
is_expected.to contain_file('$freeradius::fr_logpath/radius.log')
.with(
'group' => '$freeradius::fr_group',
'owner' => '$freeradius::fr_user',
'require' => '[Package[$freeradius::fr_package], User[$freeradius::fr_user], Group[$freeradius::fr_group]]',
'seltype' => 'radiusd_log_t'
)
end
it do
is_expected.to contain_logrotate__rule('radacct')
.with(
'compress' => 'true',
'create' => 'false',
'missingok' => 'true',
'path' => '$freeradius::fr_logpath/radacct/*/*.log',
'postrotate' => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`',
'rotate' => '7',
'rotate_every' => 'day',
'sharedscripts' => 'true'
)
end
it do
is_expected.to contain_logrotate__rule('checkrad')
.with(
'compress' => 'true',
'create' => 'true',
'missingok' => 'true',
'path' => '$freeradius::fr_logpath/checkrad.log',
'postrotate' => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`',
'rotate' => '1',
'rotate_every' => 'week',
'sharedscripts' => 'true'
)
end
it do
is_expected.to contain_logrotate__rule('radiusd')
.with(
'compress' => 'true',
'create' => 'true',
'missingok' => 'true',
'path' => '$freeradius::fr_logpath/radius*.log',
'postrotate' => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`',
'rotate' => '26',
'rotate_every' => 'week',
'sharedscripts' => 'true'
)
end
it do
is_expected.to contain_file('[$freeradius::fr_basepath/certs/dh, $freeradius::fr_basepath/certs/random]')
.with(
'require' => 'Exec[dh, random]'
)
end
it do
is_expected.to contain_exec('dh')
.with(
'command' => 'openssl dhparam -out $freeradius::fr_basepath/certs/dh 1024',
'creates' => '$freeradius::fr_basepath/certs/dh',
'path' => '/usr/bin'
)
end
it do
is_expected.to contain_exec('random')
.with(
'command' => 'dd if=/dev/urandom of=$freeradius::fr_basepath/certs/random count=10 >/dev/null 2>&1',
'creates' => '$freeradius::fr_basepath/certs/random',
'path' => '/bin'
)
end
it do
is_expected.to contain_exec('radiusd-config-test')
.with(
'command' => 'sudo radiusd -XC | grep 'Configuration appears to be OK.' | wc -l',
'logoutput' => 'on_failure',
'path' => '[/bin/, /sbin/, /usr/bin/, /usr/sbin/]',
'refreshonly' => 'true',
'returns' => '0'
)
end
it do
is_expected.to contain_file('[$freeradius::fr_basepath/sites-available/default, $freeradius::fr_basepath/sites-available/inner-tunnel, $freeradius::fr_basepath/clients.conf, $freeradius::fr_basepath/sql.conf]')
.with(
'content' => '# FILE INTENTIONALLY BLANK\\n',
'group' => '$freeradius::fr_group',
'mode' => '0644',
'notify' => 'Service[$freeradius::fr_service]',
'owner' => 'root',
'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]'
)
end
it do
is_expected.to contain_package('freeradius-mysql')
.with(
'ensure' => 'installed'
)
end
it do
is_expected.to contain_package('freeradius-perl')
.with(
'ensure' => 'installed'
)
end
it do
is_expected.to contain_package('freeradius-utils')
.with(
'ensure' => 'installed'
)
end
it do