diff --git a/.gitattributes b/.gitattributes index ea2b04679..6a4f81a9d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,6 @@ #This file is generated by ModuleSync, do not edit. *.rb eol=lf +*.erb eol=lf *.pp eol=lf *.sh eol=lf +*.epp eol=lf diff --git a/.github/workflows/daily_unit_tests_with_nightly_puppet_gem.yaml b/.github/workflows/daily_unit_tests_with_nightly_puppet_gem.yaml new file mode 100644 index 000000000..1da2f3576 --- /dev/null +++ b/.github/workflows/daily_unit_tests_with_nightly_puppet_gem.yaml @@ -0,0 +1,56 @@ +--- +name: '[Daily] Unit Tests with nightly Puppet gem' + +on: + schedule: + - cron: '0 5 * * 1-5' + +jobs: + daily_unit_tests_with_nightly_puppet_gem: + name: ${{ matrix.os_type }} / Puppet${{ matrix.puppet_version }} gem / Ruby ${{ matrix.ruby }} + strategy: + matrix: + os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2019' ] + puppet_version: [ 5, 6, 7 ] + include: + - puppet_version: 5 + ruby: 2.4 + - puppet_version: 6 + ruby: 2.5 + - puppet_version: 7 + ruby: 2.7 + + - os: 'ubuntu-18.04' + os_type: 'Linux' + env_set_cmd: 'export ' + gem_file: 'puppet-latest.gem' + - os: 'macos-10.15' + os_type: 'macOS' + env_set_cmd: 'export ' + gem_file: 'puppet-latest-universal-darwin.gem' + - os: 'windows-2019' + os_type: 'Windows' + env_set_cmd: '$env:' + gem_file: 'puppet-latest-x64-mingw32.gem' + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install ruby version ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - 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 + gem install puppet.gem -N + - name: Prepare testing environment with bundler + run: | + bundle config set system 'true' + ${{ matrix.env_set_cmd }}PUPPET_GEM_VERSION=$(ruby -e 'puts /puppet\s+\((.+)\)/.match(`gem list -eld puppet`)[1]') + bundle update --jobs 4 --retry 3 + - name: Run unit tests + run: bundle exec rake parallel_spec diff --git a/.github/workflows/static_code_analysis.yaml b/.github/workflows/static_code_analysis.yaml new file mode 100644 index 000000000..fd8318585 --- /dev/null +++ b/.github/workflows/static_code_analysis.yaml @@ -0,0 +1,46 @@ +--- +name: Static Code Analysis + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + static_code_analysis: + name: Run checks + + env: + ruby_version: 2.5 + + runs-on: 'ubuntu-18.04' + steps: + - name: Checkout current PR code + uses: actions/checkout@v2 + + - name: Install ruby version ${{ env.ruby_version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ env.ruby_version }} + + - name: Prepare testing environment with bundler + run: bundle update --jobs 4 --retry 3 + + - name: Run commits check + run: bundle exec rake commits + + - name: Run validate check + run: bundle exec rake validate + + - name: Run lint check + run: bundle exec rake lint + + - name: Run metadata_lint check + run: bundle exec rake metadata_lint + + - name: Run syntax check + run: bundle exec rake syntax syntax:hiera syntax:manifests syntax:templates + + - name: Run rubocop check + run: bundle exec rake rubocop diff --git a/.github/workflows/task_acceptance_tests.yaml b/.github/workflows/task_acceptance_tests.yaml new file mode 100644 index 000000000..f82a0f91c --- /dev/null +++ b/.github/workflows/task_acceptance_tests.yaml @@ -0,0 +1,43 @@ +--- +name: Task Acceptance Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + task_acceptance_tests: + name: On ${{ matrix.os }} + strategy: + matrix: + os: [ 'centos-7', 'ubuntu-18.04' ] + + env: + ruby_version: 2.4 + GEM_BOLT: true + BEAKER_debug: true + BEAKER_set: docker/${{ matrix.os }} + + runs-on: 'ubuntu-18.04' + steps: + - name: Checkout current PR code + uses: actions/checkout@v2 + + - name: Install docker + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + + - name: Install ruby version ${{ env.ruby_version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ env.ruby_version }} + + - name: Prepare testing environment with bundler + run: | + bundle update --jobs 4 --retry 3 + - name: Run task acceptance tests + run: cd task_spec && bundle exec rake task_acceptance diff --git a/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml b/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml new file mode 100644 index 000000000..323d91265 --- /dev/null +++ b/.github/workflows/unit_tests_with_nightly_puppet_gem.yaml @@ -0,0 +1,58 @@ +--- +name: Unit Tests with nightly Puppet gem + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + unit_tests_with_nightly_puppet_gem: + name: ${{ matrix.os_type }} / Puppet${{ matrix.puppet_version }} gem / Ruby ${{ matrix.ruby }} + strategy: + matrix: + os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2019' ] + puppet_version: [ 5, 6, 7 ] + include: + - puppet_version: 5 + ruby: 2.4 + - puppet_version: 6 + ruby: 2.5 + - puppet_version: 7 + ruby: 2.7 + + - os: 'ubuntu-18.04' + os_type: 'Linux' + env_set_cmd: 'export ' + gem_file: 'puppet-latest.gem' + - os: 'macos-10.15' + os_type: 'macOS' + env_set_cmd: 'export ' + gem_file: 'puppet-latest-universal-darwin.gem' + - os: 'windows-2019' + os_type: 'Windows' + env_set_cmd: '$env:' + gem_file: 'puppet-latest-x64-mingw32.gem' + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current PR code + uses: actions/checkout@v2 + + - name: Install ruby version ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - 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 + gem install puppet.gem -N + - name: Prepare testing environment with bundler + run: | + bundle config set system 'true' + ${{ matrix.env_set_cmd }}PUPPET_GEM_VERSION=$(ruby -e 'puts /puppet\s+\((.+)\)/.match(`gem list -eld puppet`)[1]') + bundle update --jobs 4 --retry 3 + - name: Run unit tests + run: bundle exec rake parallel_spec diff --git a/.github/workflows/unit_tests_with_released_puppet_gem.yaml b/.github/workflows/unit_tests_with_released_puppet_gem.yaml new file mode 100644 index 000000000..034701c11 --- /dev/null +++ b/.github/workflows/unit_tests_with_released_puppet_gem.yaml @@ -0,0 +1,47 @@ +--- +name: Unit Tests with released Puppet gem + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + unit_tests_with_released_puppet_gem: + name: ${{ matrix.os_type }} / Puppet${{ matrix.puppet_version }} gem / Ruby ${{ matrix.ruby }} + strategy: + matrix: + os: [ 'ubuntu-18.04', 'macos-10.15', 'windows-2019' ] + puppet_version: [ 5, 6 ] + include: + - puppet_version: 5 + ruby: 2.4 + - puppet_version: 6 + ruby: 2.5 + + - os: 'ubuntu-18.04' + os_type: 'Linux' + - os: 'macos-10.15' + os_type: 'macOS' + - os: 'windows-2019' + os_type: 'Windows' + + runs-on: ${{ matrix.os }} + continue-on-error: true + env: + PUPPET_GEM_VERSION: ~> ${{ matrix.puppet_version }}.0 + steps: + - name: Checkout current PR code + uses: actions/checkout@v2 + + - name: Install ruby version ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Prepare testing environment with bundler + run: | + bundle update --jobs 4 --retry 3 + - name: Run unit tests + run: bundle exec rake parallel_spec diff --git a/.rubocop.yml b/.rubocop.yml index c29479fda..83d80e3a3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,11 @@ AllCops: Include: - "./**/*.rb" Exclude: + - 'acceptance/**/*' + - '**/*.erb' + - 'spec/**/*' + - 'task_spec/**/*' + - 'tasks/**/*' - bin/* - ".vendor/**/*" - Gemfile @@ -64,35 +69,632 @@ 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 + +Style/SafeNavigation: + Enabled: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b929e99c2..000000000 --- a/.travis.yml +++ /dev/null @@ -1,47 +0,0 @@ ---- -sudo: false -git: - depth: 150 -dist: trusty -language: ruby -cache: bundler -script: bundle exec rake $CHECK -# Note - Bundler args are currently not supported in modsync -bundler_args: --without system_tests -before_install: - # Additional instructions - - bundle -v - - rm Gemfile.lock || true - - gem update --system - - gem --version - - bundle -v -matrix: - fast_finish: true - include: - - rvm: 2.5.3 - env: CHECK="commits" - - rvm: 2.5.3 - env: CHECK="validate lint spec" - - rvm: 2.5.3 - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=spec - - rvm: 2.5.3 - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=spec - - rvm: 2.3.8 - env: PUPPET_GEM_VERSION="~> 4.10" CHECK=spec - # These cells test the task on different platforms - - rvm: 2.3.8 - dist: trusty - env: GEM_BOLT=true BEAKER_debug=true BEAKER_set=docker/ubuntu-18.04 - install: bundle install - script: cd task_spec && bundle exec rake task_acceptance - services: docker - sudo: required - - rvm: 2.3.8 - dist: trusty - env: GEM_BOLT=true BEAKER_debug=true BEAKER_set=docker/centos-7 - install: bundle install - script: cd task_spec && bundle exec rake task_acceptance - services: docker - sudo: required -notifications: - email: false diff --git a/Gemfile b/Gemfile index cdd4b7059..ff3abf178 100644 --- a/Gemfile +++ b/Gemfile @@ -2,28 +2,13 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" -# Determines what type of gem is requested based on place_or_version. -def gem_type(place_or_version) - if place_or_version =~ /^git:/ - :git - elsif place_or_version =~ /^file:/ - :file - else - :gem - end -end - -# Find a location or specific version for a gem. place_or_version can be a -# version, which is most often used. It can also be git, which is specified as -# `git://somewhere.git#branch`. You can also use a file source location, which -# is specified as `file://some/location/on/disk`. -def location_for(place_or_version, fake_version = nil) - if place_or_version =~ /^(git[:@][^#]*)#(.*)/ +def location_for(place, fake_version = nil) + if place.is_a?(String) && place =~ /^(git[:@][^#]*)#(.*)/ [fake_version, { :git => $1, :branch => $2, :require => false }].compact - elsif place_or_version =~ /^file:\/\/(.*)/ + elsif place.is_a?(String) && place =~ /^file:\/\/(.*)/ ['>= 0', { :path => File.expand_path($1), :require => false }] else - [place_or_version, { :require => false }] + [place, { :require => false }] end end @@ -42,14 +27,32 @@ minor_version = "#{ruby_version_segments[0]}.#{ruby_version_segments[1]}" #end group :development do - gem "puppet-lint", '2.3.6' + gem "facterdb", '~> 1.4', :require => false + gem "mocha", '~> 1.1', :require => false + gem "parser", '~> 2.5', :require => false + gem "puppet-syntax", '~> 2.6', :require => false + gem "specinfra", '2.82.2', :require => false + gem "diff-lcs", '~> 1.3', :require => false + gem "faraday", '~> 0.17', :require => false + gem "pry-byebug", '~> 3.8', :require => false + gem "pry", '~> 0.10', :require => false + gem "method_source", '~> 0.8', :require => false + gem "rake", '~> 12', :require => false + gem "parallel_tests", '>= 2.14.1', '< 2.14.3', :require => false + gem "metadata-json-lint", '>= 2.0.2', '< 3.0.0', :require => false + gem "rspec-puppet-facts", '~> 1.10.0', :require => false + gem "rspec_junit_formatter", '~> 0.2', :require => false + gem "rubocop", '~> 0.49.0', :require => false + gem "rubocop-rspec", '~> 1.16.0', :require => false + gem "rubocop-i18n", '~> 1.2.0', :require => false + gem "puppetlabs_spec_helper", '>= 2.9.0', '< 3.0.0', :require => false gem "puppet-module-posix-default-r#{minor_version}", :require => false, :platforms => "ruby" gem "puppet-module-win-default-r#{minor_version}", :require => false, :platforms => ["mswin", "mingw", "x64_mingw"] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.3', :require => false, :platforms => "ruby" - gem "puppet-module-win-dev-r#{minor_version}", '~> 0.0.7', :require => false, :platforms => ["mswin", "mingw", "x64_mingw"] + gem "rspec-puppet", :require => true, git: "https://github.com/rodjek/rspec-puppet", tag: "v2.7.9" gem "json_pure", '<= 2.0.1', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') gem "fast_gettext", '1.1.0', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') gem "fast_gettext", :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') + gem "puppet-lint", '2.3.6' end group :system_tests do @@ -62,11 +65,12 @@ group :system_tests do gem "beaker-vmpooler", '~> 1.3' gem "serverspec", '~> 2.39' gem "beaker-pe", :require => false - gem "beaker-rspec", *location_for(ENV['BEAKER_RSPEC_VERSION'] || '~> 6.2') + gem "beaker-rspec", *location_for(ENV['BEAKER_RSPEC_VERSION']) gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION']) gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1') gem 'pdk', *location_for(ENV['PDK_GEM_VERSION']) - gem "puppet-blacksmith", '~> 3.4', :require => false + gem "puppet-blacksmith", '~> 3.4', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.7.0') + gem "puppet-blacksmith", '~> 6', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.7.0') # Bundler fails on 2.1.9 even though this group is excluded if ENV['GEM_BOLT'] gem 'bolt', '~> 1.15', require: false diff --git a/acceptance/README.md b/acceptance/README.md index 487b77ecc..d0a917d3a 100644 --- a/acceptance/README.md +++ b/acceptance/README.md @@ -1,3 +1,10 @@ +[![Modules Status](https://github.com/puppetlabs/puppetlabs-puppet_agent/workflows/[Daily]%20Unit%20Tests%20with%nightly%20Puppet%20gem/badge.svg?branch=main)](https://github.com/puppetlabs/puppetlabs-puppet_agent/actions) +[![Modules Status](https://github.com/puppetlabs/puppetlabs-puppet_agent/workflows/Static%20Code%20Analysis/badge.svg?branch=main)](https://github.com/puppetlabs/puppetlabs-puppet_agent/actions) +[![Modules Status](https://github.com/puppetlabs/puppetlabs-puppet_agent/workflows/Unit%20Tests%20with%20nightly%20Puppet%20gem/badge.svg?branch=main)](https://github.com/puppetlabs/puppetlabs-puppet_agent/actions) +[![Modules Status](https://github.com/puppetlabs/puppetlabs-puppet_agent/workflows/Unit%20Tests%20with%20released%20Puppet%20gem/badge.svg?branch=main)](https://github.com/puppetlabs/puppetlabs-puppet_agent/actions) +[![Modules Status](https://github.com/puppetlabs/puppetlabs-puppet_agent/workflows/Task%20Acceptance%20Tests/badge.svg?branch=main)](https://github.com/puppetlabs/puppetlabs-puppet_agent/actions) + + # Acceptance tests for puppetlabs-puppet_agent These integration tests use the [beaker](https://github.com/puppetlabs/beaker) 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/spec_helper_local.rb b/spec/spec_helper_local.rb index d1c44fb77..fd75665da 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -2,6 +2,8 @@ require 'rspec-puppet-facts' include RspecPuppetFacts +location = File.expand_path('/dev/null') + RSpec.configure do |c| c.default_facts = { :aio_agent_version => '5.5.10', @@ -22,31 +24,31 @@ :system32 => nil, :fips_enabled => false, - :puppet_ssldir => '/dev/null/ssl', - :puppet_config => '/dev/null/puppet.conf', + :puppet_ssldir => "#{location}/ssl", + :puppet_config => "#{location}/puppet.conf", :puppet_sslpaths => { 'privatedir' => { - 'path' => '/dev/null/ssl/private', + 'path' => "#{location}/ssl/private", 'path_exists' => true, }, 'privatekeydir' => { - 'path' => '/dev/null/ssl/private_keys', + 'path' => "#{location}/ssl/private_keys", 'path_exists' => true, }, 'publickeydir' => { - 'path' => '/dev/null/ssl/public_keys', + 'path' => "#{location}/ssl/public_keys", 'path_exists' => true, }, 'certdir' => { - 'path' => '/dev/null/ssl/certs', + 'path' => "#{location}/ssl/certs", 'path_exists' => true, }, 'requestdir' => { - 'path' => '/dev/null/ssl/certificate_requests', + 'path' => "#{location}/ssl/certificate_requests", 'path_exists' => true, }, 'hostcrl' => { - 'path' => '/dev/null/ssl/crl.pem', + 'path' => "#{location}/ssl/crl.pem", 'path_exists' => true, }, }, diff --git a/spec/unit/facter/settings_spec.rb b/spec/unit/facter/settings_spec.rb index cd23a9c4f..8f35d5d86 100644 --- a/spec/unit/facter/settings_spec.rb +++ b/spec/unit/facter/settings_spec.rb @@ -1,45 +1,49 @@ require 'spec_helper' -describe 'puppet_ssldir fact' do - subject { Facter.fact(:puppet_ssldir).value } - after(:each) { Facter.clear } +describe 'settings' do + let(:location) { File.expand_path('/dev/null') } - describe 'should point to an existing directory' do - it { is_expected.to eq('/dev/null/ssl') } + describe 'puppet_ssldir fact' do + subject { Facter.fact(:puppet_ssldir).value } + after(:each) { Facter.clear } + + describe 'should point to an existing directory' do + it { is_expected.to eq("#{location}/ssl") } + end end -end -describe 'puppet_config fact' do - subject { Facter.fact(:puppet_config).value } - after(:each) { Facter.clear } + describe 'puppet_config fact' do + subject { Facter.fact(:puppet_config).value } + after(:each) { Facter.clear } - describe 'should point to an existing file' do - it { is_expected.to eq('/dev/null/puppet.conf') } + describe 'should point to an existing file' do + it { is_expected.to eq("#{location}/puppet.conf") } + end end -end -describe "puppet_stringify_facts fact" do - subject { Facter.fact("puppet_stringify_facts".to_sym).value } - after(:each) { Facter.clear } + describe "puppet_stringify_facts fact" do + subject { Facter.fact("puppet_stringify_facts".to_sym).value } + after(:each) { Facter.clear } - describe 'should always be false' do + describe 'should always be false' do it { is_expected.to eq(false) } + end end -end -describe "puppet_sslpaths fact" do - subject { Facter.fact("puppet_sslpaths".to_sym).value } - after(:each) { Facter.clear } - - { 'privatedir' => 'ssl/private', - 'privatekeydir' => 'ssl/private_keys', - 'publickeydir' => 'ssl/public_keys', - 'certdir' => 'ssl/certs', - 'requestdir' => 'ssl/certificate_requests', - 'hostcrl' => 'ssl/crl.pem', - }.each_pair do |name, path| - describe name do - it { is_expected.to include(name => { 'path' => "/dev/null/#{path}", 'path_exists' => false})} + describe "puppet_sslpaths fact" do + subject { Facter.fact("puppet_sslpaths".to_sym).value } + after(:each) { Facter.clear } + + { 'privatedir' => 'ssl/private', + 'privatekeydir' => 'ssl/private_keys', + 'publickeydir' => 'ssl/public_keys', + 'certdir' => 'ssl/certs', + 'requestdir' => 'ssl/certificate_requests', + 'hostcrl' => 'ssl/crl.pem', + }.each_pair do |name, path| + describe name do + it { is_expected.to include(name => { 'path' => "#{location}/#{path}", 'path_exists' => false})} + end end 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']