diff --git a/.rubocop.yml b/.rubocop.yml index daa9538..c74c8f9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,486 +1,462 @@ AllCops: Exclude: # Ignore HTML related things - '**/*.erb' # Ignore vendored gems - 'vendor/**/*' # Ignore code from test fixtures - 'spec/fixtures/**/*' Lint/ConditionPosition: Enabled: true Lint/ElseLayout: Enabled: true Lint/UnreachableCode: Enabled: true Lint/UselessComparison: Enabled: true Lint/EnsureReturn: Enabled: true Lint/HandleExceptions: Enabled: true -Lint/LiteralInCondition: - Enabled: true - Lint/ShadowingOuterLocalVariable: Enabled: true Lint/LiteralInInterpolation: Enabled: true Style/RedundantReturn: Enabled: true Lint/AmbiguousOperator: Enabled: true Lint/AssignmentInCondition: Enabled: true -Style/SpaceBeforeComment: +Layout/SpaceBeforeComment: Enabled: true # DISABLED - not useful Style/HashSyntax: Enabled: false # USES: as shortcut for non nil&valid checking a = x() and a.empty? # DISABLED - not useful Style/AndOr: Enabled: false # DISABLED - not useful Style/RedundantSelf: Enabled: false # DISABLED - not useful Metrics/MethodLength: Enabled: false +Metrics/BlockLength: + Enabled: false + # DISABLED - not useful Style/WhileUntilModifier: Enabled: false # DISABLED - the offender is just haskell envy Lint/AmbiguousRegexpLiteral: Enabled: false # DISABLED -Lint/Eval: +Security/Eval: Enabled: false # DISABLED Lint/BlockAlignment: Enabled: false # DISABLED Lint/DefEndAlignment: Enabled: false # DISABLED Lint/EndAlignment: Enabled: false # DISABLED Lint/DeprecatedClassMethods: Enabled: false # DISABLED Lint/Loop: Enabled: false # DISABLED Lint/ParenthesesAsGroupedExpression: Enabled: false Lint/RescueException: Enabled: false Lint/StringConversionInInterpolation: Enabled: false Lint/UnusedBlockArgument: Enabled: false Lint/UnusedMethodArgument: Enabled: false Lint/UselessAccessModifier: Enabled: true Lint/UselessAssignment: Enabled: true Lint/Void: Enabled: true -Style/AccessModifierIndentation: +Layout/AccessModifierIndentation: Enabled: false -Style/AccessorMethodName: +Naming/AccessorMethodName: Enabled: false Style/Alias: Enabled: false -Style/AlignArray: +Layout/AlignArray: Enabled: false -Style/AlignHash: +Layout/AlignHash: Enabled: false -Style/AlignParameters: +Layout/AlignParameters: Enabled: false Metrics/BlockNesting: Enabled: false Style/AsciiComments: Enabled: false Style/Attr: Enabled: false Style/BracesAroundHashParameters: Enabled: false Style/CaseEquality: Enabled: false -Style/CaseIndentation: +Layout/CaseIndentation: Enabled: false Style/CharacterLiteral: Enabled: false -Style/ClassAndModuleCamelCase: - Enabled: false - Style/ClassAndModuleChildren: Enabled: false Style/ClassCheck: Enabled: false Metrics/ClassLength: Enabled: false Style/ClassMethods: Enabled: false Style/ClassVars: Enabled: false Style/WhenThen: Enabled: false # DISABLED - not useful Style/WordArray: Enabled: false Style/UnneededPercentQ: Enabled: false -Style/Tab: - Enabled: false - -Style/SpaceBeforeSemicolon: - Enabled: false - -Style/TrailingBlankLines: - Enabled: false - -Style/SpaceInsideBlockBraces: +Layout/Tab: Enabled: false -Style/SpaceInsideBrackets: +Layout/SpaceInsideBlockBraces: Enabled: false -Style/SpaceInsideHashLiteralBraces: +Layout/SpaceInsideBrackets: Enabled: false -Style/SpaceInsideParens: +Layout/SpaceInsideHashLiteralBraces: Enabled: false -Style/LeadingCommentSpace: +Layout/SpaceInsideParens: Enabled: false -Style/SingleSpaceBeforeFirstArg: +Layout/LeadingCommentSpace: Enabled: false -Style/SpaceAfterColon: +Layout/SpaceBeforeFirstArg: Enabled: false -Style/SpaceAfterComma: +Layout/SpaceAroundKeyword: Enabled: false -Style/SpaceAfterControlKeyword: +Layout/SpaceAfterMethodName: Enabled: false -Style/SpaceAfterMethodName: +Layout/SpaceAfterSemicolon: Enabled: false -Style/SpaceAfterNot: +Layout/SpaceAroundOperators: Enabled: false -Style/SpaceAfterSemicolon: +Layout/SpaceBeforeBlockBraces: Enabled: false -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - -Style/SpaceAroundOperators: - Enabled: false - -Style/SpaceBeforeBlockBraces: - Enabled: false - -Style/SpaceBeforeComma: +Layout/SpaceBeforeComma: Enabled: false Style/CollectionMethods: Enabled: false -Style/CommentIndentation: +Layout/CommentIndentation: Enabled: false Style/ColonMethodCall: Enabled: false Style/CommentAnnotation: Enabled: false Metrics/CyclomaticComplexity: Enabled: false -Style/ConstantName: +Naming/ConstantName: Enabled: false Style/Documentation: Enabled: false Style/DefWithParentheses: Enabled: false -Style/DeprecatedHashMethods: +Style/PreferredHashMethods: Enabled: false -Style/DotPosition: +Layout/DotPosition: Enabled: false # DISABLED - used for converting to bool Style/DoubleNegation: Enabled: false Style/EachWithObject: Enabled: false -Style/EmptyLineBetweenDefs: +Layout/EmptyLineBetweenDefs: Enabled: false -Style/IndentArray: +Layout/IndentArray: Enabled: false -Style/IndentHash: +Layout/IndentHash: Enabled: false -Style/IndentationConsistency: +Layout/IndentationConsistency: Enabled: false -Style/IndentationWidth: +Layout/IndentationWidth: Enabled: false -Style/EmptyLines: +Layout/EmptyLines: Enabled: false -Style/EmptyLinesAroundAccessModifier: +Layout/EmptyLinesAroundAccessModifier: Enabled: false -Style/EmptyLinesAroundBlockBody: +Layout/EmptyLinesAroundBlockBody: Enabled: false Style/EmptyLiteral: Enabled: false Metrics/LineLength: Enabled: false -Style/MethodCallParentheses: +Style/MethodCallWithoutArgsParentheses: Enabled: false Style/MethodDefParentheses: Enabled: false Style/LineEndConcatenation: Enabled: false -Style/TrailingWhitespace: +Layout/TrailingWhitespace: Enabled: false Style/StringLiterals: Enabled: false -Style/TrailingComma: +Style/TrailingCommaInLiteral: Enabled: false Style/GlobalVars: Enabled: false Style/GuardClause: Enabled: false Style/IfUnlessModifier: Enabled: false Style/MultilineIfThen: Enabled: false -Style/MultilineOperationIndentation: +Layout/MultilineMethodCallIndentation: Enabled: false Style/NegatedIf: Enabled: false Style/NegatedWhile: Enabled: false Style/Next: Enabled: false Style/SingleLineBlockParams: Enabled: false Style/SingleLineMethods: Enabled: false Style/SpecialGlobalVars: Enabled: false Style/TrivialAccessors: Enabled: false Style/UnlessElse: Enabled: false Style/VariableInterpolation: Enabled: false -Style/VariableName: +Naming/VariableName: Enabled: false Style/WhileUntilDo: Enabled: false Style/EvenOdd: Enabled: false -Style/FileName: +Naming/FileName: Enabled: false Style/For: Enabled: false Style/Lambda: Enabled: false -Style/MethodName: +Naming/MethodName: Enabled: false Style/MultilineTernaryOperator: Enabled: false -Style/NestedTernaryOperator: - Enabled: false - Style/NilComparison: Enabled: false Style/FormatString: Enabled: false Style/MultilineBlockChain: Enabled: false +Layout/MultilineHashBraceLayout: + Enabled: false + Style/Semicolon: Enabled: false Style/SignalException: Enabled: false Style/NonNilCheck: Enabled: false Style/Not: Enabled: false Style/NumericLiterals: Enabled: false Style/OneLineConditional: Enabled: false -Style/OpMethod: - Enabled: false - Style/ParenthesesAroundCondition: Enabled: false Style/PercentLiteralDelimiters: Enabled: false Style/PerlBackrefs: Enabled: false -Style/PredicateName: +Naming/PredicateName: Enabled: false Style/RedundantException: Enabled: false Style/SelfAssignment: Enabled: false Style/Proc: Enabled: false Style/RaiseArgs: Enabled: false Style/RedundantBegin: Enabled: false Style/RescueModifier: Enabled: false Style/RegexpLiteral: Enabled: false Lint/UnderscorePrefixedVariableName: Enabled: false Metrics/ParameterLists: Enabled: false Lint/RequireParentheses: Enabled: false -Lint/SpaceBeforeFirstArg: +Layout/SpaceBeforeFirstArg: Enabled: false Style/ModuleFunction: Enabled: false Lint/Debugger: Enabled: false Style/IfWithSemicolon: Enabled: false Style/Encoding: Enabled: false diff --git a/Gemfile b/Gemfile index ca3fd4e..2c238e1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,33 +1,32 @@ source "https://rubygems.org" group :test do - gem "rake" - gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 3.8.0' - gem "rspec", '< 3.2.0' - gem "rspec-puppet" - gem "puppetlabs_spec_helper" gem "metadata-json-lint" - gem "rspec-puppet-facts" - gem 'rubocop', '0.33.0' - gem 'simplecov', '>= 0.11.0' - gem 'simplecov-console' - + gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 3.8.0' gem "puppet-lint-absolute_classname-check" + gem "puppet-lint-classes_and_types_beginning_with_digits-check" gem "puppet-lint-leading_zero-check" gem "puppet-lint-trailing_comma-check" - gem "puppet-lint-version_comparison-check" - gem "puppet-lint-classes_and_types_beginning_with_digits-check" gem "puppet-lint-unquoted_string-check" + gem "puppet-lint-version_comparison-check" + gem "puppetlabs_spec_helper" + gem "rake" + gem "rspec", '~> 3.0' # works with '~> 3.6.0' + gem "rspec-puppet" + gem "rspec-puppet-facts" + gem 'rubocop' # works with '0.51.0' + gem 'simplecov', '>= 0.11.0' + gem 'simplecov-console' end group :development do + gem "guard-rake" gem "travis" gem "travis-lint" - gem "guard-rake" end group :system_tests do gem "beaker" - gem "beaker-rspec" gem "beaker-puppet_install_helper" + gem "beaker-rspec" end diff --git a/Rakefile b/Rakefile index 8ac719e..fcfda3a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,62 +1,62 @@ require 'rubygems' require 'bundler/setup' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet/version' require 'puppet/vendor/semantic/lib/semantic' unless Puppet.version.to_f < 3.6 require 'puppet-lint/tasks/puppet-lint' require 'puppet-syntax/tasks/puppet-syntax' require 'metadata-json-lint/rake_task' require 'rubocop/rake_task' # These gems aren't always present, for instance # on Travis with --without development begin rescue LoadError # rubocop:disable Lint/HandleExceptions end RuboCop::RakeTask.new exclude_paths = [ "bundle/**/*", "pkg/**/*", "vendor/**/*", "spec/**/*", ] # Coverage from puppetlabs-spec-helper requires rcov which # doesn't work in anything since 1.8.7 Rake::Task[:coverage].clear Rake::Task[:lint].clear PuppetLint.configuration.relative = true PuppetLint.configuration.disable_80chars PuppetLint.configuration.disable_class_inherits_from_params_class PuppetLint.configuration.disable_class_parameter_defaults PuppetLint.configuration.fail_on_warnings = true PuppetLint::RakeTask.new :lint do |config| config.ignore_paths = exclude_paths end PuppetSyntax.exclude_paths = exclude_paths desc "Run acceptance tests" RSpec::Core::RakeTask.new(:acceptance) do |t| t.pattern = 'spec/acceptance' end desc "Populate CONTRIBUTORS file" task :contributors do system("git log --format='%aN' | sort -u > CONTRIBUTORS") end desc "Run syntax, lint, and spec tests." -task :test => [ - :metadata_lint, - :syntax, - :lint, - :rubocop, - :spec, +task :test => %i[ + metadata_lint + syntax + lint + rubocop + spec ] diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 7cd8cdf..dfa9a7b 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,30 +1,30 @@ require 'spec_helper_acceptance' describe 'munin and munin-node' do context 'default parameters' do # Using puppet_apply as a helper it 'should work idempotently with no errors' do - pp = <<-EOS + pp = <<-PUPPET_CODE class { 'munin::master': } class { 'munin::node': } - EOS + PUPPET_CODE # Run it twice and test for idempotency apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe package('munin') do it { is_expected.to be_installed } end describe package('munin-node') do it { is_expected.to be_installed } end describe service('munin-node') do it { is_expected.to be_enabled } it { is_expected.to be_running } end end end diff --git a/spec/acceptance/munin__master_spec.rb b/spec/acceptance/munin__master_spec.rb index 4e045f7..4cbb8f6 100644 --- a/spec/acceptance/munin__master_spec.rb +++ b/spec/acceptance/munin__master_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper_acceptance' describe 'munin::master class' do context 'default parameters' do # Using puppet_apply as a helper it 'should work idempotently with no errors' do - pp = <<-EOS + pp = <<-PUPPET_CODE class { 'munin::master': } - EOS + PUPPET_CODE # Run it twice and test for idempotency apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe package('munin') do it { is_expected.to be_installed } end end end diff --git a/spec/acceptance/munin__node_spec.rb b/spec/acceptance/munin__node_spec.rb index a338a40..e38a0b2 100644 --- a/spec/acceptance/munin__node_spec.rb +++ b/spec/acceptance/munin__node_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper_acceptance' describe 'munin::node class' do context 'default parameters' do # Using puppet_apply as a helper it 'should work idempotently with no errors' do - pp = <<-EOS + pp = <<-PUPPET_CODE class { 'munin::node': } - EOS + PUPPET_CODE # Run it twice and test for idempotency apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe package('munin-node') do it { is_expected.to be_installed } end describe service('munin-node') do it { is_expected.to be_enabled } it { is_expected.to be_running } end end end diff --git a/spec/classes/munin_master_spec.rb b/spec/classes/munin_master_spec.rb index d8c35e8..0643d1e 100644 --- a/spec/classes/munin_master_spec.rb +++ b/spec/classes/munin_master_spec.rb @@ -1,184 +1,184 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' describe 'munin::master' do on_supported_os.each do |os, facts| # Avoid testing on distributions similar to RedHat and Debian - next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + next if os =~ /^(ubuntu|centos|scientific|oraclelinux)-/ # No need to test all os versions as long as os version is not # used in the params class - next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + next if os =~ /^(debian-[67]|redhat-[56]|freebsd-9)-/ context "on #{os}" do let(:facts) do facts end conf_dir = _conf_dir[facts[:osfamily]] it { should compile.with_all_deps } it { should contain_package('munin') } context 'with default params' do it do should contain_file("#{conf_dir}/munin.conf") .with_content(/graph_strategy\s+cgi/) .with_content(/html_strategy\s+cgi/) end it do should contain_file("#{conf_dir}/munin-conf.d") .with_ensure('directory') end end context 'with html_strategy => cron' do let (:params) { { :html_strategy => 'cron' } } it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/html_strategy\s+cron/) end end context 'with graph_strategy => cron' do let (:params) { { :graph_strategy => 'cron' } } it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/graph_strategy\s+cron/) end end context 'with dbdir => /var/lib/munin' do let (:params) { { :dbdir => '/var/lib/munin' } } it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/dbdir\s+\/var\/lib\/munin/) end end context 'with htmldir => /var/www/munin' do let (:params) { { :htmldir => '/var/www/munin' } } it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/htmldir\s+\/var\/www\/munin/) end end context 'with logdir => /var/log/munin' do let (:params) { { :dbdir => '/var/log/munin' } } it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/dbdir\s+\/var\/log\/munin/) end end context 'with rundir => /var/run/munin' do let (:params) { { :dbdir => '/var/run/munin' } } it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/dbdir\s+\/var\/run\/munin/) end end context 'with tls => enabled' do let(:params) do { :tls => 'enabled', :tls_certificate => '/path/to/certificate.pem', :tls_private_key => '/path/to/key.pem', :tls_verify_certificate => 'yes', } end it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/tls = enabled/) .with_content(/tls_certificate = \/path\/to\/certificate\.pem/) .with_content(/tls_private_key = \/path\/to\/key\.pem/) .with_content(/tls_verify_certificate = yes/) end end context 'with node_definitions' do let(:params) do { :node_definitions => { 'node-a' => { 'address' => 'munin://node-a.example.com', }, 'node-b' => { 'address' => 'munin://node-b.example.com', } } } end it { should compile.with_all_deps } it { should contain_munin__master__node_definition('node-a') } it { should contain_munin__master__node_definition('node-b') } end context 'with extra_config' do token = '1b7febce-bb2d-4c18-b889-84c73538a900' let(:params) do { :extra_config => [ token ] } end it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/#{token}/) end end context 'with extra_config set to a string' do token = '1b7febce-bb2d-4c18-b889-84c73538a900' let(:params) do { :extra_config => token } end it { should raise_error(Puppet::Error, /is not an Array/) } end ['test.example.com', 'invalid/hostname.example.com'].each do |param| context "with host_name => #{param}" do let(:params) do { :host_name => param } end if param =~ /invalid/ it { should raise_error(Puppet::Error, /valid domain name/) } else it { should compile.with_all_deps } end end end - %w( enabled disabled mine unclaimed invalid ).each do |param| + %w(enabled disabled mine unclaimed invalid).each do |param| context "with collect_nodes => #{param}" do let(:params) do { :collect_nodes => param } end if param == 'invalid' it { should raise_error(Puppet::Error, /validate_re/) } else it { should compile.with_all_deps } end end end - end # on os + end end end diff --git a/spec/classes/munin_node_export_spec.rb b/spec/classes/munin_node_export_spec.rb index 67fcf3f..6487a60 100644 --- a/spec/classes/munin_node_export_spec.rb +++ b/spec/classes/munin_node_export_spec.rb @@ -1,69 +1,67 @@ require 'spec_helper' _params = { :address => '127.0.0.2', :fqn => 'example;foo.example.com', :masterconfig => [], :mastername => 'munin.example.com' } _extra_nodes = { 'example;svc10.example.com' => { 'address' => '127.0.0.10', 'config' => [], }, 'example;svc11.example.com' => { 'address' => '127.0.0.11', 'config' => ['env foo.warn 12'], } } describe 'munin::node::export' do on_supported_os.each do |os, facts| context "on #{os}" do - let(:facts) do facts end - let(:params) do _params end + let(:facts) { facts } + let(:params) { _params } - it do - should compile.with_all_deps - end + it { should compile.with_all_deps } it do expect(exported_resources).to have_munin__master__node_definition_resource_count(1) end it do expect(exported_resources).to contain_munin__master__node_definition(_params[:fqn]) .with_address(_params[:address]) .with_mastername(_params[:mastername]) .with_tag(["munin::master::#{_params[:mastername]}"]) end end context "on #{os} with extra nodes" do - let(:facts) do facts end - let(:params) do _params.merge({ :node_definitions => _extra_nodes }) end + let(:facts) { facts } + let(:params) { _params.merge({ :node_definitions => _extra_nodes }) } it { should compile.with_all_deps } it do expect(exported_resources).to have_munin__master__node_definition_resource_count(3) end it do expect(exported_resources).to contain_munin__master__node_definition(_params[:fqn]) .with_address(_params[:address]) .with_mastername(_params[:mastername]) .with_tag("munin::master::#{_params[:mastername]}") end - _extra_nodes.keys.each do |n| + _extra_nodes.each_key do |n| it do expect(exported_resources).to contain_munin__master__node_definition(n) .with_address(_extra_nodes[n]['address']) .with_mastername(_params[:mastername]) .with_config(_extra_nodes[n]['config']) .with_tag("munin::master::#{_params[:mastername]}") end end end end end diff --git a/spec/classes/munin_node_spec.rb b/spec/classes/munin_node_spec.rb index a95669a..65df7c4 100644 --- a/spec/classes/munin_node_spec.rb +++ b/spec/classes/munin_node_spec.rb @@ -1,199 +1,194 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['DragonFly'] = '/usr/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' describe 'munin::node' do on_supported_os.each do |os, facts| # Avoid testing on distributions similar to RedHat and Debian - next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + next if os =~ /^(ubuntu|centos|scientific|oraclelinux)-/ # No need to test all os versions as long as os version is not # used in the params class - next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + next if os =~ /^(debian-[67]|redhat-[56]|freebsd-9)-/ context "on #{os}" do - let(:facts) do - facts - end + let(:facts) { facts } it { should compile.with_all_deps } it { should contain_package('munin-node') } munin_confdir = _conf_dir[facts[:osfamily]] munin_node_conf = "#{munin_confdir}/munin-node.conf" munin_plugin_dir = "#{munin_confdir}/plugins" munin_plugin_conf_dir = "#{munin_confdir}/plugin-conf.d" - case facts[:osfamily] - when 'Solaris' - munin_node_service = 'smf:/munin-node' - else - munin_node_service = 'munin-node' - end + munin_node_service = + case facts[:osfamily] + when 'Solaris' then 'smf:/munin-node' + else 'munin-node' + end - case facts[:osfamily] - when 'Solaris' - log_dir = '/var/opt/log/munin' - when 'RedHat' - log_dir = '/var/log/munin-node' - else - log_dir = '/var/log/munin' - end + log_dir = + case facts[:osfamily] + when 'Solaris' then '/var/opt/log/munin' + when 'RedHat' then '/var/log/munin-node' + else '/var/log/munin' + end it { should contain_service(munin_node_service) } it { should contain_file(munin_node_conf) } context 'with no parameters' do it { should compile.with_all_deps } it do should contain_service(munin_node_service) .without_ensure() end it do should contain_file(munin_node_conf) .with_content(/host_name\s+foo.example.com/) .with_content(/log_file\s+#{log_dir}\/munin-node.log/) end end context 'with parameter allow' do let(:params) do { allow: ['2001:db8:1::', '2001:db8:2::/64', '192.0.2.129', '192.0.2.0/25', '192\.0\.2'] } end it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/^cidr_allow 192.0.2.0\/25$/) .with_content(/^cidr_allow 2001:db8:2::\/64$/) .with_content(/^allow \^192\\.0\\.2\\.129\$$/) .with_content(/^allow 192\\.0\\.2$/) .with_content(/^allow \^2001:db8:1::\$$/) end end context 'with parameter host_name' do let(:params) do { host_name: 'something.example.com' } end it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/host_name\s+something.example.com/) end end context 'with parameter service_ensure' do let(:params) do { service_ensure: 'running' } end it { should compile.with_all_deps } it do should contain_service('munin-node') .with_ensure('running') end end context 'logging to syslog' do context 'defaults' do let(:params) do { log_destination: 'syslog' } end it{ should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/log_file\s+Sys::Syslog/) end end context 'with syslog options' do let(:params) do { log_destination: 'syslog', syslog_facility: 'local1', } end it{ should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/log_file\s+Sys::Syslog/) .with_content(/syslog_facility\s+local1/) end end context 'with syslog_facility set to wrong value ' do let(:params) do { log_destination: 'syslog', syslog_facility: 'wrong', } end it { expect { should compile.with_all_deps }.to raise_error(/validate_re/) } end end context 'purge_configs' do context 'set' do let(:params) { { purge_configs: true } } it { should compile.with_all_deps } it do should contain_file(munin_plugin_dir) .with_ensure('directory') .with_recurse(true) .with_purge(true) end it do should contain_file(munin_plugin_conf_dir) .with_ensure('directory') .with_recurse(true) .with_purge(true) end end context 'unset' do it { should compile.with_all_deps } it { should_not contain_file(munin_plugin_dir) } it { should_not contain_file(munin_plugin_conf_dir) } end end context 'timeout' do context 'set' do let(:params) { { timeout: 123 } } it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/^timeout 123/) end end context 'unset' do it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .without_content(/^timeout/) end end end end end context 'unsupported' do include_context :unsupported it do expect do should contain_class('munin::node') end.to raise_error(Puppet::Error, /Unsupported osfamily/) end end end diff --git a/spec/defines/munin_plugin_spec.rb b/spec/defines/munin_plugin_spec.rb index f38ce96..3769802 100644 --- a/spec/defines/munin_plugin_spec.rb +++ b/spec/defines/munin_plugin_spec.rb @@ -1,143 +1,143 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' _share_dir = {} _share_dir.default = '/usr/share/munin' _share_dir['Solaris'] = '/opt/local/share/munin' _share_dir['FreeBSD'] = '/usr/local/share/munin' describe 'munin::plugin', :type => 'define' do let(:title) { 'testplugin' } on_supported_os.each do |os, facts| # Avoid testing on distributions similar to RedHat and Debian - next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + next if os =~ /^(ubuntu|centos|scientific|oraclelinux)-/ # No need to test all os versions as long as os version is not # used in the params class - next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + next if os =~ /^(debian-[67]|redhat-[56]|freebsd-9)-/ context "on #{os}" do let(:facts) do facts end conf_dir = _conf_dir[facts[:osfamily]] plugin_share_dir = "#{_share_dir[facts[:osfamily]]}/plugins" context 'with no parameters' do it do expect { should contain_file("#{conf_dir}/plugins/testplugin") } .to raise_error("expected that the catalogue would contain File[#{conf_dir}/plugins/testplugin]") end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=link parameter' do let(:params) { { :ensure => 'link' } } it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('link') .with_target("#{plugin_share_dir}/testplugin") end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=link and target parameters' do let(:title) { 'test_foo' } let(:params) do { :ensure => 'link', :target => 'test_' } end it do should contain_file("#{conf_dir}/plugins/test_foo") .with_ensure('link') .with_target("#{plugin_share_dir}/test_") end it do should contain_file("#{conf_dir}/plugin-conf.d/test_foo.conf") .with_ensure('absent') end end context 'with ensure=present and source parameters' do let(:params) do { :ensure => 'present', :source => 'puppet:///modules/munin/plugins/testplugin' } end it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('present') .with_source('puppet:///modules/munin/plugins/testplugin') end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=present, source and config parameters' do let(:params) do { :ensure => 'present', :source => 'puppet:///modules/munin/plugins/testplugin', :config => [ 'something wonderful' ], } end it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('present') .with_source('puppet:///modules/munin/plugins/testplugin') end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('present') .with_content(/something wonderful/) end end context 'only configuration' do let(:params) do { :config => ['env.rootdn cn=admin,dc=example,dc=org'], :config_label => 'slapd_*', } end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('present') .with_content(/env.rootdn/) end it do expect { should contain_file("#{conf_dir}/plugins/testplugin") } .to raise_error("expected that the catalogue would contain File[#{conf_dir}/plugins/testplugin]") end end context 'with absolute target' do let(:params) do { ensure: 'link', target: '/full/path/to/testplugin' } end it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('link') .with_target('/full/path/to/testplugin') end end end end end diff --git a/spec/defines/regression_13_munin_plugin_config_name_spec.rb b/spec/defines/regression_13_munin_plugin_config_name_spec.rb index 862327c..f663ba2 100644 --- a/spec/defines/regression_13_munin_plugin_config_name_spec.rb +++ b/spec/defines/regression_13_munin_plugin_config_name_spec.rb @@ -1,52 +1,49 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' describe 'munin::plugin' do let(:title) { 'testplugin' } on_supported_os.each do |os, facts| # Avoid testing on distributions similar to RedHat and Debian - next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + next if os =~ /^(ubuntu|centos|scientific|oraclelinux)-/ # No need to test all os versions as long as os version is not # used in the params class - next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + next if os =~ /^(debian-[67]|redhat-[56]|freebsd-9)-/ context "on #{os}" do - let(:facts) do - facts - end + let(:facts) { facts } conf_dir = _conf_dir[facts[:osfamily]] context 'with config_label unset, label should be set to title' do let(:params) do { config: ['env.foo bar'] } end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_content(/^\[testplugin\]$/) end end context 'with config_label set, label should be set to config_label' do let(:params) do - { config: ['env.foo bar'], - config_label: 'foo_' } + { config: ['env.foo bar'], config_label: 'foo_' } end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_content(/^\[foo_\]$/) end end + end - end # on os end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 538b7a3..7929a70 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,22 +1,22 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' require 'beaker/puppet_install_helper' run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Readable test descriptions c.formatter = :documentation # Configure all nodes in nodeset c.before :suite do # Install module and dependencies puppet_module_install(:source => proj_root, :module_name => 'munin') hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0, 1] } end end end