diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 000000000..692ca0b1f --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,6 @@ +fixtures: + repositories: + stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git + concat: git://github.com/puppetlabs/puppetlabs-concat.git + symlinks: + autofs: "#{source_dir}" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 154579485..43fc6ac5b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ ./*/.DS_Store ./pkg/* .idea/ -.idea/* .exvim.autofs/ -.exvim.autofs/* autofs.exvim +Gemfile.lock +spec/fixtures/manifests/ +spec/fixtures/modules/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..0ac21fb17 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +--- +sudo: false +language: ruby +bundler_args: --without system_tests +script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec" +matrix: + fast_finish: true + include: + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 2.1.5 + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" +notifications: + email: false \ No newline at end of file diff --git a/Gemfile b/Gemfile index c30ca69bc..7bd34cda7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' -gem 'puppet', '>= 3.3' +puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3'] +gem 'puppet', puppetversion gem 'puppetlabs_spec_helper', '>= 0.1.0' gem 'puppet-lint', '>= 0.3.2' gem 'facter', '>= 1.7.0' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 15cef0b46..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,51 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - CFPropertyList (2.2.8) - diff-lcs (1.2.5) - facter (2.3.0) - CFPropertyList (~> 2.2.6) - hiera (1.3.4) - json_pure - json_pure (1.8.2) - metaclass (0.0.4) - mocha (1.1.0) - metaclass (~> 0.0.1) - puppet (3.7.3) - facter (> 1.6, < 3) - hiera (~> 1.0) - json_pure - puppet-lint (1.1.0) - puppet-syntax (1.4.1) - rake - puppetlabs_spec_helper (0.8.2) - mocha - puppet-lint - puppet-syntax - rake - rspec - rspec-puppet - rake (10.4.2) - rspec (3.1.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) - rspec-core (3.1.7) - rspec-support (~> 3.1.0) - rspec-expectations (3.1.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-mocks (3.1.3) - rspec-support (~> 3.1.0) - rspec-puppet (1.0.1) - rspec - rspec-support (3.1.2) - -PLATFORMS - ruby - -DEPENDENCIES - facter (>= 1.7.0) - puppet (>= 3.3) - puppet-lint (>= 0.3.2) - puppetlabs_spec_helper (>= 0.1.0) diff --git a/Readme.md b/Readme.md index 2ee5a4dbb..478601467 100644 --- a/Readme.md +++ b/Readme.md @@ -45,17 +45,21 @@ generate the mapfiles and mount points from the entries in your YAML file. ###Example: ```yaml +--- mapOptions: home: mount: '/home' mapfile: '/etc/auto.home' - mapcontents: '* -user,rw,soft,intr,rsize=32768,wsize=32768,tcp,nfsvers=3,noacl server.example.com:/path/to/home/shares' + mapcontents: + - '* -user,rw,soft,intr,rsize=32768,wsize=32768,tcp,nfsvers=3,noacl server.example.com:/path/to/home/shares' options: '--timeout=120' order: 01 tmp: mount: '/tmp' mapfile: '/etc/auto.tmp' - mapcontent: 'tempfiles -rw,noacl server.example.com:/path/to/tmp/mount' + mapcontent: + - 'tempfiles -rw,noacl server.example.com:/path/to/tmp/mount' + - 'temparchive -rw,noacl server.example.com:/path/to/tmp/archive' options: '--timeout=60' order: 02 ``` diff --git a/manifests/config.pp b/manifests/config.pp index f183257e8..7c13bb8e0 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -9,6 +9,13 @@ class autofs::config { $map_options = hiera('mapOptions') + concat { '/etc/auto.master': + owner => 'root', + group => 'root', + mode => '0644', + notify => Service[ 'autofs' ], + } + create_resources( 'autofs::mount', $map_options) } diff --git a/manifests/init.pp b/manifests/init.pp index 85b61173c..f8816ac8d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -16,9 +16,7 @@ # Copyright 2014 David Hollinger III # class autofs { - anchor { 'autofs::begin': } - class { 'autofs::install': } -> - class { 'autofs::config': } ~> - class { 'autofs::service': } - anchor { 'autofs::end': } + include autofs::package + include autofs::config + include autofs::service } diff --git a/manifests/mount.pp b/manifests/mount.pp index e0fb46456..ecd2f98ee 100644 --- a/manifests/mount.pp +++ b/manifests/mount.pp @@ -8,22 +8,16 @@ $order, ) { - concat { '/etc/auto.master': - owner => 'root', - group => 'root', - mode => '0644', - notify => Service[ 'autofs' ], - } - - concat::fragment { 'autofs::fragment preamble /etc/auto.master': + concat::fragment { "autofs::fragment preamble ${mount}": ensure => present, target => '/etc/auto.master', - content => "${mount} ${mapfile} ${options}", + content => "${mount} ${mapfile} ${options}\n", order => $order, } file { $mount: - ensure => directory, + ensure => directory, + require => Package[ 'autofs' ], } file { $mapfile: diff --git a/manifests/install.pp b/manifests/package.pp similarity index 93% rename from manifests/install.pp rename to manifests/package.pp index dfe887c3b..ba8297acc 100644 --- a/manifests/install.pp +++ b/manifests/package.pp @@ -2,7 +2,7 @@ # # This class ensures that autofs is installed. # -class autofs::install { +class autofs::package { Package { ensure => installed } diff --git a/metadata.json b/metadata.json index 6287f795c..9220315c4 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "EagleDelta2-autofs", - "version": "1.1.1", + "version": "1.1.2", "author": "David Hollinger", "summary": "Module for installing and managing autofs", "license": "Apache-2.0", diff --git a/spec/classes/autofs_spec.rb b/spec/classes/autofs_spec.rb new file mode 100644 index 000000000..8c2aac560 --- /dev/null +++ b/spec/classes/autofs_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' +describe 'autofs', :type => :class do + + context 'main init tests' do + let(:facts) do + { + :osfamily => 'RedHat', + :concat_basedir => '/etc' + } + end + it { should contain_class('autofs::package') } + it { should contain_class('autofs::config') } + it { should contain_class('autofs::service') } + end + +end diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 981a16b5b..53fb2c714 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,4 +1,8 @@ require 'spec_helper' -describe 'autofs::config' do +describe 'autofs::config', :type => :class do + hiera = Hiera.new(:config => 'spec/fixtures/hiera/hiera.yaml') + mapoptions = hiera.lookup('mapOptions', nil, nil) + let(:params) {{ :map_options => mapoptions}} -end + +end \ No newline at end of file diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb deleted file mode 100644 index 5cee36d9d..000000000 --- a/spec/classes/init_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' -describe 'autofs' do - - context 'with defaults for all parameters' do - it { should contain_class('autofs') } - it { should contain_class('autofs::install'.that_comes_before('Class[autofs::config]'))} - it { should contain_class('autofs::config'.that_comes_before('Class[autofs::sevice]'))} - it { should compile.with_all_deps } - end - -end diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb new file mode 100644 index 000000000..60ec9947d --- /dev/null +++ b/spec/classes/package_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' +describe 'autofs::package', :type => :class do + opsys = %w( + Debian + Ubuntu + RedHat + CentOS + ) + + opsys.each do |os| + context "install autofs #{os}" do + let(:facts){ {:osfamily => "#{os}"} } + + it { should contain_package('autofs').with_ensure('installed') } + + end + end + +end \ No newline at end of file diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb new file mode 100644 index 000000000..c5e0325c6 --- /dev/null +++ b/spec/classes/service_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' +describe 'autofs::service', :type => :class do + + context 'test default service' do + it { should contain_service('autofs').with( + 'ensure' => 'running', + 'enable' => 'true', + 'hasstatus' => 'true', + 'hasrestart' => 'true', + ) + } + end + +end \ No newline at end of file diff --git a/spec/defines/mount_spec.rb b/spec/defines/mount_spec.rb new file mode 100644 index 000000000..08e471928 --- /dev/null +++ b/spec/defines/mount_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' +describe 'autofs::mount', :type => :define do + let(:title) { 'auto.home' } + + let(:facts) do + { + :concat_basedir => '/etc' + } + end + + let(:params) do + { + :mount => '/home', + :mapfile => '/etc/auto.home', + :mapcontents => %W( test foo bar ), + :options => '--timeout=120', + :order => '01' + } + end + + context 'with default parameters' do + + it do + should contain_concat__fragment('autofs::fragment preamble /home').with('target' => '/etc/auto.master') + end + + it do + should contain_file('/home').with('ensure' => 'directory') + end + + it do + should contain_file('/etc/auto.home').with( + 'ensure' => 'present', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644' + ) + end + end + + +end \ No newline at end of file diff --git a/spec/fixtures/hiera/hiera.yaml b/spec/fixtures/hiera/hiera.yaml new file mode 100644 index 000000000..ecc943713 --- /dev/null +++ b/spec/fixtures/hiera/hiera.yaml @@ -0,0 +1,7 @@ +--- +:backends: + - yaml +:hierarchy: + - test +:yaml: + :datadir: 'spec/fixtures/hiera' \ No newline at end of file diff --git a/spec/fixtures/hiera/test.yaml b/spec/fixtures/hiera/test.yaml new file mode 100644 index 000000000..034706fa0 --- /dev/null +++ b/spec/fixtures/hiera/test.yaml @@ -0,0 +1,11 @@ +--- +mapOptions: + home: + mount: '/home' + mapfile: '/etc/auto.home' + mapcontents: + - 'test' + - 'foo' + - 'bar' + options: '--timeout=120' + order: 01 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f56649..50b9fbae0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,43 @@ +require 'rspec-puppet' require 'puppetlabs_spec_helper/module_spec_helper' +require 'mocha' +require 'hiera' +require 'erb' +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) +# include common helpers +support_path = File.expand_path(File.join(File.dirname(__FILE__), '..', + 'spec/support/*.rb')) +Dir[support_path].each {|f| require f} +RSpec.configure do |c| + c.config = '/doesnotexist' + c.manifest_dir = File.join(fixture_path, 'manifests') + c.mock_with :rspec do |mock| + mock.syntax = [:expect, :should] + end + c.hiera_config = File.join(fixture_path, 'hiera/hiera.yaml') + c.include PuppetlabsSpec::Files + + if ENV['PARSER'] == 'future' + c.parser = 'future' + end + + c.before :each do + # Ensure that we don't accidentally cache facts and environment + # between test cases. + Facter::Util::Loader.any_instance.stubs(:load_all) + Facter.clear + Facter.clear_messages + + # Store any environment variables away to be restored later + @old_env = {} + ENV.each_key {|k| @old_env[k] = ENV[k]} + + if Gem::Version.new(`puppet --version`) >= Gem::Version.new('3.5') + Puppet.settings[:strict_variables]=true + end + end + + c.after :each do + PuppetlabsSpec::Files.cleanup + end +end diff --git a/templates/auto.map.erb b/templates/auto.map.erb index 56543e702..211534b07 100644 --- a/templates/auto.map.erb +++ b/templates/auto.map.erb @@ -5,6 +5,6 @@ # # ############################################################### -<% @map_options.each do |map| -%> -<%= @mapcontents %> -<% end -%> +<% @mapcontents.each do |content| -%> +<%= content %> +<% end -%> \ No newline at end of file