diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..12ed4ff1 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM puppet/pdk:latest + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 00000000..cc4675e5 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,34 @@ +# devcontainer + + +For format details, see https://aka.ms/devcontainer.json. + +For config options, see the README at: +https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet + +``` json +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "pdk --version", +} +``` + + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..fe7a8b12 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "bash", + } + } + }, + + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/.fixtures.yml b/.fixtures.yml index 34bf88cd..591090fc 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -10,6 +10,17 @@ fixtures: file_concat: 'https://github.com/electrical/puppet-lib-file_concat.git' systemd: 'https://github.com/camptocamp/puppet-systemd.git' cron: 'https://github.com/voxpupuli/puppet-cron.git' - cron_core: 'https://github.com/puppetlabs/puppetlabs-cron_core.git' - yumrepo_core: 'https://github.com/puppetlabs/puppetlabs-yumrepo_core.git' - augeas_core: 'https://github.com/puppetlabs/puppetlabs-augeas_core.git' + provision: 'https://github.com/puppetlabs/provision.git' + puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' + cron_core: + repo: https://github.com/puppetlabs/puppetlabs-cron_core.git + puppet_version: ">= 6.0.0" + yumrepo_core: + repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git + puppet_version: ">= 6.0.0" + augeas_core: + repo: https://github.com/puppetlabs/puppetlabs-augeas_core.git + puppet_version: ">= 6.0.0" + symlinks: + puppetdb: '#{source_dir}' diff --git a/.github/workflows/auto_release.yml b/.github/workflows/auto_release.yml new file mode 100644 index 00000000..f4aed440 --- /dev/null +++ b/.github/workflows/auto_release.yml @@ -0,0 +1,90 @@ +name: "Auto release" + +on: + workflow_dispatch: + +env: + HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 + HONEYCOMB_DATASET: litmus tests + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + auto_release: + name: "Automatic release prep" + runs-on: ubuntu-20.04 + + steps: + + - name: "Honeycomb: Start recording" + uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1 + with: + apikey: ${{ env.HONEYCOMB_WRITEKEY }} + dataset: ${{ env.HONEYCOMB_DATASET }} + job-status: ${{ job.status }} + + - name: "Honeycomb: start first step" + run: | + echo STEP_ID="auto-release" >> $GITHUB_ENV + echo STEP_START=$(date +%s) >> $GITHUB_ENV + - name: "Checkout Source" + if: ${{ github.repository_owner == 'puppetlabs' }} + uses: actions/checkout@v2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: "PDK Release prep" + uses: docker://puppet/iac_release:ci + with: + args: 'release prep --force' + env: + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: "Get Version" + if: ${{ github.repository_owner == 'puppetlabs' }} + id: gv + run: | + echo "::set-output name=ver::$(jq --raw-output .version metadata.json)" + + - name: "Check if a release is necessary" + if: ${{ github.repository_owner == 'puppetlabs' }} + id: check + run: | + git diff --quiet CHANGELOG.md && echo "::set-output name=release::false" || echo "::set-output name=release::true" + + - name: "Commit changes" + if: ${{ github.repository_owner == 'puppetlabs' && steps.check.outputs.release == 'true' }} + run: | + git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com" + git config --local user.name "GitHub Action" + git add . + git commit -m "Release prep v${{ steps.gv.outputs.ver }}" + + - name: Create Pull Request + id: cpr + uses: puppetlabs/peter-evans-create-pull-request@v3 + if: ${{ github.repository_owner == 'puppetlabs' && steps.check.outputs.release == 'true' }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Release prep v${{ steps.gv.outputs.ver }}" + branch: "release-prep" + delete-branch: true + title: "Release prep v${{ steps.gv.outputs.ver }}" + body: | + Automated release-prep through [pdk-templates](https://github.com/puppetlabs/pdk-templates/blob/main/moduleroot/.github/workflows/auto_release.yml.erb) from commit ${{ github.sha }}. + Please verify before merging: + - [ ] last [nightly](https://github.com/${{ github.repository }}/actions/workflows/nightly.yml) run is green + - [ ] [Changelog](https://github.com/${{ github.repository }}/blob/release-prep/CHANGELOG.md) is readable and has no unlabeled pull requests + - [ ] Ensure the [changelog](https://github.com/${{ github.repository }}/blob/release-prep/CHANGELOG.md) version and [metadata](https://github.com/${{ github.repository }}/blob/release-prep/metadata.json) version match + labels: "maintenance" + + - name: PR outputs + if: ${{ github.repository_owner == 'puppetlabs' && steps.check.outputs.release == 'true' }} + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" + + - name: "Honeycomb: Record finish step" + if: ${{ always() }} + run: | + buildevents step $TRACE_ID $STEP_ID $STEP_START 'Finished auto release workflow' diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 00000000..1b06c471 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,16 @@ +name: "nightly" + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + Spec: + uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" + secrets: "inherit" + + Acceptance: + needs: Spec + uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" + secrets: "inherit" diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml new file mode 100644 index 00000000..fd310e65 --- /dev/null +++ b/.github/workflows/pr_test.yml @@ -0,0 +1,185 @@ +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: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1 + with: + apikey: ${{ env.HONEYCOMB_WRITEKEY }} + dataset: ${{ env.HONEYCOMB_DATASET }} + job-status: ${{ job.status }} + + - name: "Honeycomb: Start first step" + run: | + echo STEP_ID=setup-environment >> $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: ruby/setup-ruby@v1 + if: ${{ github.repository_owner == 'puppetlabs' }} + with: + ruby-version: "2.7" + bundler-cache: true + + - name: Print bundle environment + if: ${{ github.repository_owner == 'puppetlabs' }} + run: | + echo ::group::bundler environment + buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env + echo ::endgroup:: + + - name: "Honeycomb: Record Setup Environment time" + if: ${{ github.repository_owner == 'puppetlabs' }} + run: | + buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Environment' + echo STEP_ID=Setup-Acceptance-Test-Matrix >> $GITHUB_ENV + echo STEP_START=$(date +%s) >> $GITHUB_ENV + - name: Run validation steps + run: | + bundle exec rake validate + if: ${{ github.repository_owner == 'puppetlabs' }} + + - name: Setup Acceptance Test Matrix + id: get-matrix + run: | + if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then + buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata_v2 + else + echo "::set-output name=matrix::{}" + fi + + - name: "Honeycomb: Record Setup Test Matrix time" + if: ${{ always() }} + run: | + buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix' + Acceptance: + name: "${{matrix.platforms.label}}, ${{matrix.collection}}" + needs: + - setup_matrix + if: ${{ needs.setup_matrix.outputs.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.platforms.image }}' >> $BUILDEVENT_FILE + echo 'collection=${{ matrix.collection }}' >> $BUILDEVENT_FILE + echo 'label=${{ matrix.platforms.label }}' >> $BUILDEVENT_FILE + + - name: "Honeycomb: Start recording" + uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1 + with: + apikey: ${{ env.HONEYCOMB_WRITEKEY }} + dataset: ${{ env.HONEYCOMB_DATASET }} + job-status: ${{ job.status }} + matrix-key: ${{ matrix.platforms.label }}-${{ matrix.collection }} + + - name: "Honeycomb: start first step" + run: | + echo STEP_ID=${{ matrix.platforms.image }}-${{ 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: ruby/setup-ruby@v1 + with: + ruby-version: "2.7" + bundler-cache: true + + - name: Print bundle environment + run: | + echo ::group::bundler environment + buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env + echo ::endgroup:: + + - name: "Honeycomb: Record Setup Environment time" + if: ${{ always() }} + run: | + buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Environment' + echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-2 >> $GITHUB_ENV + echo STEP_START=$(date +%s) >> $GITHUB_ENV + - name: Provision test environment + run: | + buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:provision ${{ matrix.platforms.image }}' -- bundle exec rake 'litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }}]' + echo ::group::=== REQUEST === + cat request.json || true + echo + echo ::endgroup:: + echo ::group::=== INVENTORY === + if [ -f 'spec/fixtures/litmus_inventory.yaml' ]; + then + FILE='spec/fixtures/litmus_inventory.yaml' + elif [ -f 'inventory.yaml' ]; + then + FILE='inventory.yaml' + fi + sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true + echo ::endgroup:: + + - name: Install agent + run: | + buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]' + + - name: 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.platforms.image }}-${{ matrix.collection }}-3 >> $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.platforms.image }}-${{ matrix.collection }}-4 >> $GITHUB_ENV + echo STEP_START=$(date +%s) >> $GITHUB_ENV + - name: Remove test environment + if: ${{ always() }} + continue-on-error: true + run: | + if [[ -f inventory.yaml || -f spec/fixtures/litmus_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/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..0b7b8a05 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,9 @@ +name: "Publish module" + +on: + workflow_dispatch: + +jobs: + release: + uses: "puppetlabs/cat-github-actions/.github/workflows/module_release.yml@main" + secrets: "inherit" diff --git a/.github/workflows/spec.yml b/.github/workflows/spec.yml new file mode 100644 index 00000000..6c1ae10d --- /dev/null +++ b/.github/workflows/spec.yml @@ -0,0 +1,126 @@ +name: "Spec Tests" + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + pull_request: + + +env: + HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 + HONEYCOMB_DATASET: litmus tests + +jobs: + setup_matrix: + name: "Setup Test Matrix" + runs-on: ubuntu-20.04 + outputs: + spec_matrix: ${{ steps.get-matrix.outputs.spec_matrix }} + + steps: + + - name: "Honeycomb: Start recording" + uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1 + with: + apikey: ${{ env.HONEYCOMB_WRITEKEY }} + dataset: ${{ env.HONEYCOMB_DATASET }} + job-status: ${{ job.status }} + + - name: "Honeycomb: Start first step" + run: | + echo STEP_ID=setup-environment >> $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: ruby/setup-ruby@v1 + if: ${{ github.repository_owner == 'puppetlabs' }} + with: + ruby-version: "2.7" + bundler-cache: true + + - name: Print bundle environment + if: ${{ github.repository_owner == 'puppetlabs' }} + run: | + echo ::group::bundler environment + buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env + echo ::endgroup:: + - name: "Honeycomb: Record Setup Environment time" + if: ${{ github.repository_owner == 'puppetlabs' }} + run: | + buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Environment' + echo STEP_ID=Setup-Acceptance-Test-Matrix >> $GITHUB_ENV + echo STEP_START=$(date +%s) >> $GITHUB_ENV + - name: Run Static & Syntax Tests + if: ${{ github.repository_owner == 'puppetlabs' }} + run: | + buildevents cmd $TRACE_ID $STEP_ID 'static_syntax_checks' -- bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + + - name: Setup Spec Test Matrix + id: get-matrix + run: | + if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then + buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata_v2 + else + echo "::set-output name=spec_matrix::{}" + fi + - name: "Honeycomb: Record Setup Test Matrix time" + if: ${{ always() }} + run: | + buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix' + Spec: + name: "Spec Tests (Puppet: ${{matrix.puppet_version}}, Ruby Ver: ${{matrix.ruby_version}})" + needs: + - setup_matrix + if: ${{ needs.setup_matrix.outputs.spec_matrix != '{}' }} + + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: ${{fromJson(needs.setup_matrix.outputs.spec_matrix)}} + + env: + BUILDEVENT_FILE: '../buildevents.txt' + PUPPET_GEM_VERSION: ${{ matrix.puppet_version }} + FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' + + steps: + - run: | + echo "SANITIZED_PUPPET_VERSION=$(echo '${{ matrix.puppet_version }}' | sed 's/~> //g')" >> $GITHUB_ENV + + - run: | + echo 'puppet_version=${{ env.SANITIZED_PUPPET_VERSION }}' >> $BUILDEVENT_FILE + - name: "Honeycomb: Start first step" + run: | + echo "STEP_ID=${{ env.SANITIZED_PUPPET_VERSION }}-spec" >> $GITHUB_ENV + echo STEP_START=$(date +%s) >> $GITHUB_ENV + + - name: "Honeycomb: Start recording" + uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1 + with: + apikey: ${{ env.HONEYCOMB_WRITEKEY }} + dataset: ${{ env.HONEYCOMB_DATASET }} + job-status: ${{ job.status }} + matrix-key: ${{ env.SANITIZED_PUPPET_VERSION }} + - name: Checkout Source + uses: actions/checkout@v2 + + - name: "Activate Ruby ${{ matrix.ruby_version }}" + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby_version}} + bundler-cache: true + + - name: Print bundle environment + run: | + echo ::group::bundler environment + buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env + echo ::endgroup:: + + + - name: Run parallel_spec tests + run: | + buildevents cmd $TRACE_ID $STEP_ID 'rake parallel_spec Puppet ${{ matrix.puppet_version }}, Ruby ${{ matrix.ruby_version }}' -- bundle exec rake parallel_spec diff --git a/.gitignore b/.gitignore index 2767022c..3f155121 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ /log/ /pkg/ /spec/fixtures/manifests/ -/spec/fixtures/modules/ +/spec/fixtures/modules/* /tmp/ /vendor/ /convert_report.txt @@ -25,3 +25,4 @@ .project .envrc /inventory.yaml +/spec/fixtures/litmus_inventory.yaml diff --git a/.pdkignore b/.pdkignore index e6215cd0..584438f9 100644 --- a/.pdkignore +++ b/.pdkignore @@ -16,7 +16,7 @@ /log/ /pkg/ /spec/fixtures/manifests/ -/spec/fixtures/modules/ +/spec/fixtures/modules/* /tmp/ /vendor/ /convert_report.txt @@ -25,18 +25,19 @@ .project .envrc /inventory.yaml -/appveyor.yml +/spec/fixtures/litmus_inventory.yaml /.fixtures.yml /Gemfile /.gitattributes /.gitignore -/.gitlab-ci.yml /.pdkignore +/.puppet-lint.rc /Rakefile /rakelib/ /.rspec -/.rubocop.yml -/.travis.yml +/..yml /.yardopts /spec/ /.vscode/ +/.sync.yml +/.devcontainer/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece0..b4372aaf 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,5 @@ --relative +--no-parameter_types-check +--no-parameter_documentation-check +--no-documentation-check +--no-140chars-check diff --git a/.rubocop.yml b/.rubocop.yml index 5307849e..5be1f9fa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,12 +1,12 @@ --- require: +- rubocop-performance - rubocop-rspec -- rubocop-i18n AllCops: DisplayCopNames: true - TargetRubyVersion: '2.1' + TargetRubyVersion: '2.6' Include: - - "./**/*.rb" + - "**/*.rb" Exclude: - bin/* - ".vendor/**/*" @@ -18,16 +18,9 @@ AllCops: - "**/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. @@ -36,14 +29,13 @@ RSpec/BeforeAfterAll: RSpec/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each +RSpec/DescribeSymbol: + Exclude: + - spec/unit/facter/**/*.rb 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: true Style/ClassAndModuleChildren: Description: Compact style reduces the required amount of indentation. EnforcedStyle: compact @@ -72,7 +64,7 @@ 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 @@ -87,26 +79,176 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets +Performance/AncestorsInclude: + Enabled: true +Performance/BigDecimalWithNumericArgument: + Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true +Performance/CaseWhenSplat: + Enabled: true +Performance/ConstantRegexp: + Enabled: true +Performance/MethodObjectAsBlock: + Enabled: true +Performance/RedundantSortBlock: + Enabled: true +Performance/RedundantStringChars: + Enabled: true +Performance/ReverseFirst: + Enabled: true +Performance/SortReverse: + Enabled: true +Performance/Squeeze: + Enabled: true +Performance/StringInclude: + Enabled: true +Performance/Sum: + Enabled: true Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true -GetText/DecorateFunctionMessage: +Bundler/GemFilename: Enabled: false -GetText/DecorateStringFormattingUsingInterpolation: +Bundler/InsecureProtocolSource: Enabled: false -GetText/DecorateStringFormattingUsingPercent: +Capybara/CurrentPathExpectation: + Enabled: false +Capybara/VisibilityMatcher: + Enabled: false +Gemspec/DuplicatedAssignment: + Enabled: false +Gemspec/OrderedDependencies: + Enabled: false +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/DuplicateElsifCondition: + Enabled: false +Lint/DuplicateRequire: + Enabled: false +Lint/DuplicateRescueException: + 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/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/ToJSON: + Enabled: false +Lint/TopLevelReturnWithArgument: + Enabled: false +Lint/TrailingCommaInAttributeDeclaration: + 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: @@ -119,19 +261,463 @@ 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 +Naming/VariableNumber: + Enabled: false +Performance/BindCall: + Enabled: false +Performance/DeletePrefix: + Enabled: false +Performance/DeleteSuffix: + Enabled: false +Performance/InefficientHashSearch: + Enabled: false +Performance/UnfreezeString: + Enabled: false +Performance/UriDefaultParser: + Enabled: false +RSpec/Be: + Enabled: false +RSpec/Capybara/FeatureMethods: + Enabled: false +RSpec/ContainExactly: + 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/MatchArray: + Enabled: false +RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/MultipleSubjects: + Enabled: false RSpec/NestedGroups: Enabled: false -Style/AsciiComments: +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/BisectedAttrAccessor: + Enabled: false +Style/CaseLikeIf: + Enabled: false +Style/ClassEqualityComparison: + Enabled: false +Style/ColonMethodDefinition: + Enabled: false +Style/CombinableLoops: + Enabled: false +Style/CommentedKeyword: + Enabled: false +Style/Dir: + 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/FrozenStringLiteralComment: + 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/NegatedUnless: + Enabled: false +Style/NumericPredicate: + Enabled: false +Style/OptionalBooleanParameter: + Enabled: false +Style/OrAssignment: + Enabled: false +Style/RandomWithOffset: + 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/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 +Capybara/MatchStyle: + Enabled: false +Capybara/NegationMatcher: + Enabled: false +Capybara/SpecificActions: + Enabled: false +Capybara/SpecificFinders: + Enabled: false +Capybara/SpecificMatcher: + Enabled: false +Gemspec/DeprecatedAttributeAssignment: + Enabled: false +Gemspec/DevelopmentDependencies: + Enabled: false +Gemspec/RequireMFA: + Enabled: false +Layout/LineContinuationLeadingSpace: + Enabled: false +Layout/LineContinuationSpacing: + Enabled: false +Layout/LineEndStringConcatenationIndentation: + Enabled: false +Layout/SpaceBeforeBrackets: + Enabled: false +Lint/AmbiguousAssignment: + Enabled: false +Lint/AmbiguousOperatorPrecedence: + Enabled: false +Lint/AmbiguousRange: + Enabled: false +Lint/ConstantOverwrittenInRescue: + Enabled: false +Lint/DeprecatedConstants: + Enabled: false +Lint/DuplicateBranch: + Enabled: false +Lint/DuplicateMagicComment: + Enabled: false +Lint/DuplicateRegexpCharacterClassElement: + Enabled: false +Lint/EmptyBlock: + Enabled: false +Lint/EmptyClass: + Enabled: false +Lint/EmptyInPattern: + Enabled: false +Lint/IncompatibleIoSelectWithFiberScheduler: + Enabled: false +Lint/LambdaWithoutLiteralBlock: + Enabled: false +Lint/NoReturnInBeginEndBlocks: + Enabled: false +Lint/NonAtomicFileOperation: + Enabled: false +Lint/NumberedParameterAssignment: + Enabled: false +Lint/OrAssignmentToConstant: + Enabled: false +Lint/RedundantDirGlobSort: + Enabled: false +Lint/RefinementImportMethods: + Enabled: false +Lint/RequireRangeParentheses: + Enabled: false +Lint/RequireRelativeSelfPath: + Enabled: false +Lint/SymbolConversion: + Enabled: false +Lint/ToEnumArguments: + Enabled: false +Lint/TripleQuotes: + Enabled: false +Lint/UnexpectedBlockArity: + Enabled: false +Lint/UnmodifiedReduceAccumulator: + Enabled: false +Lint/UselessRescue: + Enabled: false +Lint/UselessRuby2Keywords: + Enabled: false +Metrics/CollectionLiteralLength: + Enabled: false +Naming/BlockForwarding: + Enabled: false +Performance/CollectionLiteralInLoop: + Enabled: false +Performance/ConcurrentMonotonicTime: + Enabled: false +Performance/MapCompact: + Enabled: false +Performance/RedundantEqualityComparisonBlock: + Enabled: false +Performance/RedundantSplitRegexpArgument: + Enabled: false +Performance/StringIdentifierArgument: + Enabled: false +RSpec/BeEq: + Enabled: false +RSpec/BeNil: + Enabled: false +RSpec/ChangeByZero: + Enabled: false +RSpec/ClassCheck: + Enabled: false +RSpec/DuplicatedMetadata: + Enabled: false +RSpec/ExcessiveDocstringSpacing: + Enabled: false +RSpec/FactoryBot/ConsistentParenthesesStyle: + Enabled: false +RSpec/FactoryBot/FactoryNameStyle: + Enabled: false +RSpec/FactoryBot/SyntaxMethods: + Enabled: false +RSpec/IdenticalEqualityAssertion: + Enabled: false +RSpec/NoExpectationExample: + Enabled: false +RSpec/PendingWithoutReason: + Enabled: false +RSpec/Rails/AvoidSetupHook: + Enabled: false +RSpec/Rails/HaveHttpStatus: + Enabled: false +RSpec/Rails/InferredSpecType: + Enabled: false +RSpec/Rails/MinitestAssertions: + Enabled: false +RSpec/Rails/TravelAround: + Enabled: false +RSpec/RedundantAround: + Enabled: false +RSpec/SkipBlockInsideExample: + Enabled: false +RSpec/SortMetadata: + Enabled: false +RSpec/SubjectDeclaration: + Enabled: false +RSpec/VerifiedDoubleReference: + Enabled: false +Security/CompoundHash: + Enabled: false +Security/IoMethods: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false +Style/ArrayIntersect: + Enabled: false +Style/CollectionCompact: + Enabled: false +Style/ComparableClamp: + Enabled: false +Style/ConcatArrayLiterals: + Enabled: false +Style/DirEmpty: + Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false +Style/EmptyHeredoc: + Enabled: false +Style/EndlessMethod: + Enabled: false +Style/EnvHome: + Enabled: false +Style/FetchEnvVar: + Enabled: false +Style/FileEmpty: + Enabled: false +Style/FileRead: + Enabled: false +Style/FileWrite: + Enabled: false +Style/HashConversion: + Enabled: false +Style/HashExcept: + Enabled: false +Style/IfWithBooleanLiteralBranches: + Enabled: false +Style/InPatternThen: + Enabled: false +Style/MagicCommentFormat: + Enabled: false +Style/MapCompactWithConditionalBlock: + Enabled: false +Style/MapToHash: + Enabled: false +Style/MapToSet: + Enabled: false +Style/MinMaxComparison: + Enabled: false +Style/MultilineInPatternThen: + Enabled: false +Style/NegatedIfElseCondition: + Enabled: false +Style/NestedFileDirname: + Enabled: false +Style/NilLambda: + Enabled: false +Style/NumberedParameters: + Enabled: false +Style/NumberedParametersLimit: + Enabled: false +Style/ObjectThen: + Enabled: false +Style/OpenStructUse: + Enabled: false +Style/OperatorMethodCall: + Enabled: false +Style/QuotedSymbols: + Enabled: false +Style/RedundantArgument: + Enabled: false +Style/RedundantConstantBase: + Enabled: false +Style/RedundantDoubleSplatHashBraces: + Enabled: false +Style/RedundantEach: + Enabled: false +Style/RedundantHeredocDelimiterQuotes: + Enabled: false +Style/RedundantInitialize: + Enabled: false +Style/RedundantSelfAssignmentBranch: + Enabled: false +Style/RedundantStringEscape: + Enabled: false +Style/SelectByRegexp: + Enabled: false +Style/StringChars: + Enabled: false +Style/SwapValues: + Enabled: false diff --git a/.sync.yml b/.sync.yml index c6ff6c37..e2afdd0c 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,14 +1,34 @@ +--- +".gitlab-ci.yml": + delete: true +appveyor.yml: + delete: true Gemfile: required: ':system_tests': - - gem: 'puppet-module-posix-system-r#{minor_version}' - platforms: ruby - - gem: 'puppet-module-win-system-r#{minor_version}' - platforms: - - mswin - - mingw - - x64_mingw - gem: 'nokogiri' platforms: ruby - - gem: 'serverspec' - platforms: ruby +Rakefile: + default_disabled_lint_checks: + - relative + - parameter_types + - parameter_documentation + - documentation + - 140chars +spec/default_facts.yml: + unmanaged: true +spec/spec_helper.rb: + mock_with: ":rspec" + coverage_report: true +.github/workflows/pr_test.yml: + unmanaged: false +.github/workflows/nightly.yml: + unmanaged: false +.github/workflows/spec.yml: + unmanaged: false +.github/workflows/release.yml: + unmanaged: false +.github/workflows/auto_release.yml: + unmanaged: false +.travis.yml: + delete: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0aaaef2b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -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: - - 'bundle exec rake $CHECK' -bundler_args: --without system_tests -rvm: - - 2.5.7 -stages: - - static - - spec - - acceptance - - - if: tag =~ ^v\d - name: deploy -jobs: - fast_finish: true - include: - - - 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 - - - env: PUPPET_GEM_VERSION="~> 7.0" CHECK=parallel_spec - rvm: 2.7.2 - stage: spec - - - env: DEPLOY_TO_FORGE=yes - stage: deploy -branches: - only: - - master - - /^v\d/ -notifications: - email: false diff --git a/Gemfile b/Gemfile index 0d3a975d..21af2ec8 100644 --- a/Gemfile +++ b/Gemfile @@ -13,27 +13,34 @@ def location_for(place_or_version, fake_version = nil) 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 "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 "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', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '~> 3.0', require: false + gem "puppetlabs_spec_helper", '~> 6.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 1.0.0', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "puppet-strings", '~> 4.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] end group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", '~> 0.5', require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", '~> 0.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "nokogiri", require: false, platforms: [:ruby] - gem "serverspec", require: false, platforms: [:ruby] + gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false + gem "nokogiri", require: false, platforms: [:ruby] end puppet_version = ENV['PUPPET_GEM_VERSION'] @@ -50,16 +57,6 @@ gems['puppet'] = location_for(puppet_version) 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 diff --git a/Rakefile b/Rakefile index cb7ed0cc..1763bb6a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? +require 'bundler' +require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? -require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? -require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? +require 'github_changelog_generator/task' if Gem.loaded_specs.key? 'github_changelog_generator' +require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' def changelog_user return unless Rake.application.top_level_tasks.include? "changelog" @@ -41,8 +41,13 @@ def changelog_future_release end PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_parameter_types') +PuppetLint.configuration.send('disable_parameter_documentation') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_140chars') -if Bundler.rubygems.find_name('github_changelog_generator').any? + +if Gem.loaded_specs.key? 'github_changelog_generator' GitHubChangelogGenerator::RakeTask.new :changelog do |config| raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? config.user = "#{changelog_user}" @@ -52,7 +57,7 @@ if Bundler.rubygems.find_name('github_changelog_generator').any? config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." config.add_pr_wo_labels = true config.issues = false - config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" + config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" config.configure_sections = { "Changed" => { "prefix" => "### Changed", @@ -60,11 +65,11 @@ if Bundler.rubygems.find_name('github_changelog_generator').any? }, "Added" => { "prefix" => "### Added", - "labels" => ["feature", "enhancement"], + "labels" => ["enhancement", "feature"], }, "Fixed" => { "prefix" => "### Fixed", - "labels" => ["bugfix"], + "labels" => ["bug", "documentation", "bugfix"], }, } end @@ -72,16 +77,15 @@ else desc 'Generate a Changelog from GitHub' task :changelog do raise <= Gem::Version.new('2.2.2')" + version: '~> 1.15' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" EOM end end diff --git a/lib/puppet/util/puppetdb_validator.rb b/lib/puppet/util/puppetdb_validator.rb index 8cd360d0..5cb966b7 100644 --- a/lib/puppet/util/puppetdb_validator.rb +++ b/lib/puppet/util/puppetdb_validator.rb @@ -63,6 +63,6 @@ def attempt_connection end rescue StandardError => e log_error(e.message) - return false + false end end diff --git a/manifests/database/default_read_grant.pp b/manifests/database/default_read_grant.pp index 80d798b1..fea87f96 100644 --- a/manifests/database/default_read_grant.pp +++ b/manifests/database/default_read_grant.pp @@ -1,12 +1,12 @@ # Private class. Grant read permissions to $database_read_only_username by default, for new tables created by # $database_username. -define puppetdb::database::default_read_grant( +define puppetdb::database::default_read_grant ( String $database_name, String $schema, String $database_username, String $database_read_only_username, ) { - postgresql_psql {"grant default select permission for ${database_read_only_username}": + postgresql_psql { "grant default select permission for ${database_read_only_username}": db => $database_name, command => "ALTER DEFAULT PRIVILEGES FOR USER \"${database_username}\" @@ -23,7 +23,7 @@ AND nspname = '${schema}'", } - postgresql_psql {"grant default usage permission for ${database_read_only_username}": + postgresql_psql { "grant default usage permission for ${database_read_only_username}": db => $database_name, command => "ALTER DEFAULT PRIVILEGES FOR USER \"${database_username}\" @@ -40,7 +40,7 @@ AND nspname = '${schema}'", } - postgresql_psql {"grant default execute permission for ${database_read_only_username}": + postgresql_psql { "grant default execute permission for ${database_read_only_username}": db => $database_name, command => "ALTER DEFAULT PRIVILEGES FOR USER \"${database_username}\" diff --git a/manifests/database/postgresql.pp b/manifests/database/postgresql.pp index 62da6464..7a6c833f 100644 --- a/manifests/database/postgresql.pp +++ b/manifests/database/postgresql.pp @@ -19,14 +19,13 @@ $read_database_password = $puppetdb::params::read_database_password, $read_database_host = $puppetdb::params::read_database_host ) inherits puppetdb::params { - if $manage_server { - class { '::postgresql::globals': + class { 'postgresql::globals': manage_package_repo => $manage_package_repo, version => $postgres_version, } # get the pg server up and running - class { '::postgresql::server': + class { 'postgresql::server': ip_mask_allow_all_users => '0.0.0.0/0', listen_addresses => $listen_addresses, port => scanf($database_port, '%i')[0], @@ -35,7 +34,7 @@ # We need to create the ssl connection for the read user, when # manage_database is set to true, or when read_database_host is defined. # Otherwise we don't create it. - if $manage_database or $read_database_host != undef{ + if $manage_database or $read_database_host != undef { $create_read_user_rule = true } else { $create_read_user_rule = false @@ -52,15 +51,16 @@ postgresql_ssl_key_path => $postgresql_ssl_key_path, postgresql_ssl_cert_path => $postgresql_ssl_cert_path, postgresql_ssl_ca_cert_path => $postgresql_ssl_ca_cert_path, - create_read_user_rule => $create_read_user_rule + create_read_user_rule => $create_read_user_rule, } } # Only install pg_trgm extension, if database it is actually managed by the module if $manage_database { - # get the pg contrib to use pg_trgm extension - class { '::postgresql::server::contrib': } + if (versioncmp($postgresql::globals::globals_version, '10') < 0) { + include postgresql::server::contrib + } postgresql::server::extension { 'pg_trgm': database => $database_name, @@ -97,7 +97,7 @@ read_database_username => $read_database_username, database_name => $database_name, password_hash => postgresql::postgresql_password($read_database_username, $read_database_password), - database_owner => $database_username + database_owner => $database_username, } -> postgresql_psql { "grant ${read_database_username} role to ${database_username}": diff --git a/manifests/database/postgresql_ssl_rules.pp b/manifests/database/postgresql_ssl_rules.pp index 56b48395..a217d612 100644 --- a/manifests/database/postgresql_ssl_rules.pp +++ b/manifests/database/postgresql_ssl_rules.pp @@ -13,7 +13,7 @@ address => '0.0.0.0/0', auth_method => 'cert', order => 0, - auth_option => "map=${identity_map_key} clientcert=1" + auth_option => "map=${identity_map_key} clientcert=1", } postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as ${database_username} (ipv6)": @@ -23,7 +23,7 @@ address => '::0/0', auth_method => 'cert', order => 0, - auth_option => "map=${identity_map_key} clientcert=1" + auth_option => "map=${identity_map_key} clientcert=1", } postgresql::server::pg_ident_rule { "Map the SSL certificate of the server as a ${database_username} user": diff --git a/manifests/database/ssl_configuration.pp b/manifests/database/ssl_configuration.pp index 0d2473c6..a5c085e5 100644 --- a/manifests/database/ssl_configuration.pp +++ b/manifests/database/ssl_configuration.pp @@ -31,25 +31,25 @@ postgresql::server::config_entry { 'ssl': ensure => present, value => 'on', - require => [File['postgres private key'], File['postgres public key']] + require => [File['postgres private key'], File['postgres public key']], } postgresql::server::config_entry { 'ssl_cert_file': ensure => present, value => "${postgresql::server::datadir}/server.crt", - require => [File['postgres private key'], File['postgres public key']] + require => [File['postgres private key'], File['postgres public key']], } postgresql::server::config_entry { 'ssl_key_file': ensure => present, value => "${postgresql::server::datadir}/server.key", - require => [File['postgres private key'], File['postgres public key']] + require => [File['postgres private key'], File['postgres public key']], } postgresql::server::config_entry { 'ssl_ca_file': ensure => present, value => $postgresql_ssl_ca_cert_path, - require => [File['postgres private key'], File['postgres public key']] + require => [File['postgres private key'], File['postgres public key']], } puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${database_username}": diff --git a/manifests/globals.pp b/manifests/globals.pp index 413339aa..6e088eb6 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -2,10 +2,8 @@ class puppetdb::globals ( $version = 'present', $database = 'postgres', - ) { - +) { if !(fact('os.family') in ['RedHat', 'Suse', 'Archlinux', 'Debian', 'OpenBSD', 'FreeBSD']) { fail("${module_name} does not support your osfamily ${fact('os.family')}") } - } diff --git a/manifests/init.pp b/manifests/init.pp index c999441d..b0978d02 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -91,8 +91,7 @@ Integer[1] $dlo_max_age = $puppetdb::params::dlo_max_age, Optional[Stdlib::Absolutepath] $java_bin = $puppetdb::params::java_bin, ) inherits puppetdb::params { - - class { '::puppetdb::server': + class { 'puppetdb::server': listen_address => $listen_address, listen_port => $listen_port, disable_cleartext => $disable_cleartext, @@ -176,14 +175,13 @@ } if ($database == 'postgres') { - $database_before = str2bool($database_validate) ? { - false => Class['::puppetdb::server'], - default => [Class['::puppetdb::server'], - Class['::puppetdb::server::validate_db']], + false => Class['puppetdb::server'], + default => [Class['puppetdb::server'], + Class['puppetdb::server::validate_db']], } - class { '::puppetdb::database::postgresql': + class { 'puppetdb::database::postgresql': listen_addresses => $database_listen_address, database_name => $database_name, puppetdb_server => $puppetdb_server, @@ -201,7 +199,7 @@ read_database_username => $read_database_username, read_database_password => $read_database_password, read_database_host => $read_database_host, - before => $database_before + before => $database_before, } } } diff --git a/manifests/master/config.pp b/manifests/master/config.pp index 7463ed3e..eb9fb1d9 100644 --- a/manifests/master/config.pp +++ b/manifests/master/config.pp @@ -2,14 +2,14 @@ class puppetdb::master::config ( $puppetdb_server = fact('networking.fqdn'), $puppetdb_port = defined(Class['puppetdb']) ? { - true => $::puppetdb::disable_ssl ? { + true => $puppetdb::disable_ssl ? { true => 8080, default => 8081, }, default => 8081, }, $puppetdb_disable_ssl = defined(Class['puppetdb']) ? { - true => $::puppetdb::disable_ssl, + true => $puppetdb::disable_ssl, default => false, }, $masterless = $puppetdb::params::masterless, @@ -30,7 +30,6 @@ $test_url = $puppetdb::params::test_url, $restart_puppet = true, ) inherits puppetdb::params { - # **WARNING**: Ugly hack to work around a yum bug with metadata parsing. This # should not be copied, replicated or even looked at. In short, never rename # your packages... @@ -66,7 +65,6 @@ } if ($strict_validation) { - # Validate the puppetdb connection. If we can't connect to puppetdb then we # *must* not perform the other configuration steps, or else @@ -192,5 +190,4 @@ Class['puppetdb::master::report_processor'] ~> Service[$puppet_service_name] } } - } diff --git a/manifests/master/puppetdb_conf.pp b/manifests/master/puppetdb_conf.pp index a3dd72fc..3cf8d706 100644 --- a/manifests/master/puppetdb_conf.pp +++ b/manifests/master/puppetdb_conf.pp @@ -12,8 +12,7 @@ /(puppetdb-terminus)/ => true, default => false, }, - ) inherits puppetdb::params { - +) inherits puppetdb::params { Ini_setting { ensure => present, section => 'main', diff --git a/manifests/master/report_processor.pp b/manifests/master/report_processor.pp index f97130bd..4002d596 100644 --- a/manifests/master/report_processor.pp +++ b/manifests/master/report_processor.pp @@ -5,7 +5,6 @@ $masterless = $puppetdb::params::masterless, $enable = false ) inherits puppetdb::params { - if $masterless { $puppet_conf_section = 'main' } else { diff --git a/manifests/master/routes.pp b/manifests/master/routes.pp index fcdda80a..87435b06 100644 --- a/manifests/master/routes.pp +++ b/manifests/master/routes.pp @@ -5,7 +5,6 @@ $masterless = $puppetdb::params::masterless, $routes = undef, ) inherits puppetdb::params { - if $masterless { $routes_real = { 'apply' => { @@ -16,8 +15,8 @@ 'facts' => { 'terminus' => 'facter', 'cache' => 'puppetdb_apply', - } - } + }, + }, } } elsif $routes { $routes_real = $routes @@ -32,8 +31,8 @@ 'facts' => { 'terminus' => 'puppetdb', 'cache' => $default_fact_cache, - } - } + }, + }, } } diff --git a/manifests/master/storeconfigs.pp b/manifests/master/storeconfigs.pp index cb46cc09..a547e517 100644 --- a/manifests/master/storeconfigs.pp +++ b/manifests/master/storeconfigs.pp @@ -5,7 +5,6 @@ $masterless = $puppetdb::params::masterless, $enable = true, ) inherits puppetdb::params { - if $masterless { $puppet_conf_section = 'main' } else { diff --git a/manifests/params.pp b/manifests/params.pp index 456f7b4b..02ceb957 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -25,11 +25,7 @@ $manage_pg_repo = false } - if $puppetdb_version in ['latest','present'] or versioncmp($puppetdb_version, '7.0.0') >= 0 { - $postgres_version = '11' - } else { - $postgres_version = '9.6' - } + $postgres_version = undef # The remaining database settings are not used for an embedded database $database_host = 'localhost' @@ -208,7 +204,7 @@ $certificate_whitelist_file = "${etcdir}/certificate-whitelist" # the default is free access for now - $certificate_whitelist = [ ] + $certificate_whitelist = [] # change to this to only allow access by the puppet master by default: #$certificate_whitelist = [ $::servername ] diff --git a/manifests/server.pp b/manifests/server.pp index b9def8af..6ec90c88 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -81,7 +81,6 @@ Integer[1] $dlo_max_age = $puppetdb::params::dlo_max_age, Optional[Stdlib::Absolutepath] $java_bin = $puppetdb::params::java_bin, ) inherits puppetdb::params { - # Apply necessary suffix if zero is specified. # Can we drop this in the next major release? if $node_ttl == '0' { @@ -263,21 +262,21 @@ if $postgresql_ssl_on { exec { $ssl_key_pk8_path: - path => [ '/opt/puppetlabs/puppet/bin', $facts['path'] ], + path => ['/opt/puppetlabs/puppet/bin', $facts['path']], command => "openssl pkcs8 -topk8 -inform PEM -outform DER -in ${ssl_key_path} -out ${ssl_key_pk8_path} -nocrypt", # Generate a .pk8 key if one doesn't exist or is older than the .pem input. # NOTE: bash file time checks, like -ot, can't always discern sub-second # differences. onlyif => "test ! -e '${ssl_key_pk8_path}' -o '${ssl_key_pk8_path}' -ot '${ssl_key_path}'", - before => File[$ssl_key_pk8_path] + before => File[$ssl_key_pk8_path], } file { $ssl_key_pk8_path: - ensure => present, + ensure => file, owner => $puppetdb_user, group => $puppetdb_group, mode => '0600', - notify => Service[$puppetdb_service] + notify => Service[$puppetdb_service], } } @@ -324,7 +323,7 @@ setting => 'JAVA_ARGS', require => Package[$puppetdb_package], notify => Service[$puppetdb_service], - })) + })) } else { ini_setting { 'java_args': ensure => present, @@ -357,14 +356,14 @@ # https://puppet.com/docs/puppetdb/5.2/maintain_and_tune.html#clean-up-the-dead-letter-office systemd::unit_file { 'puppetdb-dlo-cleanup.service': content => epp("${module_name}/puppetdb-DLO-cleanup.service.epp", { - 'puppetdb_user' => $puppetdb_user, - 'puppetdb_group' => $puppetdb_group, - 'vardir' => $vardir, - 'dlo_max_age' => $dlo_max_age + 'puppetdb_user' => $puppetdb_user, + 'puppetdb_group' => $puppetdb_group, + 'vardir' => $vardir, + 'dlo_max_age' => $dlo_max_age }), } -> systemd::unit_file { 'puppetdb-dlo-cleanup.timer': - content => epp("${module_name}/puppetdb-DLO-cleanup.timer.epp", {'cleanup_timer_interval' => $cleanup_timer_interval }), + content => epp("${module_name}/puppetdb-DLO-cleanup.timer.epp", { 'cleanup_timer_interval' => $cleanup_timer_interval }), enable => true, active => true, } diff --git a/manifests/server/command_processing.pp b/manifests/server/command_processing.pp index 6d05e562..7a3cd2a3 100644 --- a/manifests/server/command_processing.pp +++ b/manifests/server/command_processing.pp @@ -6,7 +6,6 @@ $temp_usage = $puppetdb::params::temp_usage, $confdir = $puppetdb::params::confdir, ) inherits puppetdb::params { - $config_ini = "${confdir}/config.ini" # Set the defaults diff --git a/manifests/server/database.pp b/manifests/server/database.pp index 12dff9ff..d541a1e4 100644 --- a/manifests/server/database.pp +++ b/manifests/server/database.pp @@ -30,7 +30,6 @@ $ssl_key_pk8_path = $puppetdb::params::ssl_key_pk8_path, $ssl_ca_cert_path = $puppetdb::params::ssl_ca_cert_path ) inherits puppetdb::params { - if str2bool($database_validate) { # Validate the database connection. If we can't connect, we want to fail # and skip the rest of the configuration, so that we don't leave puppetdb @@ -69,15 +68,13 @@ path => $database_ini, ensure => present, section => 'database', - require => $ini_setting_require + require => $ini_setting_require, } if $database == 'embedded' { - $classname = 'org.hsqldb.jdbcDriver' $subprotocol = 'hsqldb' $subname = "file:${database_embedded_path};hsqldb.tx=mvcc;sql.syntax_pgs=true" - } elsif $database == 'postgres' { $classname = 'org.postgresql.Driver' $subprotocol = 'postgresql' @@ -91,8 +88,7 @@ $subname_default = "//${database_host}:${database_port}/${database_name}${database_suffix}" - if $postgresql_ssl_on and !empty($jdbc_ssl_properties) - { + if $postgresql_ssl_on and !empty($jdbc_ssl_properties) { fail("Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!") } diff --git a/manifests/server/global.pp b/manifests/server/global.pp index f03f281f..874601a8 100644 --- a/manifests/server/global.pp +++ b/manifests/server/global.pp @@ -4,7 +4,6 @@ $confdir = $puppetdb::params::confdir, $puppetdb_group = $puppetdb::params::puppetdb_group, ) inherits puppetdb::params { - $config_ini = "${confdir}/config.ini" file { $config_ini: diff --git a/manifests/server/jetty.pp b/manifests/server/jetty.pp index ea050faf..bb155ec3 100644 --- a/manifests/server/jetty.pp +++ b/manifests/server/jetty.pp @@ -17,7 +17,6 @@ $puppetdb_user = $puppetdb::params::puppetdb_user, $puppetdb_group = $puppetdb::params::puppetdb_group, ) inherits puppetdb::params { - $jetty_ini = "${confdir}/jetty.ini" file { $jetty_ini: @@ -70,7 +69,6 @@ } if $ssl_protocols { - ini_setting { 'puppetdb_sslprotocols': ensure => $ssl_setting_ensure, setting => 'ssl-protocols', @@ -79,7 +77,6 @@ } if $cipher_suites { - ini_setting { 'puppetdb_cipher-suites': ensure => $ssl_setting_ensure, setting => 'cipher-suites', diff --git a/manifests/server/puppetdb.pp b/manifests/server/puppetdb.pp index 54fa4d2d..b77e48a9 100644 --- a/manifests/server/puppetdb.pp +++ b/manifests/server/puppetdb.pp @@ -7,7 +7,6 @@ $puppetdb_user = $puppetdb::params::puppetdb_user, $puppetdb_group = $puppetdb::params::puppetdb_group, ) inherits puppetdb::params { - $puppetdb_ini = "${confdir}/puppetdb.ini" file { $puppetdb_ini: @@ -31,7 +30,7 @@ } # accept connections only from puppet master - ini_setting {'puppetdb-connections-from-master-only': + ini_setting { 'puppetdb-connections-from-master-only': ensure => $certificate_whitelist_setting_ensure, section => 'puppetdb', setting => 'certificate-whitelist', diff --git a/manifests/server/read_database.pp b/manifests/server/read_database.pp index 688a74fe..e3407b7d 100644 --- a/manifests/server/read_database.pp +++ b/manifests/server/read_database.pp @@ -22,7 +22,6 @@ $ssl_key_pk8_path = $puppetdb::params::ssl_key_pk8_path, $ssl_ca_cert_path = $puppetdb::params::ssl_ca_cert_path ) inherits puppetdb::params { - if $read_database_host != undef { if str2bool($database_validate) { # Validate the database connection. If we can't connect, we want to fail @@ -78,18 +77,17 @@ $subname_default = "//${read_database_host}:${read_database_port}/${read_database_name}${database_suffix}" - if $postgresql_ssl_on and !empty($jdbc_ssl_properties) - { + if $postgresql_ssl_on and !empty($jdbc_ssl_properties) { fail("Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!") } if $postgresql_ssl_on { $subname = @("EOT"/L) - ${subname_default}?\ - ssl=true&sslfactory=org.postgresql.ssl.LibPQFactory&\ - sslmode=verify-full&sslrootcert=${ssl_ca_cert_path}&\ - sslkey=${ssl_key_pk8_path}&sslcert=${ssl_cert_path}\ - | EOT + ${subname_default}?\ + ssl=true&sslfactory=org.postgresql.ssl.LibPQFactory&\ + sslmode=verify-full&sslrootcert=${ssl_ca_cert_path}&\ + sslkey=${ssl_key_pk8_path}&sslcert=${ssl_cert_path}\ + | EOT } else { $subname = $subname_default } diff --git a/manifests/server/validate_db.pp b/manifests/server/validate_db.pp index cf2e5b41..faa06410 100644 --- a/manifests/server/validate_db.pp +++ b/manifests/server/validate_db.pp @@ -8,7 +8,6 @@ $database_name = $puppetdb::params::database_name, $jdbc_ssl_properties = $puppetdb::params::jdbc_ssl_properties, ) inherits puppetdb::params { - # We don't need any validation for the embedded database, presumably. if ( $database == 'postgres' and diff --git a/manifests/server/validate_read_db.pp b/manifests/server/validate_read_db.pp index d857676d..bbf19986 100644 --- a/manifests/server/validate_read_db.pp +++ b/manifests/server/validate_read_db.pp @@ -8,7 +8,6 @@ $database_name = $puppetdb::params::database_name, $jdbc_ssl_properties = $puppetdb::params::jdbc_ssl_properties, ) inherits puppetdb::params { - # Currently we only support postgres if ( $database == 'postgres' and diff --git a/metadata.json b/metadata.json index 123f6890..4d43e87e 100644 --- a/metadata.json +++ b/metadata.json @@ -82,7 +82,7 @@ } ], "description": "Module for installing/configuring PuppetDB", - "pdk-version": "1.18.0", - "template-url": "https://github.com/puppetlabs/pdk-templates#1.18.0", - "template-ref": "tags/1.18.0-0-g095317c" + "pdk-version": "3.0.0", + "template-url": "https://github.com/puppetlabs/pdk-templates#3.0.0", + "template-ref": "tags/3.0.0-0-g5bfc1c0" } diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb index a17cb9c9..318b7db6 100644 --- a/spec/acceptance/basic_spec.rb +++ b/spec/acceptance/basic_spec.rb @@ -1,14 +1,24 @@ -require 'beaker-puppet' -require 'beaker-pe' require 'spec_helper_acceptance' describe 'basic tests:' do it 'make sure we have copied the module across' do # No point diagnosing any more if the module wasn't copied properly - shell('ls /etc/puppetlabs/code/modules/puppetdb') do |r| + run_shell('ls /etc/puppetlabs/code/environments/production/modules/puppetdb') do |r| r.exit_code.should be_zero - r.stdout.should =~ %r{metadata\.json} - r.stderr.should == '' + r.stdout.should include('metadata.json') + end + end + + describe 'setup puppetserver' do + pp = <<-EOS + package { 'puppetserver': ensure => installed, } -> + exec { '/opt/puppetlabs/bin/puppetserver ca setup': creates => '/etc/puppetlabs/puppetserver/ca/ca_crt.pem', } + service { 'puppetserver': ensure => running, enable => true, } + EOS + + it 'make sure it runs without error' do + apply_manifest(pp, catch_errors: true) + apply_manifest(pp, catch_changes: true) end end @@ -33,6 +43,7 @@ class { 'puppetdb': postgresql_ssl_on => true, EOS it 'make sure it runs without error' do + pending('By default postgresql use snakeoil certs and puppetdb puppetserver ones') apply_manifest(ssl_config, catch_errors: true) apply_manifest(ssl_config, catch_changes: true) end @@ -52,6 +63,7 @@ class { 'puppetdb': postgresql_ssl_on => true, } EOS it 'make sure it starts with wrong password' do + pending('By default postgresql use snakeoil certs and puppetdb puppetserver ones') apply_manifest(change_password, catch_errors: true) apply_manifest(change_password, catch_changes: true) end @@ -72,7 +84,7 @@ class { 'puppetdb::master::config': apply_manifest(pp, catch_errors: true) apply_manifest(pp, catch_changes: true) - shell('cat /etc/puppetlabs/puppet/puppet.conf') do |r| + run_shell('cat /etc/puppetlabs/puppet/puppet.conf') do |r| expect(r.stdout).to match(%r{^reports\s*=\s*([^,]+,)*puppetdb(,[^,]+)*$}) end end @@ -91,7 +103,7 @@ class { 'puppetdb::master::config': apply_manifest(pp, catch_errors: true) apply_manifest(pp, catch_changes: true) - shell('psql "postgresql://puppetdb-read:puppetdb-read@localhost/puppetdb" -c "create table tables(id int)" || true') do |r| + run_shell('psql "postgresql://puppetdb-read:puppetdb-read@localhost/puppetdb" -c "create table tables(id int)" || true') do |r| expect(r.stderr).to match(%r{^ERROR: permission denied for schema public.*}) end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml deleted file mode 100644 index f777abfc..00000000 --- a/spec/default_facts.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Use default_module_facts.yml for module specific facts. -# -# Facts specified here will override the values provided by rspec-puppet-facts. ---- -ipaddress: "172.16.254.254" -ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" -is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d3778cac..6820cebe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +RSpec.configure do |c| + c.mock_with :rspec +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' @@ -21,8 +25,8 @@ next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin - default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + default_facts.merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end @@ -42,6 +46,19 @@ end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) + end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 0b734325..73a02388 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,136 +1,6 @@ -require 'beaker-rspec' -require 'beaker-puppet' -require 'beaker/puppet_install_helper' -require 'beaker/module_install_helper' +# frozen_string_literal: true -def use_puppet4? - (ENV['PUPPET_INSTALL_VERSION'] =~ %r{^2016}) ? true : false -end +require 'puppet_litmus' +PuppetLitmus.configure! -def use_puppet5? - (ENV['BEAKER_PUPPET_COLLECTION'] =~ %r{^puppet5}) ? true : false -end - -def use_puppet6? - (ENV['BEAKER_PUPPET_COLLECTION'] =~ %r{^puppet6}) ? true : false -end - -def use_puppet7? - (ENV['BEAKER_PUPPET_COLLECTION'] =~ %r{^puppet7}) ? true : false -end - -def build_url(platform) - if use_puppet4? - url4 = 'http://%{mngr}.puppetlabs.com/puppetlabs-release-pc1%{plat}' - case platform - when 'el' then url4 % { mngr: 'yum', plat: '-el-' } - when 'fedora' then url4 % { mngr: 'yum', plat: '-fedora-' } - when 'debian', 'ubuntu' then url4 % { mngr: 'apt', plat: '-' } - else - raise "build_url() called with unsupported platform '#{platform}'" - end - elsif use_puppet5? - url5 = 'http://%{mngr}.puppetlabs.com/%{dir}puppet5-release%{plat}' - case platform - when 'el' then url5 % { mngr: 'yum', dir: 'puppet5/', plat: '-el-' } - when 'fedora' then url5 % { mngr: 'yum', dir: 'puppet5/', plat: '-fedora-' } - when 'debian', 'ubuntu' then url5 % { mngr: 'apt', dir: '', plat: '-' } - else - raise "build_url() called with unsupported platform '#{platform}'" - end - elsif use_puppet6? - url6 = 'http://%{mngr}.puppetlabs.com/%{dir}puppet6-release%{plat}' - case platform - when 'el' then url6 % { mngr: 'yum', dir: 'puppet6/', plat: '-el-' } - when 'fedora' then url6 % { mngr: 'yum', dir: 'puppet6/', plat: '-fedora-' } - when 'debian', 'ubuntu' then url6 % { mngr: 'apt', dir: '', plat: '-' } - else - raise "build_url() called with unsupported platform '#{platform}'" - end - else - url7 = 'http://%{mngr}.puppetlabs.com/%{dir}puppet7-release%{plat}' - case platform - when 'el' then url7 % { mngr: 'yum', dir: 'puppet7/', plat: '-el-' } - when 'fedora' then url7 % { mngr: 'yum', dir: 'puppet7/', plat: '-fedora-' } - when 'debian', 'ubuntu' then url7 % { mngr: 'apt', dir: '', plat: '-' } - else - raise "build_url() called with unsupported platform '#{platform}'" - end - end -end - -hosts.each do |host| - if host['platform'] =~ %r{debian} - on host, 'echo \'export PATH=/var/lib/gems/1.8/bin/:${PATH}\' >> ~/.bashrc' - end - # install_puppet - if host['platform'] =~ %r{el-(5|6|7|8)} - relver = Regexp.last_match(1) - on host, "rpm -ivh #{build_url('el')}#{relver}.noarch.rpm" - on host, 'yum install -y puppetserver' - on host, '/opt/puppetlabs/bin/puppetserver ca setup' - - # TODO: we should probably be using the relatively new postgresql - # module settings manage_dnf_module on el8 when we are managing the postgresql - # database - if relver == '8' - on host, 'dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm' - on host, 'dnf -qy module disable postgresql' - end - elsif host['platform'] =~ %r{fedora-(\d+)} - relver = Regexp.last_match(1) - on host, "rpm -ivh #{build_url('fedora')}#{relver}.noarch.rpm" - on host, 'yum install -y puppetserver' - elsif host['platform'] =~ %r{(ubuntu|debian)} - unless host.check_for_package 'curl' - on host, 'apt-get install -y curl' - end - # For openjdk8 - if host['platform'].version == '8' && !use_puppet4? - create_remote_file(host, - '/etc/apt/sources.list.d/jessie-backports.list', - 'deb https://artifactory.delivery.puppetlabs.net/artifactory/debian_archive__remote/ jessie-backports main') - on host, 'apt-get -y -m update' - install_package(host, 'openjdk-8-jre-headless') - end - on host, 'apt-get install apt-transport-https --assume-yes' - on host, "curl -O #{build_url('debian')}$(lsb_release -c -s).deb" - if use_puppet4? - on host, 'dpkg -i puppetlabs-release-pc1-$(lsb_release -c -s).deb' - elsif use_puppet5? - on host, 'dpkg -i puppet5-release-$(lsb_release -c -s).deb' - elsif use_puppet6? - on host, 'dpkg -i puppet6-release-$(lsb_release -c -s).deb' - else - on host, 'dpkg -i puppet7-release-$(lsb_release -c -s).deb' - end - on host, 'apt-get -y -m update' - on host, 'apt-get install -y puppetserver' - on host, '/opt/puppetlabs/bin/puppetserver ca setup' - else - raise "install_puppet() called for unsupported platform '#{host['platform']}' on '#{host.name}'" - end -end - -opts = { puppet_agent_version: 'latest' } -opts[:puppet_collection] = if use_puppet5? - 'puppet5' - elsif use_puppet6? - 'puppet6' - elsif use_puppet7? - 'puppet7' - end -install_puppet_agent_on(hosts, opts) unless ENV['BEAKER_provision'] == 'no' -install_ca_certs unless ENV['PUPPET_INSTALL_TYPE'] =~ %r{pe}i -install_module_on(hosts) -install_module_dependencies_on(hosts) - -RSpec.configure do |c| - # Readable test descriptions - c.formatter = :documentation - hosts.each do |host| - if host[:platform] =~ %r{el-7-x86_64} && host[:hypervisor] =~ %r{docker} - on(host, "sed -i '/nodocs/d' /etc/yum.conf") - end - end -end +require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) diff --git a/spec/unit/classes/database/postgresql_spec.rb b/spec/unit/classes/database/postgresql_spec.rb index d53066e7..efc92e69 100644 --- a/spec/unit/classes/database/postgresql_spec.rb +++ b/spec/unit/classes/database/postgresql_spec.rb @@ -16,6 +16,7 @@ release: { 'full' => '7.0', 'major' => '7' }, selinux: { 'enabled' => true }, }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/database/ssl_configuration_spec.rb b/spec/unit/classes/database/ssl_configuration_spec.rb index b5620df2..1ee8cc7a 100644 --- a/spec/unit/classes/database/ssl_configuration_spec.rb +++ b/spec/unit/classes/database/ssl_configuration_spec.rb @@ -10,13 +10,17 @@ operatingsystemrelease: '7.0', kernel: 'Linux', selinux: true, + path: '/usr/bin:/bin', os: { family: 'RedHat', name: 'RedHat', release: { 'full' => '7.0', 'major' => '7' }, selinux: { 'enabled' => true }, }, - fqdn: 'cheery-rime@puppet', + networking: { + fqdn: 'cheery-rime@puppet', + }, + service_provider: 'systemd', } end @@ -125,7 +129,7 @@ it 'has ident rule' do is_expected.to contain_postgresql__server__pg_ident_rule("Map the SSL certificate of the server as a #{params[:database_username]} user") .with_map_name(identity_map) - .with_system_username(facts[:fqdn]) + .with_system_username(facts[:networking][:fqdn]) .with_database_username(params[:database_name]) end @@ -184,7 +188,7 @@ it 'has read ident rule' do is_expected.to contain_postgresql__server__pg_ident_rule("Map the SSL certificate of the server as a #{params[:read_database_username]} user") .with_map_name(read_identity_map) - .with_system_username(facts[:fqdn]) + .with_system_username(facts[:networking][:fqdn]) .with_database_username(params[:read_database_username]) end end diff --git a/spec/unit/classes/init_spec.rb b/spec/unit/classes/init_spec.rb index d35eee37..f9532ee7 100644 --- a/spec/unit/classes/init_spec.rb +++ b/spec/unit/classes/init_spec.rb @@ -6,7 +6,7 @@ on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do - facts.merge(selinux: false) + facts.merge(selinux: false, service_provider: 'systemd') end describe 'when using default values for puppetdb class' do diff --git a/spec/unit/classes/master/config_spec.rb b/spec/unit/classes/master/config_spec.rb index 17a338ab..72496edf 100644 --- a/spec/unit/classes/master/config_spec.rb +++ b/spec/unit/classes/master/config_spec.rb @@ -5,7 +5,8 @@ context "on #{os}" do let(:facts) do facts.merge(puppetversion: Puppet.version, - fqdn: 'puppetdb.example.com', + networking: { fqdn: 'puppetdb.example.com' }, + service_provider: 'systemd', selinux: true) end @@ -114,6 +115,7 @@ release: { 'full' => '7.0', 'major' => '7' }, selinux: { 'enabled' => true }, }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/master/puppetdb_conf_spec.rb b/spec/unit/classes/master/puppetdb_conf_spec.rb index 9444eb06..f3b65c52 100644 --- a/spec/unit/classes/master/puppetdb_conf_spec.rb +++ b/spec/unit/classes/master/puppetdb_conf_spec.rb @@ -9,6 +9,7 @@ context "on #{os}" do let(:facts) do facts.merge(puppetversion: Puppet.version, + service_provider: 'systemd', selinux: false) end diff --git a/spec/unit/classes/master/report_processor_spec.rb b/spec/unit/classes/master/report_processor_spec.rb index 9a68f82c..4473f69e 100644 --- a/spec/unit/classes/master/report_processor_spec.rb +++ b/spec/unit/classes/master/report_processor_spec.rb @@ -12,6 +12,7 @@ context "on #{os}" do let(:facts) do facts.merge(puppetversion: Puppet.version, + service_provider: 'systemd', clientcert: 'test.domain.local') end diff --git a/spec/unit/classes/server/command_processing_spec.rb b/spec/unit/classes/server/command_processing_spec.rb index 06a9315f..d1d4a835 100644 --- a/spec/unit/classes/server/command_processing_spec.rb +++ b/spec/unit/classes/server/command_processing_spec.rb @@ -4,8 +4,11 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'OpenBSD', + os: { + family: 'OpenBSD', + }, puppetversion: Puppet.version, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/server/database_ini_spec.rb b/spec/unit/classes/server/database_ini_spec.rb index 06f2865c..9df8a4e4 100644 --- a/spec/unit/classes/server/database_ini_spec.rb +++ b/spec/unit/classes/server/database_ini_spec.rb @@ -4,11 +4,15 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'RedHat', - operatingsystem: 'RedHat', + os: { + family: 'RedHat', + }, puppetversion: Puppet.version, operatingsystemrelease: '7.0', - fqdn: 'test.domain.local', + networking: { + fqdn: 'test.domain.local', + }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/server/db_connection_uri_spec.rb b/spec/unit/classes/server/db_connection_uri_spec.rb index 1c949e2e..80d0bad5 100644 --- a/spec/unit/classes/server/db_connection_uri_spec.rb +++ b/spec/unit/classes/server/db_connection_uri_spec.rb @@ -4,10 +4,14 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'RedHat', - operatingsystem: 'RedHat', + os: { + family: 'RedHat', + }, operatingsystemrelease: '7.0', - fqdn: 'test.domain.local', + networking: { + fqdn: 'test.domain.local', + }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/server/db_read_uri_spec.rb b/spec/unit/classes/server/db_read_uri_spec.rb index b7943e15..c9bb0992 100644 --- a/spec/unit/classes/server/db_read_uri_spec.rb +++ b/spec/unit/classes/server/db_read_uri_spec.rb @@ -4,10 +4,14 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'RedHat', - operatingsystem: 'RedHat', + os: { + family: 'RedHat', + }, operatingsystemrelease: '7.0', - fqdn: 'test.domain.local', + networking: { + fqdn: 'test.domain.local', + }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/server/global_ini_spec.rb b/spec/unit/classes/server/global_ini_spec.rb index 9b7b75a2..4101852b 100644 --- a/spec/unit/classes/server/global_ini_spec.rb +++ b/spec/unit/classes/server/global_ini_spec.rb @@ -4,8 +4,13 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'RedHat', - fqdn: 'foo.com', + os: { + family: 'RedHat', + }, + networking: { + fqdn: 'foo.com', + }, + service_provider: 'systemd', } end @@ -26,9 +31,9 @@ is_expected.to contain_file('/etc/puppetlabs/puppetdb/conf.d/config.ini') .with( 'ensure' => 'file', - 'owner' => 'puppetdb', + 'owner' => 'root', 'group' => 'puppetdb', - 'mode' => '0600', + 'mode' => '0640', ) } end diff --git a/spec/unit/classes/server/jetty_ini_spec.rb b/spec/unit/classes/server/jetty_ini_spec.rb index 749d4238..bf54959f 100644 --- a/spec/unit/classes/server/jetty_ini_spec.rb +++ b/spec/unit/classes/server/jetty_ini_spec.rb @@ -4,8 +4,13 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'RedHat', - fqdn: 'test.domain.local', + os: { + family: 'RedHat', + }, + networking: { + fqdn: 'test.domain.local', + }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/server/puppetdb_ini_spec.rb b/spec/unit/classes/server/puppetdb_ini_spec.rb index a64fb25e..abcb7bd6 100644 --- a/spec/unit/classes/server/puppetdb_ini_spec.rb +++ b/spec/unit/classes/server/puppetdb_ini_spec.rb @@ -4,8 +4,13 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'RedHat', - fqdn: 'test.domain.local', + os: { + family: 'RedHat', + }, + networking: { + fqdn: 'test.domain.local', + }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/server/read_database_ini_spec.rb b/spec/unit/classes/server/read_database_ini_spec.rb index 502cdbcd..e637428a 100644 --- a/spec/unit/classes/server/read_database_ini_spec.rb +++ b/spec/unit/classes/server/read_database_ini_spec.rb @@ -4,11 +4,15 @@ context 'on a supported platform' do let(:facts) do { - osfamily: 'RedHat', - operatingsystem: 'RedHat', + os: { + family: 'RedHat', + }, puppetversion: Puppet.version, operatingsystemrelease: '7.0', - fqdn: 'test.domain.local', + networking: { + fqdn: 'test.domain.local', + }, + service_provider: 'systemd', } end diff --git a/spec/unit/classes/server_spec.rb b/spec/unit/classes/server_spec.rb index c3d2d315..6ffbf4e3 100644 --- a/spec/unit/classes/server_spec.rb +++ b/spec/unit/classes/server_spec.rb @@ -9,6 +9,7 @@ context "on #{os}" do let(:facts) do facts.merge(puppetversion: Puppet.version, + service_provider: 'systemd', selinux: true) end @@ -201,7 +202,7 @@ it 'contains file private.pk8' do is_expected.to contain_file('/etc/puppetlabs/puppetdb/ssl/private.pk8') .with( - ensure: 'present', + ensure: 'file', owner: 'puppetdb', group: 'puppetdb', mode: '0600', diff --git a/spec/unit/util/puppetdb_validator_spec.rb b/spec/unit/util/puppetdb_validator_spec.rb index c96cd801..47355f5a 100644 --- a/spec/unit/util/puppetdb_validator_spec.rb +++ b/spec/unit/util/puppetdb_validator_spec.rb @@ -8,51 +8,34 @@ url = '/pdb/meta/v1/version' if Puppet::PUPPETVERSION.to_f < 7 - conn_ok = stub - conn_ok.stubs(:get).with(url, 'Accept' => 'application/json').returns(nethttpok) - conn_ok.stubs(:read_timeout=).with(2) - conn_ok.stubs(:open_timeout=).with(2) + conn_ok = double + allow(conn_ok).to receive(:get).with(url, 'Accept' => 'application/json').and_return(nethttpok) + allow(conn_ok).to receive(:read_timeout=).with(2) + allow(conn_ok).to receive(:open_timeout=).with(2) - conn_not_found = stub - conn_not_found.stubs(:get).with('/pdb/meta/v1/version', 'Accept' => 'application/json').returns(notfound) + conn_not_found = double + allow(conn_not_found).to receive(:get).with('/pdb/meta/v1/version', 'Accept' => 'application/json').and_return(notfound) - Puppet::Network::HttpPool.stubs(:http_instance).raises('Unknown host') - Puppet::Network::HttpPool.stubs(:http_instance).with('mypuppetdb.com', 8080, true).raises('Connection refused') - Puppet::Network::HttpPool.stubs(:http_instance).with('mypuppetdb.com', 8080, false).returns(conn_ok) - Puppet::Network::HttpPool.stubs(:http_instance).with('mypuppetdb.com', 8081, true).returns(conn_ok) - Puppet::Network::HttpPool.stubs(:http_instance).with('wrongserver.com', 8081, true).returns(conn_not_found) + allow(Puppet::Network::HttpPool).to receive(:http_instance).and_raise('Unknown host') + allow(Puppet::Network::HttpPool).to receive(:http_instance).with('mypuppetdb.com', 8080, true).and_raise('Connection refused') + allow(Puppet::Network::HttpPool).to receive(:http_instance).with('mypuppetdb.com', 8080, false).and_return(conn_ok) + allow(Puppet::Network::HttpPool).to receive(:http_instance).with('mypuppetdb.com', 8081, true).and_return(conn_ok) + allow(Puppet::Network::HttpPool).to receive(:http_instance).with('wrongserver.com', 8081, true).and_return(conn_not_found) else - http = stub - Puppet::HTTP::Client.stubs(:new).returns(http) + http = double + allow(Puppet::HTTP::Client).to receive(:new).and_return(http) - http.stubs(:get).with { |uri, _opts| - uri.hostname == 'mypuppetdb.com' && - uri.port == 8080 && - uri.scheme == 'https' - }.raises Puppet::HTTP::HTTPError, 'Connection refused' + allow(http).to receive(:get) do |uri, _opts| + raise(Puppet::HTTP::HTTPError, 'Connection refused') if uri.hostname == 'mypuppetdb.com' && uri.port == 8080 && uri.scheme == 'https' + raise Puppet::HTTP::ResponseError, Puppet::HTTP::ResponseNetHTTP.new(url, notfound) if uri.hostname == 'wrongserver.com' && uri.port == 8081 && uri.scheme == 'https' + raise Puppet::HTTP::HTTPError, 'Unknown host' if uri.hostname == 'non-existing.com' && uri.scheme == 'https' - http.stubs(:get).with { |uri, _opts| - uri.hostname == 'mypuppetdb.com' && - uri.port == 8080 && - uri.scheme == 'http' - }.returns(Puppet::HTTP::ResponseNetHTTP.new(url, nethttpok)) - - http.stubs(:get).with { |uri, _opts| - uri.hostname == 'mypuppetdb.com' && - uri.port == 8081 && - uri.scheme == 'https' - }.returns(Puppet::HTTP::ResponseNetHTTP.new(url, nethttpok)) - - http.stubs(:get).with { |uri, _opts| - uri.hostname == 'wrongserver.com' && - uri.port == 8081 && - uri.scheme == 'https' - }.raises Puppet::HTTP::ResponseError, Puppet::HTTP::ResponseNetHTTP.new(url, notfound) - - http.stubs(:get).with { |uri, _opts| - uri.hostname == 'non-existing.com' && - uri.scheme == 'https' - }.raises Puppet::HTTP::HTTPError, 'Unknown host' + if uri.hostname == 'mypuppetdb.com' && uri.port == 8080 && uri.scheme == 'http' + Puppet::HTTP::ResponseNetHTTP.new(url, nethttpok) + elsif uri.hostname == 'mypuppetdb.com' && uri.port == 8081 && uri.scheme == 'https' + Puppet::HTTP::ResponseNetHTTP.new(url, nethttpok) + end + end end end @@ -70,7 +53,7 @@ puppetdb_server = 'mypuppetdb.com' puppetdb_port = 8080 validator = Puppet::Util::PuppetdbValidator.new(puppetdb_server, puppetdb_port) - Puppet.expects(:notice).with("Unable to connect to puppetdb server (https://#{puppetdb_server}:#{puppetdb_port}): Connection refused") + expect(Puppet).to receive(:notice).with("Unable to connect to puppetdb server (https://#{puppetdb_server}:#{puppetdb_port}): Connection refused") expect(validator.attempt_connection).to be false end @@ -78,7 +61,7 @@ puppetdb_server = 'wrongserver.com' puppetdb_port = 8081 validator = Puppet::Util::PuppetdbValidator.new(puppetdb_server, puppetdb_port) - Puppet.expects(:notice).with("Unable to connect to puppetdb server (https://#{puppetdb_server}:#{puppetdb_port}): [404] Not found") + expect(Puppet).to receive(:notice).with("Unable to connect to puppetdb server (https://#{puppetdb_server}:#{puppetdb_port}): [404] Not found") expect(validator.attempt_connection).to be false end @@ -86,7 +69,7 @@ puppetdb_server = 'non-existing.com' puppetdb_port = nil validator = Puppet::Util::PuppetdbValidator.new(puppetdb_server, puppetdb_port) - Puppet.expects(:notice).with("Unable to connect to puppetdb server (https://#{puppetdb_server}:#{puppetdb_port}): Unknown host") + expect(Puppet).to receive(:notice).with("Unable to connect to puppetdb server (https://#{puppetdb_server}:#{puppetdb_port}): Unknown host") expect(validator.attempt_connection).to be false end end