diff --git a/.rubocop.yml b/.rubocop.yml index 02afb31..c2ebc88 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,520 +1,546 @@ require: rubocop-rspec AllCops: - TargetRubyVersion: 2.2 +# Puppet Server 5 defaults to jruby 1.7 so TargetRubyVersion must stay at 1.9 until we drop support for puppet 5 + TargetRubyVersion: 1.9 Include: - ./**/*.rb Exclude: - files/**/* - vendor/**/* - - Gemfile - - Rakefile - .vendor/**/* - pkg/**/* - spec/fixtures/**/* - Gemfile - Rakefile + - Guardfile + - Vagrantfile 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/HashSyntax: - Enabled: False + Enabled: True Style/RedundantReturn: Enabled: True Layout/EndOfLine: Enabled: False Lint/AmbiguousOperator: Enabled: True Lint/AssignmentInCondition: Enabled: True Layout/SpaceBeforeComment: Enabled: True Style/AndOr: Enabled: True Style/RedundantSelf: Enabled: True Metrics/BlockLength: Enabled: False # Method length is not necessarily an indicator of code quality Metrics/MethodLength: Enabled: False # Module length is not necessarily an indicator of code quality Metrics/ModuleLength: Enabled: False Style/WhileUntilModifier: Enabled: True Lint/AmbiguousRegexpLiteral: Enabled: True Security/Eval: Enabled: True Lint/BlockAlignment: Enabled: True Lint/DefEndAlignment: Enabled: True Lint/EndAlignment: Enabled: True Lint/DeprecatedClassMethods: Enabled: True Lint/Loop: Enabled: True Lint/ParenthesesAsGroupedExpression: Enabled: True Lint/RescueException: Enabled: True Lint/StringConversionInInterpolation: Enabled: True Lint/UnusedBlockArgument: Enabled: True Lint/UnusedMethodArgument: Enabled: True Lint/UselessAccessModifier: Enabled: True Lint/UselessAssignment: Enabled: True Lint/Void: Enabled: True Layout/AccessModifierIndentation: Enabled: True Style/AccessorMethodName: Enabled: True Style/Alias: Enabled: True Layout/AlignArray: Enabled: True Layout/AlignHash: Enabled: True Layout/AlignParameters: Enabled: True Metrics/BlockNesting: Enabled: True Style/AsciiComments: Enabled: True Style/Attr: Enabled: True Style/BracesAroundHashParameters: Enabled: True Style/CaseEquality: Enabled: True Layout/CaseIndentation: Enabled: True Style/CharacterLiteral: Enabled: True Style/ClassAndModuleCamelCase: Enabled: True Style/ClassAndModuleChildren: Enabled: False Style/ClassCheck: Enabled: True # Class length is not necessarily an indicator of code quality Metrics/ClassLength: Enabled: False Style/ClassMethods: Enabled: True Style/ClassVars: Enabled: True Style/WhenThen: Enabled: True Style/WordArray: Enabled: True Style/UnneededPercentQ: Enabled: True Layout/Tab: Enabled: True Layout/SpaceBeforeSemicolon: Enabled: True Layout/TrailingBlankLines: Enabled: True Layout/SpaceInsideBlockBraces: Enabled: True +Layout/SpaceInsideBrackets: + Enabled: True + Layout/SpaceInsideHashLiteralBraces: Enabled: True Layout/SpaceInsideParens: Enabled: True Layout/LeadingCommentSpace: Enabled: True Layout/SpaceBeforeFirstArg: Enabled: True Layout/SpaceAfterColon: Enabled: True Layout/SpaceAfterComma: Enabled: True Layout/SpaceAfterMethodName: Enabled: True Layout/SpaceAfterNot: Enabled: True Layout/SpaceAfterSemicolon: Enabled: True Layout/SpaceAroundEqualsInParameterDefault: Enabled: True Layout/SpaceAroundOperators: Enabled: True Layout/SpaceBeforeBlockBraces: Enabled: True Layout/SpaceBeforeComma: Enabled: True Style/CollectionMethods: Enabled: True Layout/CommentIndentation: Enabled: True Style/ColonMethodCall: Enabled: True Style/CommentAnnotation: Enabled: True # 'Complexity' is very relative Metrics/CyclomaticComplexity: Enabled: False Style/ConstantName: Enabled: True Style/Documentation: Enabled: False Style/DefWithParentheses: Enabled: True Style/PreferredHashMethods: Enabled: True Layout/DotPosition: EnforcedStyle: trailing Style/DoubleNegation: Enabled: True Style/EachWithObject: Enabled: True Layout/EmptyLineBetweenDefs: Enabled: True Layout/IndentArray: Enabled: True Layout/IndentHash: Enabled: True Layout/IndentationConsistency: Enabled: True Layout/IndentationWidth: Enabled: True Layout/EmptyLines: Enabled: True Layout/EmptyLinesAroundAccessModifier: Enabled: True Style/EmptyLiteral: Enabled: True # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Enabled: False Style/MethodCallWithoutArgsParentheses: Enabled: True Style/MethodDefParentheses: Enabled: True Style/LineEndConcatenation: Enabled: True Layout/TrailingWhitespace: Enabled: True Style/StringLiterals: Enabled: True Style/TrailingCommaInArguments: Enabled: True Style/TrailingCommaInLiteral: Enabled: True Style/GlobalVars: Enabled: True Style/GuardClause: Enabled: True Style/IfUnlessModifier: Enabled: True Style/MultilineIfThen: Enabled: True Style/NegatedIf: Enabled: True Style/NegatedWhile: Enabled: True Style/Next: Enabled: True Style/SingleLineBlockParams: Enabled: True Style/SingleLineMethods: Enabled: True Style/SpecialGlobalVars: Enabled: True Style/TrivialAccessors: Enabled: True Style/UnlessElse: Enabled: True Style/VariableInterpolation: Enabled: True Style/VariableName: Enabled: True Style/WhileUntilDo: Enabled: True Style/EvenOdd: Enabled: True Style/FileName: Enabled: True Style/For: Enabled: True Style/Lambda: Enabled: True Style/MethodName: Enabled: True Style/MultilineTernaryOperator: Enabled: True Style/NestedTernaryOperator: Enabled: True Style/NilComparison: Enabled: True Style/FormatString: Enabled: True Style/MultilineBlockChain: Enabled: True Style/Semicolon: Enabled: True Style/SignalException: Enabled: True Style/NonNilCheck: Enabled: True Style/Not: Enabled: True Style/NumericLiterals: Enabled: True Style/OneLineConditional: Enabled: True Style/OpMethod: Enabled: True Style/ParenthesesAroundCondition: Enabled: True Style/PercentLiteralDelimiters: Enabled: True Style/PerlBackrefs: Enabled: True Style/PredicateName: Enabled: True Style/RedundantException: Enabled: True Style/SelfAssignment: Enabled: True Style/Proc: Enabled: True Style/RaiseArgs: Enabled: True Style/RedundantBegin: Enabled: True Style/RescueModifier: Enabled: True # based on https://github.com/voxpupuli/modulesync_config/issues/168 Style/RegexpLiteral: EnforcedStyle: percent_r Enabled: True Lint/UnderscorePrefixedVariableName: Enabled: True Metrics/ParameterLists: Enabled: False Lint/RequireParentheses: Enabled: True -Layout/SpaceBeforeFirstArg: - Enabled: True - Style/ModuleFunction: Enabled: True Lint/Debugger: Enabled: True Style/IfWithSemicolon: Enabled: True Style/Encoding: Enabled: True Style/BlockDelimiters: Enabled: True -Style/FormatStringToken: - Enabled: False - Layout/MultilineBlockLayout: Enabled: True # 'Complexity' is very relative Metrics/AbcSize: Enabled: False -Metrics/BlockLength: - Enabled: False - # 'Complexity' is very relative Metrics/PerceivedComplexity: Enabled: False Lint/UselessAssignment: Enabled: True Layout/ClosingParenthesisIndentation: - Enabled: False + Enabled: True # RSpec +RSpec/BeforeAfterAll: + Exclude: + - spec/acceptance/**/* + # We don't use rspec in this way RSpec/DescribeClass: Enabled: False # Example length is not necessarily an indicator of code quality RSpec/ExampleLength: Enabled: False -RSpec/NestedGroups: - Max: 4 -RSpec/MultipleExpectations: - Max: 2 + +RSpec/NamedSubject: + Enabled: False + +# disabled for now since they cause a lot of issues +# these issues aren't easy to fix +RSpec/RepeatedDescription: + Enabled: False + +RSpec/NestedGroups: + Enabled: False + +# this is broken on ruby1.9 +Layout/IndentHeredoc: + Enabled: False + +# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs +Security/YAMLLoad: + Enabled: false + +# This affects hiera interpolation, as well as some configs that we push. +Style/FormatStringToken: + Enabled: false + +# This is useful, but sometimes a little too picky about where unit tests files +# are located. +RSpec/FilePath: + Enabled: false diff --git a/Rakefile b/Rakefile index 6b3af46..c4fdaf4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,51 +1,58 @@ require 'puppetlabs_spec_helper/rake_tasks' # load optional tasks for releases # only available if gem group releases is installed begin require 'voxpupuli/release/rake_tasks' rescue LoadError end +PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' + +desc 'Auto-correct puppet-lint offenses' +task 'lint:auto_correct' do + Rake::Task[:lint_fix].invoke +end + desc 'Run acceptance tests' RSpec::Core::RakeTask.new(:acceptance) do |t| t.pattern = 'spec/acceptance' end desc 'Run tests' task test: [:release_checks] namespace :check do desc 'Check for trailing whitespace' task :trailing_whitespace do Dir.glob('**/*.md', File::FNM_DOTMATCH).sort.each do |filename| next if filename =~ %r{^((modules|acceptance|\.?vendor|spec/fixtures|pkg)/|REFERENCE.md)} File.foreach(filename).each_with_index do |line, index| if line =~ %r{\s\n$} puts "#{filename} has trailing whitespace on line #{index + 1}" exit 1 end end end end end Rake::Task[:release_checks].enhance ['check:trailing_whitespace'] desc "Run main 'test' task and report merged results to coveralls" task test_with_coveralls: [:test] do if Dir.exist?(File.expand_path('../lib', __FILE__)) require 'coveralls/rake/task' Coveralls::RakeTask.new Rake::Task['coveralls:push'].invoke else puts 'Skipping reporting to coveralls. Module has no lib dir' end end desc 'Generate REFERENCE.md' task :reference, [:debug, :backtrace] do |t, args| patterns = '' Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) end # vim: syntax=ruby diff --git a/spec/acceptance/timezone_spec.rb b/spec/acceptance/timezone_spec.rb index b4f23e3..cced91d 100644 --- a/spec/acceptance/timezone_spec.rb +++ b/spec/acceptance/timezone_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper_acceptance' describe 'timezone class' do describe 'running puppet code' do it 'works with no errors' do pp = <<-PUPPET class { '::timezone': } PUPPET # Run it twice and test for idempotency - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end end end diff --git a/spec/support/debian.rb b/spec/support/debian.rb index 0cb6c82..4ec9dde 100644 --- a/spec/support/debian.rb +++ b/spec/support/debian.rb @@ -1,53 +1,49 @@ shared_examples 'Debian' do let(:facts) do { - :os => { - :name => 'Debian', - :family => 'Debian', - :release => { :major => '8' } + os: { + name: 'Debian', + family: 'Debian', + release: { major: '8' } } } end describe 'when using default class parameters' do let(:params) { {} } it { is_expected.to create_class('timezone') } it { is_expected.to contain_file('/etc/timezone') } it { is_expected.to contain_file('/etc/timezone').with_ensure('file') } it { is_expected.to contain_file('/etc/timezone').with_content(%r{Etc/UTC}) } it { is_expected.to contain_exec('update_timezone').with_command(%r{^dpkg-reconfigure -f noninteractive tzdata$}) } it do - is_expected.to contain_package('tzdata').with(:ensure => 'present', - :before => 'File[/etc/localtime]') + is_expected.to contain_package('tzdata').with(ensure: 'present', before: 'File[/etc/localtime]') end it do - is_expected.to contain_file('/etc/localtime').with(:ensure => 'link', - :target => '/usr/share/zoneinfo/Etc/UTC') + is_expected.to contain_file('/etc/localtime').with(ensure: 'link', target: '/usr/share/zoneinfo/Etc/UTC') end context 'when timezone => "Europe/Berlin"' do - let(:params) { { :timezone => 'Europe/Berlin' } } + let(:params) { { timezone: 'Europe/Berlin' } } it { is_expected.to contain_file('/etc/timezone').with_content(%r{^Europe/Berlin$}) } it { is_expected.to contain_file('/etc/localtime').with_target('/usr/share/zoneinfo/Europe/Berlin') } end context 'when autoupgrade => true' do - let(:params) { { :autoupgrade => true } } + let(:params) { { autoupgrade: true } } it { is_expected.to contain_package('tzdata').with_ensure('latest') } end context 'when ensure => absent' do - let(:params) { { :ensure => 'absent' } } + let(:params) { { ensure: 'absent' } } it { is_expected.to contain_package('tzdata').with_ensure('present') } it { is_expected.to contain_file('/etc/timezone').with_ensure('absent') } it { is_expected.to contain_file('/etc/localtime').with_ensure('absent') } end - - include_examples 'validate parameters' end end diff --git a/spec/support/freebsd.rb b/spec/support/freebsd.rb index 006a1a8..63a7805 100644 --- a/spec/support/freebsd.rb +++ b/spec/support/freebsd.rb @@ -1,41 +1,39 @@ shared_examples 'FreeBSD' do let(:facts) do { - :os => { - :family => 'FreeBSD', - :release => { :major => '9' } + os: { + family: 'FreeBSD', + release: { major: '9' } } } end describe 'when using default class parameters' do let(:params) { {} } it { is_expected.to create_class('timezone') } it do - is_expected.to contain_file('/etc/localtime').with(:ensure => 'link', - :target => '/usr/share/zoneinfo/Etc/UTC') + is_expected.to contain_file('/etc/localtime').with(ensure: 'link', + target: '/usr/share/zoneinfo/Etc/UTC') end context 'when timezone => "Europe/Berlin"' do - let(:params) { { :timezone => 'Europe/Berlin' } } + let(:params) { { timezone: 'Europe/Berlin' } } it { is_expected.to contain_file('/etc/localtime').with_target('/usr/share/zoneinfo/Europe/Berlin') } end context 'when autoupgrade => true' do - let(:params) { { :autoupgrade => true } } + let(:params) { { autoupgrade: true } } it { is_expected.to compile.with_all_deps } end context 'when ensure => absent' do - let(:params) { { :ensure => 'absent' } } + let(:params) { { ensure: 'absent' } } it { is_expected.to contain_file('/etc/localtime').with_ensure('absent') } end - - include_examples 'validate parameters' end end diff --git a/spec/support/gentoo.rb b/spec/support/gentoo.rb index 7f7f7f1..779ee1f 100644 --- a/spec/support/gentoo.rb +++ b/spec/support/gentoo.rb @@ -1,55 +1,53 @@ shared_examples 'Gentoo' do let(:facts) do { - :os => { - :family => 'Gentoo', - :release => { - :full => '4.8.0', - :major => '4' + os: { + family: 'Gentoo', + release: { + full: '4.8.0', + major: '4' } } } end describe 'when using default class parameters' do let(:params) { {} } it { is_expected.to create_class('timezone') } it do - is_expected.to contain_package('sys-libs/timezone-data').with(:ensure => 'present', - :before => 'File[/etc/localtime]') + is_expected.to contain_package('sys-libs/timezone-data').with(ensure: 'present', + before: 'File[/etc/localtime]') end it { is_expected.to contain_file('/etc/timezone').with_ensure('file') } it { is_expected.to contain_file('/etc/timezone').with_content(%r{^Etc/UTC$}) } it { is_expected.to contain_exec('update_timezone').with_command(%r{^emerge --config timezone-data$}) } it do - is_expected.to contain_file('/etc/localtime').with(:ensure => 'link', - :target => '/usr/share/zoneinfo/Etc/UTC') + is_expected.to contain_file('/etc/localtime').with(ensure: 'link', + target: '/usr/share/zoneinfo/Etc/UTC') end context 'when timezone => "Europe/Berlin"' do - let(:params) { { :timezone => 'Europe/Berlin' } } + let(:params) { { timezone: 'Europe/Berlin' } } it { is_expected.to contain_file('/etc/timezone').with_content(%r{^Europe/Berlin$}) } it { is_expected.to contain_file('/etc/localtime').with_target('/usr/share/zoneinfo/Europe/Berlin') } end context 'when autoupgrade => true' do - let(:params) { { :autoupgrade => true } } + let(:params) { { autoupgrade: true } } it { is_expected.to contain_package('sys-libs/timezone-data').with_ensure('latest') } end context 'when ensure => absent' do - let(:params) { { :ensure => 'absent' } } + let(:params) { { ensure: 'absent' } } it { is_expected.to contain_package('sys-libs/timezone-data').with_ensure('present') } it { is_expected.to contain_file('/etc/timezone').with_ensure('absent') } it { is_expected.to contain_file('/etc/localtime').with_ensure('absent') } end - - include_examples 'validate parameters' end end diff --git a/spec/support/redhat.rb b/spec/support/redhat.rb index f2ab3af..29a7b0a 100644 --- a/spec/support/redhat.rb +++ b/spec/support/redhat.rb @@ -1,73 +1,88 @@ shared_examples 'RedHat' do describe 'when using default class parameters with osfamily => RedHat and major release => 6' do let(:params) { {} } let(:facts) do { - :os => { - :name => 'CentOS', - :family => 'RedHat', - :release => { :major => '6' } + os: { + name: 'CentOS', + family: 'RedHat', + release: { major: '6' } } } end it { is_expected.to create_class('timezone') } it do - is_expected.to contain_package('tzdata').with(:ensure => 'present', - :before => 'File[/etc/localtime]') + is_expected.to contain_package('tzdata').with(ensure: 'present', + before: 'File[/etc/localtime]') end it { is_expected.to contain_file('/etc/sysconfig/clock').with_ensure('file') } it { is_expected.to contain_file('/etc/sysconfig/clock').with_content(%r{^ZONE="Etc/UTC"$}) } it { is_expected.not_to contain_exec('update_timezone') } it do - is_expected.to contain_file('/etc/localtime').with(:ensure => 'link', - :target => '/usr/share/zoneinfo/Etc/UTC') + is_expected.to contain_file('/etc/localtime').with(ensure: 'link', + target: '/usr/share/zoneinfo/Etc/UTC') end context 'when timezone => "Europe/Berlin"' do - let(:params) { { :timezone => 'Europe/Berlin' } } + let(:params) { { timezone: 'Europe/Berlin' } } it { is_expected.to contain_file('/etc/sysconfig/clock').with_content(%r{^ZONE="Europe/Berlin"$}) } it { is_expected.to contain_file('/etc/localtime').with_target('/usr/share/zoneinfo/Europe/Berlin') } end context 'when autoupgrade => true' do - let(:params) { { :autoupgrade => true } } + let(:params) { { autoupgrade: true } } it { is_expected.to contain_package('tzdata').with_ensure('latest') } end context 'when ensure => absent' do - let(:params) { { :ensure => 'absent' } } + let(:params) { { ensure: 'absent' } } it { is_expected.to contain_package('tzdata').with_ensure('present') } it { is_expected.to contain_file('/etc/sysconfig/clock').with_ensure('absent') } it { is_expected.to contain_file('/etc/localtime').with_ensure('absent') } end - - include_examples 'validate parameters' end describe 'when using default class parameters with osfamily => RedHat and major release => 7' do let(:params) { {} } let(:facts) do { - :os => { - :name => 'CentOS', - :family => 'RedHat', - :release => { :major => '7' } + os: { + name: 'CentOS', + family: 'RedHat', + release: { major: '7' } } } end it { is_expected.to create_class('timezone') } it { is_expected.not_to contain_file('/etc/sysconfig/clock') } it { is_expected.to contain_file('/etc/localtime').with_ensure('link') } it { is_expected.to contain_exec('update_timezone').with_command('timedatectl set-timezone Etc/UTC').with_unless('timedatectl status | grep "Timezone:\|Time zone:" | grep -q Etc/UTC') } - include_examples 'validate parameters' + end + + describe 'when using default class parameters with osfamily => RedHat and major release => 8' do + let(:params) { {} } + let(:facts) do + { + os: { + name: 'CentOS', + family: 'RedHat', + release: { major: '8' } + } + } + end + + it { is_expected.to create_class('timezone') } + it { is_expected.not_to contain_file('/etc/sysconfig/clock') } + it { is_expected.to contain_file('/etc/localtime').with_ensure('link') } + it { is_expected.to contain_exec('update_timezone').with_command('timedatectl set-timezone Etc/UTC').with_unless('timedatectl status | grep "Timezone:\|Time zone:" | grep -q Etc/UTC') } end end diff --git a/spec/support/validate_params.rb b/spec/support/validate_params.rb deleted file mode 100644 index 0e12d8d..0000000 --- a/spec/support/validate_params.rb +++ /dev/null @@ -1,20 +0,0 @@ -shared_examples_for 'validate parameters' do - [ - 'autoupgrade' - ].each do |param| - context "with #{param} => 'foo'" do - let(:facts) do - { - :os => { - :name => 'Debian', - :family => 'Debian', - :release => { :major => 8, :full => 8 } - } - } - end - let(:params) { { param.to_sym => 'foo' } } - - it { expect { is_expected.to create_class('timezone') }.to raise_error(Puppet::Error, %r{expects a Boolean value}) } - end - end -end