diff --git a/Gemfile b/Gemfile index 7445244..6a777eb 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' group :test do gem 'rake' - gem 'puppet', ENV['PUPPET_VERSION'] || '~> 3.4.0' + gem 'puppet', ENV['PUPPET_VERSION'] || '~> 3.8.0' gem 'puppet-lint' gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git' gem 'puppet-syntax' diff --git a/Gemfile.lock b/Gemfile.lock index d515400..7e4a6d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -224,10 +224,10 @@ GEM coderay (~> 1.0) method_source (~> 0.8) slop (~> 3.4) - puppet (3.4.3) - facter (~> 1.6) + puppet (3.8.1) + facter (> 1.6, < 3) hiera (~> 1.0) - rgen (~> 0.6.5) + json_pure puppet-blacksmith (3.2.0) puppet (>= 2.7.16) rest-client @@ -256,7 +256,6 @@ GEM mime-types (>= 1.16, < 3.0) netrc (~> 0.7) retriable (1.4.1) - rgen (0.6.6) rspec (3.2.0) rspec-core (~> 3.2.0) rspec-expectations (~> 3.2.0) @@ -332,7 +331,7 @@ DEPENDENCIES beaker-rspec guard-rake metadata-json-lint - puppet (~> 3.4.0) + puppet (~> 3.8.0) puppet-blacksmith puppet-lint puppet-module @@ -343,3 +342,6 @@ DEPENDENCIES simplecov travis travis-lint + +BUNDLED WITH + 1.10.5 diff --git a/README.markdown b/README.markdown index 6439775..a4a7ebf 100644 --- a/README.markdown +++ b/README.markdown @@ -66,7 +66,7 @@ class { 'swap_file': However, this had many problems, such as not being able to declare more than one swap_file because of duplicate class errors. -This is now deprecated and will give a warning. +This is now removed from 2.x.x onwards. ##Limitations diff --git a/manifests/init.pp b/manifests/init.pp deleted file mode 100644 index a8943a8..0000000 --- a/manifests/init.pp +++ /dev/null @@ -1,68 +0,0 @@ -# Class: swap_file -# -# This class creates a swapspace on a node. -# -# Using this class is now deprecated, use the swap_file::files defined type -# -# == Parameters -# [*ensure*] -# Allows creation or removal of swapspace and the corresponding file. -# [*swapfile*] -# Location of swapfile, defaults to /mnt -# [*swapfilesize*] -# Size of the swapfile as a string (eg. 10 MB, 1.2 GB). -# Defaults to $::memorysize fact on the node -# [*add_mount*] -# Add a mount to the swapfile so it persists on boot -# [*options*] -# Mount options for the swapfile -# -# == Examples -# -# include swap_file -# -# class { 'swap_file': -# ensure => present, -# } -# -# class { 'swap_file': -# swapfile => '/mount/swapfile', -# swapfilesize => '100 MB', -# } -# -# == Authors -# @petems - Peter Souter -# @Yggdrasil -# -class swap_file ( - $ensure = 'present', - $swapfile = '/mnt/swap.1', - $swapfilesize = $::memorysize, - $add_mount = true, - $options = 'defaults' -) inherits swap_file::params { - - # Parameter validation - validate_re($ensure, ['^absent$', '^present$'], "Invalid ensure: ${ensure} - (Must be 'present' or 'absent')") - validate_string($swapfile) - $swapfilesize_mb = to_bytes($swapfilesize) / 1000000 - validate_bool($add_mount) - - warning('Use of swap_file class is now deprecated') - warning('Use the swap_file::files defined type (Or downgrade the swap_file module to 1.0.1') - - if $ensure == 'present' { - ::swap_file::files{ $swapfile: - ensure => 'present', - swapfile => $swapfile, - swapfilesize => $swapfilesize, - add_mount => $add_mount, - options => $options, - } - } - elsif $ensure == 'absent' { - ::swap_file::files{ $swapfile: - ensure => 'absent', - } - } -} diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index 5d696d3..0000000 --- a/manifests/params.pp +++ /dev/null @@ -1,24 +0,0 @@ -# == Class swap_file::params -# -# This class is meant to be called from swap_file -# It sets variables according to platform -# -class swap_file::params { - case $::osfamily { - 'Debian': { - - } - 'RedHat': { - - } - 'windows': { - fail('Swap files dont work on windows') - } - 'FreeBSD': { - fail('FreeBSD is not yet supported (See https://github.com/petems/puppet-swap_file/issues/9)') - } - default: { - warning("${::operatingsystem} not officially supported, but should work") - } - } -} diff --git a/metadata.json b/metadata.json index e399dd9..9787d52 100644 --- a/metadata.json +++ b/metadata.json @@ -43,7 +43,7 @@ "requirements": [ { "name": "pe", - "version_requirement": ">= 3.2.0 < 3.4.0" + "version_requirement": ">= 3.2.0" }, { "name": "puppet", diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb deleted file mode 100644 index b4ae0dd..0000000 --- a/spec/acceptance/class_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'swap_file class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - - context 'swap_file' do - context 'ensure => present' do - it 'should work with no errors' do - pp = <<-EOS - class { 'swap_file': } - EOS - - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end - it 'should contain the default swapfile' do - shell('/sbin/swapon -s | grep /mnt/swap.1', :acceptable_exit_codes => [0]) - end - it 'should contain the default fstab setting' do - shell('cat /etc/fstab | grep /mnt/swap.1', :acceptable_exit_codes => [0]) - shell('cat /etc/fstab | grep defaults', :acceptable_exit_codes => [0]) - end - end - context 'custom parameters' do - it 'should work with no errors' do - pp = <<-EOS - class { 'swap_file': - swapfile => '/tmp/swapfile', - swapfilesize => '5 MB', - } - EOS - - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end - it 'should contain the given swapfile' do - shell('/sbin/swapon -s | grep /tmp/swapfile', :acceptable_exit_codes => [0]) - shell('/sbin/swapon -s | grep 5116', :acceptable_exit_codes => [0]) - end - it 'should contain the default fstab setting' do - shell('cat /etc/fstab | grep /tmp/swapfile', :acceptable_exit_codes => [0]) - shell('cat /etc/fstab | grep defaults', :acceptable_exit_codes => [0]) - end - end - end -end \ No newline at end of file diff --git a/spec/acceptance/swap_file_files_multiple_spec.rb b/spec/acceptance/swap_file_files_multiple_spec.rb new file mode 100644 index 0000000..2e0837d --- /dev/null +++ b/spec/acceptance/swap_file_files_multiple_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper_acceptance' + +describe 'swap_file class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + + context 'multiple swap_file::files', :unless => ['FreeBSD'].include?(fact('osfamily')) do + it 'should work with no errors' do + pp = <<-EOS + swap_file::files { 'tmp file swap 1': + ensure => present, + swapfile => '/tmp/swapfile1', + } + + swap_file::files { 'tmp file swap 2': + ensure => present, + swapfile => '/tmp/swapfile2', + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + it 'should contain the given swapfile' do + shell('/sbin/swapon -s | grep /tmp/swapfile1', :acceptable_exit_codes => [0]) + shell('/sbin/swapon -s | grep /tmp/swapfile2', :acceptable_exit_codes => [0]) + end + it 'should contain the default fstab setting' do + shell('cat /etc/fstab | grep /tmp/swapfile1', :acceptable_exit_codes => [0]) + shell('cat /etc/fstab | grep /tmp/swapfile2', :acceptable_exit_codes => [0]) + end + end +end \ No newline at end of file diff --git a/spec/acceptance/swap_file_files_parameters_spec.rb b/spec/acceptance/swap_file_files_parameters_spec.rb new file mode 100644 index 0000000..adf1bb5 --- /dev/null +++ b/spec/acceptance/swap_file_files_parameters_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_acceptance' + +describe 'swap_file class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + + context 'swap_file' do + context 'custom parameters' do + it 'should work with no errors' do + pp = <<-EOS + swap_file::files { 'tmp file swap': + ensure => present, + swapfile => '/tmp/swapfile', + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + it 'should contain the given swapfile' do + if ["FreeBSD"].include?(fact('osfamily')) + shell('/usr/sbin/swapinfo | grep /dev/md99', :acceptable_exit_codes => [0]) + else + shell('/sbin/swapon -s | grep /tmp/swapfile', :acceptable_exit_codes => [0]) + end + end + it 'should contain the given fstab setting' do + shell('cat /etc/fstab | grep /tmp/swapfile', :acceptable_exit_codes => [0]) + if ["FreeBSD"].include?(fact('osfamily')) + shell('cat /etc/fstab | grep md99', :acceptable_exit_codes => [0]) + else + shell('cat /etc/fstab | grep defaults', :acceptable_exit_codes => [0]) + end + end + end + end +end \ No newline at end of file diff --git a/spec/classes/swap_file_spec.rb b/spec/classes/swap_file_spec.rb deleted file mode 100644 index 62a15f4..0000000 --- a/spec/classes/swap_file_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -require 'spec_helper' - -describe 'swap_file' do - - shared_examples "compiles and contains classes" do - it { should compile.with_all_deps } - it { should contain_class('Swap_file::Params') } - it { should contain_class('Swap_file') } - end - - shared_examples "with default parameters" do |osfamily| - let(:facts) {{ - :osfamily => osfamily, :memorysize => '1 GB', - }} - it { should compile.with_all_deps } - it { should contain_file('/mnt/swap.1') } - - it { should contain_swap_file__files('/mnt/swap.1') } - it { - should contain_exec('Create swap file /mnt/swap.1'). - with_command('/bin/dd if=/dev/zero of=/mnt/swap.1 bs=1M count=1073') - } - it { should contain_exec('Attach swap file /mnt/swap.1') } - it { should contain_mount('/mnt/swap.1').with_ensure('present') } - end - - shared_examples "with swapfile and size parameters" do |osfamily| - let(:params) {{ :swapfile => '/foo/bar', :swapfilesize => '2 GB' }} - let(:facts) {{ - :osfamily => osfamily, :memorysize => '1 GB', - }} - it { should compile.with_all_deps } - it { should contain_file('/foo/bar') } - - it { should contain_swap_file__files('/foo/bar') } - it { - should contain_exec('Create swap file /foo/bar'). - with_command('/bin/dd if=/dev/zero of=/foo/bar bs=1M count=2147') - } - it { should contain_exec('Attach swap file /foo/bar') } - it { should contain_mount('/foo/bar').with_ensure('present') } - end - - shared_examples "can specify no mount" do |osfamily| - let(:params) {{ :add_mount => false, }} - let(:facts) {{ - :osfamily => osfamily, :memorysize => '1 GB', - }} - it { should compile.with_all_deps } - it { should contain_file('/foo/bar') } - - it { should contain_swap_file__files('/foo/bar') } - it { - should contain_exec('Create swap file /foo/bar'). - with_command('/bin/dd if=/dev/zero of=/foo/bar bs=1M count=1073') - } - it { should contain_exec('Attach swap file /foo/bar') } - it { should_not contain_mount('/foo/bar').with_ensure('present') } - end - - context 'officially support operating system' do - describe 'Debian' do - it_behaves_like "compiles and contains classes" - - it_behaves_like "with default parameters", :osfamily => 'Debian' - - it_behaves_like "with swapfile and size parameters", :osfamily => 'Debian' - end - - describe 'RedHat' do - it_behaves_like "compiles and contains classes" - - it_behaves_like "with default parameters", :osfamily => 'RedHat' - - it_behaves_like "with swapfile and size parameters", :osfamily => 'RedHat' - end - end - - context 'not officially support operating system' do - describe 'Solaris' do - it_behaves_like "compiles and contains classes" - - it_behaves_like "with default parameters", :osfamily => 'Solaris' - - it_behaves_like "with swapfile and size parameters", :osfamily => 'Solaris' - end - end - - context 'windows operating system' do - describe 'swap_file class without any parameters on Windows' do - let(:facts) {{ - :osfamily => 'windows', - :operatingsystem => 'windows', - }} - - it { expect { should contain_class('swap_file') }.to raise_error(/Swap files dont work on windows/) } - end - end - - context 'FreeBSD operating system' do - describe 'swap_file class without any parameters on FreeBSD' do - let(:facts) {{ - :osfamily => 'FreeBSD', - :operatingsystem => 'FreeBSD', - }} - - it { expect { should contain_class('swap_file') }.to raise_error(/FreeBSD is not yet supported/) } - end - end - -end diff --git a/spec/defines/files_spec.rb b/spec/defines/files_spec.rb new file mode 100644 index 0000000..e511f50 --- /dev/null +++ b/spec/defines/files_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe 'swap_file::files' do + let(:title) { 'default' } + + let(:facts) do + { + :operatingsystem => 'RedHat', + :osfamily => 'RedHat', + :operatingsystemrelease => '7', + :concat_basedir => '/tmp', + :memorysize => '1.00 GB' + } + 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) + + context 'default parameters' do + it do + is_expected.to compile.with_all_deps + end + it do + is_expected.to contain_exec('Create swap file /mnt/swap.1'). + with({"command"=>"/bin/dd if=/dev/zero of=/mnt/swap.1 bs=1M count=1073", + "creates"=>"/mnt/swap.1"}) + end + it do + is_expected.to contain_file('/mnt/swap.1'). + with({"owner"=>"root", + "group"=>"root", + "mode"=>"0600", + "require"=>"Exec[Create swap file /mnt/swap.1]"}) + end + it do + is_expected.to contain_exec('Attach swap file /mnt/swap.1'). + with({"command"=>"/sbin/mkswap /mnt/swap.1 && /sbin/swapon /mnt/swap.1", + "require"=>"File[/mnt/swap.1]", + "unless"=>"/sbin/swapon -s | grep /mnt/swap.1"}) + end + it do + is_expected.to contain_mount('/mnt/swap.1'). + with({"require"=>"Exec[Attach swap file /mnt/swap.1]"}) + end + end + + context 'custom swapfilesize parameter' do + let(:params) do + { + #:ensure => "present", + #:swapfile => "/mnt/swap.1", + :swapfilesize => '4.1 GB', + #:add_mount => true, + #:options => "defaults", + } + end + it do + is_expected.to compile.with_all_deps + end + it do + is_expected.to contain_exec('Create swap file /mnt/swap.1'). + with({"command"=>"/bin/dd if=/dev/zero of=/mnt/swap.1 bs=1M count=4402", + "creates"=>"/mnt/swap.1"}) + end + end + +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index c13a5e0..98eee10 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -25,7 +25,6 @@ # Install module and dependencies puppet_module_install(:source => proj_root, :module_name => 'swap_file') hosts.each do |host| - shell('/bin/touch /etc/puppet/hiera.yaml') shell('puppet module install puppetlabs-stdlib --version 3.2.0', { :acceptable_exit_codes => [0,1] }) end end