diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ecb10a8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# editorconfig.org + +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +tab_width = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..593e7aa --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## Affected Puppet, Ruby, OS and module versions/distributions + +- Puppet: +- Ruby: +- Distribution: +- Module version: + +## How to reproduce (e.g Puppet code you use) + +## What are you seeing + +## What behaviour did you expect instead + +## Output log + +## Any additional information you'd like to impart diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..342807b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,20 @@ + +#### Pull Request (PR) description + + +#### This Pull Request (PR) fixes the following issues + diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..f2d08d6 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,6 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +skip-changelog: + - head-branch: ['^release-*', 'release'] diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..f5b5d7a --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,42 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes + +changelog: + exclude: + labels: + - duplicate + - invalid + - modulesync + - question + - skip-changelog + - wont-fix + - wontfix + + categories: + - title: Breaking Changes 🛠 + labels: + - backwards-incompatible + + - title: New Features 🎉 + labels: + - enhancement + + - title: Bug Fixes 🐛 + labels: + - bug + + - title: Documentation Updates 📚 + labels: + - documentation + - docs + + - title: Dependency Updates ⬆️ + labels: + - dependencies + + - title: Other Changes + labels: + - "*" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4467415 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: CI + +# yamllint disable-line rule:truthy +on: + pull_request: {} + push: + branches: + - main + - master + +concurrency: + group: ${{ github.ref_name }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v3 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..eacd0b3 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,22 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: "Pull Request Labeler" + +# yamllint disable-line rule:truthy +on: + pull_request_target: {} + +permissions: + contents: read + pull-requests: write + +jobs: + labeler: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml new file mode 100644 index 0000000..2e3cc68 --- /dev/null +++ b/.github/workflows/prepare_release.yml @@ -0,0 +1,27 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: 'Prepare Release' + +on: + workflow_dispatch: + inputs: + version: + description: 'Module version to be released. Must be a valid semver string without leading v. (1.2.3)' + required: false + +permissions: + contents: write + pull-requests: write + +jobs: + release_prep: + uses: 'voxpupuli/gha-puppet/.github/workflows/prepare_release.yml@v3' + with: + version: ${{ github.event.inputs.version }} + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + github_pat: '${{ secrets.PCCI_PAT_RELEASE_PREP }}' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0a8b1b1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: Release + +# yamllint disable-line rule:truthy +on: + push: + tags: + - '*' + +permissions: + contents: write + +jobs: + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v3 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.gitignore b/.gitignore index 3f15512..adea1b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,25 @@ -.git/ -.*.sw[op] -.metadata -.yardoc -.yardwarns -*.iml -/.bundle/ -/.idea/ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +/pkg/ +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ /.vagrant/ +/.bundle/ +/.ruby-version /coverage/ -/bin/ -/doc/ -/Gemfile.local -/Gemfile.lock -/junit/ /log/ -/pkg/ -/spec/fixtures/manifests/ -/spec/fixtures/modules/* -/tmp/ -/vendor/ -/convert_report.txt -/update_report.txt -.DS_Store -.project -.envrc -/inventory.yaml -/spec/fixtures/litmus_inventory.yaml +/.idea/ +/.dependencies/ +/.librarian/ +/Puppetfile.lock +*.iml +.*.sw? +/.yardoc/ +/Guardfile +bolt-debug.log +.rerun.json diff --git a/.msync.yml b/.msync.yml new file mode 100644 index 0000000..814fbd0 --- /dev/null +++ b/.msync.yml @@ -0,0 +1,5 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +modulesync_config_version: '10.3.0' diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..4ed994c --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,67 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ +# +# Hooks are only enabled if you take action. +# +# To enable the hooks run: +# +# ``` +# bundle exec overcommit --install +# # ensure .overcommit.yml does not harm to you and then +# bundle exec overcommit --sign +# ``` +# +# (it will manage the .git/hooks directory): +# +# Examples howto skip a test for a commit or push: +# +# ``` +# SKIP=RuboCop git commit +# SKIP=PuppetLint git commit +# SKIP=RakeTask git push +# ``` +# +# Don't invoke overcommit at all: +# +# ``` +# OVERCOMMIT_DISABLE=1 git commit +# ``` +# +# Read more about overcommit: https://github.com/brigade/overcommit +# +# To manage this config yourself in your module add +# +# ``` +# .overcommit.yml: +# unmanaged: true +# ``` +# +# to your modules .sync.yml config +--- +PreCommit: + RuboCop: + enabled: true + description: 'Runs rubocop on modified files only' + command: ['bundle', 'exec', 'rubocop'] + RakeTarget: + enabled: true + description: 'Runs lint on modified files only' + targets: + - 'lint' + command: ['bundle', 'exec', 'rake'] + YamlSyntax: + enabled: true + JsonSyntax: + enabled: true + TrailingWhitespace: + enabled: true + +PrePush: + RakeTarget: + enabled: true + description: 'Run rake targets' + targets: + - 'validate' + - 'test' + - 'rubocop' + command: ['bundle', 'exec', 'rake'] diff --git a/.pdkignore b/.pdkignore deleted file mode 100644 index fe5cdba..0000000 --- a/.pdkignore +++ /dev/null @@ -1,50 +0,0 @@ -.git/ -.*.sw[op] -.metadata -.yardoc -.yardwarns -*.iml -/.bundle/ -/.idea/ -/.vagrant/ -/coverage/ -/bin/ -/doc/ -/Gemfile.local -/Gemfile.lock -/junit/ -/log/ -/pkg/ -/spec/fixtures/manifests/ -/spec/fixtures/modules/* -/tmp/ -/vendor/ -/convert_report.txt -/update_report.txt -.DS_Store -.project -.envrc -/inventory.yaml -/spec/fixtures/litmus_inventory.yaml -/.fixtures.yml -/Gemfile -/.gitattributes -/.github/ -/.gitignore -/.pdkignore -/.puppet-lint.rc -/Rakefile -/rakelib/ -/.rspec -/..yml -/.yardopts -/spec/ -/.vscode/ -/.sync.yml -/.devcontainer/ -/.*.yml -/pdk.yaml -/.pmtignore -/.git* -/.editorconfig -/provision.yaml diff --git a/.pmtignore b/.pmtignore index 37dc865..a9d37aa 100644 --- a/.pmtignore +++ b/.pmtignore @@ -1,4 +1,39 @@ -spec/ -Rakefile -Gemfile -Gemfile.lock +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +/docs/ +/pkg/ +/Gemfile +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/ +/Rakefile +/.vagrant/ +/.bundle/ +/.ruby-version +/coverage/ +/log/ +/.idea/ +/.dependencies/ +/.github/ +/.librarian/ +/Puppetfile.lock +/Puppetfile +*.iml +/.editorconfig +/.fixtures.yml +/.gitignore +/.msync.yml +/.overcommit.yml +/.pmtignore +/.rspec +/.rspec_parallel +/.rubocop.yml +/.sync.yml +.*.sw? +/.yardoc/ +/.yardopts +/Dockerfile +/HISTORY.md diff --git a/.puppet-lint.rc b/.puppet-lint.rc index 59a96b0..05d28a2 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1,3 +1,6 @@ ---relative +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +--fail-on-warnings +--no-parameter_documentation-check --no-parameter_types-check ---no-140chars-check diff --git a/.rspec b/.rspec deleted file mode 100644 index 16f9cdb..0000000 --- a/.rspec +++ /dev/null @@ -1,2 +0,0 @@ ---color ---format documentation diff --git a/.rspec_parallel b/.rspec_parallel deleted file mode 100644 index e4d136b..0000000 --- a/.rspec_parallel +++ /dev/null @@ -1 +0,0 @@ ---format progress diff --git a/.rubocop.yml b/.rubocop.yml index 043ef9d..fded90c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,725 +1,7 @@ --- -require: -- rubocop-performance -- rubocop-rspec -AllCops: - DisplayCopNames: true - TargetRubyVersion: '2.6' - Include: - - "**/*.rb" - - "**/*.rake" - Exclude: - - bin/* - - ".vendor/**/*" - - "**/Gemfile" - - "**/Rakefile" - - pkg/**/* - - spec/fixtures/**/* - - vendor/**/* - - "**/Puppetfile" - - "**/Vagrantfile" - - "**/Guardfile" - NewCops: enable -Layout/LineLength: - Description: People have wide screens, use them. - Max: 200 -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 -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/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/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/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 -Bundler/GemFilename: - Enabled: false -Bundler/InsecureProtocolSource: - Enabled: false -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/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: - 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 -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/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 -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 +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +inherit_from: .rubocop_todo.yml +inherit_gem: + voxpupuli-test: rubocop.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..a32e229 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,74 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --no-auto-gen-timestamp` +# using RuboCop version 1.50.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'spec/defines/database/postgresql_ssl_rules_spec.rb' + +# Offense count: 1 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +Lint/DuplicateBranch: + Exclude: + - 'spec/unit/util/puppetdb_validator_spec.rb' + +# Offense count: 2 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'spec/acceptance/standalone_spec.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/BeEq: + Exclude: + - 'spec/functions/create_subsetting_resource_hash_spec.rb' + - 'spec/functions/flatten_java_args_spec.rb' + +# Offense count: 4 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 9 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 8 + +# Offense count: 2 +RSpec/RepeatedExampleGroupBody: + Exclude: + - 'spec/acceptance/standalone_spec.rb' + +# Offense count: 2 +RSpec/RepeatedExampleGroupDescription: + Exclude: + - 'spec/unit/classes/master/config_spec.rb' + +# Offense count: 1 +RSpec/StubbedMock: + Exclude: + - 'spec/unit/facter/puppetdb_version_spec.rb' + +# Offense count: 28 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper_local.rb' diff --git a/.sync.yml b/.sync.yml index 5fff93c..5d21319 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,24 +1,3 @@ --- -.rubocop.yml: - default_configs: - AllCops: - NewCops: enable - Include: - - '**/*.rake' -.pdkignore: - paths: - - /.*.yml - - /pdk.yaml - - /.pmtignore - - /.git* - - /.editorconfig - - /provision.yaml -Rakefile: - default_disabled_lint_checks: - - parameter_types - - 140chars -spec/default_facts.yml: - unmanaged: true -spec/spec_helper.rb: - coverage_report: true - minimum_code_coverage_percentage: 100 +spec/spec_helper_acceptance.rb: + unmanaged: false diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 2f1e4f7..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "recommendations": [ - "puppet.puppet-vscode", - "rebornix.Ruby" - ] -} diff --git a/.yardopts b/.yardopts deleted file mode 100644 index 29c933b..0000000 --- a/.yardopts +++ /dev/null @@ -1 +0,0 @@ ---markup markdown diff --git a/Gemfile b/Gemfile index ca0e773..5625986 100644 --- a/Gemfile +++ b/Gemfile @@ -1,78 +1,28 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -def location_for(place_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} +source ENV['GEM_SOURCE'] || 'https://rubygems.org' - 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 +group :test do + gem 'voxpupuli-test', '~> 13.0', :require => false + gem 'puppet_metadata', '~> 5.0', :require => false end group :development do - 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] + gem 'guard-rake', :require => false + gem 'overcommit', '>= 0.39.1', :require => false end + group :system_tests do - gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] - gem "serverspec", '~> 2.41', require: false + gem 'voxpupuli-acceptance', '~> 4.0', :require => false end -group :release_prep do - gem "puppet-strings", '~> 4.0', require: false - gem "puppetlabs_spec_helper", '~> 6.0', require: false -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 - -gems.each do |gem_name, gem_params| - gem gem_name, *gem_params +group :release do + gem 'voxpupuli-release', '~> 5.0', :require => false end -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] +gem 'rake', :require => false + +gem 'openvox', ENV.fetch('OPENVOX_GEM_VERSION', [">= 7", "< 9"]), :require => false, :groups => [:test] -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/Rakefile b/Rakefile index aff8119..cab0f7a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,90 +1,36 @@ -# frozen_string_literal: true +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -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 '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" - returnVal = nil || JSON.load(File.read('metadata.json'))['author'] - raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator user:#{returnVal}" - returnVal +begin + require 'voxpupuli/test/rake' +rescue LoadError + # only available if gem group test is installed end -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - - returnVal = nil - returnVal ||= begin - metadata_source = JSON.load(File.read('metadata.json'))['source'] - metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) - - metadata_source_match && metadata_source_match[1] - end - - raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? - - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal +begin + require 'voxpupuli/acceptance/rake' +rescue LoadError + # only available if gem group acceptance is installed end -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] - raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator future_release:#{returnVal}" - returnVal +begin + require 'voxpupuli/release/rake_tasks' +rescue LoadError + # only available if gem group releases is installed +else + GCGConfig.user = 'voxpupuli' + GCGConfig.project = 'puppet-openvoxdb' end -PuppetLint.configuration.send('disable_relative') -PuppetLint.configuration.send('disable_parameter_types') -PuppetLint.configuration.send('disable_140chars') - - -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}" - config.project = "#{changelog_project}" - config.future_release = "#{changelog_future_release}" - config.exclude_labels = ['maintenance'] - 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; LABEL THEM ON GITHUB" - config.configure_sections = { - "Changed" => { - "prefix" => "### Changed", - "labels" => ["backwards-incompatible"], - }, - "Added" => { - "prefix" => "### Added", - "labels" => ["enhancement", "feature"], - }, - "Fixed" => { - "prefix" => "### Fixed", - "labels" => ["bug", "documentation", "bugfix"], - }, - } - end -else - desc 'Generate a Changelog from GitHub' - task :changelog do - raise < 1.15' - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" -EOM +desc "Run main 'test' task and report merged results to coveralls" +task test_with_coveralls: [:test] do + if Dir.exist?(File.expand_path('../lib', __FILE__)) + require 'coveralls/rake/task' + Coveralls::RakeTask.new + Rake::Task['coveralls:push'].invoke + else + puts 'Skipping reporting to coveralls. Module has no lib dir' end end +# vim: syntax=ruby diff --git a/lib/puppet/provider/puppetdb_conn_validator/puppet_https.rb b/lib/puppet/provider/puppetdb_conn_validator/puppet_https.rb index 0167253..5330b75 100644 --- a/lib/puppet/provider/puppetdb_conn_validator/puppet_https.rb +++ b/lib/puppet/provider/puppetdb_conn_validator/puppet_https.rb @@ -43,9 +43,7 @@ def exists? success = validator.attempt_connection end - unless success - Puppet.notice("Failed to connect to puppetdb within timeout window of #{timeout} seconds; giving up.") - end + Puppet.notice("Failed to connect to puppetdb within timeout window of #{timeout} seconds; giving up.") unless success success end diff --git a/lib/puppet/util/puppetdb_validator.rb b/lib/puppet/util/puppetdb_validator.rb index 5cb966b..b0f483e 100644 --- a/lib/puppet/util/puppetdb_validator.rb +++ b/lib/puppet/util/puppetdb_validator.rb @@ -2,11 +2,7 @@ # Validator class, for testing that PuppetDB is alive class Puppet::Util::PuppetdbValidator - attr_reader :puppetdb_server - attr_reader :puppetdb_port - attr_reader :use_ssl - attr_reader :test_path - attr_reader :test_headers + attr_reader :puppetdb_server, :puppetdb_port, :use_ssl, :test_path, :test_headers def initialize(puppetdb_server, puppetdb_port, use_ssl = true, test_path = '/pdb/meta/v1/version') @puppetdb_server = puppetdb_server diff --git a/manifests/server.pp b/manifests/server.pp index e6a708d..3b9f533 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -639,10 +639,10 @@ # 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': diff --git a/pdk.yaml b/pdk.yaml deleted file mode 100644 index 4bef4bd..0000000 --- a/pdk.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -ignore: [] diff --git a/spec/acceptance/standalone_spec.rb b/spec/acceptance/standalone_spec.rb index 72db256..a88b1a2 100644 --- a/spec/acceptance/standalone_spec.rb +++ b/spec/acceptance/standalone_spec.rb @@ -1,13 +1,12 @@ require 'spec_helper_acceptance' describe 'standalone' do - it_behaves_like 'puppetserver' - - let(:puppetdb_params) {} + let(:manage_firewall) { "(getvar('facts.os.family') == 'RedHat' and Integer(getvar('facts.os.release.major')) > 7)" } + let(:postgres_version) { 'undef' } # default let(:puppetdb_master_config_params) {} + let(:puppetdb_params) {} - let(:postgres_version) { 'undef' } # default - let(:manage_firewall) { "(getvar('facts.os.family') == 'RedHat' and Integer(getvar('facts.os.release.major')) > 7)" } + it_behaves_like 'puppetserver' describe 'with defaults' do it_behaves_like 'puppetdb' @@ -27,30 +26,30 @@ context 'puppetdb postgres user', :status do it 'is not allowing read-only user to create tables' do - run_shell('psql "postgresql://puppetdb-read:puppetdb-read@localhost/puppetdb" -c "create table tables(id int)"', expect_failures: true) do |r| - expect(r.stderr).to match(%r{^ERROR: permission denied for schema public.*}) - expect(r.exit_code).to eq 1 + command('psql "postgresql://puppetdb-read:puppetdb-read@localhost/puppetdb" -c "create table tables(id int)"') do + its(:stderr) { is_expected.to match %r{^ERROR: permission denied for schema public.*} } + its(:exit_status) { is_expected.to eq 1 } end end it 'is allowing normal user to manage schema' do - run_shell('psql "postgresql://puppetdb:puppetdb@localhost/puppetdb" -c "create table testing(id int); drop table testing"') do |r| - expect(r.exit_status).to eq 0 + command('psql "postgresql://puppetdb:puppetdb@localhost/puppetdb" -c "create table testing(id int); drop table testing"') do + its(:exit_status) { is_expected.to eq 0 } end end it 'is allowing read-only user to select' do - run_shell('psql "postgresql://puppetdb-read:puppetdb-read@localhost/puppetdb" -c "select * from catalogs limit 1"') do |r| - expect(r.exit_status).to eq 0 + command('psql "postgresql://puppetdb-read:puppetdb-read@localhost/puppetdb" -c "select * from catalogs limit 1"') do + its(:exit_status) { is_expected.to eq 0 } end end end end context 'with manage report processor', :change do - ['remove', 'add'].each do |outcome| + %w[remove add].each do |outcome| context "#{outcome}s puppet config puppetdb report processor" do - let(:enable_reports) { (outcome == 'add') ? true : false } + let(:enable_reports) { outcome == 'add' } let(:puppetdb_master_config_params) do <<~EOS @@ -96,7 +95,7 @@ ~> service { 'puppetdb': ensure => 'running', } - EOS + EOS apply_manifest(pp, expect_failures: false, debug: ENV.key?('DEBUG')) end diff --git a/spec/defines/database/default_read_grant_spec.rb b/spec/defines/database/default_read_grant_spec.rb index 95393df..8f86d15 100644 --- a/spec/defines/database/default_read_grant_spec.rb +++ b/spec/defines/database/default_read_grant_spec.rb @@ -10,7 +10,7 @@ database_read_only_username: 'puppetdb-read', } valid = { - 'standard': defaults, + standard: defaults, 'standard with port': defaults.merge({ database_port: 5433 }), } diff --git a/spec/defines/database/postgresql_ssl_rules_spec.rb b/spec/defines/database/postgresql_ssl_rules_spec.rb index 852ca56..24d0bcb 100644 --- a/spec/defines/database/postgresql_ssl_rules_spec.rb +++ b/spec/defines/database/postgresql_ssl_rules_spec.rb @@ -9,7 +9,7 @@ postgres_version: '11', puppetdb_server: 'localhost', }, - 'monitor': { + monitor: { database_name: 'opensesame', database_username: 'grover', postgres_version: '11', @@ -24,7 +24,7 @@ postgres_version: '12', puppetdb_server: 'localhost', }, - 'monitor': { + monitor: { database_name: 'opensesame', database_username: 'grover', postgres_version: '12', diff --git a/spec/defines/database/read_only_user_spec.rb b/spec/defines/database/read_only_user_spec.rb index c482024..720a0f4 100644 --- a/spec/defines/database/read_only_user_spec.rb +++ b/spec/defines/database/read_only_user_spec.rb @@ -10,7 +10,7 @@ valid = { 'puppetdb-read': defaults.merge({ password_hash: 'blash' }), - 'spectest': { + spectest: { read_database_username: 'spectest-read', database_name: 'spectest', database_owner: 'spectest', diff --git a/spec/functions/create_subsetting_resource_hash_spec.rb b/spec/functions/create_subsetting_resource_hash_spec.rb index 7ad8cc6..87d3818 100644 --- a/spec/functions/create_subsetting_resource_hash_spec.rb +++ b/spec/functions/create_subsetting_resource_hash_spec.rb @@ -6,8 +6,9 @@ it { is_expected.to run.with_params('test' => 1).and_raise_error(ArgumentError) } it { is_expected.to run.with_params('foo', 'bar').and_raise_error(ArgumentError) } it { is_expected.to run.with_params({ 'foo' => 1 }, { 'bar' => 2 }, 'baz' => 3).and_raise_error(ArgumentError) } + it { - is_expected.to run.with_params({ 'foo' => 1, 'bar' => 2 }, 'baz' => 3) - .and_return("'foo'" => { 'subsetting' => 'foo', 'value' => 1, 'baz' => 3 }, "'bar'" => { 'subsetting' => 'bar', 'value' => 2, 'baz' => 3 }) + is_expected.to run.with_params({ 'foo' => 1, 'bar' => 2 }, 'baz' => 3). + and_return("'foo'" => { 'subsetting' => 'foo', 'value' => 1, 'baz' => 3 }, "'bar'" => { 'subsetting' => 'bar', 'value' => 2, 'baz' => 3 }) } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61df294..58c9b66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,74 +1,24 @@ # frozen_string_literal: true -RSpec.configure do |c| - c.mock_with :rspec -end - -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' - -require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) - -include RspecPuppetFacts +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -default_facts = { - puppetversion: Puppet.version, - facterversion: Facter.version, -} - -default_fact_files = [ - File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), - File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), -] - -default_fact_files.each do |f| - next unless File.exist?(f) && File.readable?(f) && File.size?(f) - - begin - 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 +# puppetlabs_spec_helper will set up coverage if the env variable is set. +# We want to do this if lib exists and it hasn't been explicitly set. +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) -# read default_facts and merge them over what is provided by facterdb -default_facts.each do |fact, value| - add_custom_fact fact, value -end +require 'voxpupuli/test/spec_helper' RSpec.configure do |c| - c.default_facts = default_facts - c.before :each do - # set to strictest setting for testing - # by default Puppet runs at warning level - Puppet.settings[:strict] = :warning - Puppet.settings[:strict_variables] = true - end - c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] - c.after(:suite) do - RSpec::Puppet::Coverage.report!(100) - 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 + c.facterdb_string_keys = false end -# Ensures that a module is defined -# @param module_name Name of the module -def ensure_module_defined(module_name) - module_name.split('::').reduce(Object) do |last_module, next_module| - last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) - last_module.const_get(next_module, false) +add_mocked_facts! + +if File.exist?(File.join(__dir__, 'default_module_facts.yml')) + facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) + facts&.each do |name, value| + add_custom_fact name.to_sym, value end end - -# 'spec_overrides' from sync.yml will appear below this line +Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 73a0238..2681792 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true -require 'puppet_litmus' -PuppetLitmus.configure! +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) +require 'voxpupuli/acceptance/spec_helper_acceptance' + +configure_beaker(modules: :metadata) + +Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } diff --git a/spec/support/acceptance/shared/puppetdb.rb b/spec/support/acceptance/shared/puppetdb.rb index fd78af4..37abd2e 100644 --- a/spec/support/acceptance/shared/puppetdb.rb +++ b/spec/support/acceptance/shared/puppetdb.rb @@ -3,47 +3,48 @@ shared_examples 'puppetdb' do let(:pp) do <<~PP - if $facts['os']['family'] == 'RedHat' { - # Work-around EL systemd in docker bug affecting forked services - file_line { 'puppetdb-unit-remove-pidfile': - path => '/lib/systemd/system/puppetdb.service', - line => '#PIDFile=/run/puppetlabs/puppetdb/puppetdb.pid', - match => '^PIDFile.*', - append_on_no_match => false, - require => Package['puppetdb'], - notify => Service['puppetdb'], + if $facts['os']['family'] == 'RedHat' { + # Work-around EL systemd in docker bug affecting forked services + file_line { 'puppetdb-unit-remove-pidfile': + path => '/lib/systemd/system/puppetdb.service', + line => '#PIDFile=/run/puppetlabs/puppetdb/puppetdb.pid', + match => '^PIDFile.*', + append_on_no_match => false, + require => Package['puppetdb'], + notify => Service['puppetdb'], + } } - } - # reduce pgs memory - postgresql::server::config_entry { 'max_connections': value => '20' } - postgresql::server::config_entry { 'shared_buffers': value => '128kB' } - postgresql::server::config_entry { 'effective_cache_size': value => '24MB' } - postgresql::server::config_entry { 'maintenance_work_mem': value => '1MB' } - postgresql::server::config_entry { 'checkpoint_completion_target': value => '0.9' } - postgresql::server::config_entry { 'wal_buffers': value => '32kB' } - postgresql::server::config_entry { 'random_page_cost': value => '4' } - postgresql::server::config_entry { 'effective_io_concurrency': value => '2' } - postgresql::server::config_entry { 'work_mem': value => '204kB' } - postgresql::server::config_entry { 'huge_pages': value => 'off' } - postgresql::server::config_entry { 'min_wal_size': value => '80MB' } - postgresql::server::config_entry { 'max_wal_size': value => '1GB' } + # reduce pgs memory + postgresql::server::config_entry { 'max_connections': value => '20' } + postgresql::server::config_entry { 'shared_buffers': value => '128kB' } + postgresql::server::config_entry { 'effective_cache_size': value => '24MB' } + postgresql::server::config_entry { 'maintenance_work_mem': value => '1MB' } + postgresql::server::config_entry { 'checkpoint_completion_target': value => '0.9' } + postgresql::server::config_entry { 'wal_buffers': value => '32kB' } + postgresql::server::config_entry { 'random_page_cost': value => '4' } + postgresql::server::config_entry { 'effective_io_concurrency': value => '2' } + postgresql::server::config_entry { 'work_mem': value => '204kB' } + postgresql::server::config_entry { 'huge_pages': value => 'off' } + postgresql::server::config_entry { 'min_wal_size': value => '80MB' } + postgresql::server::config_entry { 'max_wal_size': value => '1GB' } - class { 'puppetdb': - postgres_version => #{postgres_version}, - manage_firewall => #{manage_firewall}, - database_max_pool_size => '2', - read_database_max_pool_size => '2', - #{puppetdb_params} - } - -> class { 'puppetdb::master::config': - #{puppetdb_master_config_params} - } + class { 'puppetdb': + postgres_version => #{postgres_version}, + manage_firewall => #{manage_firewall}, + database_max_pool_size => '2', + read_database_max_pool_size => '2', + #{puppetdb_params} + } + -> class { 'puppetdb::master::config': + #{puppetdb_master_config_params} + } PP end it 'applies idempotently' do - idempotent_apply(pp, debug: ENV.key?('DEBUG')) + apply_manifest(pp, expect_failures: false, debug: ENV.key?('DEBUG')) + apply_manifest(pp, expect_failures: false, debug: ENV.key?('DEBUG')) end it 'agent can puppetdb_query' do diff --git a/spec/support/acceptance/shared/puppetserver.rb b/spec/support/acceptance/shared/puppetserver.rb index d4732cd..39cd684 100644 --- a/spec/support/acceptance/shared/puppetserver.rb +++ b/spec/support/acceptance/shared/puppetserver.rb @@ -4,6 +4,7 @@ let(:pp) { File.read(File.join(File.dirname(__FILE__), 'puppetserver.pp')) } it 'applies idempotently' do - idempotent_apply(pp, debug: ENV.key?('DEBUG')) + apply_manifest(pp, expect_failures: false, debug: ENV.key?('DEBUG')) + apply_manifest(pp, expect_failures: false, debug: ENV.key?('DEBUG')) end end diff --git a/spec/support/unit/shared/database.rb b/spec/support/spec/shared/database.rb similarity index 83% rename from spec/support/unit/shared/database.rb rename to spec/support/spec/shared/database.rb index 23a7755..6dbfe4b 100644 --- a/spec/support/unit/shared/database.rb +++ b/spec/support/spec/shared/database.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals' - shared_examples 'postgresql_psql read grant' do it { - is_expected.to contain_postgresql_psql("grant select permission for #{with[:database_read_only_username]}") - .with( + is_expected.to contain_postgresql_psql("grant select permission for #{with[:database_read_only_username]}"). + with( db: with[:database_name], command: "GRANT SELECT ON ALL TABLES IN SCHEMA \"public\" @@ -16,13 +14,13 @@ WHERE schemaname='public' AND has_table_privilege('#{with[:database_read_only_username]}', schemaname || '.' || tablename, 'SELECT')=false ) x - WHERE x.count=0", + WHERE x.count=0" ) } it { - is_expected.to contain_postgresql_psql("grant usage permission for #{with[:database_read_only_username]}") - .with( + is_expected.to contain_postgresql_psql("grant usage permission for #{with[:database_read_only_username]}"). + with( db: with[:database_name], command: "GRANT USAGE ON ALL SEQUENCES IN SCHEMA \"public\" @@ -33,33 +31,33 @@ WHERE sequence_schema='public' AND has_sequence_privilege('#{with[:database_read_only_username]}', sequence_schema || '.' || sequence_name, 'USAGE')=false ) x - WHERE x.count=0", + WHERE x.count=0" ) } it { - is_expected.to contain_postgresql_psql("grant execution permission for #{with[:database_read_only_username]}") - .with( + is_expected.to contain_postgresql_psql("grant execution permission for #{with[:database_read_only_username]}"). + with( db: with[:database_name], command: "GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA \"public\" TO \"#{with[:database_read_only_username]}\"", - unless: "SELECT * FROM ( + unless: "SELECT * FROM ( SELECT COUNT(*) FROM pg_catalog.pg_proc p LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace WHERE n.nspname='public' AND has_function_privilege('#{with[:database_read_only_username]}', p.oid, 'EXECUTE')=false ) x - WHERE x.count=0", + WHERE x.count=0" ) } end shared_examples 'postgresql_psql default read grant' do it { - is_expected.to contain_postgresql_psql("grant default select permission for #{with[:database_read_only_username]}") - .with( + is_expected.to contain_postgresql_psql("grant default select permission for #{with[:database_read_only_username]}"). + with( db: with[:database_name], command: "ALTER DEFAULT PRIVILEGES FOR USER \"#{with[:database_username]}\" @@ -73,13 +71,13 @@ FROM pg_default_acl acl JOIN pg_namespace ns ON acl.defaclnamespace=ns.oid WHERE '@' || array_to_string(acl.defaclacl, '@') || '@' ~ '@(\"?)#{with[:database_read_only_username]}\\1=r/(\"?)#{with[:database_username]}\\2@' - AND nspname = 'public'", + AND nspname = 'public'" ) } it { - is_expected.to contain_postgresql_psql("grant default usage permission for #{with[:database_read_only_username]}") - .with( + is_expected.to contain_postgresql_psql("grant default usage permission for #{with[:database_read_only_username]}"). + with( db: with[:database_name], command: "ALTER DEFAULT PRIVILEGES FOR USER \"#{with[:database_username]}\" @@ -93,13 +91,13 @@ FROM pg_default_acl acl JOIN pg_namespace ns ON acl.defaclnamespace=ns.oid WHERE '@' || array_to_string(acl.defaclacl, '@') || '@' ~ '@(\"?)#{with[:database_read_only_username]}\\1=U/(\"?)#{with[:database_username]}\\2@' - AND nspname = 'public'", + AND nspname = 'public'" ) } it { - is_expected.to contain_postgresql_psql("grant default execute permission for #{with[:database_read_only_username]}") - .with( + is_expected.to contain_postgresql_psql("grant default execute permission for #{with[:database_read_only_username]}"). + with( db: with[:database_name], command: "ALTER DEFAULT PRIVILEGES FOR USER \"#{with[:database_username]}\" @@ -113,7 +111,7 @@ FROM pg_default_acl acl JOIN pg_namespace ns ON acl.defaclnamespace=ns.oid WHERE '@' || array_to_string(acl.defaclacl, '@') || '@' ~ '@(\"?)#{with[:database_read_only_username]}\\1=X/(\"?)#{with[:database_username]}\\2@' - AND nspname = 'public'", + AND nspname = 'public'" ) } end @@ -135,31 +133,31 @@ it { is_expected.to contain_puppetdb__database__read_only_user(name).with(with) } it { - is_expected.to contain_postgresql__server__role(with[:read_database_username]) - .that_comes_before("Postgresql::Server::Database_grant[#{with[:database_name]} grant connection permission to #{with[:read_database_username]}]") - .with_password_hash(with[:password_hash]) + is_expected.to contain_postgresql__server__role(with[:read_database_username]). + that_comes_before("Postgresql::Server::Database_grant[#{with[:database_name]} grant connection permission to #{with[:read_database_username]}]"). + with_password_hash(with[:password_hash]) } it { btitle = "#{with[:database_name]} grant read permission on new objects from #{with[:database_owner]} to #{with[:read_database_username]}" - is_expected.to contain_postgresql__server__database_grant("#{with[:database_name]} grant connection permission to #{with[:read_database_username]}") - .that_comes_before("Puppetdb::Database::Default_read_grant[#{btitle}]") - .with( + is_expected.to contain_postgresql__server__database_grant("#{with[:database_name]} grant connection permission to #{with[:read_database_username]}"). + that_comes_before("Puppetdb::Database::Default_read_grant[#{btitle}]"). + with( privilege: 'CONNECT', db: with[:database_name], - role: with[:read_database_username], + role: with[:read_database_username] ) } it { rtitle = "#{with[:database_name]} grant read permission on new objects from #{with[:database_owner]} to #{with[:read_database_username]}" - is_expected.to contain_puppetdb__database__default_read_grant(rtitle) - .that_comes_before("Puppetdb::Database::Read_grant[#{with[:database_name]} grant read-only permission on existing objects to #{with[:read_database_username]}]") - .with( + is_expected.to contain_puppetdb__database__default_read_grant(rtitle). + that_comes_before("Puppetdb::Database::Read_grant[#{with[:database_name]} grant read-only permission on existing objects to #{with[:read_database_username]}]"). + with( database_username: with[:database_owner], database_read_only_username: with[:read_database_username], database_name: with[:database_name], - schema: 'public', + schema: 'public' ) } @@ -174,11 +172,11 @@ end it { - is_expected.to contain_puppetdb__database__read_grant("#{with[:database_name]} grant read-only permission on existing objects to #{with[:read_database_username]}") - .with( + is_expected.to contain_puppetdb__database__read_grant("#{with[:database_name]} grant read-only permission on existing objects to #{with[:read_database_username]}"). + with( database_read_only_username: with[:read_database_username], database_name: with[:database_name], - schema: 'public', + schema: 'public' ) } @@ -227,42 +225,42 @@ it { is_expected.to raise_error(error) } else let(:identity_map_key) { "#{with[:database_name]}-#{with[:database_username]}-map" } - let(:client_cert) { (with[:postgres_version].to_f >= 12.0) ? 'verify-full' : '1' } + let(:client_cert) { with[:postgres_version].to_f >= 12.0 ? 'verify-full' : '1' } it { is_expected.to contain_puppetdb__database__postgresql_ssl_rules(name).with(with) } it { - is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{with[:database_name]} as #{with[:database_username]} (ipv4)") - .with( + is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{with[:database_name]} as #{with[:database_username]} (ipv4)"). + with( type: 'hostssl', database: with[:database_name], user: with[:database_username], address: '0.0.0.0/0', auth_method: 'cert', order: 0, - auth_option: "map=#{identity_map_key} clientcert=#{client_cert}", + auth_option: "map=#{identity_map_key} clientcert=#{client_cert}" ) } it { - is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{with[:database_name]} as #{with[:database_username]} (ipv6)") - .with( + is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{with[:database_name]} as #{with[:database_username]} (ipv6)"). + with( type: 'hostssl', database: with[:database_name], user: with[:database_username], address: '::0/0', auth_method: 'cert', order: 0, - auth_option: "map=#{identity_map_key} clientcert=#{client_cert}", + auth_option: "map=#{identity_map_key} clientcert=#{client_cert}" ) } it { - is_expected.to contain_postgresql__server__pg_ident_rule("Map the SSL certificate of the server as a #{with[:database_username]} user") - .with( + is_expected.to contain_postgresql__server__pg_ident_rule("Map the SSL certificate of the server as a #{with[:database_username]} user"). + with( map_name: identity_map_key, system_username: with[:puppetdb_server], - database_username: with[:database_username], + database_username: with[:database_username] ) } end diff --git a/spec/support/unit/shared/inherits.rb b/spec/support/spec/shared/inherits.rb similarity index 100% rename from spec/support/unit/shared/inherits.rb rename to spec/support/spec/shared/inherits.rb diff --git a/spec/support/unit/shared/server.rb b/spec/support/spec/shared/server.rb similarity index 85% rename from spec/support/unit/shared/server.rb rename to spec/support/spec/shared/server.rb index d15b498..ee78dab 100644 --- a/spec/support/unit/shared/server.rb +++ b/spec/support/spec/shared/server.rb @@ -17,21 +17,21 @@ it { option = with[:open_http_port] ? 'to' : 'not_to' - is_expected.method(option).call contain_firewall("#{with[:http_port]} accept - puppetdb") - .with( + is_expected.method(option).call contain_firewall("#{with[:http_port]} accept - puppetdb"). + with( dport: with[:http_port], proto: 'tcp', - jump: 'accept', + jump: 'accept' ) } it { option = with[:open_ssl_port] ? 'to' : 'not_to' - is_expected.method(option).call contain_firewall("#{with[:ssl_port]} accept - puppetdb") - .with( + is_expected.method(option).call contain_firewall("#{with[:ssl_port]} accept - puppetdb"). + with( dport: with[:ssl_port], proto: 'tcp', - jump: 'accept', + jump: 'accept' ) } end diff --git a/spec/support/unit/facts.rb b/spec/support/unit/facts.rb deleted file mode 100644 index ca0dda6..0000000 --- a/spec/support/unit/facts.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Rough conversion of grepping in the puppet source: -# grep defaultfor lib/puppet/provider/service/*.rb -# Source https://github.com/voxpupuli/voxpupuli-test/blob/master/lib/voxpupuli/test/facts.rb -add_custom_fact :service_provider, ->(_os, facts) do - os = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os] - case os['family'].downcase - when 'archlinux' - 'systemd' - when 'darwin' - 'launchd' - when 'debian' - 'systemd' - when 'freebsd' - 'freebsd' - when 'gentoo' - 'openrc' - when 'openbsd' - 'openbsd' - when 'redhat' - (os['release']['major'].to_i >= 7) ? 'systemd' : 'redhat' - when 'suse' - (os['release']['major'].to_i >= 12) ? 'systemd' : 'redhat' - when 'windows' - 'windows' - else - 'init' - end -end diff --git a/spec/unit/classes/database/postgresql_spec.rb b/spec/unit/classes/database/postgresql_spec.rb index 74fd63b..00e6e34 100644 --- a/spec/unit/classes/database/postgresql_spec.rb +++ b/spec/unit/classes/database/postgresql_spec.rb @@ -11,9 +11,9 @@ it { is_expected.to contain_class('postgresql::server::contrib') } it { - is_expected.to contain_postgresql__server__extension('pg_trgm') - .that_requires('Postgresql::Server::Db[puppetdb]') - .with_database('puppetdb') + is_expected.to contain_postgresql__server__extension('pg_trgm'). + that_requires('Postgresql::Server::Db[puppetdb]'). + with_database('puppetdb') } context 'when ssl communication is used' do @@ -56,41 +56,41 @@ end it { - is_expected.to contain_postgresql__server__db(params[:database_name]) - .with( + is_expected.to contain_postgresql__server__db(params[:database_name]). + with( user: params[:database_username], password: params[:database_password], grant: 'all', port: params[:database_port].to_i, encoding: 'UTF8', - locale: 'en_US.UTF-8', + locale: 'en_US.UTF-8' ) } it { - is_expected.to contain_postgresql_psql('revoke all access on public schema') - .that_requires("Postgresql::Server::Db[#{params[:database_name]}]") - .with( + is_expected.to contain_postgresql_psql('revoke all access on public schema'). + that_requires("Postgresql::Server::Db[#{params[:database_name]}]"). + with( db: params[:database_name], port: params[:database_port].to_i, command: 'REVOKE CREATE ON SCHEMA public FROM public', unless: "SELECT * FROM (SELECT has_schema_privilege('public', 'public', 'create') can_create) privs - WHERE privs.can_create=false", + WHERE privs.can_create=false" ) } it { - is_expected.to contain_postgresql_psql("grant all permissions to #{params[:database_username]}") - .that_requires('Postgresql_psql[revoke all access on public schema]') - .that_comes_before("Puppetdb::Database::Read_only_user[#{params[:read_database_username]}]") - .with( + is_expected.to contain_postgresql_psql("grant all permissions to #{params[:database_username]}"). + that_requires('Postgresql_psql[revoke all access on public schema]'). + that_comes_before("Puppetdb::Database::Read_only_user[#{params[:read_database_username]}]"). + with( db: params[:database_name], port: params[:database_port].to_i, command: "GRANT CREATE ON SCHEMA public TO \"#{params[:database_username]}\"", unless: "SELECT * FROM (SELECT has_schema_privilege('#{params[:database_username]}', 'public', 'create') can_create) privs - WHERE privs.can_create=true", + WHERE privs.can_create=true" ) } @@ -108,14 +108,14 @@ end it { - is_expected.to contain_postgresql_psql("grant #{params[:read_database_username]} role to #{params[:database_username]}") - .that_requires("Puppetdb::Database::Read_only_user[#{params[:read_database_username]}]") - .with( + is_expected.to contain_postgresql_psql("grant #{params[:read_database_username]} role to #{params[:database_username]}"). + that_requires("Puppetdb::Database::Read_only_user[#{params[:read_database_username]}]"). + with( db: params[:database_name], port: params[:database_port].to_i, command: "GRANT \"#{params[:read_database_username]}\" TO \"#{params[:database_username]}\"", unless: "SELECT oid, rolname FROM pg_roles WHERE - pg_has_role( '#{params[:database_username]}', oid, 'member') and rolname = '#{params[:read_database_username]}'", + pg_has_role( '#{params[:database_username]}', oid, 'member') and rolname = '#{params[:read_database_username]}'" ) } end diff --git a/spec/unit/classes/database/ssl_configuration_spec.rb b/spec/unit/classes/database/ssl_configuration_spec.rb index 59702de..989b5c4 100644 --- a/spec/unit/classes/database/ssl_configuration_spec.rb +++ b/spec/unit/classes/database/ssl_configuration_spec.rb @@ -27,53 +27,53 @@ it { is_expected.to compile.with_all_deps } it 'has server.key file' do - is_expected.to contain_file('postgres private key') - .with( + is_expected.to contain_file('postgres private key'). + with( ensure: 'present', owner: 'postgres', mode: '0600', - path: "#{datadir_path}/server.key", - ) - .that_requires('Package[postgresql-server]') + path: "#{datadir_path}/server.key" + ). + that_requires('Package[postgresql-server]') end it 'has server.crt file' do - is_expected.to contain_file('postgres public key') - .with( + is_expected.to contain_file('postgres public key'). + with( ensure: 'present', owner: 'postgres', mode: '0600', - path: "#{datadir_path}/server.crt", - ) - .that_requires('Package[postgresql-server]') + path: "#{datadir_path}/server.crt" + ). + that_requires('Package[postgresql-server]') end it 'has ssl config attribute' do - is_expected.to contain_postgresql__server__config_entry('ssl') - .with_value('on').with_ensure('present') - .that_requires('File[postgres private key]') - .that_requires('File[postgres public key]') + is_expected.to contain_postgresql__server__config_entry('ssl'). + with_value('on').with_ensure('present'). + that_requires('File[postgres private key]'). + that_requires('File[postgres public key]') end it 'has ssl_cert_file config attribute' do - is_expected.to contain_postgresql__server__config_entry('ssl_cert_file') - .with_value("#{datadir_path}/server.crt").with_ensure('present') - .that_requires('File[postgres private key]') - .that_requires('File[postgres public key]') + is_expected.to contain_postgresql__server__config_entry('ssl_cert_file'). + with_value("#{datadir_path}/server.crt").with_ensure('present'). + that_requires('File[postgres private key]'). + that_requires('File[postgres public key]') end it 'has ssl_key_file config attribute' do - is_expected.to contain_postgresql__server__config_entry('ssl_key_file') - .with_value("#{datadir_path}/server.key").with_ensure('present') - .that_requires('File[postgres private key]') - .that_requires('File[postgres public key]') + is_expected.to contain_postgresql__server__config_entry('ssl_key_file'). + with_value("#{datadir_path}/server.key").with_ensure('present'). + that_requires('File[postgres private key]'). + that_requires('File[postgres public key]') end it 'has ssl_ca_file config attribute' do - is_expected.to contain_postgresql__server__config_entry('ssl_ca_file') - .with_value(params[:postgresql_ssl_ca_cert_path]).with_ensure('present') - .that_requires('File[postgres private key]') - .that_requires('File[postgres public key]') + is_expected.to contain_postgresql__server__config_entry('ssl_ca_file'). + with_value(params[:postgresql_ssl_ca_cert_path]).with_ensure('present'). + that_requires('File[postgres private key]'). + that_requires('File[postgres public key]') end context 'does not create ssl rules for puppetdb-read user by default' do diff --git a/spec/unit/classes/init_spec.rb b/spec/unit/classes/init_spec.rb index 423b97a..67ef6dc 100644 --- a/spec/unit/classes/init_spec.rb +++ b/spec/unit/classes/init_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'puppetdb', type: :class do - ttl_args = ['node_ttl', 'node_purge_ttl', 'report_ttl'] + ttl_args = %w[node_ttl node_purge_ttl report_ttl] on_supported_os.each do |os, facts| context "on #{os}" do @@ -35,6 +35,7 @@ class { 'postgresql::server': it { is_expected.to compile.with_all_deps } end end + describe 'without managed postgresql database' do let :params do { @@ -75,11 +76,11 @@ class { 'postgresql::server': end it do - is_expected.to contain_postgresql__server__pg_hba_rule('allow access to all users for instance main') - .with_type('host') - .with_database('all') - .with_user('all') - .with_auth_method('md5') + is_expected.to contain_postgresql__server__pg_hba_rule('allow access to all users for instance main'). + with_type('host'). + with_database('all'). + with_user('all'). + with_auth_method('md5') end end @@ -92,11 +93,12 @@ class { 'postgresql::server': end it { is_expected.to contain_class('puppetdb::server').with('postgresql_ssl_on' => true) } + it { - is_expected.to contain_class('puppetdb::database::postgresql') - .with( + is_expected.to contain_class('puppetdb::database::postgresql'). + with( 'postgresql_ssl_on' => true, - 'puppetdb_server' => 'puppetdb_host', + 'puppetdb_server' => 'puppetdb_host' ) } end diff --git a/spec/unit/classes/master/config_spec.rb b/spec/unit/classes/master/config_spec.rb index 8747b41..eb00eca 100644 --- a/spec/unit/classes/master/config_spec.rb +++ b/spec/unit/classes/master/config_spec.rb @@ -21,7 +21,7 @@ is_expected.to contain_puppetdb_conn_validator('puppetdb_conn').with( puppetdb_server: 'puppetdb.example.com', puppetdb_port: '8081', - use_ssl: 'true', + use_ssl: 'true' ) } end @@ -32,7 +32,7 @@ it { is_expected.to contain_puppetdb_conn_validator('puppetdb_conn').with( puppetdb_port: '8080', - use_ssl: 'false', + use_ssl: 'false' ) } end @@ -44,7 +44,7 @@ it { is_expected.to contain_puppetdb_conn_validator('puppetdb_conn').with( puppetdb_port: '1234', - use_ssl: 'true', + use_ssl: 'true' ) } end @@ -56,7 +56,7 @@ it { is_expected.to contain_puppetdb_conn_validator('puppetdb_conn').with( puppetdb_port: '1234', - use_ssl: 'false', + use_ssl: 'false' ) } end @@ -71,10 +71,11 @@ it { is_expected.to contain_package('puppetdb-terminus').with(ensure: '2.2.0') } it { is_expected.to contain_puppetdb_conn_validator('puppetdb_conn').with(test_url: '/v3/version') } + it { - is_expected.to contain_service('puppetmaster') - .with_ensure('running') - .with_enable(true) + is_expected.to contain_service('puppetmaster'). + with_ensure('running'). + with_enable(true) } end end diff --git a/spec/unit/classes/master/puppetdb_conf_spec.rb b/spec/unit/classes/master/puppetdb_conf_spec.rb index 04e9356..e19764d 100644 --- a/spec/unit/classes/master/puppetdb_conf_spec.rb +++ b/spec/unit/classes/master/puppetdb_conf_spec.rb @@ -16,9 +16,9 @@ let(:pre_condition) { 'class { "puppetdb": }' } it { - is_expected.to contain_ini_setting('soft_write_failure') - .with_setting('soft_write_failure') - .with_value(false) + is_expected.to contain_ini_setting('soft_write_failure'). + with_setting('soft_write_failure'). + with_value(false) } context 'when using default values' do diff --git a/spec/unit/classes/master/report_processor_spec.rb b/spec/unit/classes/master/report_processor_spec.rb index 4473f69..22fbcd8 100644 --- a/spec/unit/classes/master/report_processor_spec.rb +++ b/spec/unit/classes/master/report_processor_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'puppetdb::master::report_processor', type: :class do - around(:each) do |example| + around do |example| confdir = RSpec.configuration.confdir RSpec.configuration.confdir = '/etc/puppet' example.run @@ -20,14 +20,14 @@ describe 'when using default values' do it { - is_expected.to contain_ini_subsetting('puppet.conf/reports/puppetdb') - .with( - 'ensure' => 'absent', - 'path' => '/etc/puppet/puppet.conf', - 'section' => 'master', - 'setting' => 'reports', - 'subsetting' => 'puppetdb', - 'subsetting_separator' => ',', + is_expected.to contain_ini_subsetting('puppet.conf/reports/puppetdb'). + with( + 'ensure' => 'absent', + 'path' => '/etc/puppet/puppet.conf', + 'section' => 'master', + 'setting' => 'reports', + 'subsetting' => 'puppetdb', + 'subsetting_separator' => ',' ) } end @@ -40,14 +40,14 @@ end it { - is_expected.to contain_ini_subsetting('puppet.conf/reports/puppetdb') - .with( - 'ensure' => 'present', - 'path' => '/etc/puppet/puppet.conf', - 'section' => 'master', - 'setting' => 'reports', - 'subsetting' => 'puppetdb', - 'subsetting_separator' => ',', + is_expected.to contain_ini_subsetting('puppet.conf/reports/puppetdb'). + with( + 'ensure' => 'present', + 'path' => '/etc/puppet/puppet.conf', + 'section' => 'master', + 'setting' => 'reports', + 'subsetting' => 'puppetdb', + 'subsetting_separator' => ',' ) } end diff --git a/spec/unit/classes/master/routes_spec.rb b/spec/unit/classes/master/routes_spec.rb index 41a6553..4e40f1a 100644 --- a/spec/unit/classes/master/routes_spec.rb +++ b/spec/unit/classes/master/routes_spec.rb @@ -43,7 +43,7 @@ master: { facts: { terminus: 'puppetdb', - cache: (Puppet::Util::Package.versioncmp(serverversion, '7.0') >= 0) ? 'json' : 'yaml' + cache: Puppet::Util::Package.versioncmp(serverversion, '7.0') >= 0 ? 'json' : 'yaml' }, } } @@ -52,10 +52,10 @@ context 'with defaults' do it { - is_expected.to contain_file("#{params[:puppet_confdir]}/routes.yaml") - .with( - ensure: 'file', - mode: '0644', + is_expected.to contain_file("#{params[:puppet_confdir]}/routes.yaml"). + with( + ensure: 'file', + mode: '0644' ) } diff --git a/spec/unit/classes/master/storeconfigs_spec.rb b/spec/unit/classes/master/storeconfigs_spec.rb index 7e36af0..c688803 100644 --- a/spec/unit/classes/master/storeconfigs_spec.rb +++ b/spec/unit/classes/master/storeconfigs_spec.rb @@ -17,23 +17,24 @@ context 'with default parameters' do it { - is_expected.to contain_ini_setting("puppet.conf/#{puppet_conf_section}/storeconfigs") - .with_ensure(param_ensure) - .with( + is_expected.to contain_ini_setting("puppet.conf/#{puppet_conf_section}/storeconfigs"). + with_ensure(param_ensure). + with( section: puppet_conf_section, path: puppet_conf, setting: 'storeconfigs', - value: true, + value: true ) } + it { - is_expected.to contain_ini_setting("puppet.conf/#{puppet_conf_section}/storeconfigs_backend") - .with_ensure(param_ensure) - .with( + is_expected.to contain_ini_setting("puppet.conf/#{puppet_conf_section}/storeconfigs_backend"). + with_ensure(param_ensure). + with( section: puppet_conf_section, path: puppet_conf, setting: 'storeconfigs_backend', - value: 'puppetdb', + value: 'puppetdb' ) } end diff --git a/spec/unit/classes/server/command_processing_spec.rb b/spec/unit/classes/server/command_processing_spec.rb index c3c9875..d4c7539 100644 --- a/spec/unit/classes/server/command_processing_spec.rb +++ b/spec/unit/classes/server/command_processing_spec.rb @@ -9,39 +9,42 @@ describe 'when using default values' do it { - is_expected.to contain_ini_setting('puppetdb_command_processing_threads') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_threads'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', - 'setting' => 'threads', + 'setting' => 'threads' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_concurrent_writes') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_concurrent_writes'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', - 'setting' => 'concurrent-writes', + 'setting' => 'concurrent-writes' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_store_usage') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_store_usage'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', - 'setting' => 'store-usage', + 'setting' => 'store-usage' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_temp_usage') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_temp_usage'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', - 'setting' => 'temp-usage', + 'setting' => 'temp-usage' ) } end @@ -55,30 +58,32 @@ end it { - is_expected.to contain_ini_setting('puppetdb_command_processing_threads') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_threads'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetdb/conf.d/config.ini', 'section' => 'command-processing', - 'setting' => 'threads', + 'setting' => 'threads' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_store_usage') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_store_usage'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetdb/conf.d/config.ini', 'section' => 'command-processing', - 'setting' => 'store-usage', + 'setting' => 'store-usage' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_temp_usage') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_temp_usage'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetdb/conf.d/config.ini', 'section' => 'command-processing', - 'setting' => 'temp-usage', + 'setting' => 'temp-usage' ) } end @@ -94,43 +99,46 @@ end it { - is_expected.to contain_ini_setting('puppetdb_command_processing_threads') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_threads'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'threads', - 'value' => '10', + 'value' => '10' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_concurrent_writes') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_concurrent_writes'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'concurrent-writes', - 'value' => '3', + 'value' => '3' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_store_usage') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_store_usage'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'store-usage', - 'value' => '4000', + 'value' => '4000' ) } + it { - is_expected.to contain_ini_setting('puppetdb_command_processing_temp_usage') - .with( + is_expected.to contain_ini_setting('puppetdb_command_processing_temp_usage'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'temp-usage', - 'value' => '2000', + 'value' => '2000' ) } end diff --git a/spec/unit/classes/server/database_ini_spec.rb b/spec/unit/classes/server/database_ini_spec.rb index 41af248..2589e73 100644 --- a/spec/unit/classes/server/database_ini_spec.rb +++ b/spec/unit/classes/server/database_ini_spec.rb @@ -5,7 +5,7 @@ it { is_expected.to contain_class('puppetdb::server::database') } - ['default', 'legacy'].each do |values| + %w[default legacy].each do |values| describe "when using #{values} values" do let(:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' } if values == 'legacy' let(:pdbconfdir) do @@ -17,143 +17,157 @@ end it { - is_expected.to contain_file("#{pdbconfdir}/database.ini") - .with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'puppetdb', - 'mode' => '0640', + is_expected.to contain_file("#{pdbconfdir}/database.ini"). + with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'puppetdb', + 'mode' => '0640' ) } + it { - is_expected.to contain_ini_setting('puppetdb_psdatabase_username') - .with( + is_expected.to contain_ini_setting('puppetdb_psdatabase_username'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'username', - 'value' => 'puppetdb', + 'value' => 'puppetdb' ) } + it { - is_expected.to contain_ini_setting('puppetdb_psdatabase_password') - .with( + is_expected.to contain_ini_setting('puppetdb_psdatabase_password'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'password', 'value' => 'puppetdb', - 'show_diff' => false, + 'show_diff' => false ) } + it { - is_expected.to contain_ini_setting('puppetdb_pgs') - .with( + is_expected.to contain_ini_setting('puppetdb_pgs'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'syntax_pgs', - 'value' => true, + 'value' => true ) } + it { - is_expected.to contain_ini_setting('puppetdb_subname') - .with( + is_expected.to contain_ini_setting('puppetdb_subname'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'subname', - 'value' => '//localhost:5432/puppetdb', + 'value' => '//localhost:5432/puppetdb' ) } + it { - is_expected.to contain_ini_setting('puppetdb_gc_interval') - .with( + is_expected.to contain_ini_setting('puppetdb_gc_interval'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'gc-interval', - 'value' => '60', + 'value' => '60' ) } + it { - is_expected.to contain_ini_setting('puppetdb_node_purge_gc_batch_limit') - .with( + is_expected.to contain_ini_setting('puppetdb_node_purge_gc_batch_limit'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'node-purge-gc-batch-limit', - 'value' => '25', + 'value' => '25' ) } + it { - is_expected.to contain_ini_setting('puppetdb_node_ttl') - .with( + is_expected.to contain_ini_setting('puppetdb_node_ttl'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'node-ttl', - 'value' => '7d', + 'value' => '7d' ) } + it { - is_expected.to contain_ini_setting('puppetdb_node_purge_ttl') - .with( + is_expected.to contain_ini_setting('puppetdb_node_purge_ttl'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'node-purge-ttl', - 'value' => '14d', + 'value' => '14d' ) } + it { - is_expected.to contain_ini_setting('puppetdb_report_ttl') - .with( + is_expected.to contain_ini_setting('puppetdb_report_ttl'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'report-ttl', - 'value' => '14d', + 'value' => '14d' ) } + it { - is_expected.to contain_ini_setting('puppetdb_conn_max_age') - .with( + is_expected.to contain_ini_setting('puppetdb_conn_max_age'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'conn-max-age', - 'value' => '60', + 'value' => '60' ) } + it { - is_expected.to contain_ini_setting('puppetdb_conn_lifetime') - .with( + is_expected.to contain_ini_setting('puppetdb_conn_lifetime'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'conn-lifetime', - 'value' => '0', + 'value' => '0' ) } + it { - is_expected.to contain_ini_setting('puppetdb_migrate') - .with( + is_expected.to contain_ini_setting('puppetdb_migrate'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', 'setting' => 'migrate', - 'value' => true, + 'value' => true ) } + it { is_expected.not_to contain_ini_setting('puppetdb_database_max_pool_size') } + it { - is_expected.to contain_ini_setting('puppetdb_facts_blacklist') - .with( + is_expected.to contain_ini_setting('puppetdb_facts_blacklist'). + with( 'ensure' => 'absent', 'path' => "#{pdbconfdir}/database.ini", 'section' => 'database', - 'setting' => 'facts-blacklist', + 'setting' => 'facts-blacklist' ) } end @@ -162,21 +176,21 @@ describe 'when using facts_blacklist' do let(:params) do { - 'facts_blacklist' => [ - 'one_fact', - 'another_fact', + 'facts_blacklist' => %w[ + one_fact + another_fact ], } end it { - is_expected.to contain_ini_setting('puppetdb_facts_blacklist') - .with( + is_expected.to contain_ini_setting('puppetdb_facts_blacklist'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini', 'section' => 'database', 'setting' => 'facts-blacklist', - 'value' => 'one_fact, another_fact', + 'value' => 'one_fact, another_fact' ) } end @@ -191,13 +205,13 @@ end it { - is_expected.to contain_ini_setting('puppetdb_database_max_pool_size') - .with( + is_expected.to contain_ini_setting('puppetdb_database_max_pool_size'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini', 'section' => 'database', 'setting' => 'maximum-pool-size', - 'value' => '12345', + 'value' => '12345' ) } end @@ -210,12 +224,12 @@ end it { - is_expected.to contain_ini_setting('puppetdb_database_max_pool_size') - .with( + is_expected.to contain_ini_setting('puppetdb_database_max_pool_size'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini', 'section' => 'database', - 'setting' => 'maximum-pool-size', + 'setting' => 'maximum-pool-size' ) } end @@ -232,13 +246,13 @@ end it { - is_expected.to contain_ini_setting('puppetdb_database_max_pool_size') - .with( + is_expected.to contain_ini_setting('puppetdb_database_max_pool_size'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini', 'section' => 'database', 'setting' => 'partition-conn-max', - 'value' => '12345', + 'value' => '12345' ) } end @@ -251,12 +265,12 @@ end it { - is_expected.to contain_ini_setting('puppetdb_database_max_pool_size') - .with( + is_expected.to contain_ini_setting('puppetdb_database_max_pool_size'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini', 'section' => 'database', - 'setting' => 'partition-conn-max', + 'setting' => 'partition-conn-max' ) } end @@ -296,8 +310,8 @@ end it 'configures subname correctly' do - is_expected.to contain_ini_setting('puppetdb_subname') - .with( + is_expected.to contain_ini_setting('puppetdb_subname'). + with( ensure: 'present', path: '/etc/puppetlabs/puppetdb/conf.d/database.ini', section: 'database', @@ -307,7 +321,7 @@ 'sslmode=verify-full&' \ 'sslrootcert=/etc/puppetlabs/puppetdb/ssl/ca.pem&' \ 'sslkey=/tmp/private_key.pk8&' \ - 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem', + 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem' ) end end diff --git a/spec/unit/classes/server/db_connection_uri_spec.rb b/spec/unit/classes/server/db_connection_uri_spec.rb index 80d0bad..4301912 100644 --- a/spec/unit/classes/server/db_connection_uri_spec.rb +++ b/spec/unit/classes/server/db_connection_uri_spec.rb @@ -23,11 +23,11 @@ end it { - is_expected.to contain_ini_setting('puppetdb_subname') - .with( + is_expected.to contain_ini_setting('puppetdb_subname'). + with( section: 'database', setting: 'subname', - value: '//localhost:5432/puppetdb?ssl=true', + value: '//localhost:5432/puppetdb?ssl=true' ) } end @@ -41,9 +41,9 @@ end it 'configures subname correctly' do - is_expected.to contain_ini_setting('puppetdb_subname') - .with( - ensure: 'present', + is_expected.to contain_ini_setting('puppetdb_subname'). + with( + ensure: 'present', path: '/etc/puppetlabs/puppetdb/conf.d/database.ini', section: 'database', setting: 'subname', @@ -52,7 +52,7 @@ 'sslmode=verify-full&' \ 'sslrootcert=/etc/puppetlabs/puppetdb/ssl/ca.pem&' \ 'sslkey=/tmp/private_key.pk8&' \ - 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem', + 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem' ) end @@ -65,8 +65,8 @@ end it 'raises an error' do - is_expected.to compile - .and_raise_error(%r{Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!}) + is_expected.to compile. + and_raise_error(%r{Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!}) end end end diff --git a/spec/unit/classes/server/db_read_uri_spec.rb b/spec/unit/classes/server/db_read_uri_spec.rb index c9bb099..98301aa 100644 --- a/spec/unit/classes/server/db_read_uri_spec.rb +++ b/spec/unit/classes/server/db_read_uri_spec.rb @@ -24,11 +24,11 @@ end it { - is_expected.to contain_ini_setting('puppetdb_read_subname') - .with( + is_expected.to contain_ini_setting('puppetdb_read_subname'). + with( section: 'read-database', setting: 'subname', - value: '//localhost:5432/puppetdb?ssl=true', + value: '//localhost:5432/puppetdb?ssl=true' ) } end @@ -43,8 +43,8 @@ end it 'configures subname correctly' do - is_expected.to contain_ini_setting('puppetdb_read_subname') - .with( + is_expected.to contain_ini_setting('puppetdb_read_subname'). + with( ensure: 'present', path: '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', section: 'read-database', @@ -54,7 +54,7 @@ 'sslmode=verify-full&' \ 'sslrootcert=/etc/puppetlabs/puppetdb/ssl/ca.pem&' \ 'sslkey=/tmp/private_key.pk8&' \ - 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem', + 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem' ) end @@ -68,8 +68,8 @@ end it 'raises an error' do - is_expected.to compile - .and_raise_error(%r{Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!}) + is_expected.to compile. + and_raise_error(%r{Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!}) end end end diff --git a/spec/unit/classes/server/global_ini_spec.rb b/spec/unit/classes/server/global_ini_spec.rb index 24ff8e3..665207a 100644 --- a/spec/unit/classes/server/global_ini_spec.rb +++ b/spec/unit/classes/server/global_ini_spec.rb @@ -7,22 +7,23 @@ include_examples 'puppetdb::params' it { - is_expected.to contain_ini_setting('puppetdb_global_vardir') - .with( + is_expected.to contain_ini_setting('puppetdb_global_vardir'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'global', 'setting' => 'vardir', - 'value' => '/opt/puppetlabs/server/data/puppetdb', + 'value' => '/opt/puppetlabs/server/data/puppetdb' ) } + it { - is_expected.to contain_file('/etc/puppetlabs/puppetdb/conf.d/config.ini') - .with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'puppetdb', - 'mode' => '0640', + is_expected.to contain_file('/etc/puppetlabs/puppetdb/conf.d/config.ini'). + with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'puppetdb', + 'mode' => '0640' ) } end @@ -31,23 +32,23 @@ let(:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' } it { - is_expected.to contain_ini_setting('puppetdb_global_vardir') - .with( + is_expected.to contain_ini_setting('puppetdb_global_vardir'). + with( 'ensure' => 'present', 'path' => '/etc/puppetdb/conf.d/config.ini', 'section' => 'global', 'setting' => 'vardir', - 'value' => '/var/lib/puppetdb', + 'value' => '/var/lib/puppetdb' ) } it { - is_expected.to contain_file('/etc/puppetdb/conf.d/config.ini') - .with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'puppetdb', - 'mode' => '0640', + is_expected.to contain_file('/etc/puppetdb/conf.d/config.ini'). + with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'puppetdb', + 'mode' => '0640' ) } end diff --git a/spec/unit/classes/server/jetty_ini_spec.rb b/spec/unit/classes/server/jetty_ini_spec.rb index 1baf749..9f0ac8f 100644 --- a/spec/unit/classes/server/jetty_ini_spec.rb +++ b/spec/unit/classes/server/jetty_ini_spec.rb @@ -5,7 +5,7 @@ it { is_expected.to contain_class('puppetdb::server::jetty') } - ['default', 'legacy'].each do |values| + %w[default legacy].each do |values| describe "when using #{values} values" do let(:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' } if values == 'legacy' let(:pdbconfdir) do @@ -17,54 +17,59 @@ end it { - is_expected.to contain_file("#{pdbconfdir}/jetty.ini") - .with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'puppetdb', - 'mode' => '0640', + is_expected.to contain_file("#{pdbconfdir}/jetty.ini"). + with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'puppetdb', + 'mode' => '0640' ) } + it { - is_expected.to contain_ini_setting('puppetdb_host') - .with( + is_expected.to contain_ini_setting('puppetdb_host'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/jetty.ini", 'section' => 'jetty', 'setting' => 'host', - 'value' => 'localhost', + 'value' => 'localhost' ) } + it { - is_expected.to contain_ini_setting('puppetdb_port') - .with( + is_expected.to contain_ini_setting('puppetdb_port'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/jetty.ini", 'section' => 'jetty', 'setting' => 'port', - 'value' => 8080, + 'value' => 8080 ) } + it { - is_expected.to contain_ini_setting('puppetdb_sslhost') - .with( + is_expected.to contain_ini_setting('puppetdb_sslhost'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/jetty.ini", 'section' => 'jetty', 'setting' => 'ssl-host', - 'value' => '0.0.0.0', + 'value' => '0.0.0.0' ) } + it { - is_expected.to contain_ini_setting('puppetdb_sslport') - .with( + is_expected.to contain_ini_setting('puppetdb_sslport'). + with( 'ensure' => 'present', 'path' => "#{pdbconfdir}/jetty.ini", 'section' => 'jetty', 'setting' => 'ssl-port', - 'value' => 8081, + 'value' => 8081 ) } + it { is_expected.not_to contain_ini_setting('puppetdb_sslprotocols') } end end @@ -77,41 +82,44 @@ end it { - is_expected.to contain_ini_setting('puppetdb_host') - .with( + is_expected.to contain_ini_setting('puppetdb_host'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', 'setting' => 'host', - 'value' => 'localhost', + 'value' => 'localhost' ) } + it { - is_expected.to contain_ini_setting('puppetdb_port') - .with( + is_expected.to contain_ini_setting('puppetdb_port'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', 'setting' => 'port', - 'value' => 8080, + 'value' => 8080 ) } + it { - is_expected.to contain_ini_setting('puppetdb_sslhost') - .with( + is_expected.to contain_ini_setting('puppetdb_sslhost'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', - 'setting' => 'ssl-host', + 'setting' => 'ssl-host' ) } + it { - is_expected.to contain_ini_setting('puppetdb_sslport') - .with( + is_expected.to contain_ini_setting('puppetdb_sslport'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', - 'setting' => 'ssl-port', + 'setting' => 'ssl-port' ) } end @@ -124,13 +132,13 @@ end it { - is_expected.to contain_ini_setting('puppetdb_max_threads') - .with( + is_expected.to contain_ini_setting('puppetdb_max_threads'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', 'setting' => 'max-threads', - 'value' => '150', + 'value' => '150' ) } end @@ -145,18 +153,18 @@ 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', 'setting' => 'ssl-protocols', - 'value' => 'TLSv1, TLSv1.1, TLSv1.2', + 'value' => 'TLSv1, TLSv1.1, TLSv1.2' ) } end context 'to an invalid type (non-string)' do - let(:params) { { 'ssl_protocols' => ['invalid', 'type'] } } + let(:params) { { 'ssl_protocols' => %w[invalid type] } } it 'fails' do - expect { + expect do is_expected.to contain_class('puppetdb::server::jetty') - }.to raise_error(Puppet::Error) + end.to raise_error(Puppet::Error) end end end @@ -170,13 +178,13 @@ end it { - is_expected.to contain_ini_setting('puppetdb_cipher-suites') - .with( + is_expected.to contain_ini_setting('puppetdb_cipher-suites'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', 'setting' => 'cipher-suites', - 'value' => 'SSL_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, SSL_ECDHE_RSA_WITH_AES_256_CBC_SHA384, SSL_RSA_WITH_AES_256_CBC_SHA256', + 'value' => 'SSL_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, SSL_ECDHE_RSA_WITH_AES_256_CBC_SHA384, SSL_RSA_WITH_AES_256_CBC_SHA256' ) } end @@ -190,23 +198,24 @@ end it { - is_expected.to contain_ini_setting('puppetdb_host') - .with( + is_expected.to contain_ini_setting('puppetdb_host'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', 'setting' => 'host', - 'value' => 'localhost', + 'value' => 'localhost' ) } + it { - is_expected.to contain_ini_setting('puppetdb_port') - .with( + is_expected.to contain_ini_setting('puppetdb_port'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/jetty.ini', 'section' => 'jetty', 'setting' => 'port', - 'value' => 8080, + 'value' => 8080 ) } end diff --git a/spec/unit/classes/server/puppetdb_ini_spec.rb b/spec/unit/classes/server/puppetdb_ini_spec.rb index 8ccb1bc..311ba7b 100644 --- a/spec/unit/classes/server/puppetdb_ini_spec.rb +++ b/spec/unit/classes/server/puppetdb_ini_spec.rb @@ -7,41 +7,44 @@ describe 'when using default values' do it { - is_expected.to contain_ini_setting('puppetdb-connections-from-master-only') - .with( + is_expected.to contain_ini_setting('puppetdb-connections-from-master-only'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/puppetdb.ini', 'section' => 'puppetdb', 'setting' => 'certificate-whitelist', - 'value' => '/etc/puppetlabs/puppetdb/certificate-whitelist', + 'value' => '/etc/puppetlabs/puppetdb/certificate-whitelist' ) } + it { - is_expected.to contain_file('/etc/puppetlabs/puppetdb/certificate-whitelist') - .with( + is_expected.to contain_file('/etc/puppetlabs/puppetdb/certificate-whitelist'). + with( 'ensure' => 'absent', 'owner' => 0, 'group' => 0, 'mode' => '0644', - 'content' => '', + 'content' => '' ) } + it { - is_expected.to contain_file('/etc/puppetlabs/puppetdb/conf.d/puppetdb.ini') - .with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'puppetdb', - 'mode' => '0640', + is_expected.to contain_file('/etc/puppetlabs/puppetdb/conf.d/puppetdb.ini'). + with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'puppetdb', + 'mode' => '0640' ) } + it { - is_expected.to contain_ini_setting('puppetdb_disable_update_checking') - .with( + is_expected.to contain_ini_setting('puppetdb_disable_update_checking'). + with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/puppetdb.ini', 'section' => 'puppetdb', - 'setting' => 'disable-update-checking', + 'setting' => 'disable-update-checking' ) } end @@ -54,23 +57,24 @@ end it { - is_expected.to contain_ini_setting('puppetdb-connections-from-master-only') - .with( + is_expected.to contain_ini_setting('puppetdb-connections-from-master-only'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/puppetdb.ini', 'section' => 'puppetdb', 'setting' => 'certificate-whitelist', - 'value' => '/etc/puppetlabs/puppetdb/certificate-whitelist', + 'value' => '/etc/puppetlabs/puppetdb/certificate-whitelist' ) } + it { - is_expected.to contain_file('/etc/puppetlabs/puppetdb/certificate-whitelist') - .with( + is_expected.to contain_file('/etc/puppetlabs/puppetdb/certificate-whitelist'). + with( 'ensure' => 'present', 'owner' => 0, 'group' => 0, 'mode' => '0644', - 'content' => "puppetmaster\n", + 'content' => "puppetmaster\n" ) } end @@ -83,13 +87,13 @@ end it { - is_expected.to contain_ini_setting('puppetdb_disable_update_checking') - .with( + is_expected.to contain_ini_setting('puppetdb_disable_update_checking'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/puppetdb.ini', 'section' => 'puppetdb', 'setting' => 'disable-update-checking', - 'value' => 'true', + 'value' => 'true' ) } end diff --git a/spec/unit/classes/server/read_database_ini_spec.rb b/spec/unit/classes/server/read_database_ini_spec.rb index b5a6161..5082b30 100644 --- a/spec/unit/classes/server/read_database_ini_spec.rb +++ b/spec/unit/classes/server/read_database_ini_spec.rb @@ -17,73 +17,79 @@ end it { - is_expected.to contain_file('/etc/puppetlabs/puppetdb/conf.d/read_database.ini') - .with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'puppetdb', - 'mode' => '0640', + is_expected.to contain_file('/etc/puppetlabs/puppetdb/conf.d/read_database.ini'). + with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'puppetdb', + 'mode' => '0640' ) } + it { - is_expected.to contain_ini_setting('puppetdb_read_database_username') - .with( + is_expected.to contain_ini_setting('puppetdb_read_database_username'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', 'section' => 'read-database', 'setting' => 'username', - 'value' => 'puppetdb-read', + 'value' => 'puppetdb-read' ) } + it { - is_expected.to contain_ini_setting('puppetdb_read_database_password') - .with( + is_expected.to contain_ini_setting('puppetdb_read_database_password'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', 'section' => 'read-database', 'setting' => 'password', 'value' => 'puppetdb-read', - 'show_diff' => false, + 'show_diff' => false ) } + it { - is_expected.to contain_ini_setting('puppetdb_read_pgs') - .with( + is_expected.to contain_ini_setting('puppetdb_read_pgs'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', 'section' => 'read-database', 'setting' => 'syntax_pgs', - 'value' => true, + 'value' => true ) } + it { - is_expected.to contain_ini_setting('puppetdb_read_subname') - .with( + is_expected.to contain_ini_setting('puppetdb_read_subname'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', 'section' => 'read-database', 'setting' => 'subname', - 'value' => '//puppetdb:5432/puppetdb', + 'value' => '//puppetdb:5432/puppetdb' ) } + it { - is_expected.to contain_ini_setting('puppetdb_read_conn_max_age') - .with( + is_expected.to contain_ini_setting('puppetdb_read_conn_max_age'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', 'section' => 'read-database', 'setting' => 'conn-max-age', - 'value' => '60', + 'value' => '60' ) } + it { - is_expected.to contain_ini_setting('puppetdb_read_conn_lifetime') - .with( + is_expected.to contain_ini_setting('puppetdb_read_conn_lifetime'). + with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', 'section' => 'read-database', 'setting' => 'conn-lifetime', - 'value' => '0', + 'value' => '0' ) } @@ -97,8 +103,8 @@ end it 'configures subname correctly' do - is_expected.to contain_ini_setting('puppetdb_read_subname') - .with( + is_expected.to contain_ini_setting('puppetdb_read_subname'). + with( ensure: 'present', path: '/etc/puppetlabs/puppetdb/conf.d/read_database.ini', section: 'read-database', @@ -108,7 +114,7 @@ 'sslmode=verify-full&' \ 'sslrootcert=/etc/puppetlabs/puppetdb/ssl/ca.pem&' \ 'sslkey=/tmp/private_key.pk8&' \ - 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem', + 'sslcert=/etc/puppetlabs/puppetdb/ssl/public.pem' ) end @@ -122,8 +128,8 @@ end it 'raises an error' do - is_expected.to compile - .and_raise_error(%r{Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!}) + is_expected.to compile. + and_raise_error(%r{Variables 'postgresql_ssl_on' and 'jdbc_ssl_properties' can not be used at the same time!}) end end end diff --git a/spec/unit/classes/server/validate_db_spec.rb b/spec/unit/classes/server/validate_db_spec.rb index 8ab6eeb..e252931 100644 --- a/spec/unit/classes/server/validate_db_spec.rb +++ b/spec/unit/classes/server/validate_db_spec.rb @@ -12,14 +12,14 @@ context 'with default params' do it { - is_expected.to contain_class('puppetdb::server::validate_db') - .with( - database_host: 'localhost', - database_port: '5432', + is_expected.to contain_class('puppetdb::server::validate_db'). + with( + database_host: 'localhost', + database_port: '5432', database_username: 'puppetdb', database_password: 'puppetdb', - database_name: 'puppetdb', - jdbc_ssl_properties: '', + database_name: 'puppetdb', + jdbc_ssl_properties: '' ) } @@ -31,13 +31,13 @@ context 'with jdbc_ssl_properties set false' do it { - is_expected.to contain_postgresql_conn_validator('validate puppetdb postgres connection') - .with( + is_expected.to contain_postgresql_conn_validator('validate puppetdb postgres connection'). + with( host: 'localhost', port: '5432', db_username: 'puppetdb', db_password: 'puppetdb', - db_name: 'puppetdb', + db_name: 'puppetdb' ) } end diff --git a/spec/unit/classes/server/validate_read_db_spec.rb b/spec/unit/classes/server/validate_read_db_spec.rb index 0fa1541..f5932b7 100644 --- a/spec/unit/classes/server/validate_read_db_spec.rb +++ b/spec/unit/classes/server/validate_read_db_spec.rb @@ -12,14 +12,14 @@ context 'with default params' do it { - is_expected.to contain_class('puppetdb::server::validate_read_db') - .with( - database_host: 'localhost', - database_port: '5432', + is_expected.to contain_class('puppetdb::server::validate_read_db'). + with( + database_host: 'localhost', + database_port: '5432', database_username: 'puppetdb', database_password: 'puppetdb', - database_name: 'puppetdb', - jdbc_ssl_properties: '', + database_name: 'puppetdb', + jdbc_ssl_properties: '' ) } @@ -31,13 +31,13 @@ context 'with jdbc_ssl_properties set false' do it { - is_expected.to contain_postgresql_conn_validator('validate puppetdb postgres (read) connection') - .with( + is_expected.to contain_postgresql_conn_validator('validate puppetdb postgres (read) connection'). + with( host: 'localhost', port: '5432', db_username: 'puppetdb', db_password: 'puppetdb', - db_name: 'puppetdb', + db_name: 'puppetdb' ) } end diff --git a/spec/unit/classes/server_spec.rb b/spec/unit/classes/server_spec.rb index 7b9a3e1..4a7bd82 100644 --- a/spec/unit/classes/server_spec.rb +++ b/spec/unit/classes/server_spec.rb @@ -28,14 +28,14 @@ it { is_expected.to contain_class('puppetdb::server::puppetdb') } it { - is_expected.to contain_package('puppetdb') - .that_notifies('Service[puppetdb]') + is_expected.to contain_package('puppetdb'). + that_notifies('Service[puppetdb]') } it { - is_expected.to contain_service('puppetdb') - .with_ensure('running') - .with_enable(true) + is_expected.to contain_service('puppetdb'). + with_ensure('running'). + with_enable(true) } end @@ -53,15 +53,15 @@ end it { - is_expected.to contain_ini_subsetting("'-Xms'") - .with( + is_expected.to contain_ini_subsetting("'-Xms'"). + with( 'ensure' => 'present', 'path' => pathdir.to_s, 'section' => '', 'key_val_separator' => '=', 'setting' => 'JAVA_ARGS', 'subsetting' => '-Xms', - 'value' => '2g', + 'value' => '2g' ) } end @@ -76,13 +76,13 @@ context 'on standard PuppetDB' do it { - is_expected.to contain_ini_setting('java_args') - .with( + is_expected.to contain_ini_setting('java_args'). + with( 'ensure' => 'present', 'path' => pathdir.to_s, 'section' => '', 'setting' => 'JAVA_ARGS', - 'value' => '"-Xms2g"', + 'value' => '"-Xms2g"' ) } end @@ -197,22 +197,22 @@ context 'private key file is converted from .pem to .pk8 format' do it 'runs exec command' do - is_expected.to contain_exec(key_pk8_path) - .with( + is_expected.to contain_exec(key_pk8_path). + with( path: ['/opt/puppetlabs/puppet/bin', facts[:path]], command: "openssl pkcs8 -topk8 -inform PEM -outform DER -in #{key_path} -out #{key_pk8_path} -nocrypt", onlyif: "test ! -e '#{key_pk8_path}' -o '#{key_pk8_path}' -ot '#{key_path}'", - before: "File[#{key_pk8_path}]", + before: "File[#{key_pk8_path}]" ) end it 'contains file private.pk8' do - is_expected.to contain_file('/etc/puppetlabs/puppetdb/ssl/private.pk8') - .with( + is_expected.to contain_file('/etc/puppetlabs/puppetdb/ssl/private.pk8'). + with( ensure: 'file', owner: 'root', group: 'puppetdb', - mode: '0640', + mode: '0640' ) end end diff --git a/spec/unit/facter/puppetdb_version_spec.rb b/spec/unit/facter/puppetdb_version_spec.rb index 587c9a0..e6f3504 100644 --- a/spec/unit/facter/puppetdb_version_spec.rb +++ b/spec/unit/facter/puppetdb_version_spec.rb @@ -1,20 +1,20 @@ require 'facter' describe 'puppetdb_version' do - before(:each) do + before do Facter.clear end context 'when puppetdb is available' do - before(:each) do + before do allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') end context 'on a default system' do it 'returns the correct version from puppetdb --version' do - expect(Facter::Core::Execution).to receive(:execute) - .with('puppetdb --version') - .and_return('puppetdb version: 7.19.0') + expect(Facter::Core::Execution).to receive(:execute). + with('puppetdb --version'). + and_return('puppetdb version: 7.19.0') expect(Facter.fact(:puppetdb_version).value).to eq('7.19.0') end @@ -28,7 +28,7 @@ end context 'when puppetdb is not available' do - before(:each) do + before do allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) end diff --git a/spec/unit/util/puppetdb_validator_spec.rb b/spec/unit/util/puppetdb_validator_spec.rb index 47355f5..11fa61a 100644 --- a/spec/unit/util/puppetdb_validator_spec.rb +++ b/spec/unit/util/puppetdb_validator_spec.rb @@ -2,7 +2,7 @@ require 'puppet/util/puppetdb_validator' describe 'Puppet::Util::PuppetdbValidator' do - before(:each) do + before do nethttpok = Net::HTTPOK.new('1.1', 200, 'OK') notfound = Net::HTTPNotFound.new('1.1', 404, 'Not found')