diff --git a/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml b/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml index d32aadadd..924ca8a68 100644 --- a/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml +++ b/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml @@ -46,6 +46,10 @@ jobs: with: ruby-version: ${{ matrix.ruby }} + - run: ruby -e 'puts Encoding.default_external' + - run: ruby -e 'puts $stdin.external_encoding' + - run: ruby -e 'puts $stdout.external_encoding' + - name: Install the latest nightly build of puppet${{ matrix.puppet_version }} gem run: | curl http://nightlies.puppet.com/downloads/gems/puppet${{ matrix.puppet_version }}-nightly/${{ matrix.gem_file }} --output puppet.gem diff --git a/.rubocop.yml b/.rubocop.yml index c29479fda..817ee1801 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,11 @@ AllCops: Include: - "./**/*.rb" Exclude: + - 'acceptance/**/*' + - '**/*.erb' + - 'spec/**/*' + - 'task_spec/**/*' + - 'tasks/**/*' - bin/* - ".vendor/**/*" - Gemfile @@ -13,7 +18,6 @@ AllCops: - pkg/**/* - spec/fixtures/**/* - vendor/**/* -inherit_from: .rubocop_todo.yml Metrics/LineLength: Description: People have wide screens, use them. Max: 200 @@ -64,35 +68,641 @@ Style/TrailingCommaInLiteral: Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets -Style/CollectionMethods: - Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true -Metrics/AbcSize: +RSpec/DescribeClass: Enabled: false -Metrics/BlockLength: +RSpec/MessageExpectation: Enabled: false -Metrics/ClassLength: + +# MAYBE useful - no return inside ensure block. +Lint/EnsureReturn: Enabled: false -Metrics/CyclomaticComplexity: + +# MAYBE useful - errors when rescue {} happens. +Lint/HandleExceptions: + Enabled: false + +# DISABLED really useless. Detects return as last statement. +Style/RedundantReturn: + Enabled: false + +# Disabled. Throws an error trying to run. +Style/RedundantParentheses: + Enabled: false + +# DISABLED since the instances do not seem to indicate any specific errors. +Lint/AmbiguousOperator: + Enabled: false + +# DISABLED - not useful +Layout/SpaceBeforeComment: + Enabled: false + +# 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/ModuleLength: + +# DISABLED - not useful +Style/WhileUntilModifier: Enabled: false -Metrics/ParameterLists: + +# DISABLED - the offender is just haskell envy +Lint/AmbiguousRegexpLiteral: Enabled: false -Metrics/PerceivedComplexity: + +# DISABLED +Security/Eval: Enabled: false -RSpec/DescribeClass: +# DISABLED +Lint/BlockAlignment: Enabled: false -RSpec/MessageExpectation: + +# DISABLED +Lint/DefEndAlignment: + Enabled: false + +# DISABLED +Lint/EndAlignment: + Enabled: false + +# DISABLED +Lint/ParenthesesAsGroupedExpression: + Enabled: false + +Lint/RescueException: + Enabled: false + +Lint/UnusedBlockArgument: + Enabled: false + +Lint/UnusedMethodArgument: + Enabled: false + +Layout/AccessModifierIndentation: + Enabled: false + +Style/AccessorMethodName: Enabled: false + +Style/Alias: + Enabled: false + +Layout/AlignArray: + Enabled: false + +Layout/AlignHash: + Enabled: false + +Layout/AlignParameters: + Enabled: false + +Metrics/BlockNesting: + Enabled: false + Style/AsciiComments: Enabled: false + +Style/Attr: + Enabled: false + +Style/BracesAroundHashParameters: + Enabled: false + +Style/CaseEquality: + Enabled: false + +Layout/CaseIndentation: + Enabled: false + +Style/CharacterLiteral: + Enabled: false + +Style/ClassAndModuleCamelCase: + 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 + +Layout/Tab: + Enabled: false + +Layout/SpaceBeforeSemicolon: + Enabled: false + +Layout/TrailingBlankLines: + Enabled: false + +Layout/SpaceInsideBlockBraces: + Enabled: false + +Layout/SpaceInsideBrackets: + Enabled: false + +Layout/SpaceInsideHashLiteralBraces: + Enabled: false + +Layout/SpaceInsideParens: + Enabled: false + +Layout/LeadingCommentSpace: + Enabled: false + +Layout/SpaceAfterColon: + Enabled: false + +Layout/SpaceAfterComma: + Enabled: false + +Layout/SpaceAroundKeyword: + Enabled: false + +Layout/SpaceAfterMethodName: + Enabled: false + +Layout/SpaceAfterNot: + Enabled: false + +Layout/SpaceAfterSemicolon: + Enabled: false + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: false + +Layout/SpaceAroundOperators: + Enabled: false + +Layout/SpaceBeforeBlockBraces: + Enabled: false + +Layout/SpaceBeforeComma: + Enabled: false + +Style/CollectionMethods: + Enabled: false + +Layout/CommentIndentation: + Enabled: false + +Style/ColonMethodCall: + Enabled: false + +Style/CommentAnnotation: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Style/ConstantName: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/DefWithParentheses: + Enabled: false + +Style/PreferredHashMethods: + Enabled: false + +Layout/DotPosition: + Enabled: false + +# DISABLED - used for converting to bool +Style/DoubleNegation: + Enabled: false + +Style/EachWithObject: + Enabled: false + +Layout/EmptyLineBetweenDefs: + Enabled: false + +Layout/IndentArray: + Enabled: false + +Layout/IndentHash: + Enabled: false + +Layout/IndentationConsistency: + Enabled: false + +Layout/IndentationWidth: + Enabled: false + +Layout/EmptyLines: + Enabled: false + +Layout/EmptyLinesAroundAccessModifier: + Enabled: false + +Style/EmptyLiteral: + Enabled: false + +Style/MethodCallWithoutArgsParentheses: + Enabled: false + +Style/MethodDefParentheses: + Enabled: false + +Style/LineEndConcatenation: + Enabled: false + +Layout/TrailingWhitespace: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Style/GlobalVars: + Enabled: false + +Style/GuardClause: + Enabled: false + Style/IfUnlessModifier: Enabled: false + +Style/MultilineIfThen: + 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: + Enabled: false + +Style/WhileUntilDo: + Enabled: false + +Style/EvenOdd: + Enabled: false + +Style/FileName: + Enabled: false + +Style/For: + Enabled: false + +Style/MethodName: + Enabled: false + +Style/MultilineTernaryOperator: + Enabled: false + +Style/NestedTernaryOperator: + Enabled: false + +Style/NilComparison: + Enabled: false + +Style/MultilineBlockChain: + 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: + 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 + +Lint/UnderscorePrefixedVariableName: + Enabled: false + +Metrics/ParameterLists: + Enabled: false + +Lint/RequireParentheses: + Enabled: false + +Layout/SpaceBeforeFirstArg: + Enabled: false + +Style/ModuleFunction: + Enabled: false + +Style/IfWithSemicolon: + Enabled: false + +Style/Encoding: + Enabled: false + +Metrics/PerceivedComplexity: + Enabled: false + Style/SymbolProc: Enabled: false + +Layout/SpaceInsideRangeLiteral: + Enabled: false + +Style/InfiniteLoop: + Enabled: false + +Style/BarePercentLiterals: + Enabled: false + +Style/PercentQLiterals: + Enabled: false + +Layout/MultilineBlockLayout: + Enabled: false + +Metrics/AbcSize: + Enabled: false + +Style/MutableConstant: + Enabled: false + +Layout/EmptyLinesAroundClassBody: + Enabled: false + +Style/ConditionalAssignment: + Enabled: false + +Layout/ExtraSpacing: + Enabled: false + +Layout/EmptyLinesAroundBlockBody: + Enabled: false + +Layout/EmptyLinesAroundModuleBody: + Enabled: false + +Layout/MultilineOperationIndentation: + Enabled: false + +Style/StringLiteralsInInterpolation: + Enabled: false + +Layout/MultilineMethodCallIndentation: + Enabled: false + +Metrics/ModuleLength: + Enabled: false + +Layout/EmptyLinesAroundMethodBody: + Enabled: false + +Layout/ClosingParenthesisIndentation: + Enabled: false + +Style/UnneededInterpolation: + Enabled: false + +Layout/ElseAlignment: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: false + +Layout/FirstParameterIndentation: + Enabled: false + +Style/IfInsideElse: + Enabled: false + +Layout/IndentAssignment: + Enabled: false + +Layout/SpaceAroundBlockParameters: + Enabled: false + +Style/ParallelAssignment: + Enabled: false + +Performance/RedundantBlockCall: + Enabled: false + +Style/IdenticalConditionalBranches: + Enabled: false + +Style/CommandLiteral: + Enabled: false + +Lint/NestedMethodDefinition: + Enabled: false + +Layout/SpaceInsideStringInterpolation: + Enabled: false + +Style/NestedModifier: + Enabled: false + +Style/NestedParenthesizedCalls: + Enabled: false + +Layout/RescueEnsureAlignment: + Enabled: false + +Style/TrailingUnderscoreVariable: + Enabled: false + +Lint/LiteralInInterpolation: + Enabled: false + +Layout/InitialIndentation: + Enabled: false + +Style/StructInheritance: + Enabled: false + +Style/SymbolLiteral: + Enabled: false + +Style/IfUnlessModifierOfIfUnless: + Enabled: false + +Style/ZeroLengthPredicate: + Enabled: false + +Bundler/OrderedGems: + Enabled: false + +Layout/EmptyLineAfterMagicComment: + Enabled: false + +Layout/EmptyLinesAroundBeginBody: + Enabled: false + +Layout/EmptyLinesAroundExceptionHandlingKeywords: + Enabled: false + +Layout/IndentHeredoc: + Enabled: false + +Layout/MultilineArrayBraceLayout: + Enabled: false + +Layout/MultilineHashBraceLayout: + Enabled: false + +Layout/MultilineMethodCallBraceLayout: + Enabled: false + +Layout/MultilineMethodDefinitionBraceLayout: + Enabled: false + +Layout/SpaceInsidePercentLiteralDelimiters: + Enabled: false + +Lint/EmptyWhen: + Enabled: false + +Lint/InheritException: + Enabled: false + +Lint/ScriptPermission: + Enabled: false + +Metrics/BlockLength: + Enabled: false + +Style/EmptyCaseCondition: + Enabled: false + +Style/EmptyMethod: + Enabled: false + +Style/InverseMethods: + Enabled: false + +Style/MethodMissing: + Enabled: false + +Style/MixinGrouping: + Enabled: false + +Style/MultilineIfModifier: + Enabled: false + +Style/MultilineMemoization: + Enabled: false + +Style/MultipleComparison: + Enabled: false + +Style/NumericLiteralPrefix: + Enabled: false + +Style/NumericPredicate: + Enabled: false + +Style/YodaCondition: + Enabled: false + +GetText/DecorateFunctionMessage: + Enabled: false + +GetText/DecorateString: + Enabled: false + +GetText/DecorateStringFormattingUsingPercent: + Enabled: false + +Style/SafeNavigation: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/facter/env_temp_variable.rb b/lib/facter/env_temp_variable.rb index 6ea10c403..739bc0cfc 100644 --- a/lib/facter/env_temp_variable.rb +++ b/lib/facter/env_temp_variable.rb @@ -1,7 +1,7 @@ require 'tmpdir' Facter.add(:env_temp_variable) do - setcode { + setcode do (ENV['TEMP'] || Dir.tmpdir) - } + end end diff --git a/lib/facter/mco_config.rb b/lib/facter/mco_config.rb index 43f46c321..ae6518e24 100644 --- a/lib/facter/mco_config.rb +++ b/lib/facter/mco_config.rb @@ -2,14 +2,14 @@ Facter.add("mco_#{node}_config") do setcode do config = nil - if Facter.fact(:kernel).value =~ /windows/i + if Facter.fact(:kernel).value =~ %r{windows}i config_dir = File.expand_path(File.join(Puppet.settings['confdir'],'../../mcollective/etc')) locations = ["#{config_dir}/#{node}.cfg"] else locations = ["/etc/puppetlabs/mcollective/#{node}.cfg", "/etc/mcollective/#{node}.cfg"] end locations.each do |cfg| - if File.exists? cfg + if File.exist? cfg config = cfg end end @@ -25,18 +25,18 @@ settings = {} File.readlines(config.value).select {|v| - v.lstrip =~ /[^#].+=.+/ + v.lstrip =~ %r{[^#].+=.+} }.map {|x| x.split('=', 2).map {|s| s.strip} }.select {|k, v| k == 'libdir' || k == 'plugin.yaml' - }.each {|k, v| + }.each do |k, v| if settings[k] settings[k] += ':' + v else settings[k] = v end - } + end end settings end diff --git a/lib/facter/puppet_agent_appdata.rb b/lib/facter/puppet_agent_appdata.rb index e55cdb912..50f75105b 100644 --- a/lib/facter/puppet_agent_appdata.rb +++ b/lib/facter/puppet_agent_appdata.rb @@ -1,9 +1,9 @@ Facter.add(:puppet_agent_appdata) do setcode do if Dir.const_defined? 'COMMON_APPDATA' then - Dir::COMMON_APPDATA.gsub(/\\\s/, " ").gsub(/\//, '\\') + Dir::COMMON_APPDATA.gsub(%r{\\\s}, " ").tr('/', '\\') elsif not ENV['ProgramData'].nil? - ENV['ProgramData'].gsub(/\\\s/, " ").gsub(/\//, '\\') + ENV['ProgramData'].gsub(%r{\\\s}, " ").tr('/', '\\') end end end diff --git a/lib/puppet/parser/functions/windows_native_path.rb b/lib/puppet/parser/functions/windows_native_path.rb index 34fdbeab1..969dceba0 100644 --- a/lib/puppet/parser/functions/windows_native_path.rb +++ b/lib/puppet/parser/functions/windows_native_path.rb @@ -6,6 +6,6 @@ module Puppet::Parser::Functions path = args[0] - return path.gsub(/\/\s/, ' ').gsub(/\//, "\\") + return path.gsub(%r{\/\s}, ' ').tr('/', "\\") end end diff --git a/lib/puppet/provider/puppet_agent_upgrade_error/puppet_agent_upgrade_error.rb b/lib/puppet/provider/puppet_agent_upgrade_error/puppet_agent_upgrade_error.rb index b72d92685..77894b61f 100644 --- a/lib/puppet/provider/puppet_agent_upgrade_error/puppet_agent_upgrade_error.rb +++ b/lib/puppet/provider/puppet_agent_upgrade_error/puppet_agent_upgrade_error.rb @@ -2,7 +2,7 @@ def ensure_notexist logfile = File.join(Puppet["statedir"].to_s, @resource[:name]) Puppet.debug "Checking for Error logfile #{logfile}" - not File.exists?(logfile) + not File.exist?(logfile) end def read_content_and_delete_file(filename) @@ -13,7 +13,7 @@ def read_content_and_delete_file(filename) # In this scenario we need to open the file in binmode and read each line # individually, then encode the result back to UTF-8 so we can sub out both # the UTF-16 header \uFEFF and the \r\n line carriages. - content = File.open(logfile,"rb:UTF-16LE"){ |file| file.readlines }[0].encode!('UTF-8').gsub("\uFEFF",'').gsub("\r",'') + content = File.open(logfile,"rb:UTF-16LE"){ |file| file.readlines }[0].encode!('UTF-8').delete("\uFEFF").delete("\r") else content = File.read(logfile) end diff --git a/spec/classes/puppet_agent_osfamily_solaris_spec.rb b/spec/classes/puppet_agent_osfamily_solaris_spec.rb index c0e1bda4d..f5e4ac8bd 100644 --- a/spec/classes/puppet_agent_osfamily_solaris_spec.rb +++ b/spec/classes/puppet_agent_osfamily_solaris_spec.rb @@ -316,7 +316,10 @@ def install_script(ver, arch) end it do - is_expected.to contain_file('/tmp/solaris_install.sh').with_ensure('file').with_content(install_script(package_version, 'i386')) + puts('################################################################') + puts(catalogue.inspect) + puts('################################################################') + is_expected.to contain_file('/tmp/solaris_install.sh').with_ensure('file').with_content(install_script(package_version, 'i386')) is_expected.to contain_exec('solaris_install script').with_command('/usr/bin/ctrun -l none /tmp/solaris_install.sh 42 2>&1 > /tmp/solaris_install.log &') end end @@ -378,7 +381,7 @@ def install_script(ver, arch) end it do - is_expected.to contain_file('/tmp/solaris_install.sh').with_ensure('file').with_content(install_script(package_version, 'sparc')) + is_expected.to contain_file('/tmp/solaris_install.sh').with_ensure('file').with_content(install_script(package_version, 'sparc')) is_expected.to contain_exec('solaris_install script').with_command('/usr/bin/ctrun -l none /tmp/solaris_install.sh 42 2>&1 > /tmp/solaris_install.log &') end end @@ -443,7 +446,7 @@ def install_script(ver, arch) } it do - is_expected.to contain_file('/tmp/solaris_install.sh').with_ensure('file').with_content(install_script) + is_expected.to contain_file('/tmp/solaris_install.sh').with_ensure('file').with_content(install_script) is_expected.to contain_exec('solaris_install script').with_command('/usr/bin/ctrun -l none /tmp/solaris_install.sh 42 2>&1 > /tmp/solaris_install.log &') end end diff --git a/task_spec/spec/acceptance/init_spec.rb b/task_spec/spec/acceptance/init_spec.rb index ca542487c..827ef4bae 100644 --- a/task_spec/spec/acceptance/init_spec.rb +++ b/task_spec/spec/acceptance/init_spec.rb @@ -65,7 +65,7 @@ def target_platform end # Check that puppet agent service has been stopped due to 'stop_service' parameter set to true - service = if target_platform =~ /win/ + service = if target_platform =~ %r{win} run_command('c:/"program files"/"puppet labs"/puppet/bin/puppet resource service puppet', 'target') else run_command('/opt/puppetlabs/bin/puppet resource service puppet', 'target') @@ -105,7 +105,7 @@ def target_platform end # Puppet Agent can't be upgraded on Windows nodes while 'puppet agent' service or 'pxp-agent' service are running - if target_platform =~ /win/ + if target_platform =~ %r{win} # Try to upgrade from puppet5 to puppet6 but fail due to puppet agent service already running results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet6', 'version' => 'latest' }) results.each do |res| @@ -144,9 +144,9 @@ def target_platform expect(res['result']['_output']).to match(%r{Puppet Agent #{installed_version} detected. Nothing to do.}) end - if target_platform !~ /sles-11/ + if target_platform !~ %r{sles-11} # Puppet Agent can't be upgraded on Windows nodes while 'puppet agent' service or 'pxp-agent' service are running - if target_platform =~ /win/ + if target_platform =~ %r{win} # Manually stop the puppet agent service service = run_command('c:/"program files"/"puppet labs"/puppet/bin/puppet resource service puppet ensure=stopped', 'target') output = service[0]['result']['stdout']