diff --git a/.rubocop.yml b/.rubocop.yml index 76f07f0..7bf7cfe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,561 +1,176 @@ -require: rubocop-rspec +--- +require: +- rubocop-rspec +- rubocop-i18n AllCops: - TargetRubyVersion: 2.1 + DisplayCopNames: true + TargetRubyVersion: '2.4' Include: - - '*.rb' - - 'rakelib/*.rake' - - 'scripts/**/*.rb' - - 'lib/**/*.rb' - - 'spec/**/*.rb' + - "lib/**/*.rb" + - "spec/**/*.rb" + - "scripts/**/*.rb" + - "puppet/**/*.rb" + - "rakelib/*.rake" Exclude: - - files/**/* - - vendor/**/* - - .vendor/**/* - - pkg/**/* - - spec/fixtures/**/* - - puppet/modules/*/spec/fixtures/* - - Gemfile - - Rakefile - - Guardfile - - Vagrantfile -Layout/ConditionPosition: - Enabled: True - -Lint/ElseLayout: - Enabled: True - -Lint/UnreachableCode: - Enabled: True - -Lint/UselessComparison: - Enabled: True - -Lint/EnsureReturn: - Enabled: True - -Lint/HandleExceptions: - Enabled: True - -Lint/LiteralAsCondition: - Enabled: True - -Lint/ShadowingOuterLocalVariable: - Enabled: True - -Lint/LiteralInInterpolation: - Enabled: True - -Style/HashSyntax: - Enabled: False - -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 - -Layout/BlockAlignment: - Enabled: True - -Layout/DefEndAlignment: - Enabled: True - -Layout/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 - + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Layout/EmptyLinesAroundAttributeAccessor: + Enabled: true +Layout/LineLength: + Description: People have wide screens, use them. + Max: 200 +Layout/SpaceAroundMethodCallOperator: + Enabled: true +Lint/RaiseException: + Enabled: true +Lint/StructNewOverride: + Enabled: false +GetText: + Enabled: false +GetText/DecorateString: + Description: We don't want to decorate test output. + Exclude: + - spec/**/* + Enabled: false Naming/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 - -Naming/ClassAndModuleCamelCase: - Enabled: True - + Exclude: + - spec/**/* +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/ExpectInHook: + Exclude: + - spec/unit/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +RSpec/NamedSubject: + Exclude: + - spec/classes/**/* + - spec/defines/**/* +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining 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: False - -Style/UnneededPercentQ: - Enabled: True - -Layout/Tab: - Enabled: True - -Layout/SpaceBeforeSemicolon: - Enabled: True - -Layout/TrailingBlankLines: - Enabled: True - -Layout/SpaceInsideBlockBraces: - 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 - -Naming/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. -Layout/TrailingWhitespace: - Enabled: True - -Metrics/LineLength: - Enabled: False - -Naming/BinaryOperatorParameterName: - Enabled: True - -Style/CommandLiteral: - EnforcedStyle: percent_x - Enabled: True - -Style/MethodCallWithoutArgsParentheses: - Enabled: True - -Style/MethodDefParentheses: - Enabled: True - -Style/LineEndConcatenation: - Enabled: True - -Style/StringLiterals: - Enabled: True - -Style/TrailingCommaInArguments: - 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 - -Naming/VariableName: - Enabled: True - -Style/WhileUntilDo: - Enabled: True - -Style/EvenOdd: - Enabled: True - -Naming/FileName: - Enabled: True - -Style/For: - Enabled: True - -Style/Lambda: - Enabled: True - -Naming/MethodName: - Enabled: True - -Style/MultilineTernaryOperator: - Enabled: True - -Style/NestedTernaryOperator: - Enabled: True - -Style/NilComparison: - Enabled: True - + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact + Enabled: false +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/ExponentialNotation: + 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/ParenthesesAroundCondition: - Enabled: True - -Style/PercentLiteralDelimiters: - Enabled: True - -Style/PerlBackrefs: - Enabled: True - -Naming/PredicateName: - Enabled: True - -Style/RedundantException: - Enabled: True - -Style/SelfAssignment: - Enabled: True - -Style/Proc: - Enabled: True - -Style/RaiseArgs: - Enabled: True - + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/HashEachMethods: + Enabled: true +Style/HashSyntax: + Enabled: false +Style/HashTransformKeys: + Enabled: false +Style/HashTransformValues: + Enabled: true +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/MixinUsage: + Exclude: + - spec/**/* Style/RedundantBegin: - Enabled: True - -Style/RescueModifier: - Enabled: True - -# based on https://github.com/voxpupuli/modulesync_config/issues/168 + Enabled: false Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 EnforcedStyle: percent_r - Enabled: True - -Lint/UnderscorePrefixedVariableName: - Enabled: True - -Metrics/ParameterLists: - Enabled: False - -Lint/RequireParentheses: - Enabled: True - -Style/ModuleFunction: - Enabled: True - -Lint/Debugger: - Enabled: True - -Style/IfWithSemicolon: - Enabled: True - -Style/Encoding: - Enabled: True - -Style/BlockDelimiters: - Enabled: True - -Layout/MultilineBlockLayout: - Enabled: True - -# 'Complexity' is very relative +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInArrayLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SlicingWithRange: + Enabled: true +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +GetText/DecorateFunctionMessage: + Enabled: false +GetText/DecorateStringFormattingUsingInterpolation: + Enabled: false +GetText/DecorateStringFormattingUsingPercent: + Enabled: false +Layout/EndOfLine: + Enabled: false +Layout/HeredocIndentation: + Enabled: false Metrics/AbcSize: - Enabled: False - -# 'Complexity' is very relative + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false Metrics/PerceivedComplexity: - Enabled: False - -Lint/UselessAssignment: - Enabled: True - -Layout/ClosingParenthesisIndentation: - Enabled: True - -# RSpec - -RSpec/BeforeAfterAll: - Exclude: - - spec/acceptance/**/* - -# We don't use rspec in this way + Enabled: false RSpec/DescribeClass: - Enabled: False - -# Example length is not necessarily an indicator of code quality + Enabled: false RSpec/ExampleLength: - Enabled: False - -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 - + Enabled: false +RSpec/MessageExpectation: + Enabled: false +RSpec/MultipleExpectations: + 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: +Style/AsciiComments: Enabled: false - -# This is useful, but sometimes a little too picky about where unit tests files -# are located. -RSpec/FilePath: +Style/IfUnlessModifier: Enabled: false - -Naming/UncommunicativeMethodParamName: - AllowedNames: [io, id, to, by, on, in, at, ip, nw] - -RSpec/BeforeAfterAll: +Style/SymbolProc: Enabled: false - -RSpec/InstanceVariable: +RailsI18n/DecorateString: Enabled: false -# Not sure how else to stub Kernel#:` -RSpec/AnyInstance: - Enabled: false diff --git a/.travis.yml b/.travis.yml index baa4ba2..a9298d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,40 @@ # # *** = Modules created for SIMP 6.2+ are not required to support Puppet < 4.10 # ### = Modules created for SIMP 6.3+ are not required to support Puppet < 5.3 +# ============================================================================== +# +# Travis CI Repo options for this pipeline: +# +# Travis CI Env Var Type Notes +# --------------------- -------- ------------------------------------------- +# GITHUB_OAUTH_TOKEN Secure Required for automated GitHub releases +# SKIP_GITHUB_PUBLISH Optional Skips publishing GitHub releases if "true" +# +# The secure env vars will be filtered in Travis CI log output, and aren't +# provided to untrusted builds (i.e, triggered by PR from another repository) +# +# ------------------------------------------------------------------------------ +# +# Travis CI Trigger options for this pipeline: +# +# To validate if $GITHUB_OAUTH_TOKEN is able to publish a GitHub release, +# trigger a custom Travis CI build for this branch using the CUSTOM CONFIG: +# +# env: VALIDATE_TOKENS=yes +# +# ------------------------------------------------------------------------------ +# +# Release Engineering notes: +# +# To automagically publish a release to GitHub and PuppetForge: +# +# - Set GITHUB_OAUTH_TOKEN as a secure env variable in this repo's Travis CI +# settings +# - Push a git tag that matches the lates version in CHANGELOG.md +# - The tag SHOULD be annotated with release notes, but nothing enforces this +# convention at present +# +# ------------------------------------------------------------------------------ --- language: ruby cache: bundler @@ -17,10 +51,14 @@ notifications: email: false stages: - - validation - - 'Spec tests' + - name: 'validate tokens' + if: 'env(VALIDATE_TOKENS) = yes' + - name: validation + if: 'NOT env(VALIDATE_TOKENS) = yes' + - name: 'Spec tests' + if: 'NOT env(VALIDATE_TOKENS) = yes' - name: deploy - if: 'tag IS present' + if: 'tag IS present AND NOT env(VALIDATE_TOKENS) = yes' before_install: - rm -f Gemfile.lock @@ -51,13 +89,13 @@ jobs: script: bundle exec rake packer:validate - stage: 'Spec tests' - rvm: 2.4.4 - name: 'Ruby unit tests (Ruby 2.4.4)' + rvm: 2.4.9 + name: 'Ruby unit tests (Ruby 2.4.9)' script: bundle exec rake spec - stage: 'Spec tests' name: 'Puppet 5.5 (SIMP 6.3+)' - rvm: 2.4.4 + rvm: 2.4.9 env: - 'PUPPET_VERSION="~> 5.5.6"' script: bundle exec rake test:puppet @@ -69,9 +107,16 @@ jobs: - 'PUPPET_VERSION="~> 5.0"' script: bundle exec rake test:puppet + - stage: 'Spec tests' + name: 'Puppet 6.18 (PE 2019.2)' + rvm: 2.5.7 + env: PUPPET_VERSION="~> 6.18.0" + script: + - bundle exec rake spec + - stage: 'Spec tests' name: 'Latest Puppet 6.x (allowed to fail)' - rvm: 2.5.1 + rvm: 2.5.7 env: - 'PUPPET_VERSION="~> 6.0"' script: bundle exec rake test:puppet @@ -81,9 +126,19 @@ jobs: - true deploy: - provider: releases + token: $GITHUB_OAUTH_TOKEN on: tags: true - condition: '($SKIP_FORGE_PUBLISH != true)' - skip_cleanup: true - api_key: - secure: "pjgpw5TbhG8JNEH8CEY06dUrBUtmi3D4uKS9PXrF03ejFG2TStY9qPC7hEUiEJVVSXhWdkSeVXn+/6vlDcKWKybVcI7sfzWGosXchlROxKwUSCWW4OUXqIYix+ek8rGLfSsojrX6ZiUcecq4a/cnbBZ3Ni+RUnkv5kSFFsT2u5L4xIBmSWxaTTTTlLc6Stk2NXDsF7ygMkIf9bbL9U10boa6g3EyYoPoNlSARfdDLBLQFMs9k2mfBax9b6XWSXi8gtGItyd9BbHT/4Z1KXa63pN7V+pOM5hG4ulJdwNWM73ChhuVYZxXbtsKQYAZxtf1P55DnjOf0VdArFf3LCO25s7/CtuMs7HrdgTgbqr7aNV+OZcD/YyWz7Oy+AcbUOfHRo/mT93qxoEsO9v7AbJKqTs1xM2cM10JI2CP19414VfxaMPxWITEIx6WVaLiLCfhQQJIPb7UvGgNxT2+MTDlW5a+Ly0C+rYvcpVikN5H4dQ/Kmrp7g/uBu2kRrR1IXZRtd3EgD7YTkvobgCxcTZ7qmYnO73BokLDmnpM6nZRVSeLKLGLA9dnPlqBiZogK750TNWTciua/LLmLi4HcWE52dPs6pH2SAXeJrzOgbqQNPDR/AUca4ZQqQ5/MFC6Xyy1QxrmTQLAlNXC3cck6D2lt6aTpi7u6oqYNladX6jH8rU=" + condition: '($SKIP_GITHUB_PUBLISH != true)' + + - stage: 'validate tokens' + language: shell + before_install: skip + install: skip + name: 'validate CI GitHub OAuth token has sufficient scope to release' + script: + - 'echo; echo "===== GITHUB_OAUTH_TOKEN validation";echo " (TRAVIS_SECURE_ENV_VARS=$TRAVIS_SECURE_ENV_VARS)"; echo' + - 'OWNER="$(echo $TRAVIS_REPO_SLUG | cut -d/ -f1)"' + - 'curl -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" + "https://api.github.com/users/$OWNER" + -I | grep ^X-OAuth-Scopes | egrep -w "repo|public_repo"' diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c7a4d..e551e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,19 +11,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for SIMP 6.5.0 Alpha ### Changed -- Use 'simp::classes' in lieu of 'classes' in hieradata. -- Use 'rndc-key' in lieu of 'rndckey' in named.conf to match the generated +- Use `simp::classes` in lieu of `classes` in hieradata. +- Use `rndc-key` in lieu of `rndckey` in named.conf to match the generated key name. (In SIMP 6.5.0 we no longer deliver the sample rndc.key file, - whose key name is 'rndckey'.) + whose key name is `rndckey`.) - Examples explicitly target SIMP 6.5.0 (instead of "6.X") -- 'site' module dependency version ranges now accomodate SIMP 6.5.0 +- 'site' module dependency version ranges now accommodate SIMP 6.5.0 - Converted CHANGELOG into format documented at https://keepachangelog.com/ - Refined regex used to check for puppetserver and puppetdb service status to support both Puppet 5 and Puppet 6. -- Update JSON comments to work with Packer 1.5+ - +- JSON comments work with Packer 1.5+ +- Project and Module Gemfile gems match SIMP 6.5.0 Puppet modules. + - Mitigated CVE-2020-10663 by updating `json` to >= 2.3 +- `.travis.yml` updated to use env var secrets + diagnostic pipelines +- Puppet tests support clean env runs under both Bundler 2.1+ and older + versions. + ### Removed -- Dropped support for all SIMP releases older than 6.5.0 +- Dropped support for all SIMP releases older than 6.5.0. - Removed data -> hieradata cruft (for SIMP < 6.3.0 - The named.conf rndc-key -> rndckey change is incompatible with SIMP 6.4.0 and earlier @@ -38,6 +43,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed extraneous call to puppet-usersetup.sh from simp-bootstrap.sh. This script was called already called between `simp config` and `simp bootstrap`. +- Fixed `YAML.safe_load` Symbol errors in pupmod' `spec_helper.rb` files. +- A LOT of rubcop warnings that were enabled by the updated Gemfile. +- puppet-lint warnings in site module ## [2.4.0] - 2019-07-05 diff --git a/Gemfile b/Gemfile index dfd9836..facad62 100644 --- a/Gemfile +++ b/Gemfile @@ -2,11 +2,12 @@ # NOTE: SIMP Puppet rake tasks support ruby 2.1.9 # ------------------------------------------------------------------------------ gem_sources = ENV.fetch('GEM_SERVERS','https://rubygems.org').split(/[, ]+/) -puppet_version = ENV.fetch('PUPPET_VERSION', '~>5.0') gem_sources.each { |gem_source| source gem_source } group :test do + puppet_version = ENV['PUPPET_VERSION'] || '~> 5.5' + major_puppet_version = puppet_version.scan(/(\d+)(?:\.|\Z)/).flatten.first.to_i gem 'rake' gem 'puppet', puppet_version gem 'rspec' @@ -18,14 +19,16 @@ group :test do gem 'puppet-strings' gem 'puppet-lint-empty_string-check', :require => false gem 'puppet-lint-trailing_comma-check', :require => false - gem 'simp-rspec-puppet-facts', ENV.fetch('SIMP_RSPEC_PUPPET_FACTS_VERSION', '~> 2.2') - gem 'simp-rake-helpers', ENV.fetch('SIMP_RAKE_HELPERS_VERSION', '~> 5.6') - gem 'rubocop', '~> 0.57.0' # supports ruby 2.1 + gem 'simp-rspec-puppet-facts', ENV.fetch('SIMP_RSPEC_PUPPET_FACTS_VERSION', '~> 3.1') + gem 'simp-rake-helpers', ENV.fetch('SIMP_RAKE_HELPERS_VERSION', '~> 5.11') + gem 'rubocop' gem 'rubocop-rspec' + gem 'rubocop-i18n' gem 'yard' gem 'redcarpet' gem 'github-markup' gem 'simplecov', require: false + gem('pdk', ENV['PDK_VERSION'] || '~> 1.0', :require => false) if major_puppet_version > 5 end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 76d0b61..d6dec71 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,45 +1,50 @@ GEM remote: https://rubygems.org/ specs: - addressable (2.4.0) + activesupport (5.2.4.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) ansi (1.5.0) - ast (2.4.0) - backports (3.15.0) - beaker (4.12.0) + ast (2.4.1) + backports (3.18.2) + beaker (4.27.1) beaker-hostgenerator hocon (~> 1.0) in-parallel (~> 0.1) inifile (~> 3.0) minitar (~> 0.6) minitest (~> 5.4) - net-ping (~> 2.0) - net-scp (~> 1.2) - net-ssh (~> 5.0) + net-scp (>= 1.2, < 4.0) + net-ssh (>= 5.0) open_uri_redirections (~> 0.2.1) - pry-byebug (~> 3.6) + pry-byebug (~> 3.9) rb-readline (~> 0.5.3) rsync (~> 1.0.9) stringify-hash (~> 0.0) - thor (~> 0.19) + thor (>= 1.0.1, < 2.0) beaker-abs (0.5.0) - beaker-answers (0.26.2) + beaker-answers (0.27.0) hocon (~> 1.0) require_all (~> 1.3.2) stringify-hash (~> 0.0.0) - beaker-docker (0.5.4) - docker-api + beaker-docker (0.7.1) + docker-api (< 2.0.0) stringify-hash (~> 0.0.0) - beaker-hostgenerator (1.1.37) + beaker-hostgenerator (1.2.8) deep_merge (~> 1.0) stringify-hash (~> 0.0.0) - beaker-pe (2.1.9) + beaker-pe (2.11.7) beaker (~> 4.0) beaker-abs beaker-answers (~> 0.0) beaker-puppet (~> 1.0) beaker-vmpooler (~> 1.0) stringify-hash (~> 0.0.0) - beaker-puppet (1.18.7) + beaker-puppet (1.20.0) beaker (~> 4.1) in-parallel (~> 0.1) oga @@ -52,16 +57,17 @@ GEM rspec (~> 3.0) serverspec (~> 2) specinfra (~> 2) - beaker-vagrant (0.6.2) + beaker-vagrant (0.6.6) stringify-hash (~> 0.0.0) beaker-vmpooler (1.3.3) stringify-hash (~> 0.0.0) - byebug (11.0.1) - coderay (1.1.2) - colored (1.2) - cri (2.15.6) + byebug (11.1.3) + coderay (1.1.3) + colored2 (3.1.2) + concurrent-ruby (1.1.7) + cri (2.15.10) deep_merge (1.2.1) - diff-lcs (1.3) + diff-lcs (1.4.4) docile (1.3.2) docker-api (1.34.2) excon (>= 0.47.0) @@ -70,90 +76,93 @@ GEM unf (>= 0.0.5, < 1.0.0) ethon (0.12.0) ffi (>= 1.3.0) - excon (0.72.0) - facter (2.5.6) - faraday (0.13.1) + excon (0.76.0) + facter (2.5.7) + facterdb (1.4.0) + facter (< 4.0.0) + jgrep + faraday (0.17.3) multipart-post (>= 1.2, < 3) - faraday_middleware (0.12.2) + faraday_middleware (0.14.0) faraday (>= 0.7.4, < 1.0) fast_gettext (1.1.2) - ffi (1.11.1) + ffi (1.13.1) gettext (3.2.9) locale (>= 2.0.5) text (>= 1.3.0) - gettext-setup (0.31) + gettext-setup (0.34) fast_gettext (~> 1.1.0) - gettext (>= 3.0.2) + gettext (>= 3.0.2, < 3.3.0) locale - gh (0.15.1) - addressable (~> 2.4.0) - backports + gh (0.16.0) + activesupport (~> 5.0) + addressable (~> 2.4) faraday (~> 0.8) + faraday_middleware (~> 0.14) multi_json (~> 1.0) net-http-persistent (~> 2.9) net-http-pipeline github-markup (3.0.4) - hiera (3.5.0) + hiera (3.6.0) hiera-puppet-helper (1.0.1) highline (1.7.10) - hocon (1.2.5) + hocon (1.3.1) http-cookie (1.0.3) domain_name (~> 0.5) + i18n (1.8.5) + concurrent-ruby (~> 1.0) in-parallel (0.1.17) inifile (3.0.0) - jaro_winkler (1.5.3) - json (1.8.6) + jgrep (1.5.4) + json (2.3.1) json-schema (2.8.1) addressable (>= 2.4) - launchy (2.4.3) - addressable (~> 2.3) - locale (2.1.2) + launchy (2.5.0) + addressable (~> 2.7) + locale (2.1.3) log4r (1.1.10) - metaclass (0.0.4) - metadata-json-lint (2.2.0) + metadata-json-lint (2.4.0) json-schema (~> 2.8) spdx-licenses (~> 1.0) - method_source (0.9.2) + method_source (1.0.0) mime-types (2.99.3) mini_portile2 (2.4.0) - minitar (0.8) - minitest (5.11.3) - mocha (1.9.0) - metaclass (~> 0.0.1) - multi_json (1.13.1) + minitar (0.9) + minitest (5.14.2) + mocha (1.11.2) + multi_json (1.15.0) multipart-post (2.1.1) net-http-persistent (2.9.4) net-http-pipeline (1.0.1) - net-ping (2.0.6) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (5.2.0) + net-scp (3.0.0) + net-ssh (>= 2.6.5, < 7.0.0) + net-ssh (6.1.0) net-telnet (0.1.1) netrc (0.11.0) - nokogiri (1.10.8) + nokogiri (1.10.10) mini_portile2 (~> 2.4.0) - oga (2.15) + oga (3.3) ast ruby-ll (~> 2.1) open_uri_redirections (0.2.1) pager (1.0.1) - parallel (1.17.0) + parallel (1.19.2) parallel_tests (2.24.0) parallel - parser (2.6.3.0) - ast (~> 2.4.0) + parser (2.7.2.0) + ast (~> 2.4.1) pathspec (0.2.1) - powerpack (0.1.2) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-byebug (3.7.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) byebug (~> 11.0) - pry (~> 0.10) - pry-doc (1.0.0) + pry (~> 0.13.0) + pry-doc (1.1.0) pry (~> 0.11) yard (~> 0.9.11) - puppet (5.5.16) + public_suffix (4.0.6) + puppet (5.5.21) facter (> 2.0.1, < 4) fast_gettext (~> 1.1.2) hiera (>= 3.2.1, < 4) @@ -162,34 +171,37 @@ GEM puppet-blacksmith (3.4.0) puppet (>= 2.7.16) rest-client (~> 1.8.0) - puppet-lint (2.3.6) + puppet-lint (2.4.2) puppet-lint-empty_string-check (0.2.2) puppet-lint (>= 1.0, < 3.0) puppet-lint-trailing_comma-check (0.4.2) puppet-lint (>= 1.0, < 3.0) - puppet-strings (2.3.0) + puppet-strings (2.5.0) rgen yard (~> 0.9.5) - puppet-syntax (2.5.0) + puppet-syntax (3.1.0) + puppet (>= 5) rake - puppet_forge (2.3.0) - faraday (>= 0.9.0, < 0.14.0) - faraday_middleware (>= 0.9.0, < 0.13.0) + puppet_forge (2.3.4) + faraday (>= 0.9.0, < 0.18.0, != 0.13.1) + faraday_middleware (>= 0.9.0, < 0.15.0) gettext-setup (~> 0.11) minitar semantic_puppet (~> 1.0) - puppetlabs_spec_helper (2.14.1) + puppetlabs_spec_helper (2.15.0) mocha (~> 1.0) pathspec (~> 0.2.1) puppet-lint (~> 2.0) - puppet-syntax (~> 2.0) + puppet-syntax (>= 2.0, < 4) rspec-puppet (~> 2.0) pusher-client (0.6.2) json websocket (~> 1.0) - r10k (3.3.1) - colored (= 1.2) - cri (= 2.15.6) + r10k (3.5.2) + colored2 (= 3.1.2) + cri (>= 2.15.10, < 3.0.0) + fast_gettext (~> 1.1.0) + gettext (>= 3.0.2, < 3.3.0) gettext-setup (~> 0.24) log4r (= 1.1.10) multi_json (~> 1.10) @@ -198,44 +210,52 @@ GEM rake (12.3.3) rb-readline (0.5.5) redcarpet (3.5.0) + regexp_parser (1.8.1) require_all (1.3.3) rest-client (1.8.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) + rexml (3.2.4) rgen (0.8.2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.4) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) + rspec-support (~> 3.9.0) rspec-its (1.3.0) rspec-core (>= 3.0.0) rspec-expectations (>= 3.0.0) - rspec-mocks (3.8.1) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-puppet (2.7.5) + rspec-support (~> 3.9.0) + rspec-puppet (2.7.10) rspec - rspec-puppet-facts (0.12.0) + rspec-puppet-facts (2.0.0) facter - json - rspec-support (3.8.2) + facterdb (>= 0.5.0) + puppet + rspec-support (3.9.3) rsync (1.0.9) - rubocop (0.57.2) - jaro_winkler (~> 1.5.1) + rubocop (0.93.0) parallel (~> 1.10) - parser (>= 2.5) - powerpack (~> 0.1) + parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8) + rexml + rubocop-ast (>= 0.6.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - rubocop-rspec (1.27.0) - rubocop (>= 0.56.0) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (0.7.1) + parser (>= 2.7.1.5) + rubocop-i18n (2.0.2) + rubocop (~> 0.51) + rubocop-rspec (1.43.2) + rubocop (~> 0.87) ruby-ll (2.1.2) ansi ast @@ -257,7 +277,7 @@ GEM highline (~> 1.6) net-telnet (~> 0.1.1) nokogiri (~> 1.8) - simp-rake-helpers (5.9.1) + simp-rake-helpers (5.11.4) bundler (>= 1.14, < 3.0) pager (~> 1.0) parallel (~> 1.0) @@ -270,26 +290,26 @@ GEM rake (>= 10.0, < 13.0) ruby-progressbar (~> 1.0) simp-beaker-helpers (~> 1.11) - simp-rspec-puppet-facts (~> 2.0) - simp-rspec-puppet-facts (2.3.0) - facter (>= 1.5.0, < 3.0) - json (~> 1) - rspec-puppet-facts (~> 0) - simplecov (0.17.0) + simp-rspec-puppet-facts (>= 2.4.1, < 4.0) + simp-rspec-puppet-facts (3.1.1) + facter (>= 2.5.0, < 3.0) + json (>= 1.0) + rspec-puppet-facts + simplecov (0.18.5) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov-html (~> 0.11) + simplecov-html (0.12.3) spdx-licenses (1.2.0) - specinfra (2.81.0) + specinfra (2.82.19) net-scp net-ssh (>= 2.7) net-telnet (= 0.1.1) sfl stringify-hash (0.0.2) text (1.3.1) - thor (0.20.3) - travis (1.8.10) + thor (1.0.1) + thread_safe (0.3.6) + travis (1.8.13) backports faraday (~> 0.9) faraday_middleware (~> 0.9, >= 0.9.1) @@ -301,12 +321,14 @@ GEM travish (1.0.0) typhoeus (0.8.0) ethon (>= 0.8.0) + tzinfo (1.2.7) + thread_safe (~> 0.1) unf (0.1.4) unf_ext - unf_ext (0.0.7.6) - unicode-display_width (1.6.0) + unf_ext (0.0.7.7) + unicode-display_width (1.7.0) websocket (1.2.8) - yard (0.9.20) + yard (0.9.25) PLATFORMS ruby @@ -319,7 +341,7 @@ DEPENDENCIES metadata-json-lint pry pry-doc - puppet (~> 5.0) + puppet (~> 5.5) puppet-lint-empty_string-check puppet-lint-trailing_comma-check puppet-strings @@ -329,11 +351,12 @@ DEPENDENCIES rspec rspec-mocks rspec-puppet - rubocop (~> 0.57.0) + rubocop + rubocop-i18n rubocop-rspec simp-beaker-helpers (~> 1.14) - simp-rake-helpers (~> 5.6) - simp-rspec-puppet-facts (~> 2.2) + simp-rake-helpers (~> 5.11) + simp-rspec-puppet-facts (~> 3.1) simplecov travis travish diff --git a/lib/simp/packer/build/matrix.rb b/lib/simp/packer/build/matrix.rb index df60b76..cb06674 100644 --- a/lib/simp/packer/build/matrix.rb +++ b/lib/simp/packer/build/matrix.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simp/tests/matrix/unroller' require 'simp/packer/build/runner' require 'fileutils' @@ -19,12 +21,12 @@ def initialize(matrix) matrix_json_files = matrix.select { |x| x =~ %r{^json=} }.map { |x| parse_glob_list(x.sub(%r{^json=}, '')) }.flatten json_str = "json=#{(env_json_files + matrix_json_files).uniq.join(':')}" full_matrix = [json_str] + matrix.delete_if { |x| x =~ %r{^json=} } - @iterations = simp_json_iteration_filter(unroll(full_matrix)) + @iterations = simp_json_iteration_filter(unroll(full_matrix)) - files_dir = ENV['SAMPLE_DIR'] || File.join( + files_dir = ENV['SAMPLE_DIR'] || File.join( File.dirname(File.dirname(__FILE__)), 'files' ) - @packer_configs_dir = ENV['SIMP_PACKER_CONFIGS_DIR'] || File.join(files_dir, 'configs') + @packer_configs_dir = ENV['SIMP_PACKER_CONFIGS_DIR'] || File.join(files_dir, 'configs') @vagrant_box_dir = ENV['VAGRANT_BOX_DIR'] || "/opt/#{ENV['USER']}/vagrant" @tmp_dir = ENV['TMP_DIR'] || File.join(Dir.pwd, 'tmp') @@ -119,8 +121,8 @@ def run(label = (ENV['MATRIX_LABEL'] || 'build') + Time.now.utc.strftime('_%Y%m% File.open(log, 'a') { |f| f.puts iterator_header_msg } packer_build_runner.run( log_file: log, - tmp_dir: @tmp_dir, - extra_packer_args: ENV['SIMP_PACKER_extra_args'] || '--on-error=ask' + tmp_dir: @tmp_dir, + extra_packer_args: ENV['SIMP_PACKER_extra_args'] || '--on-error=ask', ) next if ENV.fetch('SIMP_PACKER_dry_run', 'no') == 'yes' @@ -165,6 +167,7 @@ def simp_json_iteration_filter(unrolled_matrix) json_data = actual_json_files(unrolled_matrix.map { |c| c[:json] }.uniq) unrolled_matrix.select do |i| next unless json_data.key?(i[:json]) + el = i[:os].sub(%r{^el}, '') puts "el = '#{el}'" iso_name = File.basename(json_data[i[:json]]['iso_url']) diff --git a/lib/simp/packer/build/runner.rb b/lib/simp/packer/build/runner.rb index 48071f5..a5a6029 100644 --- a/lib/simp/packer/build/runner.rb +++ b/lib/simp/packer/build/runner.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simp/packer/config/prepper' require 'fileutils' require 'rake' @@ -55,8 +57,9 @@ def prep(vars_json, simp_conf_yaml, packer_yaml) # Raise a decriptive error if any build requirements are missing def fail_without_prereqs(packer_yaml, simp_conf_yaml, vars_json) raise "ERROR: Test dir not found at '#{@test_dir}'" unless File.directory?(@test_dir) + if @verbose - STDERR.puts( + warn( '', "Contents of test_dir (#{@test_dir}):", Dir["#{@test_dir}/*"].map { |x| " #{File.basename(x)}\n" }.join, '' ) @@ -78,20 +81,20 @@ def run(opts = {}) working_dir = opts[:working_dir] || File.join(@test_dir, "working.#{date}") opts[:log_file] ||= File.join(@test_dir, "#{date}.simp-packer.log") opts[:plog_file] || ENV['PACKER_LOGPATH'] || File.join(@test_dir, "#{date}.packer.log") - opts[:tmp_dir] ||= nil - opts[:dry_run] ||= ENV.fetch('SIMP_PACKER_dry_run', 'no') == 'yes' + opts[:tmp_dir] ||= nil + opts[:dry_run] ||= ENV.fetch('SIMP_PACKER_dry_run', 'no') == 'yes' # The files are currently needed by Simp::Packer::Config::Prepper (the # old simp_config.rb). They have to exist before this method is called. - opts[:packer_yaml] ||= File.join(@test_dir, 'packer.yaml') - opts[:simp_conf_yaml] ||= File.join(@test_dir, 'simp_conf.yaml') - opts[:vars_json] ||= File.join(@test_dir, 'vars.json') + opts[:packer_yaml] ||= File.join(@test_dir, 'packer.yaml') + opts[:simp_conf_yaml] ||= File.join(@test_dir, 'simp_conf.yaml') + opts[:vars_json] ||= File.join(@test_dir, 'vars.json') opts[:extra_packer_args] ||= ENV['SIMP_PACKER_extra_args'] || '' fail_without_prereqs(opts[:packer_yaml], opts[:simp_conf_yaml], opts[:vars_json]) # scaffold working directory rm_rf(working_dir, verbose: @verbose) if File.exist?(working_dir) mkdir_p working_dir, verbose: @verbose - %w[files puppet scripts].each do |f| + ['files', 'puppet', 'scripts'].each do |f| copy_entry(File.join(@base_dir, f), File.join(working_dir, f), verbose: @verbose) end diff --git a/lib/simp/packer/config/prepper.rb b/lib/simp/packer/config/prepper.rb index 07afdf2..dc0e557 100644 --- a/lib/simp/packer/config/prepper.rb +++ b/lib/simp/packer/config/prepper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simp/packer/config/vagrantfile_writer' require 'simp/packer/config/vbox_net_utils' require 'simp/packer/config/simpjsonfile_writer' @@ -31,25 +33,25 @@ def initialize(workingdir, testdir, basedir = File.expand_path("#{__dir__}/../.. # @return [Hash] Default `packer.yaml` settings def default_settings { - 'big_sleep' => '', - 'bootcmd' => 'simp', - 'disk_encrypt' => 'true', - 'domain' => 'simp.test', - 'fips' => 'fips=0', - 'firmware' => 'bios', - 'headless' => 'true', - 'host_only_gateway' => '192.168.101.1', + 'big_sleep' => '', + 'bootcmd' => 'simp', + 'disk_encrypt' => 'true', + 'domain' => 'simp.test', + 'fips' => 'fips=0', + 'firmware' => 'bios', + 'headless' => 'true', + 'host_only_gateway' => '192.168.101.1', 'host_only_interface' => 'enp0s8', - 'iso_dist_dir' => '/net/ISO/Distribution_ISOs', - 'mac_address' => 'aabbbbaa0007', - 'nat_interface' => 'enp0s3', - 'new_password' => 'P@ssw0rdP@ssw0rd', - 'output_directory' => "#{@testdir}/OUTPUT", - 'puppetname' => 'puppet', - 'root_umask' => '0077', - 'simpenvironment' => 'production', - 'ssh_agent_auth' => 'false', - 'vm_description' => 'SIMP-PACKER-BUILD' + 'iso_dist_dir' => '/net/ISO/Distribution_ISOs', + 'mac_address' => 'aabbbbaa0007', + 'nat_interface' => 'enp0s3', + 'new_password' => 'P@ssw0rdP@ssw0rd', + 'output_directory' => "#{@testdir}/OUTPUT", + 'puppetname' => 'puppet', + 'root_umask' => '0077', + 'simpenvironment' => 'production', + 'ssh_agent_auth' => 'false', + 'vm_description' => 'SIMP-PACKER-BUILD' } end @@ -58,6 +60,7 @@ def self.read_and_strip_comments_from_file(json_file) unless File.file?(json_file) raise "\n\nERROR: JSON file '#{json_file}' does not exist or is not a file." end + f = File.open(json_file, 'r') json = '' f.each do |line| @@ -118,6 +121,7 @@ def configure_vars(vars_data, settings) if vars_data['host_only_network_name'].nil? raise "ERROR: could not create or find a virtualbox network for #{settings['host_only_gateway']}" end + vars_data end @@ -142,19 +146,19 @@ def configure_simp_conf(settings, simp_conf) ldap_base_dn = 'dc=' + settings['domain'].split('.').join(',dc=') simp_conf.merge( - 'cli::network::gateway' => settings['host_only_gateway'], - 'simp_options::dns::servers' => [puppet_ip], - 'cli::network::ipaddress' => puppet_ip, + 'cli::network::gateway' => settings['host_only_gateway'], + 'simp_options::dns::servers' => [puppet_ip], + 'cli::network::ipaddress' => puppet_ip, 'simp_options::puppet::server' => puppet_fqdn, - 'cli::network::hostname' => puppet_fqdn, - 'simp_options::puppet::ca' => puppet_fqdn, - 'cli::network::interface' => settings['host_only_interface'], - 'cli::network::netmask' => '255.255.255.0', - 'simp_options::dns::search' => [settings['domain']], - 'simp_options::trusted_nets' => network + '.0/24', - 'simp_options::ldap::base_dn' => ldap_base_dn, - 'simp_options::fips' => settings['fips'].eql?('fips=1'), - 'simp_options::ntpd::servers' => [settings['host_only_gateway']] + 'cli::network::hostname' => puppet_fqdn, + 'simp_options::puppet::ca' => puppet_fqdn, + 'cli::network::interface' => settings['host_only_interface'], + 'cli::network::netmask' => '255.255.255.0', + 'simp_options::dns::search' => [settings['domain']], + 'simp_options::trusted_nets' => network + '.0/24', + 'simp_options::ldap::base_dn' => ldap_base_dn, + 'simp_options::fips' => settings['fips'].eql?('fips=1'), + 'simp_options::ntpd::servers' => [settings['host_only_gateway']], ) end @@ -222,7 +226,7 @@ def generate_files(settings) # Write out box-specific Vagrantfile + Vagrantfile.erb files def generate_vagrantfiles(vars_data, simpconfig_data, top_output) { - 'Vagrantfile' => 'Vagrantfile.erb', + 'Vagrantfile' => 'Vagrantfile.erb', 'Vagrantfile.erb' => 'vagrantfiles/Vagrantfile.erb.erb' }.each do |vagrantfile, template_file| vfile_contents = Simp::Packer::Config::VagrantfileWriter.new( @@ -230,7 +234,7 @@ def generate_vagrantfiles(vars_data, simpconfig_data, top_output) simpconfig_data['cli::network::ipaddress'], vars_data['mac_address'], vars_data['host_only_network_name'], - File.read(File.expand_path("templates/#{template_file}", @basedir)) + File.read(File.expand_path("templates/#{template_file}", @basedir)), ).render vagrantfile_path = File.join top_output, vagrantfile diff --git a/lib/simp/packer/config/simpjsonfile_writer.rb b/lib/simp/packer/config/simpjsonfile_writer.rb index 3225b74..af1807a 100644 --- a/lib/simp/packer/config/simpjsonfile_writer.rb +++ b/lib/simp/packer/config/simpjsonfile_writer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'erb' module Simp diff --git a/lib/simp/packer/config/vagrantfile_writer.rb b/lib/simp/packer/config/vagrantfile_writer.rb index 52df469..9968efe 100644 --- a/lib/simp/packer/config/vagrantfile_writer.rb +++ b/lib/simp/packer/config/vagrantfile_writer.rb @@ -1,3 +1,6 @@ +# frozen_string_literal: true + +# rubocop:disable Naming/MethodParameterName module Simp module Packer module Config @@ -24,3 +27,4 @@ def render end end end +# rubocop:enable Naming/MethodParameterName diff --git a/lib/simp/packer/config/vbox_net_utils.rb b/lib/simp/packer/config/vbox_net_utils.rb index dc7ae42..030229b 100644 --- a/lib/simp/packer/config/vbox_net_utils.rb +++ b/lib/simp/packer/config/vbox_net_utils.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Simp module Packer module Config @@ -5,11 +7,11 @@ module Config # and creating VirtualBox [hostonlyif networks][hostonlyif-nets]. # # [hostonlyif-nets]: https://www.virtualbox.org/manual/ch06.html#network_hostonly - + # module VBoxNetUtils # @return [Array] List of VirtualBox host-only networks def hostonlyifs - %x(VBoxManage list hostonlyifs).split("\n\n") + `VBoxManage list hostonlyifs`.split("\n\n") end # Returns the name of the vboxnet for network, creating it if it @@ -47,13 +49,15 @@ def vboxnet_for_network(network) def create_hostonlyif_for(network) puts "creating new Virtualbox hostonly network for #{network}" if @verbose - cmd_output = %x(VBoxManage hostonlyif create) + cmd_output = `VBoxManage hostonlyif create` unless cmd_output.include? 'was successfully created' raise "ERROR: Creation of network unsuccesful: #{cmd_output}" end + vboxnet = cmd_output.split("'")[1] ipconfig_cmd = "VBoxManage hostonlyif ipconfig #{vboxnet} --ip #{network} --netmask 255.255.255.0" return vboxnet if system(ipconfig_cmd) + raise "ERROR: Failure to configure: #{ipconfig_cmd}" end end diff --git a/lib/simp/packer/publish/local_dir_tree.rb b/lib/simp/packer/publish/local_dir_tree.rb index 086db19..cc668e0 100644 --- a/lib/simp/packer/publish/local_dir_tree.rb +++ b/lib/simp/packer/publish/local_dir_tree.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'fileutils' require 'json' @@ -40,6 +42,7 @@ class LocalDirTree include FileUtils attr_accessor :verbose + def initialize(base_dir) @base_dir = base_dir @verbose = ((ENV['SIMP_PACKER_verbose'] || 'no') == 'yes') @@ -119,7 +122,7 @@ def publish(box_data, action = :hardlink) when :move migrate = ->(src, dst, verbose = true) { FileUtils.mv src, dst, verbose: verbose } when :hardlink - migrate = lambda do |src, dst, verbose = true| + migrate = ->(src, dst, verbose = true) do FileUtils.ln src, dst, verbose: verbose, force: (ENV['SIMP_PACKER_publish_force'] == 'yes') end else diff --git a/lib/simp/packer/vars_json_to_vagrant_box_json.rb b/lib/simp/packer/vars_json_to_vagrant_box_json.rb index 0217834..d8824a8 100644 --- a/lib/simp/packer/vars_json_to_vagrant_box_json.rb +++ b/lib/simp/packer/vars_json_to_vagrant_box_json.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' module Simp @@ -23,7 +25,7 @@ def initialize(vars_json_path, options = {}) simp_box_flavors = infer_simp_flavors(@vars_json_data) @options = options.dup - @options[:org] ||= 'simpci' + @options[:org] ||= 'simpci' @options[:name] ||= "server-#{simp_box_flavors}" @options[:desc] ||= "SIMP server #{simp_box_flavors}" end @@ -53,6 +55,7 @@ def vagrant_box_json( unless File.file? vagrantbox_path raise Errno::ENOENT, "ERROR: Can't find .box file at '#{vagrantbox_path}'" end + created_at = File.mtime(vagrantbox_path).strftime('%Y-%m-%dT%H:%M:%S.%3NZ') updated_at = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%3NZ') @@ -61,28 +64,28 @@ def vagrant_box_json( box_checksum = Digest::SHA256.file(vagrantbox_path).hexdigest { - 'tag' => "#{@options[:org]}/#{@options[:name]}", - 'name' => @options[:name], - 'username' => @options[:org], - 'created_at' => created_at, - 'updated_at' => updated_at, - 'private' => options[:is_private] || false, - 'downloads' => options[:downloads] || 0, - 'short_description' => @options[:desc], + 'tag' => "#{@options[:org]}/#{@options[:name]}", + 'name' => @options[:name], + 'username' => @options[:org], + 'created_at' => created_at, + 'updated_at' => updated_at, + 'private' => options[:is_private] || false, + 'downloads' => options[:downloads] || 0, + 'short_description' => @options[:desc], 'description_markdown' => @options[:desc], - 'description_html' => "
#{@options[:desc]}
", - 'versions' => [{ - 'version' => options[:version] || File.mtime(vagrantbox_path).strftime('%Y%m%d.%H%M%S'), - 'status' => options[:status] || 'active', - 'description_html' => "#{@options[:desc]}
", + 'description_html' => "#{@options[:desc]}
", + 'versions' => [{ + 'version' => options[:version] || File.mtime(vagrantbox_path).strftime('%Y%m%d.%H%M%S'), + 'status' => options[:status] || 'active', + 'description_html' => "#{@options[:desc]}
", 'description_markdown' => @options[:desc], - 'created_at' => created_at, - 'updated_at' => updated_at, - 'providers' => [{ + 'created_at' => created_at, + 'updated_at' => updated_at, + 'providers' => [{ 'checksum_type' => 'sha256', - 'checksum' => box_checksum, - 'name' => options[:provider_name] || 'virtualbox', - 'url' => File.expand_path(vagrantbox_path) + 'checksum' => box_checksum, + 'name' => options[:provider_name] || 'virtualbox', + 'url' => File.expand_path(vagrantbox_path) }] }] } diff --git a/lib/simp/tests/matrix/unroller.rb b/lib/simp/tests/matrix/unroller.rb index 48693c9..1b55e90 100644 --- a/lib/simp/tests/matrix/unroller.rb +++ b/lib/simp/tests/matrix/unroller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Simp module Tests module Matrix diff --git a/lib/simp/tests/puppet.rb b/lib/simp/tests/puppet.rb index c6dd24e..4171957 100644 --- a/lib/simp/tests/puppet.rb +++ b/lib/simp/tests/puppet.rb @@ -1,5 +1,8 @@ +# frozen_string_literal: true + module Simp module Tests + # Puppet testing helpers module Puppet # Pass through environment variables that users/CI should be able to influence def filtered_env_vars @@ -11,7 +14,9 @@ def filtered_env_vars end def run_rake_tasks(cmds) - Bundler.with_clean_env do + # Bundler 2.1+ = :with_unbundled_env, old Bundler = :with_clean_env + clean_env_method = Bundler.respond_to?(:with_unbundled_env) ? :with_unbundled_env : :with_clean_env + ::Bundler.send(clean_env_method) do cmds.each do |cmd| line = cmd.to_s puts "\n\n==== EXECUTING: #{line}\n" @@ -34,7 +39,7 @@ def run_puppet_rake_tests 'bundle exec rake validate', 'bundle exec rake lint', 'bundle exec rake metadata_lint', - 'bundle exec rake test' + 'bundle exec rake test', ] end end diff --git a/lib/simp/tests/shellcheck.rb b/lib/simp/tests/shellcheck.rb index 9b560ea..2744fe2 100644 --- a/lib/simp/tests/shellcheck.rb +++ b/lib/simp/tests/shellcheck.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rake/file_utils' module Simp diff --git a/puppet/modules/simpsetup/Gemfile b/puppet/modules/simpsetup/Gemfile index 2d84b37..174c767 100644 --- a/puppet/modules/simpsetup/Gemfile +++ b/puppet/modules/simpsetup/Gemfile @@ -1,33 +1,54 @@ # ------------------------------------------------------------------------------ -# NOTE: SIMP Puppet rake tasks support ruby 2.1.9 +# NOTICE: **This file is maintained with puppetsync** +# +# This file is automatically updated as part of a puppet module baseline. +# The next baseline sync will overwrite any local changes made to this file. # ------------------------------------------------------------------------------ gem_sources = ENV.fetch('GEM_SERVERS','https://rubygems.org').split(/[, ]+/) +ENV['PDK_DISABLE_ANALYTICS'] ||= 'true' + gem_sources.each { |gem_source| source gem_source } group :test do + puppet_version = ENV['PUPPET_VERSION'] || '~> 5.5' + major_puppet_version = puppet_version.scan(/(\d+)(?:\.|\Z)/).flatten.first.to_i gem 'rake' - gem 'puppet', ENV.fetch('PUPPET_VERSION', '~> 4.0') + gem 'puppet', puppet_version gem 'rspec' - gem 'rspec-puppet', ['>= 2.6.11', '< 3.0.0'] + gem 'rspec-puppet' gem 'hiera-puppet-helper' - gem 'puppetlabs_spec_helper', '~> 2.7.0' + gem 'puppetlabs_spec_helper' gem 'metadata-json-lint' gem 'puppet-strings' gem 'puppet-lint-empty_string-check', :require => false gem 'puppet-lint-trailing_comma-check', :require => false - gem 'simp-rspec-puppet-facts', ENV.fetch('SIMP_RSPEC_PUPPET_FACTS_VERSION', '~> 2.0.0') - gem 'simp-rake-helpers', ENV.fetch('SIMP_RAKE_HELPERS_VERSION', ['>= 5.2', '< 6.0']) - gem 'facterdb' + gem 'simp-rspec-puppet-facts', ENV['SIMP_RSPEC_PUPPET_FACTS_VERSION'] || '~> 3.1' + gem 'simp-rake-helpers', ENV['SIMP_RAKE_HELPERS_VERSION'] || ['> 5.11', '< 6'] + gem( 'pdk', ENV['PDK_VERSION'] || '~> 1.0', :require => false) if major_puppet_version > 5 end group :development do gem 'pry' + gem 'pry-byebug' gem 'pry-doc' end group :system_tests do gem 'beaker' gem 'beaker-rspec' - gem 'simp-beaker-helpers', ENV.fetch('SIMP_BEAKER_HELPERS_VERSION', '~> 1.10') + gem 'simp-beaker-helpers', ENV['SIMP_BEAKER_HELPERS_VERSION'] || ['>= 1.18.7', '< 2'] +end + +# Evaluate extra gemfiles if they exist +extra_gemfiles = [ + ENV['EXTRA_GEMFILE'] || '', + "#{__FILE__}.project", + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end end diff --git a/puppet/modules/simpsetup/manifests/init.pp b/puppet/modules/simpsetup/manifests/init.pp index 80d0f94..804251e 100644 --- a/puppet/modules/simpsetup/manifests/init.pp +++ b/puppet/modules/simpsetup/manifests/init.pp @@ -29,7 +29,7 @@ String $dnsserver = $facts['networking']['fqdn'], String $ipaddress = $facts['networking']['ip'], String $relver = $facts['os']['release']['major'], - String $environment = pick("${facts['puppet_settings']['main']['environment']}",'production'), + String $environment = pick($facts['puppet_settings']['main']['environment'],'production'), Array[String] $servers = ['21','22','23','24','25','26','27','28','29'], Array[String] $clients = ['31','32','33','34','35','36','37','38','39'] ){ diff --git a/puppet/modules/simpsetup/spec/classes/autosign_spec.rb b/puppet/modules/simpsetup/spec/classes/autosign_spec.rb index ccc1d58..9ea6885 100644 --- a/puppet/modules/simpsetup/spec/classes/autosign_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/autosign_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup::autosign' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) { "include 'simpsetup'" } let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup::autosign') } end end end - diff --git a/puppet/modules/simpsetup/spec/classes/dhcp_spec.rb b/puppet/modules/simpsetup/spec/classes/dhcp_spec.rb index fd20d8a..f61566c 100644 --- a/puppet/modules/simpsetup/spec/classes/dhcp_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/dhcp_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup::dhcp' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) { "include 'simpsetup'" } let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup::dhcp') } end end end - diff --git a/puppet/modules/simpsetup/spec/classes/dns_spec.rb b/puppet/modules/simpsetup/spec/classes/dns_spec.rb index a57c867..b02fd31 100644 --- a/puppet/modules/simpsetup/spec/classes/dns_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/dns_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup::dns' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) { "include 'simpsetup'" } let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup::dns') } end end end - diff --git a/puppet/modules/simpsetup/spec/classes/init_spec.rb b/puppet/modules/simpsetup/spec/classes/init_spec.rb index 3ef7453..ee38ec0 100644 --- a/puppet/modules/simpsetup/spec/classes/init_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/init_spec.rb @@ -1,13 +1,14 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup') } end end end - diff --git a/puppet/modules/simpsetup/spec/classes/ks_spec.rb b/puppet/modules/simpsetup/spec/classes/ks_spec.rb index 63c45cf..b74ee23 100644 --- a/puppet/modules/simpsetup/spec/classes/ks_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/ks_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup::ks' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) { "include 'simpsetup'" } let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup::ks') } end end end - diff --git a/puppet/modules/simpsetup/spec/classes/ldap_spec.rb b/puppet/modules/simpsetup/spec/classes/ldap_spec.rb index a24dad0..f39ef27 100644 --- a/puppet/modules/simpsetup/spec/classes/ldap_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/ldap_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup::ldap' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) { "include 'simpsetup'" } let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup::ldap') } end end end - diff --git a/puppet/modules/simpsetup/spec/classes/site_spec.rb b/puppet/modules/simpsetup/spec/classes/site_spec.rb index 3cb9fbf..fb49ab3 100644 --- a/puppet/modules/simpsetup/spec/classes/site_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/site_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup::site' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) { "include 'simpsetup'" } let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup::site') } end end end - diff --git a/puppet/modules/simpsetup/spec/classes/togen_spec.rb b/puppet/modules/simpsetup/spec/classes/togen_spec.rb index 9f51488..b38c7e3 100644 --- a/puppet/modules/simpsetup/spec/classes/togen_spec.rb +++ b/puppet/modules/simpsetup/spec/classes/togen_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'simpsetup::togen' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) { "include 'simpsetup'" } let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } it { is_expected.to create_class('simpsetup::togen') } end end end - diff --git a/puppet/modules/simpsetup/spec/spec_helper.rb b/puppet/modules/simpsetup/spec/spec_helper.rb index fe40ad8..d3b0af5 100644 --- a/puppet/modules/simpsetup/spec/spec_helper.rb +++ b/puppet/modules/simpsetup/spec/spec_helper.rb @@ -1,15 +1,18 @@ +# frozen_string_literal: true + +# rubocop:disable Style/MixinUsage require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet' require 'simp/rspec-puppet-facts' include Simp::RspecPuppetFacts +# rubocop:enable Style/MixinUsage require 'pathname' # RSpec Material fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) -module_name = File.basename(File.expand_path(File.join(__FILE__,'../..'))) -default_hiera_config =<<-EOM +default_hiera_config = <<-HIERA --- :backends: - "rspec" @@ -21,36 +24,36 @@ - "%{spec_title}" - "%{module_name}" - "default" -EOM - +HIERA -['hieradata','modules'].each do |dir| - _dir = File.join(fixture_path,dir) - FileUtils.mkdir_p(_dir) unless File.directory?(_dir) +['hieradata', 'modules'].each do |dir| + f_dir = File.join(fixture_path, dir) + FileUtils.mkdir_p(f_dir) unless File.directory?(f_dir) end def massage_os_facts(os_facts) - _facts = os_facts.merge( {:networking => { - 'ip' => os_facts[:ipaddress], - 'fqdn' => os_facts[:fqdn], - 'domain' => os_facts[:domain], - 'primary' => 'ens3', - 'interfaces' => { - 'ens3' => { - 'ip' => os_facts[:ipaddress], - 'mac' => os_facts[:macaddress], - }}} - }) - _facts + massaged_facts = os_facts.merge({ networking: { + 'ip' => os_facts[:ipaddress], + 'fqdn' => os_facts[:fqdn], + 'domain' => os_facts[:domain], + 'primary' => 'ens3', + 'interfaces' => { + 'ens3' => { + 'ip' => os_facts[:ipaddress], + 'mac' => os_facts[:macaddress] + } + } + } }) + massaged_facts end RSpec.configure do |c| # If nothing else... c.default_facts = { - :production => { + production: { #:fqdn => 'production.rspec.test.localdomain', - :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', - :concat_basedir => '/tmp' + path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + concat_basedir: '/tmp' } } @@ -59,10 +62,10 @@ def massage_os_facts(os_facts) c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') - c.hiera_config = File.join(fixture_path,'hieradata','hiera.yaml') + c.hiera_config = File.join(fixture_path, 'hieradata', 'hiera.yaml') # Useless backtrace noise - backtrace_exclusion_patterns = [ /spec_helper/, /gems/ ] + backtrace_exclusion_patterns = [%r{spec_helper}, %r{gems}] if c.respond_to?(:backtrace_exclusion_patterns) c.backtrace_exclusion_patterns = backtrace_exclusion_patterns @@ -70,20 +73,22 @@ def massage_os_facts(os_facts) c.backtrace_clean_patterns = backtrace_exclusion_patterns end + # rubocop:disable RSpec/BeforeAfterAll c.before(:all) do - data = YAML.load(default_hiera_config) + data = YAML.safe_load(default_hiera_config, [Symbol]) data[:yaml][:datadir] = File.join(fixture_path, 'hieradata') File.open(c.hiera_config, 'w') do |f| f.write data.to_yaml end end + # rubocop:enable RSpec/BeforeAfterAll c.before(:each) do @spec_global_env_temp = Dir.mktmpdir('simpspec') if defined?(environment) - FileUtils.mkdir_p(File.join(@spec_global_env_temp,environment.to_s)) + FileUtils.mkdir_p(File.join(@spec_global_env_temp, environment.to_s)) end # ensure the user running these tests has an accessible environmentpath @@ -101,7 +106,7 @@ def massage_os_facts(os_facts) Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir| begin Pathname.new(dir).realpath - rescue - fail "ERROR: The module '#{dir}' is not installed. Tests cannot continue." + rescue StandardError + raise "ERROR: The module '#{dir}' is not installed. Tests cannot continue." end end diff --git a/puppet/modules/site/Gemfile b/puppet/modules/site/Gemfile index f328fea..174c767 100644 --- a/puppet/modules/site/Gemfile +++ b/puppet/modules/site/Gemfile @@ -1,10 +1,20 @@ +# ------------------------------------------------------------------------------ +# NOTICE: **This file is maintained with puppetsync** +# +# This file is automatically updated as part of a puppet module baseline. +# The next baseline sync will overwrite any local changes made to this file. +# ------------------------------------------------------------------------------ gem_sources = ENV.fetch('GEM_SERVERS','https://rubygems.org').split(/[, ]+/) +ENV['PDK_DISABLE_ANALYTICS'] ||= 'true' + gem_sources.each { |gem_source| source gem_source } group :test do + puppet_version = ENV['PUPPET_VERSION'] || '~> 5.5' + major_puppet_version = puppet_version.scan(/(\d+)(?:\.|\Z)/).flatten.first.to_i gem 'rake' - gem 'puppet', ENV.fetch('PUPPET_VERSION', '~> 5.5') + gem 'puppet', puppet_version gem 'rspec' gem 'rspec-puppet' gem 'hiera-puppet-helper' @@ -13,18 +23,32 @@ group :test do gem 'puppet-strings' gem 'puppet-lint-empty_string-check', :require => false gem 'puppet-lint-trailing_comma-check', :require => false - gem 'simp-rspec-puppet-facts', ENV.fetch('SIMP_RSPEC_PUPPET_FACTS_VERSION', '~> 2.2') - gem 'simp-rake-helpers', ENV.fetch('SIMP_RAKE_HELPERS_VERSION', '~> 5.6') - gem 'facterdb' + gem 'simp-rspec-puppet-facts', ENV['SIMP_RSPEC_PUPPET_FACTS_VERSION'] || '~> 3.1' + gem 'simp-rake-helpers', ENV['SIMP_RAKE_HELPERS_VERSION'] || ['> 5.11', '< 6'] + gem( 'pdk', ENV['PDK_VERSION'] || '~> 1.0', :require => false) if major_puppet_version > 5 end group :development do gem 'pry' + gem 'pry-byebug' gem 'pry-doc' end group :system_tests do gem 'beaker' gem 'beaker-rspec' - gem 'simp-beaker-helpers', ENV.fetch('SIMP_BEAKER_HELPERS_VERSION', '~> 1.12') + gem 'simp-beaker-helpers', ENV['SIMP_BEAKER_HELPERS_VERSION'] || ['>= 1.18.7', '< 2'] +end + +# Evaluate extra gemfiles if they exist +extra_gemfiles = [ + ENV['EXTRA_GEMFILE'] || '', + "#{__FILE__}.project", + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end end diff --git a/puppet/modules/site/spec/classes/vagrant_spec.rb b/puppet/modules/site/spec/classes/vagrant_spec.rb index 45d50cb..a03e54c 100644 --- a/puppet/modules/site/spec/classes/vagrant_spec.rb +++ b/puppet/modules/site/spec/classes/vagrant_spec.rb @@ -1,17 +1,17 @@ +# frozen_string_literal: true require 'spec_helper' describe 'site::vagrant' do - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) { massage_os_facts(os_facts) } + it { is_expected.to compile.with_all_deps } - it { is_expected.to create_pam__access__rule('vagrant_simp').with_users(['vagrant','simp']) } + it { is_expected.to create_pam__access__rule('vagrant_simp').with_users(['vagrant', 'simp']) } it { is_expected.to create_sudo__user_specification('simp_sudo').with_user_list(['simp']) } it { is_expected.to create_sudo__default_entry('simp_default_notty').with_content(['!env_reset, !requiretty']) } it { is_expected.to create_sudo__default_entry('vagrant_default_notty').with_content(['!env_reset, !requiretty']) } end end end - diff --git a/puppet/modules/site/spec/spec_helper.rb b/puppet/modules/site/spec/spec_helper.rb index fe40ad8..d3b0af5 100644 --- a/puppet/modules/site/spec/spec_helper.rb +++ b/puppet/modules/site/spec/spec_helper.rb @@ -1,15 +1,18 @@ +# frozen_string_literal: true + +# rubocop:disable Style/MixinUsage require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet' require 'simp/rspec-puppet-facts' include Simp::RspecPuppetFacts +# rubocop:enable Style/MixinUsage require 'pathname' # RSpec Material fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) -module_name = File.basename(File.expand_path(File.join(__FILE__,'../..'))) -default_hiera_config =<<-EOM +default_hiera_config = <<-HIERA --- :backends: - "rspec" @@ -21,36 +24,36 @@ - "%{spec_title}" - "%{module_name}" - "default" -EOM - +HIERA -['hieradata','modules'].each do |dir| - _dir = File.join(fixture_path,dir) - FileUtils.mkdir_p(_dir) unless File.directory?(_dir) +['hieradata', 'modules'].each do |dir| + f_dir = File.join(fixture_path, dir) + FileUtils.mkdir_p(f_dir) unless File.directory?(f_dir) end def massage_os_facts(os_facts) - _facts = os_facts.merge( {:networking => { - 'ip' => os_facts[:ipaddress], - 'fqdn' => os_facts[:fqdn], - 'domain' => os_facts[:domain], - 'primary' => 'ens3', - 'interfaces' => { - 'ens3' => { - 'ip' => os_facts[:ipaddress], - 'mac' => os_facts[:macaddress], - }}} - }) - _facts + massaged_facts = os_facts.merge({ networking: { + 'ip' => os_facts[:ipaddress], + 'fqdn' => os_facts[:fqdn], + 'domain' => os_facts[:domain], + 'primary' => 'ens3', + 'interfaces' => { + 'ens3' => { + 'ip' => os_facts[:ipaddress], + 'mac' => os_facts[:macaddress] + } + } + } }) + massaged_facts end RSpec.configure do |c| # If nothing else... c.default_facts = { - :production => { + production: { #:fqdn => 'production.rspec.test.localdomain', - :path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', - :concat_basedir => '/tmp' + path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', + concat_basedir: '/tmp' } } @@ -59,10 +62,10 @@ def massage_os_facts(os_facts) c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') - c.hiera_config = File.join(fixture_path,'hieradata','hiera.yaml') + c.hiera_config = File.join(fixture_path, 'hieradata', 'hiera.yaml') # Useless backtrace noise - backtrace_exclusion_patterns = [ /spec_helper/, /gems/ ] + backtrace_exclusion_patterns = [%r{spec_helper}, %r{gems}] if c.respond_to?(:backtrace_exclusion_patterns) c.backtrace_exclusion_patterns = backtrace_exclusion_patterns @@ -70,20 +73,22 @@ def massage_os_facts(os_facts) c.backtrace_clean_patterns = backtrace_exclusion_patterns end + # rubocop:disable RSpec/BeforeAfterAll c.before(:all) do - data = YAML.load(default_hiera_config) + data = YAML.safe_load(default_hiera_config, [Symbol]) data[:yaml][:datadir] = File.join(fixture_path, 'hieradata') File.open(c.hiera_config, 'w') do |f| f.write data.to_yaml end end + # rubocop:enable RSpec/BeforeAfterAll c.before(:each) do @spec_global_env_temp = Dir.mktmpdir('simpspec') if defined?(environment) - FileUtils.mkdir_p(File.join(@spec_global_env_temp,environment.to_s)) + FileUtils.mkdir_p(File.join(@spec_global_env_temp, environment.to_s)) end # ensure the user running these tests has an accessible environmentpath @@ -101,7 +106,7 @@ def massage_os_facts(os_facts) Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir| begin Pathname.new(dir).realpath - rescue - fail "ERROR: The module '#{dir}' is not installed. Tests cannot continue." + rescue StandardError + raise "ERROR: The module '#{dir}' is not installed. Tests cannot continue." end end diff --git a/rakelib/build.rake b/rakelib/build.rake index 3f60dca..28eef0a 100644 --- a/rakelib/build.rake +++ b/rakelib/build.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :simp do namespace :packer do desc <<-DESC.gsub(%r{^ }, '') @@ -28,6 +30,7 @@ namespace :simp do msg << "\n" raise msg.join("\n") unless args.vars_json + args.with_defaults(vars_json: ENV['SIMP_PACKER_vars_json_file']) end args.with_defaults(packer_yaml: ENV['SIMP_PACKER_packer_yaml_file'] || \ @@ -40,7 +43,7 @@ namespace :simp do packer_build_runner.prep( args.vars_json, args.simp_conf_yaml, - args.packer_yaml + args.packer_yaml, ) packer_build_runner.run end diff --git a/rakelib/clean.rake b/rakelib/clean.rake index 11f55c9..4c190c3 100644 --- a/rakelib/clean.rake +++ b/rakelib/clean.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rake/clean' CLEAN << FileList.new('puppet/modules/*/spec/fixtures') diff --git a/rakelib/matrix.rake b/rakelib/matrix.rake index 57cf70e..3b1fef6 100644 --- a/rakelib/matrix.rake +++ b/rakelib/matrix.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simp/packer/build/matrix' require 'rake' namespace :simp do diff --git a/rakelib/oldbuild.rake b/rakelib/oldbuild.rake index 05d775a..d93c6a3 100644 --- a/rakelib/oldbuild.rake +++ b/rakelib/oldbuild.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :simp do namespace :packer do desc <<-DESC.gsub(%r{^ }, '') @@ -17,6 +19,7 @@ namespace :simp do msg << "\n" raise msg.join("\n") unless args.test_dir + args.with_defaults(test_dir: ENV['SIMP_PACKER_test_dir']) end packer_build_runner = Simp::Packer::Build::Runner.new(args.test_dir) diff --git a/rakelib/packer.rake b/rakelib/packer.rake index 11ba3ae..e127bf2 100644 --- a/rakelib/packer.rake +++ b/rakelib/packer.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :packer do desc <<-DESC.gsub(%r{^ }, '') Validates simp.json.erb files and vars.json @@ -31,6 +33,7 @@ namespace :packer do raise "ERROR: json file '#{json}' not found. (ENV: SIMP_PACKER_json_file)" unless File.exist?(json) raise "ERROR: settings file '#{settings_file}' not found. (ENV: SIMP_PACKER_settings_file)" unless File.exist?(settings_file) + in_settings = JSON.parse(File.read(settings_file)) require 'tmpdir' diff --git a/rakelib/rspec.rake b/rakelib/rspec.rake index 95655e3..0b3ae29 100644 --- a/rakelib/rspec.rake +++ b/rakelib/rspec.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + begin require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) diff --git a/rakelib/test.rake b/rakelib/test.rake index f65b763..855306a 100644 --- a/rakelib/test.rake +++ b/rakelib/test.rake @@ -1,8 +1,10 @@ +# frozen_string_literal: true + desc 'Run all testing tasks' task :test => [ 'clean', 'test:shellcheck', 'test:rubocop', 'test:puppet', - 'clean' + 'clean', ] diff --git a/rakelib/test_puppet.rake b/rakelib/test_puppet.rake index b931905..eed2ce8 100644 --- a/rakelib/test_puppet.rake +++ b/rakelib/test_puppet.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simp/tests/puppet' namespace :test do diff --git a/rakelib/test_rubocop.rake b/rakelib/test_rubocop.rake index b0cfd25..e0be6ef 100644 --- a/rakelib/test_rubocop.rake +++ b/rakelib/test_rubocop.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubocop/rake_task' namespace :test do diff --git a/rakelib/test_shellcheck.rake b/rakelib/test_shellcheck.rake index 5708729..3ea8a56 100644 --- a/rakelib/test_shellcheck.rake +++ b/rakelib/test_shellcheck.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simp/tests/shellcheck' namespace :test do diff --git a/rakelib/vagrant.rake b/rakelib/vagrant.rake index 39d4c3c..1a94383 100644 --- a/rakelib/vagrant.rake +++ b/rakelib/vagrant.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simp/packer/vars_json_to_vagrant_box_json' require 'simp/packer/publish/local_dir_tree' @@ -32,6 +34,7 @@ namespace :vagrant do task :list, [:tree_dir] do |_t, args| args.with_defaults(tree_dir: ENV['VAGRANT_BOX_DIR'] || '') raise "ERROR: :tree_dir '#{args.tree_dir}' not found. (ENV: VAGRANT_BOX_DIR)" unless File.exist?(args.tree_dir) + dir_tree = Simp::Packer::Publish::LocalDirTree.new(args.tree_dir) puts dir_tree.list_str end @@ -51,15 +54,16 @@ namespace :vagrant do MSG task :publish, [:tree_dir, :simp_iso_json_file, :box_path, :copy] do |_t, args| args.with_defaults(:copy => 'hardlink') - copy_words = %w[hardlink move copy] + copy_words = ['hardlink', 'move', 'copy'] unless copy_words.include?(args.copy.to_s) raise "\nERROR: :copy was '#{args.copy}'; must be one of: '#{copy_words.join("', '")}'\n\n" end + Simp::Packer::Publish::LocalDirTree.publish( args.simp_iso_json_file, args.box_path, args.tree_dir, - args.copy.to_sym + args.copy.to_sym, ) end end diff --git a/rakelib/yard.rake b/rakelib/yard.rake index 52cfdf9..93f43b9 100644 --- a/rakelib/yard.rake +++ b/rakelib/yard.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yard' YARD::Rake::YardocTask.new do |t| diff --git a/scripts/config/hiera_update.rb b/scripts/config/hiera_update.rb index fd03ad8..db22a30 100755 --- a/scripts/config/hiera_update.rb +++ b/scripts/config/hiera_update.rb @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'yaml' require 'fileutils' require 'socket' diff --git a/scripts/config/sitepp_edit.rb b/scripts/config/sitepp_edit.rb index 9518a5a..fd0ed42 100755 --- a/scripts/config/sitepp_edit.rb +++ b/scripts/config/sitepp_edit.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby -# +# frozen_string_literal: true + require 'fileutils' environment = ENV['SIMP_PACKER_environment'] || 'production' sitepp_file = "/etc/puppetlabs/code/environments/#{environment}/manifests/site.pp" diff --git a/scripts/tests/check_partitions.rb b/scripts/tests/check_partitions.rb index 4319f86..7a10324 100755 --- a/scripts/tests/check_partitions.rb +++ b/scripts/tests/check_partitions.rb @@ -1,9 +1,11 @@ #! /usr/bin/env ruby +# frozen_string_literal: true + # Test to see if expect partitions exist, fail if they don't EXPECTED_PARTITIONS = ['/var', '/var/log', '/var/log/audit', '/'].sort -puts %x(df -h | grep -v tmpfs) +puts `df -h | grep -v tmpfs` -mounts = %x(findmnt --noheadings --raw).split("\n").map { |line| line.split(' ')[0] } +mounts = `findmnt --noheadings --raw`.split("\n").map { |line| line.split(' ')[0] } EXPECTED_PARTITIONS.each do |p| raise "ERROR: The expected partition '#{p}' is not mounted" unless mounts.include?(p) diff --git a/scripts/tests/check_settings.rb b/scripts/tests/check_settings.rb index 89d932b..a88d7a0 100755 --- a/scripts/tests/check_settings.rb +++ b/scripts/tests/check_settings.rb @@ -1,8 +1,11 @@ #! /usr/bin/env ruby +# frozen_string_literal: true + require 'yaml' class SettingsError < StandardError; end +# Check that fips, selinux, puppet are set up class CheckSettings def initialize(never_fail) # when true, checking stops at the first failed @@ -46,7 +49,7 @@ def check_puppet_ports # instead of the default of 8150. # TODO read configured value from the hieradata expected = 8140 - actual = %x(puppet config print masterport).to_i + actual = `puppet config print masterport`.to_i if actual == expected puts "The puppet masterport setting matches the configured value '#{expected}'." @@ -57,7 +60,7 @@ def check_puppet_ports # For the test configuration, the puppet master is also the CA server. expected = @expected_conf['simp_options::puppet::ca_port'] - actual = %x(puppet config print ca_port).to_i + actual = `puppet config print ca_port`.to_i if actual == expected puts "The puppet ca_port setting matches the configured value '#{expected}'." @@ -81,7 +84,7 @@ def check_selinux # should be 'Enforcing'. # TODO read configured value from the hieradata expected = 'Enforcing' - actual = %x(/usr/sbin/getenforce).strip + actual = `/usr/sbin/getenforce`.strip if actual == expected puts "The system selinux setting agrees with the configured value '#{expected}'." else @@ -95,7 +98,7 @@ def check_selinux # are the 'ensure' values returned by # puppet resource service