diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d59437a..4021da7 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,230 +1,217 @@ name: "nightly" on: schedule: - cron: '0 0 * * *' env: HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 HONEYCOMB_DATASET: litmus tests jobs: setup_matrix: name: "Setup Test Matrix" runs-on: ubuntu-20.04 outputs: matrix: ${{ steps.get-matrix.outputs.matrix }} steps: - name: "Honeycomb: Start recording" - uses: kvrhdn/gha-buildevents@v1.0.2 + uses: kvrhdn/gha-buildevents@5be4636b81803713c94d7cb7e3a4b85d759df112 # pin@v1.0.2 with: apikey: ${{ env.HONEYCOMB_WRITEKEY }} dataset: ${{ env.HONEYCOMB_DATASET }} job-status: ${{ job.status }} - name: "Honeycomb: Start first step" run: | echo STEP_ID=0 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Checkout Source uses: actions/checkout@v2 if: ${{ github.repository_owner == 'puppetlabs' }} - name: Activate Ruby 2.7 uses: actions/setup-ruby@v1 if: ${{ github.repository_owner == 'puppetlabs' }} with: ruby-version: "2.7" - name: Cache gems uses: actions/cache@v2 if: ${{ github.repository_owner == 'puppetlabs' }} with: path: vendor/gems key: ${{ runner.os }}-${{ github.event_name }}-${{ hashFiles('**/Gemfile') }} restore-keys: | ${{ runner.os }}-${{ github.event_name }}- ${{ runner.os }}- - name: Install gems if: ${{ github.repository_owner == 'puppetlabs' }} run: | buildevents cmd $TRACE_ID $STEP_ID 'bundle config path vendor/gems' -- bundle config path vendor/gems buildevents cmd $TRACE_ID $STEP_ID 'bundle config jobs 8' -- bundle config jobs 8 buildevents cmd $TRACE_ID $STEP_ID 'bundle config retry 3' -- bundle config retry 3 buildevents cmd $TRACE_ID $STEP_ID 'bundle install' -- bundle install buildevents cmd $TRACE_ID $STEP_ID 'bundle clean' -- bundle clean - name: Setup Acceptance Test Matrix id: get-matrix if: ${{ github.repository_owner == 'puppetlabs' }} run: | if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata else echo "::set-output name=matrix::{}" fi - name: "Honeycomb: Record setup time" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix' Acceptance: needs: - setup_matrix runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} env: BUILDEVENT_FILE: '../buildevents.txt' steps: - run: | echo 'platform=${{ matrix.platform }}' >> $BUILDEVENT_FILE echo 'collection=${{ matrix.collection }}' >> $BUILDEVENT_FILE - name: "Honeycomb: Start recording" - uses: kvrhdn/gha-buildevents@v1.0.2 + uses: kvrhdn/gha-buildevents@5be4636b81803713c94d7cb7e3a4b85d759df112 # pin@v1.0.2 with: apikey: ${{ env.HONEYCOMB_WRITEKEY }} dataset: ${{ env.HONEYCOMB_DATASET }} job-status: ${{ job.status }} matrix-key: ${{ matrix.platform }}-${{ matrix.collection }} - name: "Honeycomb: start first step" run: | echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-1 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Checkout Source uses: actions/checkout@v2 - name: Activate Ruby 2.7 uses: actions/setup-ruby@v1 with: ruby-version: "2.7" - name: Cache gems uses: actions/cache@v2 with: path: vendor/gems key: ${{ runner.os }}-${{ github.event_name }}-${{ hashFiles('**/Gemfile') }} restore-keys: | ${{ runner.os }}-${{ github.event_name }}- ${{ runner.os }}- - name: "Honeycomb: Record cache setup time" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Cache retrieval' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-2 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Bundler Setup run: | buildevents cmd $TRACE_ID $STEP_ID 'bundle config path vendor/gems' -- bundle config path vendor/gems buildevents cmd $TRACE_ID $STEP_ID 'bundle config jobs 8' -- bundle config jobs 8 buildevents cmd $TRACE_ID $STEP_ID 'bundle config retry 3' -- bundle config retry 3 buildevents cmd $TRACE_ID $STEP_ID 'bundle install' -- bundle install buildevents cmd $TRACE_ID $STEP_ID 'bundle clean' -- bundle clean echo ::group::bundler environment buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env echo ::endgroup:: - name: "Honeycomb: Record Bundler Setup time" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Bundler Setup' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-3 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Provision test environment run: | buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:provision ${{ matrix.platform }}' -- bundle exec rake 'litmus:provision[provision::provision_service,${{ matrix.platform }}]' echo ::group::=== REQUEST === cat request.json || true echo echo ::endgroup:: echo ::group::=== INVENTORY === sed -e 's/password: .*/password: "[redacted]"/' < inventory.yaml || true echo ::endgroup:: - # The provision service hands out machines as soon as they're provisioned. - # The GCP VMs might still take a while to spool up and configure themselves fully. - # This retry loop spins until all agents have been installed successfully. - name: Install agent - uses: nick-invision/retry@v1 - with: - timeout_minutes: 30 - max_attempts: 5 - retry_wait_seconds: 60 - command: buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]' + run: | + buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]' - # The agent installer on windows does not finish in time for this to work. To - # work around this for now, retry after a minute if installing the module failed. - name: Install module - uses: nick-invision/retry@v1 - with: - timeout_minutes: 30 - max_attempts: 2 - retry_wait_seconds: 60 - command: buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module' + run: | + buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module' - name: "Honeycomb: Record deployment times" if: ${{ always() }} run: | echo ::group::honeycomb step buildevents step $TRACE_ID $STEP_ID $STEP_START 'Deploy test system' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-4 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV echo ::endgroup:: - name: Run acceptance tests run: | buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:acceptance:parallel' -- bundle exec rake 'litmus:acceptance:parallel' - name: "Honeycomb: Record acceptance testing times" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Run acceptance tests' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-5 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Remove test environment if: ${{ always() }} run: | if [ -f inventory.yaml ]; then buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:tear_down' -- bundle exec rake 'litmus:tear_down' echo ::group::=== REQUEST === cat request.json || true echo echo ::endgroup:: fi - name: "Honeycomb: Record removal times" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Remove test environment' slack-workflow-status: if: always() name: Post Workflow Status To Slack needs: - Acceptance runs-on: ubuntu-20.04 steps: - name: Slack Workflow Notification - uses: Gamesight/slack-workflow-status@master + uses: Gamesight/slack-workflow-status@88ee95b73b4669825883ddf22747966204663e58 # pin@master with: # Required Input repo_token: ${{ secrets.GITHUB_TOKEN }} slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }} # Optional Input channel: '#team-ia-bots' name: 'GABot' diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 17f5a64..2b5ab1f 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -1,211 +1,198 @@ name: "PR Testing" on: [pull_request] env: HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 HONEYCOMB_DATASET: litmus tests jobs: setup_matrix: name: "Setup Test Matrix" runs-on: ubuntu-20.04 outputs: matrix: ${{ steps.get-matrix.outputs.matrix }} steps: - name: "Honeycomb: Start recording" - uses: kvrhdn/gha-buildevents@v1.0.2 + uses: kvrhdn/gha-buildevents@5be4636b81803713c94d7cb7e3a4b85d759df112 # pin@v1.0.2 with: apikey: ${{ env.HONEYCOMB_WRITEKEY }} dataset: ${{ env.HONEYCOMB_DATASET }} job-status: ${{ job.status }} - name: "Honeycomb: Start first step" run: | echo STEP_ID=0 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Checkout Source uses: actions/checkout@v2 if: ${{ github.repository_owner == 'puppetlabs' }} - name: Activate Ruby 2.7 uses: actions/setup-ruby@v1 if: ${{ github.repository_owner == 'puppetlabs' }} with: ruby-version: "2.7" - name: Cache gems uses: actions/cache@v2 if: ${{ github.repository_owner == 'puppetlabs' }} with: path: vendor/gems key: ${{ runner.os }}-${{ github.event_name }}-${{ hashFiles('**/Gemfile') }} restore-keys: | ${{ runner.os }}-${{ github.event_name }}- ${{ runner.os }}- - name: Install gems if: ${{ github.repository_owner == 'puppetlabs' }} run: | buildevents cmd $TRACE_ID $STEP_ID 'bundle config path vendor/gems' -- bundle config path vendor/gems buildevents cmd $TRACE_ID $STEP_ID 'bundle config jobs 8' -- bundle config jobs 8 buildevents cmd $TRACE_ID $STEP_ID 'bundle config retry 3' -- bundle config retry 3 buildevents cmd $TRACE_ID $STEP_ID 'bundle install' -- bundle install buildevents cmd $TRACE_ID $STEP_ID 'bundle clean' -- bundle clean - name: Setup Acceptance Test Matrix id: get-matrix if: ${{ github.repository_owner == 'puppetlabs' }} run: | if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata else echo "::set-output name=matrix::{}" fi - name: "Honeycomb: Record setup time" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix' Acceptance: needs: - setup_matrix runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} env: BUILDEVENT_FILE: '../buildevents.txt' steps: - run: | echo 'platform=${{ matrix.platform }}' >> $BUILDEVENT_FILE echo 'collection=${{ matrix.collection }}' >> $BUILDEVENT_FILE - name: "Honeycomb: Start recording" - uses: kvrhdn/gha-buildevents@v1.0.2 + uses: kvrhdn/gha-buildevents@5be4636b81803713c94d7cb7e3a4b85d759df112 # pin@v1.0.2 with: apikey: ${{ env.HONEYCOMB_WRITEKEY }} dataset: ${{ env.HONEYCOMB_DATASET }} job-status: ${{ job.status }} matrix-key: ${{ matrix.platform }}-${{ matrix.collection }} - name: "Honeycomb: start first step" run: | echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-1 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Checkout Source uses: actions/checkout@v2 - name: Activate Ruby 2.7 uses: actions/setup-ruby@v1 with: ruby-version: "2.7" - name: Cache gems uses: actions/cache@v2 with: path: vendor/gems key: ${{ runner.os }}-${{ github.event_name }}-${{ hashFiles('**/Gemfile') }} restore-keys: | ${{ runner.os }}-${{ github.event_name }}- ${{ runner.os }}- - name: "Honeycomb: Record cache setup time" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Cache retrieval' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-2 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Bundler Setup run: | buildevents cmd $TRACE_ID $STEP_ID 'bundle config path vendor/gems' -- bundle config path vendor/gems buildevents cmd $TRACE_ID $STEP_ID 'bundle config jobs 8' -- bundle config jobs 8 buildevents cmd $TRACE_ID $STEP_ID 'bundle config retry 3' -- bundle config retry 3 buildevents cmd $TRACE_ID $STEP_ID 'bundle install' -- bundle install buildevents cmd $TRACE_ID $STEP_ID 'bundle clean' -- bundle clean echo ::group::bundler environment buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env echo ::endgroup:: - name: "Honeycomb: Record Bundler Setup time" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Bundler Setup' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-3 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Provision test environment run: | buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:provision ${{ matrix.platform }}' -- bundle exec rake 'litmus:provision[provision::provision_service,${{ matrix.platform }}]' echo ::group::=== REQUEST === cat request.json || true echo echo ::endgroup:: echo ::group::=== INVENTORY === sed -e 's/password: .*/password: "[redacted]"/' < inventory.yaml || true echo ::endgroup:: - # The provision service hands out machines as soon as they're provisioned. - # The GCP VMs might still take a while to spool up and configure themselves fully. - # This retry loop spins until all agents have been installed successfully. - name: Install agent - uses: nick-invision/retry@v1 - with: - timeout_minutes: 30 - max_attempts: 5 - retry_wait_seconds: 60 - command: buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]' + run: | + buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]' - # The agent installer on windows does not finish in time for this to work. To - # work around this for now, retry after a minute if installing the module failed. - name: Install module - uses: nick-invision/retry@v1 - with: - timeout_minutes: 30 - max_attempts: 2 - retry_wait_seconds: 60 - command: buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module' + run: | + buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module' - name: "Honeycomb: Record deployment times" if: ${{ always() }} run: | echo ::group::honeycomb step buildevents step $TRACE_ID $STEP_ID $STEP_START 'Deploy test system' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-4 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV echo ::endgroup:: - name: Run acceptance tests run: | buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:acceptance:parallel' -- bundle exec rake 'litmus:acceptance:parallel' - name: "Honeycomb: Record acceptance testing times" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Run acceptance tests' echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-5 >> $GITHUB_ENV echo STEP_START=$(date +%s) >> $GITHUB_ENV - name: Remove test environment if: ${{ always() }} run: | if [ -f inventory.yaml ]; then buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:tear_down' -- bundle exec rake 'litmus:tear_down' echo ::group::=== REQUEST === cat request.json || true echo echo ::endgroup:: fi - name: "Honeycomb: Record removal times" if: ${{ always() }} run: | buildevents step $TRACE_ID $STEP_ID $STEP_START 'Remove test environment' diff --git a/.rubocop.yml b/.rubocop.yml index 858882d..07b68b8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,137 +1,540 @@ --- require: +- rubocop-performance - rubocop-rspec -- rubocop-i18n AllCops: DisplayCopNames: true - TargetRubyVersion: '2.1' + TargetRubyVersion: '2.4' Include: - - "./**/*.rb" + - "**/*.rb" Exclude: - bin/* - ".vendor/**/*" - "**/Gemfile" - "**/Rakefile" - pkg/**/* - spec/fixtures/**/* - vendor/**/* - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" -Metrics/LineLength: +Layout/LineLength: Description: People have wide screens, use them. Max: 200 -GetText: - Enabled: false -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false 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/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each Style/BlockDelimiters: Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to be consistent then. EnforcedStyle: braces_for_chaining -Style/BracesAroundHashParameters: - Description: Braces are required by Ruby 2.7. Cop removed from RuboCop v0.80.0. - See https://github.com/rubocop-hq/rubocop/pull/7643 - Enabled: false Style/ClassAndModuleChildren: Description: Compact style reduces the required amount of indentation. EnforcedStyle: compact Style/EmptyElse: Description: Enforce against empty else clauses, but allow `nil` for clarity. EnforcedStyle: empty Style/FormatString: 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/Lambda: Description: Prefer the keyword for easier discoverability. EnforcedStyle: literal Style/RegexpLiteral: Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 EnforcedStyle: percent_r 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/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma 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 +Performance/AncestorsInclude: + Enabled: true +Performance/BigDecimalWithNumericArgument: + Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true +Performance/Caller: + Enabled: true +Performance/CaseWhenSplat: + Enabled: true +Performance/Casecmp: + Enabled: true +Performance/CollectionLiteralInLoop: + Exclude: + - spec/**/* + Enabled: true +Performance/CompareWithBlock: + Enabled: true +Performance/ConstantRegexp: + Enabled: true +Performance/Count: + Enabled: true +Performance/Detect: + Enabled: true +Performance/DoubleStartEndWith: + Enabled: true +Performance/EndWith: + Enabled: true +Performance/FixedSize: + Enabled: true +Performance/FlatMap: + Enabled: true +Performance/MethodObjectAsBlock: + Enabled: true +Performance/RangeInclude: + Enabled: true +Performance/RedundantBlockCall: + Enabled: true +Performance/RedundantMatch: + Enabled: true +Performance/RedundantMerge: + Enabled: true +Performance/RedundantSortBlock: + Enabled: true +Performance/RedundantStringChars: + Enabled: true +Performance/RegexpMatch: + Enabled: true +Performance/ReverseEach: + Enabled: true +Performance/ReverseFirst: + Enabled: true +Performance/Size: + Enabled: true +Performance/SortReverse: + Enabled: true +Performance/Squeeze: + Enabled: true +Performance/StartWith: + Enabled: true +Performance/StringInclude: + Enabled: true +Performance/StringReplacement: + Enabled: true +Performance/Sum: + Enabled: true +Performance/TimesMap: + Enabled: true Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true -GetText/DecorateFunctionMessage: +Bundler/InsecureProtocolSource: + Enabled: false +Gemspec/DuplicatedAssignment: Enabled: false -GetText/DecorateStringFormattingUsingInterpolation: +Gemspec/OrderedDependencies: Enabled: false -GetText/DecorateStringFormattingUsingPercent: +Gemspec/RequiredRubyVersion: + Enabled: false +Gemspec/RubyVersionGlobalsUsage: + Enabled: false +Layout/ArgumentAlignment: + Enabled: false +Layout/BeginEndAlignment: + Enabled: false +Layout/ClosingHeredocIndentation: + Enabled: false +Layout/EmptyComment: + Enabled: false +Layout/EmptyLineAfterGuardClause: + Enabled: false +Layout/EmptyLinesAroundArguments: + Enabled: false +Layout/EmptyLinesAroundAttributeAccessor: Enabled: false Layout/EndOfLine: Enabled: false -Layout/IndentHeredoc: +Layout/FirstArgumentIndentation: + Enabled: false +Layout/HashAlignment: + Enabled: false +Layout/HeredocIndentation: + Enabled: false +Layout/LeadingEmptyLines: + Enabled: false +Layout/SpaceAroundMethodCallOperator: + Enabled: false +Layout/SpaceInsideArrayLiteralBrackets: + Enabled: false +Layout/SpaceInsideReferenceBrackets: + Enabled: false +Lint/BigDecimalNew: + Enabled: false +Lint/BooleanSymbol: + Enabled: false +Lint/ConstantDefinitionInBlock: + Enabled: false +Lint/DeprecatedOpenSSLConstant: + Enabled: false +Lint/DisjunctiveAssignmentInConstructor: + Enabled: false +Lint/DuplicateBranch: + Enabled: false +Lint/DuplicateElsifCondition: + Enabled: false +Lint/DuplicateRegexpCharacterClassElement: + Enabled: false +Lint/DuplicateRequire: + Enabled: false +Lint/DuplicateRescueException: + Enabled: false +Lint/EmptyBlock: + Enabled: false +Lint/EmptyClass: + Enabled: false +Lint/EmptyConditionalBody: + Enabled: false +Lint/EmptyFile: + Enabled: false +Lint/ErbNewArguments: + Enabled: false +Lint/FloatComparison: + Enabled: false +Lint/HashCompareByIdentity: + Enabled: false +Lint/IdentityComparison: + Enabled: false +Lint/InterpolationCheck: + Enabled: false +Lint/MissingCopEnableDirective: + Enabled: false +Lint/MixedRegexpCaptureTypes: + Enabled: false +Lint/NestedPercentLiteral: + Enabled: false +Lint/NoReturnInBeginEndBlocks: + Enabled: false +Lint/NonDeterministicRequireOrder: + Enabled: false +Lint/OrderedMagicComments: + Enabled: false +Lint/OutOfRangeRegexpRef: + Enabled: false +Lint/RaiseException: + Enabled: false +Lint/RedundantCopEnableDirective: + Enabled: false +Lint/RedundantRequireStatement: + Enabled: false +Lint/RedundantSafeNavigation: + Enabled: false +Lint/RedundantWithIndex: + Enabled: false +Lint/RedundantWithObject: + Enabled: false +Lint/RegexpAsCondition: + Enabled: false +Lint/ReturnInVoidContext: + Enabled: false +Lint/SafeNavigationConsistency: + Enabled: false +Lint/SafeNavigationWithEmpty: + Enabled: false +Lint/SelfAssignment: + Enabled: false +Lint/SendWithMixinArgument: + Enabled: false +Lint/ShadowedArgument: + Enabled: false +Lint/StructNewOverride: + Enabled: false +Lint/ToEnumArguments: + Enabled: false +Lint/ToJSON: + Enabled: false +Lint/TopLevelReturnWithArgument: + Enabled: false +Lint/TrailingCommaInAttributeDeclaration: + Enabled: false +Lint/UnexpectedBlockArity: + Enabled: false +Lint/UnmodifiedReduceAccumulator: + Enabled: false +Lint/UnreachableLoop: + Enabled: false +Lint/UriEscapeUnescape: + Enabled: false +Lint/UriRegexp: + Enabled: false +Lint/UselessMethodDefinition: + Enabled: false +Lint/UselessTimes: Enabled: false Metrics/AbcSize: Enabled: false Metrics/BlockLength: Enabled: false +Metrics/BlockNesting: + 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 +Migration/DepartmentName: + Enabled: false +Naming/AccessorMethodName: + Enabled: false +Naming/BlockParameterName: + Enabled: false +Naming/HeredocDelimiterCase: + Enabled: false +Naming/HeredocDelimiterNaming: + Enabled: false +Naming/MemoizedInstanceVariableName: + Enabled: false +Naming/MethodParameterName: + Enabled: false +Naming/RescuedExceptionsVariableName: + Enabled: false +RSpec/Be: + Enabled: false +RSpec/Capybara/CurrentPathExpectation: + Enabled: false +RSpec/Capybara/FeatureMethods: + Enabled: false +RSpec/Capybara/VisibilityMatcher: + Enabled: false +RSpec/ContextMethod: + Enabled: false +RSpec/ContextWording: + Enabled: false RSpec/DescribeClass: Enabled: false +RSpec/EmptyHook: + Enabled: false +RSpec/EmptyLineAfterExample: + Enabled: false +RSpec/EmptyLineAfterExampleGroup: + Enabled: false +RSpec/EmptyLineAfterHook: + Enabled: false RSpec/ExampleLength: Enabled: false -RSpec/MessageExpectation: +RSpec/ExampleWithoutDescription: + Enabled: false +RSpec/ExpectChange: + Enabled: false +RSpec/ExpectInHook: + Enabled: false +RSpec/FactoryBot/AttributeDefinedStatically: + Enabled: false +RSpec/FactoryBot/CreateList: + Enabled: false +RSpec/FactoryBot/FactoryClassName: + Enabled: false +RSpec/HooksBeforeExamples: + Enabled: false +RSpec/ImplicitBlockExpectation: + Enabled: false +RSpec/ImplicitSubject: + Enabled: false +RSpec/LeakyConstantDeclaration: + Enabled: false +RSpec/LetBeforeExamples: + Enabled: false +RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/MultipleSubjects: + Enabled: false RSpec/NestedGroups: Enabled: false +RSpec/PredicateMatcher: + Enabled: false +RSpec/ReceiveCounts: + Enabled: false +RSpec/ReceiveNever: + Enabled: false +RSpec/RepeatedExampleGroupBody: + Enabled: false +RSpec/RepeatedExampleGroupDescription: + Enabled: false +RSpec/RepeatedIncludeExample: + Enabled: false +RSpec/ReturnFromStub: + Enabled: false +RSpec/SharedExamples: + Enabled: false +RSpec/StubbedMock: + Enabled: false +RSpec/UnspecifiedException: + Enabled: false +RSpec/VariableDefinition: + Enabled: false +RSpec/VoidExpect: + Enabled: false +RSpec/Yield: + Enabled: false +Security/Open: + Enabled: false +Style/AccessModifierDeclarations: + Enabled: false +Style/AccessorGrouping: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false Style/AsciiComments: Enabled: false +Style/BisectedAttrAccessor: + Enabled: false +Style/CaseLikeIf: + Enabled: false +Style/ClassEqualityComparison: + Enabled: false +Style/CollectionCompact: + Enabled: false +Style/ColonMethodDefinition: + Enabled: false +Style/CombinableLoops: + Enabled: false +Style/CommentedKeyword: + Enabled: false +Style/Dir: + Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false +Style/DoubleCopDisableDirective: + Enabled: false +Style/EmptyBlockParameter: + Enabled: false +Style/EmptyLambdaParameter: + Enabled: false +Style/Encoding: + Enabled: false +Style/EvalWithLocation: + Enabled: false +Style/ExpandPathArguments: + Enabled: false +Style/ExplicitBlockArgument: + Enabled: false +Style/ExponentialNotation: + Enabled: false +Style/FloatDivision: + Enabled: false +Style/GlobalStdStream: + Enabled: false +Style/HashAsLastArrayItem: + Enabled: false +Style/HashLikeCase: + Enabled: false +Style/HashTransformKeys: + Enabled: false +Style/HashTransformValues: + Enabled: false Style/IfUnlessModifier: Enabled: false +Style/KeywordParametersOrder: + Enabled: false +Style/MinMax: + Enabled: false +Style/MixinUsage: + Enabled: false +Style/MultilineWhenThen: + Enabled: false +Style/NegatedIfElseCondition: + Enabled: false +Style/NegatedUnless: + Enabled: false +Style/NilLambda: + Enabled: false +Style/NumericPredicate: + Enabled: false +Style/OptionalBooleanParameter: + Enabled: false +Style/OrAssignment: + Enabled: false +Style/RandomWithOffset: + Enabled: false +Style/RedundantArgument: + Enabled: false +Style/RedundantAssignment: + Enabled: false +Style/RedundantCondition: + Enabled: false +Style/RedundantConditional: + Enabled: false +Style/RedundantFetchBlock: + Enabled: false +Style/RedundantFileExtensionInRequire: + Enabled: false +Style/RedundantRegexpCharacterClass: + Enabled: false +Style/RedundantRegexpEscape: + Enabled: false +Style/RedundantSelfAssignment: + Enabled: false +Style/RedundantSort: + Enabled: false +Style/RescueStandardError: + Enabled: false +Style/SingleArgumentDig: + Enabled: false +Style/SlicingWithRange: + Enabled: false +Style/SoleNestedConditional: + Enabled: false +Style/StderrPuts: + Enabled: false +Style/StringConcatenation: + Enabled: false +Style/Strip: + Enabled: false +Style/SwapValues: + Enabled: false Style/SymbolProc: Enabled: false +Style/TrailingBodyOnClass: + Enabled: false +Style/TrailingBodyOnMethodDefinition: + Enabled: false +Style/TrailingBodyOnModule: + Enabled: false +Style/TrailingCommaInHashLiteral: + Enabled: false +Style/TrailingMethodEndStatement: + Enabled: false +Style/UnpackFirst: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index e69de29..0000000 diff --git a/.sync.yml b/.sync.yml index 632c490..8a29bb7 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,59 +1,49 @@ --- ".gitlab-ci.yml": delete: true ".travis.yml": - global_env: + global_env: - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" deploy_to_forge: enabled: false branches: - release use_litmus: true litmus: provision_list: - ---travis_el - travis_deb - travis_el7 - travis_el8 complex: - collection: puppet_collection: - puppet6 provision_list: - travis_ub_6 - collection: puppet_collection: - puppet5 provision_list: - travis_ub_5 simplecov: true notifications: slack: secure: Wf7Wz3KC0G9ngPiDcOIpSqcCfdvwKQqZdNH/z3GMcj/OipMAdyFSAVnBvikIl7L1c0LMU9ATEpub+jYzViT7RZywaNyer6SRAfs6MIgAYo4xxF/mOnDHAxXeUYAsBXXL4sS3NX2XWMPa9ZWUeuUQKth8O4STWgAX298QZLyYx5k= appveyor.yml: delete: true Gemfile: optional: ":development": - gem: github_changelog_generator - git: https://github.com/skywinder/github-changelog-generator - ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 - condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') - - gem: puppet_litmus - git: https://github.com/puppetlabs/puppet_litmus - ref: main - condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0') - - gem: bolt - version: '2.32.0' - condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0') spec/spec_helper.rb: mock_with: ":rspec" coverage_report: true .gitpod.Dockerfile: unmanaged: false .gitpod.yml: unmanaged: false .github/workflows/nightly.yml: unmanaged: false .github/workflows/pr_test.yml: unmanaged: false diff --git a/.travis.yml b/.travis.yml index 3af64e6..c654691 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,137 +1,129 @@ --- os: linux dist: xenial language: ruby cache: bundler before_install: - bundle -v - rm -f Gemfile.lock - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - gem --version - bundle -v script: - 'SIMPLECOV=yes bundle exec rake $CHECK' bundler_args: --without system_tests rvm: - 2.5.7 env: global: - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" stages: - static - spec - acceptance jobs: fast_finish: true include: - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_ub_6]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_ub_6_puppet6 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_ub_5]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_ub_5_puppet5 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_deb]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_deb_puppet5 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_el7]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_el7_puppet5 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_el8]'" - "bundle exec rake 'litmus:install_agent[puppet5]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_el8_puppet5 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_deb]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_deb_puppet6 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_el7]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_el7_puppet6 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - + - bundler_args: --with system_tests before_script: - "bundle exec rake 'litmus:provision_list[travis_el8]'" - "bundle exec rake 'litmus:install_agent[puppet6]'" - "bundle exec rake litmus:install_module" - bundler_args: env: PLATFORMS=travis_el8_puppet6 rvm: 2.5.7 script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" stage: static - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec rvm: 2.4.5 stage: spec - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec rvm: 2.5.7 stage: spec branches: only: - main - /^v\d/ - release notifications: email: false slack: secure: Wf7Wz3KC0G9ngPiDcOIpSqcCfdvwKQqZdNH/z3GMcj/OipMAdyFSAVnBvikIl7L1c0LMU9ATEpub+jYzViT7RZywaNyer6SRAfs6MIgAYo4xxF/mOnDHAxXeUYAsBXXL4sS3NX2XWMPa9ZWUeuUQKth8O4STWgAX298QZLyYx5k= diff --git a/Gemfile b/Gemfile index 84b04e8..ae2b430 100644 --- a/Gemfile +++ b/Gemfile @@ -1,76 +1,73 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' def location_for(place_or_version, fake_version = nil) git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} file_url_regex = %r{\Afile:\/\/(?.*)} if place_or_version && (git_url = place_or_version.match(git_url_regex)) [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] else [place_or_version, { require: false }] end end ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments minor_version = ruby_version_segments[0..1].join('.') group :development do - 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 "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') - gem "puppet_litmus", require: false, git: 'https://github.com/puppetlabs/puppet_litmus', ref: 'main' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0') - gem "bolt", '2.32.0', require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0') + gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "github_changelog_generator", require: false +end +group :system_tests do + gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] hiera_version = ENV['HIERA_GEM_VERSION'] gems = {} gems['puppet'] = location_for(puppet_version) # If facter or hiera versions have been specified via the environment # variables gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} # If we're using a Puppet gem on Windows which handles its own win32-xxx gem # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). gems['win32-dir'] = ['<= 0.4.9', require: false] gems['win32-eventlog'] = ['<= 0.6.5', require: false] gems['win32-process'] = ['<= 0.7.5', require: false] gems['win32-security'] = ['<= 0.2.5', require: false] gems['win32-service'] = ['0.8.8', require: false] end gems.each do |gem_name, gem_params| gem gem_name, *gem_params end # Evaluate Gemfile.local and ~/.gemfile if they exist extra_gemfiles = [ "#{__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 # vim: syntax=ruby diff --git a/lib/facter/java_default_home.rb b/lib/facter/java_default_home.rb index 0f4d58e..dccbaf2 100644 --- a/lib/facter/java_default_home.rb +++ b/lib/facter/java_default_home.rb @@ -1,30 +1,32 @@ +# frozen_string_literal: true + # Fact: java_default_home # # Purpose: get absolute path of java system home # # Resolution: # Find the real java binary, and return the subsubdir # # Caveats: # java binary has to be found in $PATH # # Notes: # None Facter.add(:java_default_home) do confine kernel: ['Linux', 'OpenBSD'] java_default_home = nil setcode do java_bin = Facter::Util::Resolution.which('java').to_s.strip if java_bin.empty? nil else java_path = File.realpath(java_bin) - java_default_home = if java_path =~ %r{/jre/} + java_default_home = if %r{/jre/}.match?(java_path) File.dirname(File.dirname(File.dirname(java_path))) else File.dirname(File.dirname(java_path)) end end end java_default_home end diff --git a/lib/facter/java_libjvm_path.rb b/lib/facter/java_libjvm_path.rb index 7ae549f..cc3085b 100644 --- a/lib/facter/java_libjvm_path.rb +++ b/lib/facter/java_libjvm_path.rb @@ -1,32 +1,34 @@ +# frozen_string_literal: true + # Fact: java_libjvm_path # # Purpose: get path to libjvm.so # # Resolution: # Lists file in java default home and searches for the file # # Caveats: # Needs to list files recursively. Returns the first match # Needs working java_major_version fact # # Notes: # None Facter.add(:java_libjvm_path) do confine kernel: ['Linux', 'OpenBSD'] setcode do java_default_home = Facter.value(:java_default_home) java_major_version = Facter.value(:java_major_version) unless java_major_version.nil? java_libjvm_file = if java_major_version.to_i >= 11 Dir.glob("#{java_default_home}/lib/**/libjvm.so") else Dir.glob("#{java_default_home}/jre/lib/**/libjvm.so") end if java_libjvm_file.nil? || java_libjvm_file.empty? nil else File.dirname(java_libjvm_file[0]) end end end end diff --git a/lib/facter/java_major_version.rb b/lib/facter/java_major_version.rb index 3afd994..6ba4ec1 100644 --- a/lib/facter/java_major_version.rb +++ b/lib/facter/java_major_version.rb @@ -1,28 +1,30 @@ +# frozen_string_literal: true + # Fact: java_major_version # # Purpose: get Java's major version # # Resolution: # Tests for presence of java, returns nil if not present # returns output of "java -version" and splits on \n + '"' # eg. # # Caveats: # none # # Notes: # None Facter.add(:java_major_version) do java_major_version = nil setcode do java_version = Facter.value(:java_version) unless java_version.nil? java_major_version = if java_version.strip[0..1] == '1.' java_version.strip.split('_')[0].split('.')[1] else java_version.strip.split('.')[0] end end end java_major_version end diff --git a/lib/facter/java_patch_level.rb b/lib/facter/java_patch_level.rb index 2722d0b..d645155 100644 --- a/lib/facter/java_patch_level.rb +++ b/lib/facter/java_patch_level.rb @@ -1,26 +1,28 @@ +# frozen_string_literal: true + # Fact: java_patch_level # # Purpose: get Java's patch level # # Resolution: # Uses java_version fact splits on the patch number (after _ for 1.x and patch number for semver'ed javas) # # Caveats: # none # # Notes: # None Facter.add(:java_patch_level) do java_patch_level = nil setcode do java_version = Facter.value(:java_version) unless java_version.nil? if java_version.strip[0..1] == '1.' java_patch_level = java_version.strip.split('_')[1] unless java_version.nil? else java_patch_level = java_version.strip.split('.')[2] unless java_version.nil? end end end java_patch_level end diff --git a/lib/facter/java_version.rb b/lib/facter/java_version.rb index 6de4bb4..1c427a8 100644 --- a/lib/facter/java_version.rb +++ b/lib/facter/java_version.rb @@ -1,44 +1,46 @@ +# frozen_string_literal: true + # Fact: java_version # # Purpose: get full java version string # # Resolution: # Tests for presence of java, returns nil if not present # returns output of "java -version" and splits on '"' # # Caveats: # none # # Notes: # None Facter.add(:java_version) do # the OS-specific overrides need to be able to return nil, # to indicate "no java available". Usually returning nil # would mean that facter falls back to a lower priority # resolution, which would then trigger MODULES-2637. To # avoid that, we confine the "default" here to not run # on those OS. # Additionally, facter versions prior to 2.0.1 only support # positive matches, so this needs to be done manually in setcode. setcode do unless ['darwin'].include? Facter.value(:operatingsystem).downcase version = nil if Facter::Util::Resolution.which('java') Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line } end version end end end Facter.add(:java_version) do confine operatingsystem: 'Darwin' has_weight 100 setcode do - unless %r{Unable to find any JVMs matching version} =~ Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1') + unless Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1').include?('Unable to find any JVMs matching version') version = nil Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = Regexp.last_match(1) if %r{^.+ version \"(.+)\"} =~ line } version end end end diff --git a/metadata.json b/metadata.json index afbc9f8..71c1e3c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,87 +1,87 @@ { "name": "puppetlabs-java", "version": "6.5.0", "author": "puppetlabs", "summary": "Installs the correct Java package on various platforms.", "license": "Apache-2.0", "source": "git://github.com/puppetlabs/puppetlabs-java", "project_page": "https://github.com/puppetlabs/puppetlabs-java", "issues_url": "https://tickets.puppet.com/CreateIssueDetails!init.jspa?pid=10707&issuetype=1&team=Modules&customfield_14200=14302&labels=triage&customfield_10005=2147&summary=Issue+found+with+module%3A+puppetlabs-java", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.13.1 < 7.0.0" }, { "name": "puppet/archive", "version_requirement": ">= 1.1.0 < 5.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", "6", "7", "8" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "5", "6", "7", "8" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "6", "7" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ "6" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ "8", "9", "10" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "14.04", "16.04", "18.04", "20.04" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "11", "12", "15" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 5.5.10 < 8.0.0" } ], "template-url": "https://github.com/puppetlabs/pdk-templates#main", - "template-ref": "heads/main-0-g5afcd3d", + "template-ref": "heads/main-0-g4543421", "pdk-version": "1.18.1" } diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index 7d31564..ddefb71 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -1,280 +1,284 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' require 'pry' java_class_jre = "class { 'java':\n"\ " distribution => 'jre',\n"\ '}' java_class = "class { 'java': }" _sources = "file_line { 'non-free source':\n"\ " path => '/etc/apt/sources.list',\n"\ " match => \"deb http://osmirror.delivery.puppetlabs.net/debian/ ${::lsbdistcodename} main\",\n"\ " line => \"deb http://osmirror.delivery.puppetlabs.net/debian/ ${::lsbdistcodename} main non-free\",\n"\ '}' _sun_jre = "class { 'java':\n"\ " distribution => 'sun-jre',\n"\ '}' _sun_jdk = "class { 'java':\n"\ " distribution => 'sun-jdk',\n"\ '}' blank_version = "class { 'java':\n"\ " version => '',\n"\ '}' incorrect_distro = "class { 'java':\n"\ " distribution => 'xyz',\n"\ '}' blank_distro = "class { 'java':\n"\ " distribution => '',\n"\ '}' incorrect_package = "class { 'java':\n"\ " package => 'xyz',\n"\ '}' bogus_alternative = "class { 'java':\n"\ " java_alternative => 'whatever',\n"\ " java_alternative_path => '/whatever',\n"\ '}' # Oracle installs are disabled by default, because the links to valid oracle installations # change often. Look the parameters up from the Oracle download URLs at https://java.oracle.com and # enable the tests: oracle_enabled = false oracle_version_major = '8' oracle_version_minor = '201' oracle_version_build = '09' oracle_hash = '42970487e3af4f5aa5bca3f542482c60' install_oracle_jdk_jre = < '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jre', } java::oracle { 'test_oracle_jdk': version => '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jdk', } EOL install_oracle_jre_jce = < '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jre', jce => true, } EOL install_oracle_jdk_jce = < '#{oracle_version_major}', version_major => '#{oracle_version_major}u#{oracle_version_minor}', version_minor => 'b#{oracle_version_build}', url_hash => '#{oracle_hash}', java_se => 'jdk', jce => true, } EOL # AdoptOpenJDK URLs are quite generic, so tests are enabled by default # We need to test version 8 and >8 (here we use 9), because namings are different after version 8 adopt_enabled = true unless os[:family].casecmp('SLES').zero? adopt_version8_major = '8' adopt_version8_minor = '202' adopt_version8_build = '08' adopt_version9_major = '9' adopt_version9_full = '9.0.4' adopt_version9_build = '11' install_adopt_jdk_jre = < '#{adopt_version8_major}', version_major => '#{adopt_version8_major}u#{adopt_version8_minor}', version_minor => 'b#{adopt_version8_build}', java => 'jre', } java::adopt { 'test_adopt_jdk_version8': version => '#{adopt_version8_major}', version_major => '#{adopt_version8_major}u#{adopt_version8_minor}', version_minor => 'b#{adopt_version8_build}', java => 'jdk', } java::adopt { 'test_adopt_jre_version9': version => '#{adopt_version9_major}', version_major => '#{adopt_version9_full}', version_minor => '#{adopt_version9_build}', java => 'jre', } java::adopt { 'test_adopt_jdk_version9': version => '#{adopt_version9_major}', version_major => '#{adopt_version9_full}', version_minor => '#{adopt_version9_build}', java => 'jdk', } EOL sap_enabled = true sap_version7 = '7' sap_version7_full = '7.1.072' sap_version8 = '8' sap_version8_full = '8.1.065' sap_version11 = '11' sap_version11_full = '11.0.7' sap_version14 = '14' sap_version14_full = '14.0.1' install_sap_jdk_jre = < '#{sap_version7}', version_full => '#{sap_version7_full}', java => 'jdk', } java::sap { 'test_sap_jdk_version8': version => '#{sap_version8}', version_full => '#{sap_version8_full}', java => 'jdk', } java::sap { 'test_sap_jre_version11': version => '#{sap_version11}', version_full => '#{sap_version11_full}', java => 'jre', } java::sap { 'test_sap_jdk_version11': version => '#{sap_version11}', version_full => '#{sap_version11_full}', java => 'jdk', } java::sap { 'test_sap_jre_version14': version => '#{sap_version14}', version_full => '#{sap_version14_full}', java => 'jre', } java::sap { 'test_sap_jdk_version14': version => '#{sap_version14}', version_full => '#{sap_version14_full}', java => 'jdk', } EOL -context 'installing java jre', unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do - it 'installs jre' do - idempotent_apply(java_class_jre) +describe 'installing' do + context 'installing java jre' do + it 'installs jre' do + idempotent_apply(java_class_jre) + end end -end -context 'installing java jdk', unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do - it 'installs jdk' do - idempotent_apply(java_class) + context 'installing java jdk' do + it 'installs jdk' do + idempotent_apply(java_class) + end end -end -context 'with failure cases' do - it 'fails to install java with a blank version' do - apply_manifest(blank_version, expect_failures: true) - end + context 'with failure cases' do + it 'fails to install java with a blank version' do + apply_manifest(blank_version, expect_failures: true) + end - it 'fails to install java with an incorrect distribution' do - apply_manifest(incorrect_distro, expect_failures: true) - end + it 'fails to install java with an incorrect distribution' do + apply_manifest(incorrect_distro, expect_failures: true) + end - it 'fails to install java with a blank distribution' do - apply_manifest(blank_distro, expect_failures: true) - end + it 'fails to install java with a blank distribution' do + apply_manifest(blank_distro, expect_failures: true) + end - it 'fails to install java with an incorrect package' do - apply_manifest(incorrect_package, expect_failures: true) - end + it 'fails to install java with an incorrect package' do + apply_manifest(incorrect_package, expect_failures: true) + end - it 'fails on debian or RHEL when passed fake java_alternative and path' do - if os[:family] == 'sles' - apply_manifest(bogus_alternative, catch_failures: true) - else - apply_manifest(bogus_alternative, expect_failures: true) + it 'fails on debian or RHEL when passed fake java_alternative and path' do + if os[:family] == 'sles' + apply_manifest(bogus_alternative, catch_failures: true) + else + apply_manifest(bogus_alternative, expect_failures: true) + end end end -end -context 'java::oracle', if: oracle_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do - let(:install_path) do - (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' - end + context 'java::oracle', if: oracle_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do + let(:install_path) do + (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' + end - let(:version_suffix) do - (os[:family] == 'redhat') ? '-amd64' : '' - end + let(:version_suffix) do + (os[:family] == 'redhat') ? '-amd64' : '' + end - it 'installs oracle jdk and jre' do - idempotent_apply(install_oracle_jdk_jre) - jdk_result = shell("test ! -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar") - jre_result = shell("test ! -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar") - expect(jdk_result.exit_code).to eq(0) - expect(jre_result.exit_code).to eq(0) - end + it 'installs oracle jdk and jre' do + idempotent_apply(install_oracle_jdk_jre) + jdk_result = shell("test ! -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar") + jre_result = shell("test ! -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar") + expect(jdk_result.exit_code).to eq(0) + expect(jre_result.exit_code).to eq(0) + end - it 'installs oracle jdk with jce' do - idempotent_apply(install_oracle_jdk_jce) - result = shell("test -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar") - expect(result.exit_code).to eq(0) - end + it 'installs oracle jdk with jce' do + idempotent_apply(install_oracle_jdk_jce) + result = shell("test -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar") + expect(result.exit_code).to eq(0) + end - it 'installs oracle jre with jce' do - idempotent_apply(install_oracle_jre_jce) - result = shell("test -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar") - expect(result.exit_code).to eq(0) + it 'installs oracle jre with jce' do + idempotent_apply(install_oracle_jre_jce) + result = shell("test -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar") + expect(result.exit_code).to eq(0) + end end -end -context 'java::adopt', if: adopt_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do - let(:install_path) do - (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' - end + context 'java::adopt', if: adopt_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do + let(:install_path) do + (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' + end - let(:version_suffix) do - (os[:family] == 'redhat') ? '-amd64' : '' - end + let(:version_suffix) do + (os[:family] == 'redhat') ? '-amd64' : '' + end - it 'installs adopt jdk and jre' do - idempotent_apply(install_adopt_jdk_jre) + it 'installs adopt jdk and jre' do + idempotent_apply(install_adopt_jdk_jre) + end end -end -context 'java::adopt', if: sap_enabled && ['Sles'].include?(os[:family]), unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do - let(:install_path) do - (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' - end + context 'java::adopt', if: sap_enabled && ['Sles'].include?(os[:family]), unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do + let(:install_path) do + (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' + end - it 'installs adopt jdk and jre' do - idempotent_apply(install_sap_jdk_jre) + it 'installs adopt jdk and jre' do + idempotent_apply(install_sap_jdk_jre) + end end end diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 0480ea6..0792d6e 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -1,251 +1,253 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java', type: :class do context 'when select openjdk for CentOS 5.8' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '5.8' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.6.0/') } end context 'when select openjdk for CentOS 6.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '6.3' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0/') } end context 'when select openjdk for CentOS 7.1.1503' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '7.1.1503' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.8.0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0/') } end context 'when select openjdk for CentOS 6.2' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '6.2' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } it { is_expected.not_to contain_exec('update-java-alternatives') } end context 'when select Oracle JRE with alternatives for CentOS 6.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '6.3' }, architecture: 'x86_64' } } } let(:params) { { 'package' => 'jre', 'java_alternative' => '/usr/bin/java', 'java_alternative_path' => '/usr/java/jre1.7.0_67/bin/java' } } it { is_expected.to contain_package('java').with_name('jre') } it { is_expected.to contain_exec('create-java-alternatives').with_command('alternatives --install /usr/bin/java java /usr/java/jre1.7.0_67/bin/java 20000') } it { is_expected.to contain_exec('update-java-alternatives').with_command('alternatives --set java /usr/java/jre1.7.0_67/bin/java') } end context 'when select passed value for CentOS 5.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '5.3' }, architecture: 'x86_64' } } } let(:params) { { 'package' => 'jdk', 'java_home' => '/usr/local/lib/jre' } } it { is_expected.to contain_package('java').with_name('jdk') } it { is_expected.not_to contain_exec('update-java-alternatives') } end context 'when select default for CentOS 5.3' do let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '5.3' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } it { is_expected.not_to contain_exec('update-java-alternatives') } end context 'when select jdk for Debian Buster (10.0)' do let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'buster' }, release: { major: '10' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jdk' } } it { is_expected.to contain_package('java').with_name('openjdk-11-jdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } end context 'when select jre for Debian Buster (10.0)' do let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'buster' }, release: { major: '10' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('openjdk-11-jre-headless') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } end context 'when select jdk for Ubuntu Trusty (14.04)' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'trusty' }, release: { major: '14.04' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jdk' } } it { is_expected.to contain_package('java').with_name('openjdk-7-jdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/') } end context 'when select jre for Ubuntu Trusty (14.04)' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'trusty' }, release: { major: '14.04' }, architecture: 'amd64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('openjdk-7-jre-headless') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/') } end context 'when select jdk for Ubuntu xenial (16.04) on ARM' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'xenial' }, release: { major: '16.04' }, architecture: 'armv7l' } } } let(:params) { { 'distribution' => 'jdk' } } it { is_expected.to contain_package('java').with_name('openjdk-8-jdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-armhf/') } end context 'when select jdk for Ubuntu xenial (16.04) on ARM64' do let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'xenial' }, release: { major: '16.04' }, architecture: 'aarch64' } } } let(:params) { { 'distribution' => 'jdk' } } it { is_expected.to contain_package('java').with_name('openjdk-8-jdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-arm64/') } end context 'when select openjdk for Oracle Linux' do let(:facts) { { os: { family: 'RedHat', name: 'OracleLinux', release: { full: '6.4' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk-devel') } end context 'when select openjdk for Oracle Linux 6.2' do let(:facts) { { os: { family: 'RedHat', name: 'OracleLinux', release: { full: '6.2' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1.6.0-openjdk-devel') } end context 'when select passed value for Oracle Linux' do let(:facts) { { os: { family: 'RedHat', name: 'OracleLinux', release: { full: '6.3' }, architecture: 'x86_64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } end context 'when select passed value for Scientific Linux' do let(:facts) { { os: { family: 'RedHat', name: 'Scientific', release: { full: '6.4' }, architecture: 'x86_64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0/') } end context 'when select passed value for Scientific Linux CERN (SLC)' do let(:facts) { { os: { family: 'RedHat', name: 'SLC', release: { full: '6.4' }, architecture: 'x86_64' } } } let(:params) { { 'distribution' => 'jre' } } it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0/') } end context 'when select default for OpenSUSE 12.3' do let(:facts) { { os: { family: 'Suse', name: 'OpenSUSE', release: { major: '12.3' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_7_0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/') } end context 'when select default for SLES 11.3' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '11.3' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_6_0-ibm-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.6.0-ibm-1.6.0/') } end context 'when select default for SLES 11.4' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '11.4' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_7_1-ibm-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.7.1-ibm-1.7.1/') } end context 'when select default for SLES 12.0' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '12.0', major: '12' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_7_0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/') } end context 'when select default for SLES 12.1' do let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '12.1', major: '12' }, architecture: 'x86_64' } } } it { is_expected.to contain_package('java').with_name('java-1_8_0-openjdk-devel') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/') } end describe 'custom java package' do let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'jessie' }, release: { major: '8' }, architecture: 'amd64' } } } context 'when all params provided' do let(:params) do { 'distribution' => 'custom', 'package' => 'custom_jdk', 'java_alternative' => 'java-custom_jdk', 'java_alternative_path' => '/opt/custom_jdk/bin/java', 'java_home' => '/opt/custom_jdk', } end it { is_expected.to contain_package('java').with_name('custom_jdk') } it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/opt/custom_jdk') } it { is_expected.to contain_exec('update-java-alternatives').with_command('update-java-alternatives --set java-custom_jdk --jre') } end context 'with missing parameters' do let(:params) do { 'distribution' => 'custom', 'package' => 'custom_jdk', } end it do expect { catalogue }.to raise_error Puppet::Error, %r{is not supported. Missing default values} end end end describe 'incompatible OSs' do [ { os: { family: 'windows', name: 'windows', release: { full: '8.1' }, }, }, { os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0' }, }, }, { os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000' }, }, }, { os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216' }, }, }, { os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016' }, }, }, ].each do |facts| let(:facts) { facts } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/defines/adopt_spec.rb b/spec/defines/adopt_spec.rb index 514e788..400aa1f 100644 --- a/spec/defines/adopt_spec.rb +++ b/spec/defines/adopt_spec.rb @@ -1,358 +1,360 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java::adopt', type: :define do context 'with CentOS 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '6.0' } } } } context 'when manage_symlink is set to true' do let(:params) do { ensure: 'present', version: '11', java: 'jdk', basedir: '/usr/java', manage_symlink: true, symlink_name: 'java_home', } end let(:title) { 'jdk11_symlink' } it { is_expected.to contain_file('/usr/java/java_home') } end context 'when manage_symlink is not set' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11_nosymlink' } it { is_expected.not_to contain_file('/usr/java/java_home') } end context 'when AdoptOpenJDK Java 8 JDK' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JDK' do let(:params) { { ensure: 'present', version: '9', java: 'jdk' } } let(:title) { 'jdk9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JDK' do let(:params) { { ensure: 'present', version: '10', java: 'jdk' } } let(:title) { 'jdk10' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JDK' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JDK' do let(:params) { { ensure: 'present', version: '12', java: 'jdk' } } let(:title) { 'jdk12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when AdoptOpenJDK Java 8 JRE' do let(:params) { { ensure: 'present', version: '8', java: 'jre' } } let(:title) { 'jre8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JRE' do let(:params) { { ensure: 'present', version: '9', java: 'jre' } } let(:title) { 'jre9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JRE' do let(:params) { { ensure: 'present', version: '10', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JRE' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JRE' do let(:params) { { ensure: 'present', version: '12', java: 'jre' } } let(:title) { 'jre12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_major: '8u202', version_minor: 'b08', java: 'jdk', } end let(:title) { 'jdk8' } let(:pre_condition) do <<-EOL java::adopt { 'jdk8172': ensure => 'present', version_major => '8u172', version_minor => 'b11', java => 'jdk', } EOL end it { is_expected.to compile } end context 'when specifying package_type tar.gz and basedir' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', package_type: 'tar.gz', } end let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz -C /usr/java') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when manage_basedir is set to true' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', manage_basedir: true, } end let(:title) { 'jdk8' } it { is_expected.to contain_file('/usr/java') } end end context 'with Ubuntu 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '16.04' } } } } context 'when AdoptOpenJDK Java 8 JDK' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JDK' do let(:params) { { ensure: 'present', version: '9', java: 'jdk' } } let(:title) { 'jdk9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JDK' do let(:params) { { ensure: 'present', version: '10', java: 'jdk' } } let(:title) { 'jdk10' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JDK' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JDK' do let(:params) { { ensure: 'present', version: '12', java: 'jdk' } } let(:title) { 'jdk12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when AdoptOpenJDK Java 8 JRE' do let(:params) { { ensure: 'present', version: '8', java: 'jre' } } let(:title) { 'jre8' } it { is_expected.to contain_archive('/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').with_command('tar -zxf /tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz]') } end context 'when AdoptOpenJDK Java 9 JRE' do let(:params) { { ensure: 'present', version: '9', java: 'jre' } } let(:title) { 'jre9' } it { is_expected.to contain_archive('/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').with_command('tar -zxf /tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz]') } end context 'when AdoptOpenJDK Java 10 JRE' do let(:params) { { ensure: 'present', version: '10', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').with_command('tar -zxf /tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz]') } end context 'when AdoptOpenJDK Java 11 JRE' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').with_command('tar -zxf /tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz]') } end context 'when AdoptOpenJDK Java 12 JRE' do let(:params) { { ensure: 'present', version: '12', java: 'jre' } } let(:title) { 'jre12' } it { is_expected.to contain_archive('/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').with_command('tar -zxf /tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz -C /usr/lib/jvm') } it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz]') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_major: '8u202', version_minor: 'b08', java: 'jdk', } end let(:title) { 'jdk8' } let(:pre_condition) do <<-EOL java::adopt { 'jdk8172': ensure => 'present', version_major => '8u172', version_minor => 'b11', java => 'jdk', } EOL end it { is_expected.to compile } end end describe 'incompatible OSes' do [ { kernel: 'Windows', os: { family: 'Windows', name: 'Windows', release: { full: '8.1', }, }, }, { kernel: 'Darwin', os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016', }, }, }, ].each do |facts| let(:facts) { facts } let(:title) { 'jdk' } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/defines/download_spec.rb b/spec/defines/download_spec.rb index ae8ca75..f120c50 100644 --- a/spec/defines/download_spec.rb +++ b/spec/defines/download_spec.rb @@ -1,158 +1,160 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java::download', type: :define do let(:url) { 'http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz' } context 'with CentOS 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '6.0' } } } } context 'when passing URL to url parameter' do let(:params) do { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url, } end let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.rpm') } end context 'when no url provided' do let(:params) do { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', } end let(:title) { 'jdk8' } it { is_expected.to raise_error Puppet::Error } end context 'when manage_symlink is set to true' do let(:params) do { ensure: 'present', version: '6', java_se: 'jdk', basedir: '/usr/java', manage_symlink: true, symlink_name: 'java_home', url: url, } end let(:title) { 'jdk6' } it { is_expected.to contain_file('/usr/java/java_home') } end context 'when manage_symlink is not set' do let(:params) do { ensure: 'present', version: '6', java_se: 'jdk', basedir: '/usr/java', url: url, } end let(:title) { 'jdk6_nosymlink' } it { is_expected.not_to contain_file('/usr/java/java_home') } end end context 'with Ubuntu 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '16.04' } } } } context 'when passing URL to url parameter' do let(:params) { { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.tar.gz') } end end context 'with Debian 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Debian', release: { full: '10.0' } } } } context 'when passing URL to url parameter' do let(:params) { { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.tar.gz') } end end describe 'incompatible OSes' do [ { kernel: 'Windows', os: { family: 'Windows', name: 'Windows', release: { full: '8.1', }, }, }, { kernel: 'Darwin', os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016', }, }, }, ].each do |facts| let(:facts) { facts } let(:title) { 'jdk' } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/defines/sap_spec.rb b/spec/defines/sap_spec.rb index 9d10686..ee4fb88 100644 --- a/spec/defines/sap_spec.rb +++ b/spec/defines/sap_spec.rb @@ -1,255 +1,257 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java::sap', type: :define do context 'with CentOS 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '6.0' } } } } context 'when manage_symlink is set to true' do let(:params) do { ensure: 'present', version: '11', java: 'jdk', basedir: '/usr/java', manage_symlink: true, symlink_name: 'java_home', } end let(:title) { 'jdk11_symlink' } it { is_expected.to contain_file('/usr/java/java_home') } end context 'when manage_symlink is not set' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11_nosymlink' } it { is_expected.not_to contain_file('/usr/java/java_home') } end context 'when sapjvm 7' do let(:params) { { ensure: 'present', version: '7', java: 'jdk' } } let(:title) { 'jdk7' } it { is_expected.to contain_archive('/tmp/sapjvm-7.1.072-linux-x64.zip') } end context 'when sapjvm 8' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } end context 'when sapmachine 11 jdk' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 11 jre' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jdk' do let(:params) { { ensure: 'present', version: '14', java: 'jdk' } } let(:title) { 'jdk14' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-14.0.1_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jre' do let(:params) { { ensure: 'present', version: '14', java: 'jre' } } let(:title) { 'jre14' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-14.0.1_linux-x64_bin.tar.gz') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_full: '11.0.7', java: 'jdk', } end let(:title) { 'jdk1107' } let(:pre_condition) do <<-EOL java::sap { 'jdk1106': ensure => 'present', version_full => '11.0.6', java => 'jdk', } EOL end it { is_expected.to compile } end context 'when specifying basedir' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', } end let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } end context 'when manage_basedir is set to true' do let(:params) do { ensure: 'present', version: '8', java: 'jdk', basedir: '/usr/java', manage_basedir: true, } end let(:title) { 'jdk8' } it { is_expected.to contain_file('/usr/java') } end end context 'with Ubuntu 64-bit' do let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '16.04' } } } } context 'when sapjvm 7' do let(:params) { { ensure: 'present', version: '7', java: 'jdk' } } let(:title) { 'jdk7' } it { is_expected.to contain_archive('/tmp/sapjvm-7.1.072-linux-x64.zip') } end context 'when sapjvm 8' do let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } let(:title) { 'jdk8' } it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } end context 'when sapmachine 11 jdk' do let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } let(:title) { 'jdk11' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 11 jre' do let(:params) { { ensure: 'present', version: '11', java: 'jre' } } let(:title) { 'jre11' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-11.0.7_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jdk' do let(:params) { { ensure: 'present', version: '14', java: 'jdk' } } let(:title) { 'jdk14' } it { is_expected.to contain_archive('/tmp/sapmachine-jdk-14.0.1_linux-x64_bin.tar.gz') } end context 'when sapmachine 14 jre' do let(:params) { { ensure: 'present', version: '14', java: 'jre' } } let(:title) { 'jre14' } it { is_expected.to contain_archive('/tmp/sapmachine-jre-14.0.1_linux-x64_bin.tar.gz') } end context 'when installing multiple versions' do let(:params) do { ensure: 'present', version_full: '11.0.7', java: 'jdk', } end let(:title) { 'jdk1107' } let(:pre_condition) do <<-EOL java::sap { 'jdk1106': ensure => 'present', version_full => '11.0.6', java => 'jdk', } EOL end it { is_expected.to compile } end end describe 'incompatible OSes' do [ { kernel: 'Windows', os: { family: 'Windows', name: 'Windows', release: { full: '8.1', }, }, }, { kernel: 'Darwin', os: { family: 'Darwin', name: 'Darwin', release: { full: '13.3.0', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '7100-02-00-000', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '6100-07-04-1216', }, }, }, { kernel: 'AIX', os: { family: 'AIX', name: 'AIX', release: { full: '5300-12-01-1016', }, }, }, ].each do |facts| let(:facts) { facts } let(:title) { 'jdk' } it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} end end end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 3c3b402..664fc0e 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + UNSUPPORTED_PLATFORMS = ['darwin', 'windows'].freeze diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 2e897cb..ce4d062 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,28 +1,30 @@ +# frozen_string_literal: true + if ENV['COVERAGE'] == 'yes' require 'simplecov' require 'simplecov-console' require 'codecov' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console, SimpleCov::Formatter::Codecov, ] SimpleCov.start do track_files 'lib/**/*.rb' add_filter '/spec' # do not track vendored files add_filter '/vendor' add_filter '/.vendor' # do not track gitignored files # this adds about 4 seconds to the coverage check # this could definitely be optimized add_filter do |f| # system returns true if exit status is 0, which with git-check-ignore means file is ignored system("git check-ignore --quiet #{f.filename}") end end end diff --git a/spec/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index 31ecd68..11fb206 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -1,54 +1,56 @@ +# frozen_string_literal: true + require 'spec_helper' java_7_path = '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java' java_7_home = '/usr/lib/jvm/java-7-openjdk-amd64' java_8_path = '/usr/lib/jvm/oracle-java8-jre-amd64/bin/java' java_8_home = '/usr/lib/jvm/oracle-java8-jre-amd64' def unlink_and_delete(filename) if File.symlink?(filename) File.unlink(filename) end return unless File.exist?(filename) File.delete(filename) end def symlink_and_test(symlink_path, java_home) File.symlink(symlink_path, './java_test') expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('./java_test') expect(File).to receive(:realpath).with('./java_test').and_return(symlink_path) expect(Facter.value(:java_default_home)).to eql java_home end describe 'java_default_home' do before(:each) do Facter.clear allow(Facter.fact(:kernel)).to receive(:value).once.and_return('Linux') end context 'when java found in PATH' do context 'when java is in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java' do it do unlink_and_delete('./java_test') symlink_and_test(java_7_path, java_7_home) unlink_and_delete('./java_test') end end context 'when java is in /usr/lib/jvm/oracle-java8-jre-amd64/bin/java' do it do unlink_and_delete('./java_test') symlink_and_test(java_8_path, java_8_home) unlink_and_delete('./java_test') end end end context 'when java not present, return nil' do it do allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls expect(Facter::Util::Resolution).to receive(:which).with('java').at_least(1).and_return(nil) expect(Facter.value(:java_default_home)).to be_nil end end end diff --git a/spec/unit/facter/java_libjvm_path_spec.rb b/spec/unit/facter/java_libjvm_path_spec.rb index 3efcb47..dde5aa5 100644 --- a/spec/unit/facter/java_libjvm_path_spec.rb +++ b/spec/unit/facter/java_libjvm_path_spec.rb @@ -1,26 +1,28 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java_libjvm_path' do let(:java_default_home) { '/usr/lib/jvm/java-8-openjdk-amd64' } before(:each) do Facter.clear allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') allow(Facter.fact(:java_default_home)).to receive(:value).and_return(java_default_home) end context 'when libjvm exists' do it do allow(Facter.fact(:java_major_version)).to receive(:value).and_return(8) allow(Dir).to receive(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").and_return(['/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so']) expect(Facter.value(:java_libjvm_path)).to eql '/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server' end end context 'when libjvm does not exist' do it do allow(Dir).to receive(:glob).with("#{java_default_home}/lib/**/libjvm.so").and_return([]) expect(Facter.value(:java_libjvm_path)).to be nil end end end diff --git a/spec/unit/facter/java_major_version_spec.rb b/spec/unit/facter/java_major_version_spec.rb index 3b50e00..62a3df7 100644 --- a/spec/unit/facter/java_major_version_spec.rb +++ b/spec/unit/facter/java_major_version_spec.rb @@ -1,25 +1,27 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java_major_version' do before(:each) do Facter.clear end context 'when java_version fact present, returns major version' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71') end it do expect(Facter.fact(:java_major_version).value).to eq('7') end end context 'when java not present, returns nil' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return(nil) end it do expect(Facter.fact(:java_major_version).value).to be_nil end end end diff --git a/spec/unit/facter/java_patch_level_spec.rb b/spec/unit/facter/java_patch_level_spec.rb index 4287b29..216fdec 100644 --- a/spec/unit/facter/java_patch_level_spec.rb +++ b/spec/unit/facter/java_patch_level_spec.rb @@ -1,25 +1,27 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'java_patch_level' do before(:each) do Facter.clear end context 'when java is installed returns java patch version extracted from java_version fact' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71') end it do expect(Facter.fact(:java_patch_level).value).to eq('71') end end context 'when java is not installed returns nil' do before :each do allow(Facter.fact(:java_version)).to receive(:value).and_return('nil') end it do expect(Facter.fact(:java_patch_level).value).to be_nil end end end diff --git a/spec/unit/facter/java_version_spec.rb b/spec/unit/facter/java_version_spec.rb index 5d65a04..bb4b167 100644 --- a/spec/unit/facter/java_version_spec.rb +++ b/spec/unit/facter/java_version_spec.rb @@ -1,93 +1,95 @@ +# frozen_string_literal: true + require 'spec_helper' openjdk_7_output = "Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true\n"\ "openjdk version \"1.7.0_71\"\n"\ "OpenJDK Runtime Environment (build 1.7.0_71-b14)\n"\ "OpenJDK 64-Bit Server VM (build 24.71-b01, mixed mode)\n" jdk_7_hotspot_output = "Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true\n"\ "java version \"1.7.0_71\"\n"\ "Java(TM) SE Runtime Environment (build 1.7.0_71-b14)\n"\ "Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)\n" describe 'java_version' do before(:each) do Facter.clear end context 'when java present, returns java version' do context 'on OpenBSD', with_env: true do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') end let(:facts) { { operatingsystem: 'OpenBSD' } } it do expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('/usr/local/jdk-1.7.0/jre/bin/java') expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(openjdk_7_output) expect(Facter.value(:java_version)).to eq('1.7.0_71') end end context 'when on Darwin' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin') end let(:facts) { { operatingsystem: 'Darwin' } } it do expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home') expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) expect(Facter.value(:java_version)).to eql '1.7.0_71' end end context 'when on other systems' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS') end let(:facts) { { operatingsystem: 'MyOS' } } it do expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('/path/to/java') expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) expect(Facter.value(:java_version)).to eq('1.7.0_71') end end end context 'when java not present, returns nil' do context 'on OpenBSD', with_env: true do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') end let(:facts) { { operatingsystem: 'OpenBSD' } } it do allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls allow(Facter::Util::Resolution).to receive(:which).and_return(nil) expect(Facter.value(:java_version)).to be_nil end end context 'when on Darwin' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin') end let(:facts) { { operatingsystem: 'Darwin' } } it do expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').at_least(1).and_return('Unable to find any JVMs matching version "(null)".') expect(Facter.value(:java_version)).to be_nil end end context 'when on other systems' do before(:each) do allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS') end let(:facts) { { operatingsystem: 'MyOS' } } it do expect(Facter::Util::Resolution).to receive(:which).at_least(1).with('java').and_return(false) expect(Facter.value(:java_version)).to be_nil end end end end