From 2c1483059e460ce79206eab0b31b45e8f81ffd0c Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 09:44:19 +0100 Subject: [PATCH 1/9] fix for travis ci --- Gemfile | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 189b7c5..df38e07 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,41 @@ -source 'https://rubygems.org' - -puppetversion = ENV.key?('PUPPET_GEM_VERSION') ? "#{ENV['PUPPET_GEM_VERSION']}" : ['>= 3.3'] -facterversion = ENV.key?('FACTER_GEM_VERSION') ? "#{ENV['FACTER_GEM_VERSION']}" : ['>= 1.7'] -gem 'puppet', puppetversion -gem 'puppetlabs_spec_helper', '>= 0.1.0' -gem 'puppet-lint', '>= 0.3.2' -gem 'facter', facterversion -gem 'rspec', '< 3.2.0' +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +def location_for(place, version = nil) + if place =~ /^((?:git|https?)[:@][^#]*)#(.*)/ + [version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, version, { :require => false }].compact + end +end + +gem 'puppetlabs_spec_helper', '>= 0.1.0', :require => false +gem 'puppet-lint', '>= 0.3.2', :require => false +gem 'rspec-puppet', '>= 2.3.2', :require => false +gem 'rspec-puppet-facts', :require => false +gem 'metadata-json-lint', :require => false +# rubi <1.9 versus rake 11.0.0 workaround +gem 'rake', '< 11.0.0', :require => false if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') +gem 'json', '< 2.0.0', :require => false if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') +gem 'json_pure', '<= 2.0.1', :require => false if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') + +gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION']) + +# Only explicitly specify Facter/Hiera if a version has been specified. +# Otherwise it can lead to strange bundler behavior. If you are seeing weird +# gem resolution behavior, try setting `DEBUG_RESOLVER` environment variable +# to `1` and then run bundle install. +gem 'facter', *location_for(ENV['FACTER_GEM_VERSION']) if ENV['FACTER_GEM_VERSION'] +gem 'hiera', *location_for(ENV['HIERA_GEM_VERSION']) if ENV['HIERA_GEM_VERSION'] + + +# Evaluate Gemfile.local if it exists +if File.exists? "#{__FILE__}.local" + eval(File.read("#{__FILE__}.local"), binding) +end + +# Evaluate ~/.gemfile if it exists +if File.exists?(File.join(Dir.home, '.gemfile')) + eval(File.read(File.join(Dir.home, '.gemfile')), binding) +end From 4ad086a6510185f944224c039a40b021a0d2bcc2 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 09:45:44 +0100 Subject: [PATCH 2/9] fix for travis ci --- Rakefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 505cb2d..5be86c4 100644 --- a/Rakefile +++ b/Rakefile @@ -9,13 +9,11 @@ PuppetLint.configuration.send('disable_class_inherits_from_params_class') PuppetLint.configuration.send('disable_class_parameter_defaults') PuppetLint.configuration.send('disable_documentation') PuppetLint.configuration.send('disable_single_quote_string_with_variables') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "vendor/**/*.pp"] desc "Validate manifests, templates, and ruby files in lib." task :validate do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet parser validate --noop #{manifest}" - end + sh "puppet parser validate --noop #{Dir['manifests/**/*.pp'].join(" ")}" Dir['lib/**/*.rb'].each do |lib_file| sh "ruby -c #{lib_file}" end From 30a103e8b17a5125f10c265da15291dd28f6cbe9 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 09:48:09 +0100 Subject: [PATCH 3/9] remove checks for ruby 1.8 --- .travis.yml | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 87d702c..36a381a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,22 @@ --- sudo: false language: ruby +cache: bundler bundler_args: --without system_tests -script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" +before_install: rm Gemfile.lock || true +script: bundle exec rake validate lint spec matrix: fast_finish: true include: - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.4.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.6.0" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION='~> 4.0' COVERAGE=yes STRICT_VARIABLES=yes + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#stable + - rvm: 2.1.5 + env: PUPPET_GEM_VERSION='~> 3.0' FUTURE_PARSER=yes + - rvm: 2.1.5 + env: PUPPET_GEM_VERSION='~> 3.0' + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION='~> 3.0' notifications: email: false From e30e6babcf00632d7ca93b6d380d9557261abf1b Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 09:50:20 +0100 Subject: [PATCH 4/9] allow variables with uppercase --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 5be86c4..211feeb 100644 --- a/Rakefile +++ b/Rakefile @@ -9,6 +9,7 @@ PuppetLint.configuration.send('disable_class_inherits_from_params_class') PuppetLint.configuration.send('disable_class_parameter_defaults') PuppetLint.configuration.send('disable_documentation') PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.send('disable_variable_is_lowercase') PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "vendor/**/*.pp"] desc "Validate manifests, templates, and ruby files in lib." From 6ef32194f9ffa8ed7a6a6728c3810d3e96df3a06 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 09:52:07 +0100 Subject: [PATCH 5/9] fix alignment --- manifests/repos/yum.pp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/manifests/repos/yum.pp b/manifests/repos/yum.pp index d5e9100..3d43b45 100644 --- a/manifests/repos/yum.pp +++ b/manifests/repos/yum.pp @@ -8,11 +8,10 @@ # class mongodb::repos::yum { - yumrepo { 'mongodb_yum_repo': - descr => '10gen MongoDB Repo', - baseurl => 'http://downloads-distro.mongodb.org/repo/redhat/os/$basearch', - enabled => 1, - gpgcheck => 0; - } - + yumrepo { 'mongodb_yum_repo': + enabled => 1, + descr => '10gen MongoDB Repo', + baseurl => 'http://downloads-distro.mongodb.org/repo/redhat/os/$basearch', + gpgcheck => 0; + } } From 479a06632df89d422e743dfb8d4eb59e6218a5cf Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 10:20:32 +0100 Subject: [PATCH 6/9] prepare spec file to be more generic --- spec/classes/mongodb_spec.rb | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/spec/classes/mongodb_spec.rb b/spec/classes/mongodb_spec.rb index d3cae76..a4454ce 100644 --- a/spec/classes/mongodb_spec.rb +++ b/spec/classes/mongodb_spec.rb @@ -1,20 +1,29 @@ require 'spec_helper' -describe 'mongodb' do +describe 'mongodb', :type => 'class' do context 'Unsupported OS' do - let(:facts) {{ :osfamily => 'unsupported' }} - it { expect { should contain_class('mongodb')}.to raise_error(Puppet::Error, /Unsupported OS/ )} + let(:facts) {{ :osfamily => 'unsupported', :operatingsystem => 'UnknownOS' }} + it { is_expected.to raise_error(Puppet::Error,/Unsupported OS/ )} end - context 'with defaults for all parameters on RedHat' do - let(:facts) {{ :osfamily => 'RedHat' }} - it { should contain_class('mongodb') } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + let :pre_condition do + 'include ::mongodb' + end - context 'with defaults for all parameters on Debian' do - let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'ubuntu' }} - it { should contain_class('mongodb') } + case facts[:osfamily] + when 'Debian' then + it { should contain_class('mongodb') } + when 'RedHat' then + it { should contain_class('mongodb') } + else + it { is_expected.to raise_error(Puppet::Error,/Unsupported OS/ )} + end + end end - end From 793705bf7067dc91d37914cdf3c955d45663d996 Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 10:25:05 +0100 Subject: [PATCH 7/9] Update spec_helper.rb --- spec/spec_helper.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3d92005..95c3db2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,11 @@ -require 'puppetlabs_spec_helper/module_spec_helper' \ No newline at end of file +if ENV['COVERAGE'] == 'yes' + RSpec.configure do |c| + c.after(:suite) do + RSpec::Puppet::Coverage.report! + end + end +end + +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts From c1c4209cbd9895bb9234eca73326fcc8d75cc13e Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 11:05:19 +0100 Subject: [PATCH 8/9] fix mongodb-package install for redhat --- manifests/install.pp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index 6e9fd45..afffbc4 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -37,11 +37,27 @@ before => Anchor['mongodb::install::end'] } - package { 'mongodb-package': + + case $::osfamily { + 'Debian': { + package { 'mongodb-package': ensure => $package_ensure, name => $::mongodb::repos::apt::package_name, require => $mongodb_10gen_package_require, before => [Anchor['mongodb::install::end']] + } + } + 'RedHat': { + package { 'mongodb-package': + ensure => $package_ensure, + name => $::mongodb::package_name, + require => $mongodb_10gen_package_require, + before => [Anchor['mongodb::install::end']] + } + } + default: { + fail("Unsupported OS ${::osfamily}") } + } } From 7500e8c28e9ce32878c3da96c3bbdf67a007b1ba Mon Sep 17 00:00:00 2001 From: Daniel Werdermann Date: Tue, 15 Nov 2016 11:15:49 +0100 Subject: [PATCH 9/9] include mongodb::params for spec test --- spec/defines/mongod_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/defines/mongod_spec.rb b/spec/defines/mongod_spec.rb index 44689f5..9809e2b 100644 --- a/spec/defines/mongod_spec.rb +++ b/spec/defines/mongod_spec.rb @@ -6,6 +6,9 @@ context 'with defaults for all parameters on RedHat' do let(:facts) {{ :osfamily => 'RedHat' }} + let :pre_condition do + 'include ::mongodb::params' + end it { should contain_mongodb__mongod('testdb') } context 'with deactivate_transparent_hugepage set' do let(:params) {{ :mongod_deactivate_transparent_hugepage => true }}