diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..12ed4ff --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM puppet/pdk:latest + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f1a55dc --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pdk --version", +} diff --git a/.gitignore b/.gitignore index 2767022..988dcbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,28 @@ .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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4868bf7..6d5e786 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,44 +1,53 @@ --- stages: - syntax - unit -cache: - paths: - - vendor/bundle +default: + cache: + paths: + - vendor/bundle -before_script: - - bundle -v - - rm Gemfile.lock || true - - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - - "# Set `rubygems_version` in the .sync.yml to set a value" - - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - - gem --version - - bundle -v - - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + before_script: &before_script + - bundle -v + - rm Gemfile.lock || true + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# Set `rubygems_version` in the .sync.yml to set a value" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) -syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.7-Puppet ~> 6: +validate lint check rubocop-Ruby 2.5.7-Puppet ~> 6: stage: syntax image: ruby:2.5.7 script: - - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + - bundle exec rake validate lint check rubocop variables: PUPPET_GEM_VERSION: '~> 6' parallel_spec-Ruby 2.5.7-Puppet ~> 6: stage: unit image: ruby:2.5.7 script: - bundle exec rake parallel_spec variables: PUPPET_GEM_VERSION: '~> 6' -parallel_spec-Ruby 2.4.5-Puppet ~> 5: +validate lint check rubocop-Ruby 2.7.2-Puppet ~> 7: + stage: syntax + image: ruby:2.7.2 + script: + - bundle exec rake validate lint check rubocop + variables: + PUPPET_GEM_VERSION: '~> 7' + +parallel_spec-Ruby 2.7.2-Puppet ~> 7: stage: unit - image: ruby:2.4.5 + image: ruby:2.7.2 script: - bundle exec rake parallel_spec variables: - PUPPET_GEM_VERSION: '~> 5' + PUPPET_GEM_VERSION: '~> 7' diff --git a/.pdkignore b/.pdkignore index e6215cd..c538bea 100644 --- a/.pdkignore +++ b/.pdkignore @@ -1,42 +1,47 @@ .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 /appveyor.yml +/.editorconfig /.fixtures.yml /Gemfile /.gitattributes /.gitignore /.gitlab-ci.yml /.pdkignore +/.puppet-lint.rc /Rakefile /rakelib/ /.rspec /.rubocop.yml /.travis.yml /.yardopts /spec/ /.vscode/ +/.sync.yml +/.devcontainer/ diff --git a/.rubocop.yml b/.rubocop.yml index 5307849..6b560d9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,137 +1,520 @@ --- require: +- rubocop-performance - rubocop-rspec -- rubocop-i18n AllCops: DisplayCopNames: true - TargetRubyVersion: '2.1' + TargetRubyVersion: '2.4' Include: - - "./**/*.rb" + - "**/*.rb" Exclude: - bin/* - ".vendor/**/*" - "**/Gemfile" - "**/Rakefile" - pkg/**/* - spec/fixtures/**/* - vendor/**/* - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" -Metrics/LineLength: + - "lib/puppet_x/**/*" +Layout/LineLength: Description: People have wide screens, use them. Max: 200 -GetText: - Enabled: false -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. Exclude: - spec/acceptance/**/*.rb RSpec/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each +RSpec/DescribeSymbol: + Exclude: + - spec/unit/facter/**/*.rb Style/BlockDelimiters: Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to be consistent then. EnforcedStyle: braces_for_chaining -Style/BracesAroundHashParameters: - Description: Braces are required by Ruby 2.7. Cop removed from RuboCop v0.80.0. - See https://github.com/rubocop-hq/rubocop/pull/7643 - Enabled: true Style/ClassAndModuleChildren: Description: Compact style reduces the required amount of indentation. EnforcedStyle: compact Style/EmptyElse: Description: Enforce against empty else clauses, but allow `nil` for clarity. EnforcedStyle: empty Style/FormatString: Description: Following the main puppet project's style, prefer the % format format. EnforcedStyle: percent Style/FormatStringToken: Description: Following the main puppet project's style, prefer the simpler template tokens over annotated ones. EnforcedStyle: template Style/Lambda: Description: Prefer the keyword for easier discoverability. EnforcedStyle: literal Style/RegexpLiteral: Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 EnforcedStyle: percent_r Style/TernaryParentheses: Description: Checks for use of parentheses around ternary conditions. Enforce parentheses on complex expressions for better readability, but seriously consider breaking it up. EnforcedStyle: require_parentheses_when_complex Style/TrailingCommaInArguments: Description: Prefer always trailing comma on multiline argument lists. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: Exclude: - lib/puppet/parser/functions/**/* - spec/**/* Style/WordArray: EnforcedStyle: brackets +Performance/AncestorsInclude: + Enabled: true +Performance/BigDecimalWithNumericArgument: + Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true +Performance/CaseWhenSplat: + Enabled: true +Performance/ConstantRegexp: + Enabled: true +Performance/MethodObjectAsBlock: + Enabled: true +Performance/RedundantSortBlock: + Enabled: true +Performance/RedundantStringChars: + Enabled: true +Performance/ReverseFirst: + Enabled: true +Performance/SortReverse: + Enabled: true +Performance/Squeeze: + Enabled: true +Performance/StringInclude: + Enabled: true +Performance/Sum: + Enabled: true Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true -GetText/DecorateFunctionMessage: +Bundler/InsecureProtocolSource: + 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 -GetText/DecorateStringFormattingUsingInterpolation: +Layout/EmptyComment: Enabled: false -GetText/DecorateStringFormattingUsingPercent: +Layout/EmptyLineAfterGuardClause: + Enabled: false +Layout/EmptyLinesAroundArguments: + Enabled: false +Layout/EmptyLinesAroundAttributeAccessor: Enabled: false Layout/EndOfLine: Enabled: false -Layout/IndentHeredoc: +Layout/FirstArgumentIndentation: + Enabled: false +Layout/HashAlignment: + Enabled: false +Layout/HeredocIndentation: + Enabled: false +Layout/LeadingEmptyLines: + Enabled: false +Layout/SpaceAroundMethodCallOperator: + Enabled: false +Layout/SpaceInsideArrayLiteralBrackets: + Enabled: false +Layout/SpaceInsideReferenceBrackets: + Enabled: false +Lint/BigDecimalNew: + Enabled: false +Lint/BooleanSymbol: + Enabled: false +Lint/ConstantDefinitionInBlock: + Enabled: false +Lint/DeprecatedOpenSSLConstant: + Enabled: false +Lint/DisjunctiveAssignmentInConstructor: + Enabled: false +Lint/DuplicateElsifCondition: + Enabled: false +Lint/DuplicateRequire: + Enabled: false +Lint/DuplicateRescueException: + Enabled: false +Lint/EmptyConditionalBody: + Enabled: false +Lint/EmptyFile: + Enabled: false +Lint/ErbNewArguments: + Enabled: false +Lint/FloatComparison: + Enabled: false +Lint/HashCompareByIdentity: + Enabled: false +Lint/IdentityComparison: + Enabled: false +Lint/InterpolationCheck: + Enabled: false +Lint/MissingCopEnableDirective: + Enabled: false +Lint/MixedRegexpCaptureTypes: + Enabled: false +Lint/NestedPercentLiteral: + Enabled: false +Lint/NonDeterministicRequireOrder: + Enabled: false +Lint/OrderedMagicComments: + Enabled: false +Lint/OutOfRangeRegexpRef: + Enabled: false +Lint/RaiseException: + Enabled: false +Lint/RedundantCopEnableDirective: + Enabled: false +Lint/RedundantRequireStatement: + Enabled: false +Lint/RedundantSafeNavigation: + Enabled: false +Lint/RedundantWithIndex: + Enabled: false +Lint/RedundantWithObject: + Enabled: false +Lint/RegexpAsCondition: + Enabled: false +Lint/ReturnInVoidContext: + Enabled: false +Lint/SafeNavigationConsistency: + Enabled: false +Lint/SafeNavigationWithEmpty: + Enabled: false +Lint/SelfAssignment: + Enabled: false +Lint/SendWithMixinArgument: + Enabled: false +Lint/ShadowedArgument: + Enabled: false +Lint/StructNewOverride: + Enabled: false +Lint/ToJSON: + Enabled: false +Lint/TopLevelReturnWithArgument: + Enabled: false +Lint/TrailingCommaInAttributeDeclaration: + Enabled: false +Lint/UnreachableLoop: + Enabled: false +Lint/UriEscapeUnescape: + Enabled: false +Lint/UriRegexp: + Enabled: false +Lint/UselessMethodDefinition: + Enabled: false +Lint/UselessTimes: Enabled: false Metrics/AbcSize: Enabled: false Metrics/BlockLength: Enabled: false +Metrics/BlockNesting: + Enabled: false Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: 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/CurrentPathExpectation: + Enabled: false +RSpec/Capybara/FeatureMethods: + Enabled: false +RSpec/Capybara/VisibilityMatcher: + Enabled: false +RSpec/ContextMethod: + Enabled: false +RSpec/ContextWording: + Enabled: false RSpec/DescribeClass: Enabled: false +RSpec/EmptyHook: + Enabled: false +RSpec/EmptyLineAfterExample: + Enabled: false +RSpec/EmptyLineAfterExampleGroup: + Enabled: false +RSpec/EmptyLineAfterHook: + Enabled: false RSpec/ExampleLength: Enabled: false -RSpec/MessageExpectation: +RSpec/ExampleWithoutDescription: + Enabled: false +RSpec/ExpectChange: + Enabled: false +RSpec/ExpectInHook: + Enabled: false +RSpec/FactoryBot/AttributeDefinedStatically: + Enabled: false +RSpec/FactoryBot/CreateList: + Enabled: false +RSpec/FactoryBot/FactoryClassName: + Enabled: false +RSpec/HooksBeforeExamples: + Enabled: false +RSpec/ImplicitBlockExpectation: + Enabled: false +RSpec/ImplicitSubject: + Enabled: false +RSpec/LeakyConstantDeclaration: + Enabled: false +RSpec/LetBeforeExamples: + Enabled: false +RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/MultipleSubjects: + Enabled: false RSpec/NestedGroups: Enabled: false +RSpec/PredicateMatcher: + Enabled: false +RSpec/ReceiveCounts: + Enabled: false +RSpec/ReceiveNever: + Enabled: false +RSpec/RepeatedExampleGroupBody: + Enabled: false +RSpec/RepeatedExampleGroupDescription: + Enabled: false +RSpec/RepeatedIncludeExample: + Enabled: false +RSpec/ReturnFromStub: + Enabled: false +RSpec/SharedExamples: + Enabled: false +RSpec/StubbedMock: + Enabled: false +RSpec/UnspecifiedException: + Enabled: false +RSpec/VariableDefinition: + Enabled: false +RSpec/VoidExpect: + Enabled: false +RSpec/Yield: + Enabled: false +Security/Open: + Enabled: false +Style/AccessModifierDeclarations: + Enabled: false +Style/AccessorGrouping: + Enabled: false Style/AsciiComments: 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 +Lint/DuplicateBranch: + Enabled: false +Lint/DuplicateRegexpCharacterClassElement: + Enabled: false +Lint/EmptyBlock: + Enabled: false +Lint/EmptyClass: + Enabled: false +Lint/NoReturnInBeginEndBlocks: + Enabled: false +Lint/ToEnumArguments: + Enabled: false +Lint/UnexpectedBlockArity: + Enabled: false +Lint/UnmodifiedReduceAccumulator: + Enabled: false +Performance/CollectionLiteralInLoop: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false +Style/CollectionCompact: + Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false +Style/NegatedIfElseCondition: + Enabled: false +Style/NilLambda: + Enabled: false +Style/RedundantArgument: + Enabled: false +Style/SwapValues: + Enabled: false diff --git a/.travis.yml b/.travis.yml index 68d3e96..444e17a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,49 +1,45 @@ --- os: linux dist: xenial language: ruby cache: bundler before_install: - bundle -v - rm -f Gemfile.lock - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - gem --version - bundle -v script: - 'bundle exec rake $CHECK' bundler_args: --without system_tests rvm: - 2.5.7 stages: - static - spec - acceptance - if: tag =~ ^v\d name: deploy jobs: fast_finish: true include: - - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" + env: CHECK="validate lint check rubocop" stage: static - - - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.5 - stage: spec - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec rvm: 2.5.7 stage: spec - env: DEPLOY_TO_FORGE=yes stage: deploy branches: only: - - master + - main - /^v\d/ notifications: email: false diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2f1e4f7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/Gemfile b/Gemfile index 4f6e33b..1818b96 100644 --- a/Gemfile +++ b/Gemfile @@ -1,73 +1,63 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' def location_for(place_or_version, fake_version = nil) git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} file_url_regex = %r{\Afile:\/\/(?.*)} if place_or_version && (git_url = place_or_version.match(git_url_regex)) [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] else [place_or_version, { require: false }] end end ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments minor_version = ruby_version_segments[0..1].join('.') group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') end +group :system_tests do + gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] +end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] hiera_version = ENV['HIERA_GEM_VERSION'] gems = {} gems['puppet'] = location_for(puppet_version) # If facter or hiera versions have been specified via the environment # variables gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] -end - gems.each do |gem_name, gem_params| gem gem_name, *gem_params end # Evaluate Gemfile.local and ~/.gemfile if they exist extra_gemfiles = [ "#{__FILE__}.local", File.join(Dir.home, '.gemfile'), ] extra_gemfiles.each do |gemfile| if File.file?(gemfile) && File.readable?(gemfile) eval(File.read(gemfile), binding) end end # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 0a5093b..d3c2b37 100644 --- a/Rakefile +++ b/Rakefile @@ -1,87 +1,89 @@ # frozen_string_literal: true +require 'bundler' require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? 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 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 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 end +PuppetLint.configuration.send('disable_140chars') PuppetLint.configuration.send('disable_relative') if Bundler.rubygems.find_name('github_changelog_generator').any? 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 end end diff --git a/appveyor.yml b/appveyor.yml index ec38949..a70c01e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,56 +1,49 @@ --- version: 1.1.x.{build} +skip_branch_with_pr: true branches: only: - - master + - main - release skip_commits: message: /^\(?doc\)?.*/ clone_depth: 10 init: - SET - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0' - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0' - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' environment: matrix: - - RUBY_VERSION: 24-x64 - CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 5.0 - RUBY_VERSION: 24-x64 - CHECK: parallel_spec + RUBY_VERSION: 25-x64 + CHECK: validate lint check rubocop - PUPPET_GEM_VERSION: ~> 6.0 RUBY_VERSION: 25 CHECK: parallel_spec - PUPPET_GEM_VERSION: ~> 6.0 RUBY_VERSION: 25-x64 CHECK: parallel_spec matrix: fast_finish: true install: - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% - bundle install --jobs 4 --retry 2 --without system_tests - type Gemfile.lock build: off test_script: - bundle exec puppet -V - ruby -v - gem -v - bundle -v - bundle exec rake %CHECK% notifications: - provider: Email to: - nobody@nowhere.com on_build_success: false on_build_failure: false on_build_status_changed: false diff --git a/lib/puppet/functions/icinga2/icinga2_attributes.rb b/lib/puppet/functions/icinga2/icinga2_attributes.rb index c9eb5ff..0af15f1 100644 --- a/lib/puppet/functions/icinga2/icinga2_attributes.rb +++ b/lib/puppet/functions/icinga2/icinga2_attributes.rb @@ -1,56 +1,53 @@ # This is an autogenerated function, ported from the original legacy version. # It /should work/ as is, but will not have all the benefits of the modern # function API. You should see the function docs to learn how to add function # signatures for type safety and to document this function using puppet-strings. # # https://puppet.com/docs/puppet/latest/custom_functions_ruby.html # # ---- original file header ---- require File.join(File.dirname(__FILE__), '../../..', 'puppet_x/icinga2/utils.rb') # ---- original file header ---- # # @summary # Summarise what the function does here # Puppet::Functions.create_function(:'icinga2::icinga2_attributes') do # @param args # The original array of arguments. Port this to individually managed params # to get the full benefit of the modern function API. # # @return [Data type] # Describe what the function returns here # dispatch :default_impl do # Call the method named 'default_impl' when this is matched # Port this to match individual params for better type safety repeated_param 'Any', :args end - def default_impl(*args) - - raise Puppet::ParseError, 'icinga2_atributes(): Must provide at least one argument.' if args.length > 4 || args.length < 1 + raise Puppet::ParseError, 'icinga2_atributes(): Must provide at least one argument.' if args.length > 4 || args.empty? - if args[1] - indent = args[1] - else - indent = 0 - end + indent = if args[1] + args[1] + else + 0 + end - if args[2] - globals = args[2].concat(lookupvar('::icinga2::_reserved')) - else - globals = lookupvar('::icinga2::_reserved') - end + globals = if args[2] + args[2].concat(lookupvar('::icinga2::_reserved')) + else + lookupvar('::icinga2::_reserved') + end - if args[3] - constants = args[3].merge(lookupvar('::icinga2::_constants')) - else - constants = lookupvar('::icinga2::_constants') - end + constants = if args[3] + args[3].merge(lookupvar('::icinga2::_constants')) + else + lookupvar('::icinga2::_constants') + end Puppet::Icinga2::Utils.attributes(args[0], globals, constants, indent) - end end diff --git a/lib/puppet/functions/icinga2/icinga2_ticket_id.rb b/lib/puppet/functions/icinga2/icinga2_ticket_id.rb index 88060c1..ef2674b 100644 --- a/lib/puppet/functions/icinga2/icinga2_ticket_id.rb +++ b/lib/puppet/functions/icinga2/icinga2_ticket_id.rb @@ -1,50 +1,47 @@ # This is an autogenerated function, ported from the original legacy version. # It /should work/ as is, but will not have all the benefits of the modern # function API. You should see the function docs to learn how to add function # signatures for type safety and to document this function using puppet-strings. # # https://puppet.com/docs/puppet/latest/custom_functions_ruby.html # # ---- original file header ---- require File.join(File.dirname(__FILE__), '../../..', 'puppet_x/icinga2/pbkdf2.rb') # ---- original file header ---- # # @summary # Summarise what the function does here # Puppet::Functions.create_function(:'icinga2::icinga2_ticket_id') do # @param args # The original array of arguments. Port this to individually managed params # to get the full benefit of the modern function API. # # @return [Data type] # Describe what the function returns here # dispatch :default_impl do # Call the method named 'default_impl' when this is matched # Port this to match individual params for better type safety repeated_param 'Any', :args end - def default_impl(*args) - raise Puppet::ParseError, 'Must provide exactly two arguments to icinga2_ticket_id' if args.length != 2 - if !args[0] or args[0] == '' + if !args[0] || args[0] == '' raise Puppet::ParseError, 'first argument (cn) can not be empty for icinga2_ticket_id' end - if !args[1] or args[1] == '' + if !args[1] || args[1] == '' raise Puppet::ParseError, 'second argument (salt) can not be empty for icinga2_ticket_id' end PBKDF2.new( - :password => args[0], - :salt => args[1], - :iterations => 50000, - :hash_function => OpenSSL::Digest.new("sha1") + password: args[0], + salt: args[1], + iterations: 50_000, + hash_function: OpenSSL::Digest.new('sha1'), ).hex_string - end end diff --git a/lib/puppet/parser/functions/icinga2_attributes.rb b/lib/puppet/parser/functions/icinga2_attributes.rb index b4f3b17..01fbc15 100644 --- a/lib/puppet/parser/functions/icinga2_attributes.rb +++ b/lib/puppet/parser/functions/icinga2_attributes.rb @@ -1,33 +1,33 @@ require File.join(File.dirname(__FILE__), '../../..', 'puppet_x/icinga2/utils.rb') module Puppet::Parser::Functions # @summary # Wrapper for config parser # # @return # Parsed config as string # - newfunction(:icinga2_attributes, :type => :rvalue) do |args| - raise Puppet::ParseError, 'icinga2_atributes(): Must provide at least one argument.' if args.length > 4 || args.length < 1 + newfunction(:icinga2_attributes, type: :rvalue) do |args| + raise Puppet::ParseError, 'icinga2_atributes(): Must provide at least one argument.' if args.length > 4 || args.empty? - if args[1] - indent = args[1] - else - indent = 0 - end + indent = if args[1] + args[1] + else + 0 + end - if args[2] - globals = args[2].concat(lookupvar('::icinga2::_reserved')) - else - globals = lookupvar('::icinga2::_reserved') - end + globals = if args[2] + args[2].concat(lookupvar('::icinga2::_reserved')) + else + lookupvar('::icinga2::_reserved') + end - if args[3] - constants = args[3].merge(lookupvar('::icinga2::_constants')) - else - constants = lookupvar('::icinga2::_constants') - end + constants = if args[3] + args[3].merge(lookupvar('::icinga2::_constants')) + else + lookupvar('::icinga2::_constants') + end Puppet::Icinga2::Utils.attributes(args[0], globals, constants, indent) end end diff --git a/lib/puppet/parser/functions/icinga2_ticket_id.rb b/lib/puppet/parser/functions/icinga2_ticket_id.rb index 0f26f67..8a2d794 100644 --- a/lib/puppet/parser/functions/icinga2_ticket_id.rb +++ b/lib/puppet/parser/functions/icinga2_ticket_id.rb @@ -1,25 +1,25 @@ require File.join(File.dirname(__FILE__), '../../..', 'puppet_x/icinga2/pbkdf2.rb') module Puppet::Parser::Functions # @summary # Generates a auth ticket to get a certificate # @return # The ticket to get a certificate - newfunction(:icinga2_ticket_id, :type => :rvalue) do |args| + newfunction(:icinga2_ticket_id, type: :rvalue) do |args| raise Puppet::ParseError, 'Must provide exactly two arguments to icinga2_ticket_id' if args.length != 2 - if !args[0] or args[0] == '' + if !args[0] || args[0] == '' raise Puppet::ParseError, 'first argument (cn) can not be empty for icinga2_ticket_id' end - if !args[1] or args[1] == '' + if !args[1] || args[1] == '' raise Puppet::ParseError, 'second argument (salt) can not be empty for icinga2_ticket_id' end PBKDF2.new( - :password => args[0], - :salt => args[1], - :iterations => 50000, - :hash_function => OpenSSL::Digest.new("sha1") + password: args[0], + salt: args[1], + iterations: 50_000, + hash_function: OpenSSL::Digest.new('sha1'), ).hex_string end end diff --git a/lib/puppet_x/icinga2/utils.rb b/lib/puppet_x/icinga2/utils.rb index 0c2c2f0..47075d5 100644 --- a/lib/puppet_x/icinga2/utils.rb +++ b/lib/puppet_x/icinga2/utils.rb @@ -1,367 +1,365 @@ # == Helper function attributes # # Returns formatted attributes for objects as strings. # # === Common Explanation: # # To generate a valid Icinga 2 configuration all object attributes are parsed. This # simple parsing algorithm takes a decision for each attribute, whether part of the # string is to be quoted or not, and how an array or dictionary is to be formatted. # # Parsing of a single attribute can be disabled by tagging it with -: at the front # of the string. # # attr => '-:"unparsed string with quotes"' # # An array, a hash or a string can be assigned to an object attribute. True and false # are also valid values. # # Hashes and arrays are created recursively, and all parts – such as single items of an array, # keys and its values – are parsed separately as strings. # # Strings are parsed in chunks, by splitting the original string into separate substrings # at specific keywords (operators) such as +, -, in, &&, ||, etc. # # NOTICE: This splitting only works for keywords that are surrounded by whitespace, e.g.: # # attr => 'string1 + string2 - string3' # # The algorithm will loop over the parameter and start by splitting it into 'string1' and 'string2 - string3'. # 'string1' will be passed to the sub function 'value_types' and then the algorithm will continue parsing # the rest of the string ('string2 - string3'), splitting it, passing it to value_types, etc. # # Brackets are parsed for expressions: # # attr => '3 * (value1 - value2) / 2' # # The parser also detects function calls and will parse all parameters separately. # # attr => 'function(param1, param2, ...)' # # True and false can be used as either booleans or strings. # # attrs => true or attr => 'true' # # In Icinga you can write your own lambda functions with {{ ... }}. For puppet use: # # attrs => '{{ ... }}' # # The parser analyzes which parts of the string have to be quoted and which do not. # # As a general rule, all fragments are quoted except for the following: # # - boolean: true, false # - numbers: 3 or 2.5 # - time intervals: 3m or 2.5h (s = seconds, m = minutes, h = hours, d = days) # - functions: {{ ... }} or function () {} # - all constants, which are declared in the constants parameter in main class icinga2: # NodeName # - names of attributes that belong to the same type of object: # e.g. name and check_command for a host object # - all attributes or variables (custom attributes) from the host, service or user contexts: # host.name, service.check_command, user.groups, ... # # Assignment with += and -=: # # Now it's possible to build an Icinga DSL code snippet like # # vars += config # # simply use a string with the prefix '+ ', e.g. # # vars => '+ config', # # The blank between + and the proper string 'config' is imported for the parser because numbers # # attr => '+ -14', # # are also possible now. For numbers -= can be built, too: # # attr => '- -14', # # Arrays can also be marked to merge with '+' or reduce by '-' as the first item of the array: # # attr => [ '+', item1, item2, ... ] # # Result: attr += [ item1, item2, ... ] # # attr => [ '-' item1, item2, ... ] # # Result: attr -= [ item1, item2, ... ] # # That all works for attributes and custom attributes! # # Finally dictionaries can be merged when a key '+' is set: # # attr => { # '+' => true, # 'key1' => 'val1', # } # # Result: # # attr += { # "key1" = "val1" # } # # If 'attr' is a custom attribute this just works since level 3 of the dictionary: # # vars => { # 'level1' => { # 'level2' => { # 'level3' => { # '+' => true, # ... # }, # }, # }, # }, # # Parsed to: # # vars.level1["level2"] += level3 # # Now it's also possible to add multiple custom attributes: # # vars => [ # { # 'a' => '1', # 'b' => '2', # }, # 'config', # { # 'c' => { # 'd' => { # '+' => true, # 'e' => '5', # }, # }, # }, # ], # # And you'll get: # # vars.a = "1" # vars.b = "2" # vars += config # vars.c["d"] += { # "e" = "5" # } # # Note: Using an Array always means merge '+=' all items to vars. # # === What isn't supported? # # It's not currently possible to use dictionaries in a string WITH nested array or hash, like # # attr1 => 'hash1 + { item1 => value1, item2 => [ value1, value2 ], ... ]' # attr2 => 'hash2 + { item1 => value1, item2 => { ... },... }' # # require 'puppet' module Puppet module Icinga2 module Utils def self.attributes(attrs, globals, consts, indent=2) def self.value_types(value) if value =~ /^-?\d+\.?\d*[dhms]?$/ || value =~ /^(true|false|null)$/ || value =~ /^!?(host|service|user)\./ || value =~ /^\{{2}.*\}{2}$/ result = value else if $constants.index { |x| if $hash_attrs.include?(x) then value =~ /^!?(#{x})(\..+$|$)/ else value =~ /^!?#{x}$/ end } result = value else result = value.dump end end return result end def self.attribute_types(attr) if attr =~ /^[a-zA-Z0-9_]+$/ result = attr else result = "\"#{attr}\"" end return result end def self.parse(row) result = '' # parser is disabled if row =~ /^-:(.*)$/m return $1 end if row =~ /^\{{2}(.+)\}{2}$/m # scan function result += "{{%s}}" % [ $1 ] elsif row =~ /^(.+)\s([\+-]|\*|\/|==|!=|&&|\|{2}|in)\s\{{2}(.+)\}{2}$/m # scan expression + function (function should contain expressions, but we donno parse it) result += "%s %s {{%s}}" % [ parse($1), $2, $3 ] elsif row =~ /^(.+)\s([\+-]|\*|\/|==|!=|&&|\|{2}|in)\s(.+)$/ # scan expression result += "%s %s %s" % [ parse($1), $2, parse($3) ] else if row =~ /^(.+)\((.*)$/ result += "%s(%s" % [ $1, $2.split(',').map {|x| parse(x.lstrip)}.join(', ') ] elsif row =~ /^(.*)\)(.+)?$/ # closing bracket ) with optional access of an attribute e.g. '.arguments' result += "%s)%s" % [ $1.split(',').map {|x| parse(x.lstrip)}.join(', '), $2 ] elsif row =~ /^\((.*)$/ result += "(%s" % [ parse($1) ] elsif row =~ /^\s*\[\s*(.*)\s*\]\s?(.+)?$/ # parse array result += "[ %s]" % [ process_array($1.split(',')) ] result += " %s" % [ parse($2) ] if $2 elsif row =~ /^\s*\{\s*(.*)\s*\}\s?(.+)?$/ # parse hash result += "{\n%s}" % [ process_hash(Hash[$1.gsub(/\s*=>\s*|\s*,\s*/, ',').split(',').each_slice(2).to_a]) ] result += " %s" % [ parse($2) ] if $2 else result += value_types(row.to_s.strip) end end return result.gsub(/" in "/, ' in ') end def self.process_array(items, indent=2) result = '' items.each do |value| if value.is_a?(Hash) result += "\n%s{\n%s%s}, " % [ ' ' * indent, process_hash(value, indent + 2), ' ' * indent ] elsif value.is_a?(Array) result += "[ %s], " % [ process_array(value, indent+2) ] else result += "%s, " % [ parse(value) ] if value end end return result end def self.process_hash(attrs, indent=2, level=3, prefix=' '*indent) result = '' attrs.each do |attr, value| if value.is_a?(Hash) op = '+' if value.delete('+') if value.empty? result += case level when 1 then "%s%s #{op}= {}\n" % [ prefix, attribute_types(attr) ] when 2 then "%s[\"%s\"] #{op}= {}\n" % [ prefix, attr ] else "%s%s #{op}= {}\n" % [ prefix, attribute_types(attr) ] end else result += case level when 1 then process_hash(value, indent, 2, "%s%s" % [ prefix, attr ]) when 2 then "%s[\"%s\"] #{op}= {\n%s%s}\n" % [ prefix, attr, process_hash(value, indent), ' ' * (indent-2) ] else "%s%s #{op}= {\n%s%s}\n" % [ prefix, attribute_types(attr), process_hash(value, indent+2), ' ' * indent ] end end elsif value.is_a?(Array) op = value.delete_at(0) if value[0] == '+' or value[0] == '-' result += case level when 2 then "%s[\"%s\"] #{op}= [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ] else "%s%s #{op}= [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ] end else # String: attr = '+ value' -> attr += 'value' if value =~ /^([\+,-])\s+/ operator = "#{$1}=" value = value.sub(/^[\+,-]\s+/, '') else operator = '=' end if level > 1 if level == 3 result += "%s%s #{operator} %s\n" % [ prefix, attribute_types(attr), parse(value) ] if value != :nil else result += "%s[\"%s\"] #{operator} %s\n" % [ prefix, attr, parse(value) ] if value != :nil end else result += "%s%s #{operator} %s\n" % [ prefix, attr, parse(value) ] if value != :nil end end end return result end # globals (params.pp) and all keys of attrs hash itselfs must not quoted $constants = globals.concat(consts.keys) << "name" # select all attributes and constants if there value is a hash $hash_attrs = attrs.merge(consts).select { |x,y| y.is_a?(Hash) }.keys # initialize returned configuration config = '' attrs.each do |attr, value| if attr =~ /^(assign|ignore) where$/ value.each do |x| config += "%s%s %s\n" % [ ' ' * indent, attr, parse(x) ] if x end elsif attr == 'vars' if value.is_a?(Hash) # delete pair of key '+' because a merge at this point is not allowed value.delete('+') config += process_hash(value, indent+2, 1, "%s%s." % [ ' ' * indent, attr]) elsif value.is_a?(Array) value.each do |item| if item.is_a?(String) config += "%s%s += %s\n" % [ ' ' * indent, attr, item.sub(/^[\+,-]\s+/, '') ] else item.delete('+') if item.empty? config += "%s%s += {}\n" % [ ' ' * indent, attr] else config += process_hash(item, indent+2, 1, "%s%s." % [ ' ' * indent, attr]) end end end else op = '+' if value =~ /^\+\s+/ config += "%s%s #{op}= %s\n" % [ ' ' * indent, attr, parse(value.sub(/^\+\s+/, '')) ] end else if value.is_a?(Hash) op = '+' if value.delete('+') unless value.empty? config += "%s%s #{op}= {\n%s%s}\n" % [ ' ' * indent, attr, process_hash(value, indent+2), ' ' * indent ] else config += "%s%s #{op}= {}\n" % [ ' ' * indent, attr ] end elsif value.is_a?(Array) op = value.delete_at(0) if value[0] == '+' or value[0] == '-' config += "%s%s #{op}= [ %s]\n" % [ ' ' * indent, attr, process_array(value) ] else # String: attr = '+config' -> attr += config if value =~ /^([\+,-])\s+/ config += "%s%s #{$1}= %s\n" % [ ' ' * indent, attr, parse(value.sub(/^[\+,-]\s+/, '')) ] else config += "%s%s = %s\n" % [ ' ' * indent, attr, parse(value) ] end end end end - return config end - end end end diff --git a/metadata.json b/metadata.json index 9441925..73fdc56 100644 --- a/metadata.json +++ b/metadata.json @@ -1,107 +1,107 @@ { "name": "icinga-icinga2", "version": "3.1.3", "author": "Icinga Development Team", "summary": "Icinga 2 Puppet Module", "license": "Apache-2.0", "source": "git://github.com/icinga/puppet-icinga2", "project_page": "https://github.com/icinga/puppet-icinga2", "issues_url": "https://github.com/icinga/puppet-icinga2/issues", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 5.0.0 < 8.0.0" }, { "name": "puppetlabs/concat", "version_requirement": ">= 2.1.0 < 8.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Windows", "operatingsystemrelease": [ "Server 2012", "Server 2012 R2", "Server 2016", "Server 2019" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "6", "7", "8" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ "6", "7", "8" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "6", "7", "8" ] }, { "operatingsystem": "Fedora", "operatingsystemrelease": [ "31", "32", "33", "34" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ "8", "9", "10" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "16.04", "18.04", "20.04" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "12", "15" ] }, { "operatingsystem": "FreeBSD", "operatingsystemrelease": [ "11", "12", "13" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 4.10.0 < 8.0.0" } ], "tags": [ "monitoring" ], - "pdk-version": "1.18.1", - "template-url": "pdk-default#1.18.1", - "template-ref": "tags/1.18.1-0-g3d2e75c" + "pdk-version": "2.2.0", + "template-url": "pdk-default#2.2.0", + "template-ref": "tags/2.2.0-0-g2381db6" } diff --git a/pdk.yaml b/pdk.yaml new file mode 100644 index 0000000..4bef4bd --- /dev/null +++ b/pdk.yaml @@ -0,0 +1,2 @@ +--- +ignore: [] diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 3c3cfe9..1d11f6f 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,104 +1,102 @@ require 'spec_helper_acceptance' describe 'icinga2 class' do - describe 'with API, IDO mysql and pgsql' do let(:pp) do <<-MANIFEST case $::facts['os']['name'] { 'redhat', 'centos': { if Integer($::facts['os']['release']['major']) < 8 { $epel = true $backports = false } } # RedHat 'debian', 'ubuntu': { if $::facts['os']['distro']['codename'] in [ 'stretch', 'trusty' ] { $epel = false $backports = true } } # Debian } - + class { '::icinga::repos': manage_epel => $epel, configure_backports => $backports, } class { 'icinga2': manage_repos => true, constants => { 'TicketSalt' => 'topsecret4ticketid', }, } include mysql::server include mysql::client mysql::db { 'icinga2': user => 'icinga2', password => 'topsecret4idomysql', host => 'localhost', grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER'], } -> class { 'icinga2::feature::idomysql': host => 'localhost', user => 'icinga2', password => 'topsecret4idomysql', database => 'icinga2', import_schema => true, - } + } include ::postgresql::server postgresql::server::db { 'icinga2': user => 'icinga2', password => postgresql_password('icinga2', 'topsecret4idopgsql'), } -> class { 'icinga2::feature::idopgsql': host => 'localhost', user => 'icinga2', password => 'topsecret4idopgsql', database => 'icinga2', import_schema => true, } include ::icinga2::pki::ca class { 'icinga2::feature::api': pki => 'none', } icinga2::object::apiuser { 'ticketid': ensure => present, password => 'topsecret4ticketid', permissions => [ 'actions/generate-ticket' ], - target => '/etc/icinga2/conf.d/api-users.conf', + target => '/etc/icinga2/conf.d/api-users.conf', } MANIFEST end it_behaves_like 'a idempotent resource' describe package('icinga2') do it { is_expected.to be_installed } end describe service('icinga2') do it { is_expected.to be_running } end describe port(5665) do it { is_expected.to be_listening } end describe command("mysql icinga2 -Ns -e 'select version from icinga_dbversion;'") do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match %r{^\d+\.\d+.\d+$} } end describe command("sudo -u postgres psql -d 'icinga2' -w -c 'select version from icinga_dbversion'") do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match %r{\d+\.\d+.\d+} } end describe command("curl -k -s -u ticketid:topsecret4ticketid -X POST -H 'Accept: application/json' -d '{\"cn\": \"agent.example.org\"}' https://localhost:5665/v1/actions/generate-ticket") do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match %r{e1cfea2cff7bc91bd9be1f0f02ef40a0e5233c2e} } end end - end diff --git a/spec/classes/api_spec.rb b/spec/classes/api_spec.rb index 5bef409..37e3304 100644 --- a/spec/classes/api_spec.rb +++ b/spec/classes/api_spec.rb @@ -1,225 +1,268 @@ require 'spec_helper' -describe('icinga2::feature::api', :type => :class) do +describe('icinga2::feature::api', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }" + "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }", ] end - on_supported_os.each do |os, facts| context "on #{os}" do - let(:facts) do case facts[:kernel] when 'windows' - facts.merge({ - :icinga2_puppet_hostcert => 'C:/ProgramData/PuppetLabs/puppet/ssl/certs/host.example.org.pem', - :icinga2_puppet_hostprivkey => 'C:/ProgramData/PuppetLabs/puppet/ssl/private_keys/host.example.org.pem', - :icinga2_puppet_localcacert => 'C:/ProgramData/PuppetLabs/var/lib/puppet/ssl/certs/ca.pem', - }) + facts.merge( + { + icinga2_puppet_hostcert: 'C:/ProgramData/PuppetLabs/puppet/ssl/certs/host.example.org.pem', + icinga2_puppet_hostprivkey: 'C:/ProgramData/PuppetLabs/puppet/ssl/private_keys/host.example.org.pem', + icinga2_puppet_localcacert: 'C:/ProgramData/PuppetLabs/var/lib/puppet/ssl/certs/ca.pem', + }, + ) else - facts.merge({ - :icinga2_puppet_hostcert => '/etc/puppetlabs/puppet/ssl/certs/host.example.org.pem', - :icinga2_puppet_hostprivkey => '/etc/puppetlabs/puppet/ssl/private_keys/host.example.org.pem', - :icinga2_puppet_localcacert => '/etc/lib/puppetlabs/puppet/ssl/certs/ca.pem', - }) + facts.merge( + { + icinga2_puppet_hostcert: '/etc/puppetlabs/puppet/ssl/certs/host.example.org.pem', + icinga2_puppet_hostprivkey: '/etc/puppetlabs/puppet/ssl/private_keys/host.example.org.pem', + icinga2_puppet_localcacert: '/etc/lib/puppetlabs/puppet/ssl/certs/ca.pem', + }, + ) end end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_bin = 'C:/Program Files/icinga2/sbin/icinga2.exe' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - @icinga2_pki_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/certs' - @icinga2_sslkey_mode = nil - @icinga2_user = nil - @icinga2_group = nil - when 'FreeBSD' - @icinga2_bin = '/usr/local/sbin/icinga2' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' + case facts[:kernel] + when 'windows' + let(:icinga2_bin) { 'C:/Program Files/icinga2/sbin/icinga2.exe' } + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + let(:icinga2_pki_dir) { 'C:/ProgramData/icinga2/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { nil } + let(:icinga2_user) { nil } + let(:icinga2_group) { nil } + when 'FreeBSD' + let(:icinga2_bin) { '/usr/local/sbin/icinga2' } + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { '0600' } + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { '0600' } + case facts[:os]['family'] + when 'Debian' + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } + let(:icinga2_bin) { '/usr/sbin/icinga2' } else - @icinga2_conf_dir = '/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_sslkey_mode = '0600' - case facts[:os]['family'] - when 'Debian' - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - @icinga2_bin = '/usr/sbin/icinga2' + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + if facts[:os]['family'] != 'RedHat' + let(:icinga2_bin) { '/usr/sbin/icinga2' } else - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - if facts[:os]['family'] != 'RedHat' - @icinga2_bin = '/usr/sbin/icinga2' + case facts[:os]['release']['major'] + when '5' + let(:icinga2_bin) { '/usr/sbin/icinga2' } + when '6' + let(:icinga2_bin) { '/usr/sbin/icinga2' } else - case facts[:os]['release']['major'] - when '5' - @icinga2_bin = '/usr/sbin/icinga2' - when '6' - @icinga2_bin = '/usr/sbin/icinga2' - else - @icinga2_bin = '/sbin/icinga2' - end + let(:icinga2_bin) { '/sbin/icinga2' } end end end end context "with pki => 'puppet'" do let(:params) do { - :ensure => 'present', - :pki => 'puppet' + ensure: 'present', + pki: 'puppet', } end - it { is_expected.to contain_icinga2__feature('api').with({ - 'ensure' => 'present' - }) } - - it { is_expected.to contain_icinga2__object('icinga2::object::ApiListener::api') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/api.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/host.example.org.key") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - 'mode' => @icinga2_sslkey_mode, - 'show_diff' => false, - 'backup' => false, }) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/host.example.org.crt") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/ca.crt") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) } + it { is_expected.to contain_icinga2__feature('api').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::ApiListener::api').with( + { 'target' => "#{icinga2_conf_dir}/features-available/api.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/host.example.org.key").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + 'mode' => icinga2_sslkey_mode, + 'show_diff' => false, + 'backup' => false, + }, + ) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/host.example.org.crt").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/ca.crt").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ) + } it { is_expected.to contain_icinga2__object__endpoint('NodeName') } - it { is_expected.to contain_icinga2__object__zone('ZoneName') - .with({ 'endpoints' => [ 'NodeName' ] }) } + it { is_expected.to contain_icinga2__object__zone('ZoneName').with({ 'endpoints' => [ 'NodeName' ] }) } end context "with ensure => absent, pki => 'puppet'" do let(:params) do { - :ensure => 'absent', - :pki => 'puppet' + ensure: 'absent', + pki: 'puppet', } end - it { is_expected.to contain_icinga2__feature('api').with({ - 'ensure' => 'absent', }) } + it { is_expected.to contain_icinga2__feature('api').with({ 'ensure' => 'absent' }) } end context "with pki => 'none', ssl_key => 'foo', ssl_cert => 'bar', ssl_cacert => 'baz'" do let(:params) do { - :pki => 'none', - :ssl_key => 'foo', - :ssl_cert => 'bar', - :ssl_cacert => 'baz' + pki: 'none', + ssl_key: 'foo', + ssl_cert: 'bar', + ssl_cacert: 'baz', } end - it { is_expected.to contain_file("#{@icinga2_pki_dir}/host.example.org.key") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - 'mode' => @icinga2_sslkey_mode, - 'show_diff' => false, - 'backup' => false, }) - .with_content(/^foo$/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/host.example.org.crt") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^bar$/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/ca.crt") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^baz$/) } + it { + is_expected.to contain_file("#{icinga2_pki_dir}/host.example.org.key").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + 'mode' => icinga2_sslkey_mode, + 'show_diff' => false, + 'backup' => false, + }, + ).with_content(%r{^foo$}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/host.example.org.crt").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^bar$}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/ca.crt").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^baz$}) + } end context "with pki => 'icinga2', ca_host => 'foo', ca_port => 1234, ticket_salt => 'bar'" do let(:params) do { - :pki => 'icinga2', - :ca_host => 'foo', - :ca_port => 1234, - :ticket_salt => 'bar' + pki: 'icinga2', + ca_host: 'foo', + ca_port: 1234, + ticket_salt: 'bar', } end - it { is_expected.to contain_exec('icinga2 pki create key') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki new-cert --cn host.example.org --key #{@icinga2_pki_dir}/host.example.org.key --cert #{@icinga2_pki_dir}/host.example.org.crt", - 'creates' => "#{@icinga2_pki_dir}/host.example.org.key", }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_exec('icinga2 pki get trusted-cert') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki save-cert --host foo --port 1234 --key #{@icinga2_pki_dir}/host.example.org.key --cert #{@icinga2_pki_dir}/host.example.org.crt --trustedcert #{@icinga2_pki_dir}/trusted-cert.crt", - 'creates' => "#{@icinga2_pki_dir}/trusted-cert.crt", }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_exec('icinga2 pki request') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki request --host foo --port 1234 --ca #{@icinga2_pki_dir}/ca.crt --key #{@icinga2_pki_dir}/host.example.org.key --cert #{@icinga2_pki_dir}/host.example.org.crt --trustedcert #{@icinga2_pki_dir}/trusted-cert.crt --ticket ac5cb0d8c98f3f50ceff399b3cfedbb03782c117", - 'creates' => "#{@icinga2_pki_dir}/ca.crt", }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_exec('icinga2 pki create key').with( + { + 'command' => "\"#{icinga2_bin}\" pki new-cert --cn host.example.org --key #{icinga2_pki_dir}/host.example.org.key" \ + " --cert #{icinga2_pki_dir}/host.example.org.crt", + 'creates' => "#{icinga2_pki_dir}/host.example.org.key", + }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_exec('icinga2 pki get trusted-cert').with( + { + 'command' => "\"#{icinga2_bin}\" pki save-cert --host foo --port 1234 --key #{icinga2_pki_dir}/host.example.org.key" \ + " --cert #{icinga2_pki_dir}/host.example.org.crt --trustedcert #{icinga2_pki_dir}/trusted-cert.crt", + 'creates' => "#{icinga2_pki_dir}/trusted-cert.crt", + }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_exec('icinga2 pki request').with( + { + 'command' => "\"#{icinga2_bin}\" pki request --host foo --port 1234 --ca #{icinga2_pki_dir}/ca.crt" \ + " --key #{icinga2_pki_dir}/host.example.org.key --cert #{icinga2_pki_dir}/host.example.org.crt --trustedcert #{icinga2_pki_dir}/trusted-cert.crt" \ + ' --ticket ac5cb0d8c98f3f50ceff399b3cfedbb03782c117', + 'creates' => "#{icinga2_pki_dir}/ca.crt", + }, + ).that_notifies('Class[icinga2::service]') + } end context "with pki => 'icinga2', ca_host => 'foo', ca_port => 1234, ticket_id => 'bar'" do let(:params) do { - :pki => 'icinga2', - :ca_host => 'foo', - :ca_port => 1234, - :ticket_id => 'bar' + pki: 'icinga2', + ca_host: 'foo', + ca_port: 1234, + ticket_id: 'bar', } end - it { is_expected.to contain_exec('icinga2 pki create key') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki new-cert --cn host.example.org --key #{@icinga2_pki_dir}/host.example.org.key --cert #{@icinga2_pki_dir}/host.example.org.crt", - 'creates' => "#{@icinga2_pki_dir}/host.example.org.key", }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_exec('icinga2 pki get trusted-cert') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki save-cert --host foo --port 1234 --key #{@icinga2_pki_dir}/host.example.org.key --cert #{@icinga2_pki_dir}/host.example.org.crt --trustedcert #{@icinga2_pki_dir}/trusted-cert.crt", - 'creates' => "#{@icinga2_pki_dir}/trusted-cert.crt", }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_exec('icinga2 pki request') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki request --host foo --port 1234 --ca #{@icinga2_pki_dir}/ca.crt --key #{@icinga2_pki_dir}/host.example.org.key --cert #{@icinga2_pki_dir}/host.example.org.crt --trustedcert #{@icinga2_pki_dir}/trusted-cert.crt --ticket bar", - 'creates' => "#{@icinga2_pki_dir}/ca.crt", }) - .that_notifies('Class[icinga2::service]') } - end + it { + is_expected.to contain_exec('icinga2 pki create key').with( + { + 'command' => "\"#{icinga2_bin}\" pki new-cert --cn host.example.org --key #{icinga2_pki_dir}/host.example.org.key" \ + " --cert #{icinga2_pki_dir}/host.example.org.crt", + 'creates' => "#{icinga2_pki_dir}/host.example.org.key", + }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_exec('icinga2 pki get trusted-cert').with( + { + 'command' => "\"#{icinga2_bin}\" pki save-cert --host foo --port 1234 --key #{icinga2_pki_dir}/host.example.org.key" \ + " --cert #{icinga2_pki_dir}/host.example.org.crt --trustedcert #{icinga2_pki_dir}/trusted-cert.crt", + 'creates' => "#{icinga2_pki_dir}/trusted-cert.crt", + }, + ).that_notifies('Class[icinga2::service]') + } + it { + is_expected.to contain_exec('icinga2 pki request').with( + { + 'command' => "\"#{icinga2_bin}\" pki request --host foo --port 1234 --ca #{icinga2_pki_dir}/ca.crt --key #{icinga2_pki_dir}/host.example.org.key" \ + " --cert #{icinga2_pki_dir}/host.example.org.crt --trustedcert #{icinga2_pki_dir}/trusted-cert.crt --ticket bar", + 'creates' => "#{icinga2_pki_dir}/ca.crt", + }, + ).that_notifies('Class[icinga2::service]') + } + end end end end diff --git a/spec/classes/checker_spec.rb b/spec/classes/checker_spec.rb index 29fe2e9..961a984 100644 --- a/spec/classes/checker_spec.rb +++ b/spec/classes/checker_spec.rb @@ -1,55 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::checker', :type => :class) do +describe('icinga2::feature::checker', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('checker').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::CheckerComponent::checker') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/checker.conf", }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::checker') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/checker.conf", - 'order' => '05', }) - .with_content(/library \"checker\"$/) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('checker').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::CheckerComponent::checker').with( + { 'target' => "#{icinga2_conf_dir}/features-available/checker.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::checker').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/checker.conf", + 'order' => '05', + }, + ).with_content(%r{library \"checker\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('checker') - .with({ 'ensure' => 'absent' }) } + it { is_expected.to contain_icinga2__feature('checker').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/command_spec.rb b/spec/classes/command_spec.rb index d9f56e9..f0d38fe 100644 --- a/spec/classes/command_spec.rb +++ b/spec/classes/command_spec.rb @@ -1,60 +1,61 @@ require 'spec_helper' -describe('icinga2::feature::command', :type => :class) do +describe('icinga2::feature::command', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do + context 'with defaults' do let(:params) do { - :ensure => 'present' + ensure: 'present', } end - it { is_expected.to contain_icinga2__feature('command').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::ExternalCommandListener::command') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/command.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::command') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/command.conf", - 'order' => '05', }) - .with_content(/library \"compat\"$/) } + it { is_expected.to contain_icinga2__feature('command').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::ExternalCommandListener::command').with( + { 'target' => "#{icinga2_conf_dir}/features-available/command.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::command').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/command.conf", + 'order' => '05', + }, + ).with_content(%r{library \"compat\"$}) + } end - - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('command').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('command').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/compatlog_spec.rb b/spec/classes/compatlog_spec.rb index 9b6f5ab..b172c54 100644 --- a/spec/classes/compatlog_spec.rb +++ b/spec/classes/compatlog_spec.rb @@ -1,53 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::compatlog', :type => :class) do +describe('icinga2::feature::compatlog', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('compatlog').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::CompatLogger::compatlog') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/compatlog.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::compatlog') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/compatlog.conf", - 'order' => '05', }) - .with_content(/library \"compat\"$/) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('compatlog').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::CompatLogger::compatlog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/compatlog.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::compatlog').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/compatlog.conf", + 'order' => '05', + }, + ).with_content(%r{library \"compat\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('compatlog').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('compatlog').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/debuglog_spec.rb b/spec/classes/debuglog_spec.rb index eeaf798..3f566e5 100644 --- a/spec/classes/debuglog_spec.rb +++ b/spec/classes/debuglog_spec.rb @@ -1,60 +1,61 @@ require 'spec_helper' -describe('icinga2::feature::debuglog', :type => :class) do +describe('icinga2::feature::debuglog', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [], }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('debuglog').with({'ensure' => 'present'}) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('debuglog').with({ 'ensure' => 'present' }) } - it { is_expected.to contain_icinga2__object('icinga2::object::FileLogger::debuglog') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/debuglog.conf" }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_icinga2__object('icinga2::object::FileLogger::debuglog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/debuglog.conf" }, + ).that_notifies('Class[icinga2::service]') + } case facts[:os]['family'] when 'windows' - it { is_expected.to contain_concat__fragment('icinga2::object::FileLogger::debuglog') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/debuglog.conf", }) - .with_content(/path = \"C:\/ProgramData\/icinga2\/var\/log\/icinga2\/debug.log\"/) } + it { + is_expected.to contain_concat__fragment('icinga2::object::FileLogger::debuglog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/debuglog.conf" }, + ).with_content(%r{path = \"C:\/ProgramData\/icinga2\/var\/log\/icinga2\/debug.log\"}) + } else - it { is_expected.to contain_concat__fragment('icinga2::object::FileLogger::debuglog') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/debuglog.conf", }) - .with_content(/path = \"\/var\/log\/icinga2\/debug.log\"/) } + it { + is_expected.to contain_concat__fragment('icinga2::object::FileLogger::debuglog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/debuglog.conf" }, + ).with_content(%r{path = \"\/var\/log\/icinga2\/debug.log\"}) + } end end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('debuglog').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('debuglog').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/elasticsearch_spec.rb b/spec/classes/elasticsearch_spec.rb index 10882fa..ca7c461 100644 --- a/spec/classes/elasticsearch_spec.rb +++ b/spec/classes/elasticsearch_spec.rb @@ -1,125 +1,145 @@ require 'spec_helper' -describe('icinga2::feature::elasticsearch', :type => :class) do +describe('icinga2::feature::elasticsearch', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }" + "class { 'icinga2': features => [], constants => { 'NodeName' => 'host.example.org' } }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - @icinga2_pki_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/certs' - @icinga2_sslkey_mode = nil - @icinga2_user = nil - @icinga2_group = nil - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + let(:icinga2_pki_dir) { 'C:/ProgramData/icinga2/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { nil } + let(:icinga2_user) { nil } + let(:icinga2_group) { nil } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { '0600' } + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { '0600' } + case facts[:os]['family'] + when 'Debian' + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } else - case facts[:os]['family'] - when 'Debian' - @icinga2_conf_dir = '/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - else - @icinga2_conf_dir = '/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - end - end + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + end end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('elasticsearch').with({ - 'ensure' => 'present', }) } - - it { is_expected.to contain_icinga2__object('icinga2::object::ElasticsearchWriter::elasticsearch') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/elasticsearch.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::elasticsearch') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/elasticsearch.conf", - 'order' => '05', }) - .with_content(/library \"perfdata\"$/) } + context 'with defaults' do + it { + is_expected.to contain_icinga2__feature('elasticsearch').with( + { 'ensure' => 'present' }, + ) + } + + it { + is_expected.to contain_icinga2__object('icinga2::object::ElasticsearchWriter::elasticsearch').with( + { 'target' => "#{icinga2_conf_dir}/features-available/elasticsearch.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::elasticsearch').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/elasticsearch.conf", + 'order' => '05', + }, + ).with_content(%r{library \"perfdata\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('elasticsearch').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('elasticsearch').with({ 'ensure' => 'absent' }) } end - context "with enable_ssl = true, ssl_key => foo, ssl_cert => bar, ssl_cacert => baz" do + context "with enable_ssl = true, ssl_key => 'foo', ssl_cert => 'bar', ssl_cacert => 'baz'" do let(:params) do { - :enable_ssl => true, - :ssl_key => 'foo', - :ssl_cert => 'bar', - :ssl_cacert => 'baz' + enable_ssl: true, + ssl_key: 'foo', + ssl_cert: 'bar', + ssl_cacert: 'baz', } end - it { is_expected.to contain_file("#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.key") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - 'mode' => @icinga2_sslkey_mode }) - .with_content(/^foo$/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.crt") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^bar$/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch_ca.crt") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^baz$/) } + it { + is_expected.to contain_file("#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.key").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + 'mode' => icinga2_sslkey_mode, + }, + ).with_content(%r{^foo$}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.crt").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^bar$}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch_ca.crt").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^baz$}) + } end - context "with enable_ssl = true, ssl_key_path, ssl_cert_path and ssl_cacert_path set" do + context 'with enable_ssl = true, ssl_key_path, ssl_cert_path and ssl_cacert_path set' do let(:params) do { - :enable_ssl => true, - :ssl_key_path => "#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.key", - :ssl_cert_path => "#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.crt", - :ssl_cacert_path => "#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch_ca.crt" + enable_ssl: true, + ssl_key_path: "#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.key", + ssl_cert_path: "#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.crt", + ssl_cacert_path: "#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch_ca.crt", } end - it { is_expected.to contain_concat__fragment('icinga2::object::ElasticsearchWriter::elasticsearch') - .with_content %r{key_path = "#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.key"} } - - it { is_expected.to contain_concat__fragment('icinga2::object::ElasticsearchWriter::elasticsearch') - .with_content %r{cert_path = "#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.crt"} } - - it { is_expected.to contain_concat__fragment('icinga2::object::ElasticsearchWriter::elasticsearch') - .with_content %r{ca_path = "#{@icinga2_pki_dir}/ElasticsearchWriter_elasticsearch_ca.crt"} } + it { + is_expected.to contain_concat__fragment('icinga2::object::ElasticsearchWriter::elasticsearch').with_content( + %r{key_path = "#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.key"}, + ) + } + + it { + is_expected.to contain_concat__fragment('icinga2::object::ElasticsearchWriter::elasticsearch').with_content( + %r{cert_path = "#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch.crt"}, + ) + } + + it { + is_expected.to contain_concat__fragment('icinga2::object::ElasticsearchWriter::elasticsearch').with_content( + %r{ca_path = "#{icinga2_pki_dir}/ElasticsearchWriter_elasticsearch_ca.crt"}, + ) + } end end - end end diff --git a/spec/classes/gelf_spec.rb b/spec/classes/gelf_spec.rb index bcbdfd4..dbcd1c4 100644 --- a/spec/classes/gelf_spec.rb +++ b/spec/classes/gelf_spec.rb @@ -1,53 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::gelf', :type => :class) do +describe('icinga2::feature::gelf', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('gelf').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::GelfWriter::gelf') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/gelf.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::gelf') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/gelf.conf", - 'order' => '05', }) - .with_content(/library \"perfdata\"$/) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('gelf').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::GelfWriter::gelf').with( + { 'target' => "#{icinga2_conf_dir}/features-available/gelf.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::gelf').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/gelf.conf", + 'order' => '05', + }, + ).with_content(%r{library \"perfdata\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('gelf').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('gelf').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/graphite_spec.rb b/spec/classes/graphite_spec.rb index eab1c7c..290c3b7 100644 --- a/spec/classes/graphite_spec.rb +++ b/spec/classes/graphite_spec.rb @@ -1,53 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::graphite', :type => :class) do +describe('icinga2::feature::graphite', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('graphite').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::GraphiteWriter::graphite') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/graphite.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::graphite') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/graphite.conf", - 'order' => '05', }) - .with_content(/library \"perfdata\"$/) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('graphite').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::GraphiteWriter::graphite').with( + { 'target' => "#{icinga2_conf_dir}/features-available/graphite.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::graphite').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/graphite.conf", + 'order' => '05', + }, + ).with_content(%r{library \"perfdata\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('graphite').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('graphite').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/icinga2_spec.rb b/spec/classes/icinga2_spec.rb index d1c7975..6c6f6b5 100644 --- a/spec/classes/icinga2_spec.rb +++ b/spec/classes/icinga2_spec.rb @@ -1,172 +1,193 @@ require 'spec_helper' -describe('icinga2', :type => :class) do - +describe('icinga2', type: :class) do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end context 'with defaults' do - it { is_expected.to contain_package('icinga2') - .with({ 'ensure' => 'installed' }) } - - it { is_expected.to contain_service('icinga2') - .with({ - 'ensure' => 'running', - 'enable' => true }) } - - it { is_expected.to contain_file("#{@icinga2_conf_dir}/features-enabled") - .with({ - 'ensure' => 'directory', - 'purge' => true, - 'recurse' => true, }) } - - it { is_expected.to contain_icinga2__feature('checker') - .with({'ensure' => 'present'}) } - it { is_expected.to contain_icinga2__feature('mainlog') - .with({'ensure' => 'present'}) } - it { is_expected.to contain_icinga2__feature('notification') - .with({'ensure' => 'present'}) } + it { is_expected.to contain_package('icinga2').with({ 'ensure' => 'installed' }) } + + it { + is_expected.to contain_service('icinga2').with( + { + 'ensure' => 'running', + 'enable' => true, + }, + ) + } + + it { + is_expected.to contain_file("#{icinga2_conf_dir}/features-enabled").with( + { + 'ensure' => 'directory', + 'purge' => true, + 'recurse' => true, + }, + ) + } + + it { is_expected.to contain_icinga2__feature('checker').with({ 'ensure' => 'present' }) } + it { is_expected.to contain_icinga2__feature('mainlog').with({ 'ensure' => 'present' }) } + it { is_expected.to contain_icinga2__feature('notification').with({ 'ensure' => 'present' }) } end - context "with manage_packages => false" do + context 'with manage_packages => false' do let(:params) do - {:manage_packages => false} + { manage_packages: false } end it { is_expected.not_to contain_package('icinga2').with({ 'ensure' => 'installed' }) } end - context "with manage_selinux => true" do - let(:params) do - {:manage_selinux => true} - end + if facts[:os]['family'] == 'RedHat' + context 'with manage_selinux => true' do + let(:params) do + { manage_selinux: true } + end - case facts[:os]['family'] - when 'RedHat' it { is_expected.to contain_package('icinga2-selinux').with({ 'ensure' => 'installed' }) } end end - context "with confd => false" do + context 'with confd => false' do let(:params) do - {:confd => false} + { confd: false } end - it { is_expected.to contain_file("#{@icinga2_conf_dir}/icinga2.conf") - .without_content %r{^include_recursive \"conf.d\"} } + it { + is_expected.to contain_file("#{icinga2_conf_dir}/icinga2.conf").without_content(%r{^include_recursive \"conf.d\"}) + } end - context "with confd => example.d" do + context "with confd => 'example.d'" do let(:params) do - {:confd => "#{@icinga2_conf_dir}/example.d"} + { confd: "#{icinga2_conf_dir}/example.d" } end case facts[:kernel] when 'windows' let(:pre_condition) do [ "file { 'C:/ProgramData/icinga2/etc/icinga2/example.d': ensure => directory, tag => 'icinga2::config::file' }", "file { 'C:/ProgramData/icinga2/etc/icinga2/example.d/foo': ensure => file, tag => 'icinga2::config::file' }", ] end - it { is_expected.to contain_file("#{@icinga2_conf_dir}/icinga2.conf") - .with_content %r{^include_recursive \"C:/ProgramData/icinga2/etc/icinga2/example.d\"} } + it { + is_expected.to contain_file("#{icinga2_conf_dir}/icinga2.conf").with_content( + %r{^include_recursive \"C:/ProgramData/icinga2/etc/icinga2/example.d\"}, + ) + } when 'FreeBSD' let(:pre_condition) do [ "file { '/usr/local/etc/icinga2/example.d': ensure => directory, tag => 'icinga2::config::file' }", "file { '/usr/local/etc/icinga2/example.d/foo': ensure => file, tag => 'icinga2::config::file' }", ] end - it { is_expected.to contain_file("#{@icinga2_conf_dir}/icinga2.conf") - .with_content %r{^include_recursive \"/usr/local/etc/icinga2/example.d\"} } + it { + is_expected.to contain_file("#{icinga2_conf_dir}/icinga2.conf").with_content( + %r{^include_recursive \"/usr/local/etc/icinga2/example.d\"}, + ) + } else let(:pre_condition) do [ "file { '/etc/icinga2/example.d': ensure => directory, tag => 'icinga2::config::file' }", "file { '/etc/icinga2/example.d/foo': ensure => file, tag => 'icinga2::config::file' }", ] end - it { is_expected.to contain_file("#{@icinga2_conf_dir}/icinga2.conf") - .with_content %r{^include_recursive \"/etc/icinga2/example.d\"} } + it { + is_expected.to contain_file("#{icinga2_conf_dir}/icinga2.conf").with_content( + %r{^include_recursive \"/etc/icinga2/example.d\"}, + ) + } end - it { is_expected.to contain_file("#{@icinga2_conf_dir}/example.d") - .with({ - 'ensure' => 'directory', - 'tag' => 'icinga2::config::file', }) } - - it { is_expected.to contain_file("#{@icinga2_conf_dir}/example.d/foo") - .with({ - 'ensure' => 'file', - 'tag' => 'icinga2::config::file', }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_file("#{icinga2_conf_dir}/example.d").with( + { + 'ensure' => 'directory', + 'tag' => 'icinga2::config::file', + }, + ) + } + + it { + is_expected.to contain_file("#{icinga2_conf_dir}/example.d/foo").with( + { + 'ensure' => 'file', + 'tag' => 'icinga2::config::file', + }, + ).that_notifies('Class[icinga2::service]') + } end - context "with constants => { foo => bar }" do + context "with constants => { foo => 'bar' }" do let(:params) do { - :constants => {'foo' => 'bar'} + constants: { foo: 'bar' } } end - it { is_expected.to contain_file("#{@icinga2_conf_dir}/constants.conf") - .with_content(/^const foo = \"bar\"/) } + it { is_expected.to contain_file("#{icinga2_conf_dir}/constants.conf").with_content(%r{^const foo = \"bar\"}) } end - context "with plugins => [ foo, bar ]" do + context "with plugins => [ 'foo', 'bar' ]" do let(:params) do { - :plugins => ['foo', 'bar'] + plugins: ['foo', 'bar'] } end - it { is_expected.to contain_file("#{@icinga2_conf_dir}/icinga2.conf") - .with_content(/^include /) - .with_content(/^include /) } + it { + is_expected.to contain_file("#{icinga2_conf_dir}/icinga2.conf").with_content( + %r{^include }, + ).with_content(%r{^include }) + } end - context "with ensure => stopped, enable => false" do + context 'with ensure => stopped, enable => false' do let(:params) do { - :ensure => 'stopped', :enable => false + ensure: 'stopped', + enable: false, } end - it { is_expected.to contain_service('icinga2') - .with({ - 'ensure' => 'stopped', - 'enable' => false, }) } + it { + is_expected.to contain_service('icinga2').with( + { + 'ensure' => 'stopped', + 'enable' => false, + }, + ) + } end - context "with manage_service => false" do + context 'with manage_service => false' do let(:params) do { - :manage_service => false + manage_service: false, } end it { is_expected.not_to contain_service('icinga2') } end end - end - end diff --git a/spec/classes/icingadb_spec.rb b/spec/classes/icingadb_spec.rb index e72eecb..db27719 100644 --- a/spec/classes/icingadb_spec.rb +++ b/spec/classes/icingadb_spec.rb @@ -1,47 +1,48 @@ require 'spec_helper' -describe('icinga2::feature::icingadb', :type => :class) do +describe('icinga2::feature::icingadb', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('icingadb').with({'ensure' => 'present'}) } + context 'with defaults' do + it { + is_expected.to contain_icinga2__feature('icingadb').with({ 'ensure' => 'present' }) + } - it { is_expected.to contain_icinga2__object('icinga2::object::IcingaDB::icingadb') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/icingadb.conf" }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_icinga2__object('icinga2::object::IcingaDB::icingadb').with( + { 'target' => "#{icinga2_conf_dir}/features-available/icingadb.conf" }, + ).that_notifies('Class[icinga2::service]') + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('icingadb').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('icingadb').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/idomysql_spec.rb b/spec/classes/idomysql_spec.rb index 85adec7..38b4dfb 100644 --- a/spec/classes/idomysql_spec.rb +++ b/spec/classes/idomysql_spec.rb @@ -1,206 +1,247 @@ require 'spec_helper' -describe('icinga2::feature::idomysql', :type => :class) do +describe('icinga2::feature::idomysql', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }" + "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }", ] end on_supported_os.each do |os, facts| - context "on #{os}" do - let(:facts) do + context "on #{os}" do + let(:facts) do case facts[:kernel] when 'windows' - facts.merge({ - :icinga2_puppet_hostcert => 'C:/ProgramData/PuppetLabs/puppet/ssl/certs/host.example.org.pem', - :icinga2_puppet_hostprivkey => 'C:/ProgramData/PuppetLabs/puppet/ssl/private_keys/host.example.org.pem', - :icinga2_puppet_localcacert => 'C:/ProgramData/PuppetLabs/var/lib/puppet/ssl/certs/ca.pem', - }) + facts.merge( + { + icinga2_puppet_hostcert: 'C:/ProgramData/PuppetLabs/puppet/ssl/certs/host.example.org.pem', + icinga2_puppet_hostprivkey: 'C:/ProgramData/PuppetLabs/puppet/ssl/private_keys/host.example.org.pem', + icinga2_puppet_localcacert: 'C:/ProgramData/PuppetLabs/var/lib/puppet/ssl/certs/ca.pem', + }, + ) else - facts.merge({ - :icinga2_puppet_hostcert => '/etc/puppetlabs/puppet/ssl/certs/host.example.org.pem', - :icinga2_puppet_hostprivkey => '/etc/puppetlabs/puppet/ssl/private_keys/host.example.org.pem', - :icinga2_puppet_localcacert => '/etc/lib/puppetlabs/puppet/ssl/certs/ca.pem', - }) + facts.merge( + { + icinga2_puppet_hostcert: '/etc/puppetlabs/puppet/ssl/certs/host.example.org.pem', + icinga2_puppet_hostprivkey: '/etc/puppetlabs/puppet/ssl/private_keys/host.example.org.pem', + icinga2_puppet_localcacert: '/etc/lib/puppetlabs/puppet/ssl/certs/ca.pem', + }, + ) end end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - @icinga2_pki_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/certs' - @ido_mysql_schema_dir = 'C:/Program Files/icinga2/usr/share/icinga2-ido-mysql/schema' - @icinga2_sslkey_mode = nil - @icinga2_user = nil - @icinga2_group = nil - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @ido_mysql_schema_dir = '/usr/local/share/icinga2-ido-mysql/schema' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + let(:icinga2_pki_dir) { 'C:/ProgramData/icinga2/var/lib/icinga2/certs' } + let(:ido_mysql_schema_dir) { 'C:/Program Files/icinga2/usr/share/icinga2-ido-mysql/schema' } + let(:icinga2_sslkey_mode) { nil } + let(:icinga2_user) { nil } + let(:icinga2_group) { nil } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:ido_mysql_schema_dir) { '/usr/local/share/icinga2-ido-mysql/schema' } + let(:icinga2_sslkey_mode) { '0600' } + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:ido_mysql_schema_dir) { '/usr/share/icinga2-ido-mysql/schema' } + let(:icinga2_sslkey_mode) { '0600' } + case facts[:os]['family'] + when 'Debian' + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } else - @icinga2_conf_dir = '/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @ido_mysql_schema_dir = '/usr/share/icinga2-ido-mysql/schema' - @icinga2_sslkey_mode = '0600' - case facts[:os]['family'] - when 'Debian' - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - else - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - end + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } end end - context "with defaults" do + context 'with defaults' do let(:params) do { - :password => 'foo' + password: 'foo', } end if facts[:kernel] == 'Linux' it { is_expected.to contain_package('icinga2-ido-mysql').with({ 'ensure' => 'installed' }) } end if facts[:os]['family'] == 'Debian' - it { is_expected.to contain_file('/etc/dbconfig-common/icinga2-ido-mysql.conf') - .with({ - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'root', }) + it { + is_expected.to contain_file('/etc/dbconfig-common/icinga2-ido-mysql.conf').with( + { + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + }, + ) } end - it { is_expected.to contain_icinga2__feature('ido-mysql').with({'ensure' => 'present'}) } + it { is_expected.to contain_icinga2__feature('ido-mysql').with({ 'ensure' => 'present' }) } - it { is_expected.to contain_icinga2__object('icinga2::object::IdoMysqlConnection::ido-mysql') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/ido-mysql.conf" }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_icinga2__object('icinga2::object::IdoMysqlConnection::ido-mysql').with( + { 'target' => "#{icinga2_conf_dir}/features-available/ido-mysql.conf" }, + ).that_notifies('Class[icinga2::service]') + } - it { is_expected.to contain_concat__fragment('icinga2::feature::ido-mysql') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/ido-mysql.conf", - 'order' => '05', }) - .with_content(/library \"db_ido_mysql\"$/) } + it { + is_expected.to contain_concat__fragment('icinga2::feature::ido-mysql').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/ido-mysql.conf", + 'order' => '05', + }, + ).with_content(%r{library \"db_ido_mysql\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent', - :password => 'foo' + ensure: 'absent', + password: 'foo', } end - it { is_expected.to contain_icinga2__feature('ido-mysql').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('ido-mysql').with({ 'ensure' => 'absent' }) } end - context "with import_schema => true" do + context 'with import_schema => true' do let(:params) do { - :import_schema => true, - :password => 'foo' + import_schema: true, + password: 'foo', } end - it { is_expected.to contain_exec('idomysql-import-schema') - .with({ - 'user' => 'root', - 'command' => "mysql -u icinga -p'foo' icinga < \"#{@ido_mysql_schema_dir}/mysql.sql\"", }) } + it { + is_expected.to contain_exec('idomysql-import-schema').with( + { + user: 'root', + command: "mysql -u icinga -p'foo' icinga < \"#{ido_mysql_schema_dir}/mysql.sql\"", + }, + ) + } end if facts[:kernel] == 'Linux' - context "with icinga2::manage_packages => false" do + context 'with icinga2::manage_packages => false' do let(:params) do { - :password => 'foo' + password: 'foo', } end let(:pre_condition) do [ - "class { 'icinga2': features => [], manage_packages => false }" + "class { 'icinga2': features => [], manage_packages => false }", ] end it { is_expected.not_to contain_package('icinga2').with({ 'ensure' => 'installed' }) } it { is_expected.not_to contain_package('icinga2-ido-mysql').with({ 'ensure' => 'installed' }) } end end - context "with enable_ssl => true, host => 127.0.0.1, port => 3306, import_schema => true, ssl_key => foo, ssl_cert => bar, ssl_cacert => baz" do + context "with enable_ssl => true, host => '127.0.0.1', port => 3306, import_schema => true, ssl_key => 'foo', ssl_cert => 'bar', ssl_cacert => 'baz'" do let(:params) do { - :enable_ssl => true, - :ssl_key => 'foo', - :ssl_cert => 'bar', - :ssl_cacert => 'baz', - :host => '127.0.0.1', - :port => 3306, - :import_schema => true, - :password => 'foo' + enable_ssl: true, + ssl_key: 'foo', + ssl_cert: 'bar', + ssl_cacert: 'baz', + host: '127.0.0.1', + port: 3306, + import_schema: true, + password: 'foo', } end - it { is_expected.to contain_file("#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key") - .with({ - 'mode' => @icinga2_sslkey_mode, - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^foo/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^bar$/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^baz$/) } - - it { is_expected.to contain_exec('idomysql-import-schema') - .with({ - 'user' => 'root', - 'command' => "mysql -h 127.0.0.1 -P 3306 -u icinga -p'foo' --ssl-ca #{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt --ssl-cert #{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt --ssl-key #{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key icinga < \"#{@ido_mysql_schema_dir}/mysql.sql\"", }) } + it { + is_expected.to contain_file("#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key").with( + { + 'mode' => icinga2_sslkey_mode, + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^foo}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^bar$}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^baz$}) + } + + it { + is_expected.to contain_exec('idomysql-import-schema').with( + { + 'user' => 'root', + 'command' => "mysql -h 127.0.0.1 -P 3306 -u icinga -p'foo' --ssl-ca #{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt" \ + " --ssl-cert #{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt --ssl-key #{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key icinga < \"#{ido_mysql_schema_dir}/mysql.sql\"", + }, + ) + } end - context "with enable_ssl => true, import_schema => true, ssl_key_path, ssl_cert_path and ssl_cacert_path set" do + context 'with enable_ssl => true, import_schema => true, ssl_key_path, ssl_cert_path and ssl_cacert_path set' do let(:params) do { - :enable_ssl => true, - :ssl_key_path => "#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key", - :ssl_cert_path => "#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt", - :ssl_cacert_path => "#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt", - :import_schema => true, - :password => 'foo' + enable_ssl: true, + ssl_key_path: "#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key", + ssl_cert_path: "#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt", + ssl_cacert_path: "#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt", + import_schema: true, + password: 'foo', } end - it { is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql') - .with_content %r{ssl_key = "#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key"} } - - it { is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql') - .with_content %r{ssl_cert = "#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt"} } - - it { is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql') - .with_content %r{ssl_ca = "#{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt"} } - - it { is_expected.to contain_exec('idomysql-import-schema') - .with({ - 'user' => 'root', - 'command' => "mysql -u icinga -p'foo' --ssl-ca #{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt --ssl-cert #{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt --ssl-key #{@icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key icinga < \"#{@ido_mysql_schema_dir}/mysql.sql\"", }) } + it { + is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql').with_content( + %r{ssl_key = "#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key"}, + ) + } + + it { + is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql').with_content( + %r{ssl_cert = "#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt"}, + ) + } + + it { + is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql').with_content( + %r{ssl_ca = "#{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt"}, + ) + } + + it { + is_expected.to contain_exec('idomysql-import-schema').with( + { + 'user' => 'root', + 'command' => "mysql -u icinga -p'foo' --ssl-ca #{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql_ca.crt" \ + " --ssl-cert #{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.crt --ssl-key #{icinga2_pki_dir}/IdoMysqlConnection_ido-mysql.key icinga < \"#{ido_mysql_schema_dir}/mysql.sql\"", + }, + ) + } end end - end end diff --git a/spec/classes/idopgsql_spec.rb b/spec/classes/idopgsql_spec.rb index 7b809c8..eb8b34b 100644 --- a/spec/classes/idopgsql_spec.rb +++ b/spec/classes/idopgsql_spec.rb @@ -1,121 +1,128 @@ require 'spec_helper' -describe('icinga2::feature::idopgsql', :type => :class) do +describe('icinga2::feature::idopgsql', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - @icinga2_pki_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/certs' - @ido_pgsql_schema_dir = 'C:/Program Files/icinga2/usr/share/icinga2-ido-pgsql/schema' - @icinga2_sslkey_mode = nil - @icinga2_user = nil - @icinga2_group = nil - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @ido_pgsql_schema_dir = '/usr/local/share/icinga2-ido-pgsql/schema' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + let(:icinga2_pki_dir) { 'C:/ProgramData/icinga2/var/lib/icinga2/certs' } + let(:ido_pgsql_schema_dir) { 'C:/Program Files/icinga2/usr/share/icinga2-ido-pgsql/schema' } + let(:icinga2_sslkey_mode) { nil } + let(:icinga2_user) { nil } + let(:icinga2_group) { nil } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:ido_pgsql_schema_dir) { '/usr/local/share/icinga2-ido-pgsql/schema' } + let(:icinga2_sslkey_mode) { '0600' } + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:ido_pgsql_schema_dir) { '/usr/share/icinga2-ido-pgsql/schema' } + let(:icinga2_sslkey_mode) { '0600' } + case facts[:os]['family'] + when 'Debian' + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } else - @icinga2_conf_dir = '/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @ido_pgsql_schema_dir = '/usr/share/icinga2-ido-pgsql/schema' - @icinga2_sslkey_mode = '0600' - case facts[:os]['family'] - when 'Debian' - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - else - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - end + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } end end - context "with defaults" do + context 'with defaults' do let(:params) do { - :password => 'foo' + password: 'foo', } end if facts[:kernel] == 'Linux' it { is_expected.to contain_package('icinga2-ido-pgsql').with({ 'ensure' => 'installed' }) } end if facts[:os]['family'] == 'Debian' - it { is_expected.to contain_file('/etc/dbconfig-common/icinga2-ido-pgsql.conf') - .with({ - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'root', }) + it { + is_expected.to contain_file('/etc/dbconfig-common/icinga2-ido-pgsql.conf').with( + { + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + }, + ) } end - it { is_expected.to contain_icinga2__feature('ido-pgsql').with({'ensure' => 'present'}) } + it { is_expected.to contain_icinga2__feature('ido-pgsql').with({ 'ensure' => 'present' }) } - it { is_expected.to contain_concat__fragment('icinga2::object::IdoPgsqlConnection::ido-pgsql') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/ido-pgsql.conf" }) } + it { + is_expected.to contain_concat__fragment('icinga2::object::IdoPgsqlConnection::ido-pgsql').with( + { 'target' => "#{icinga2_conf_dir}/features-available/ido-pgsql.conf" }, + ) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent', - :password => 'foo' + ensure: 'absent', + password: 'foo', } end - it { is_expected.to contain_icinga2__feature('ido-pgsql').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('ido-pgsql').with({ 'ensure' => 'absent' }) } end - context "with import_schema => true" do + context 'with import_schema => true' do let(:params) do { - :import_schema => true, - :password => 'foo' + import_schema: true, + password: 'foo', } end - it { is_expected.to contain_exec('idopgsql-import-schema') - .with({ - 'user' => 'root', - 'environment' => ["PGPASSWORD=foo"], - 'command' => "psql -h 'localhost' -U 'icinga' -p '5432' -d 'icinga' -w -f \"#{@ido_pgsql_schema_dir}/pgsql.sql\"" }) } + it { + is_expected.to contain_exec('idopgsql-import-schema').with( + { + 'user' => 'root', + 'environment' => ['PGPASSWORD=foo'], + 'command' => "psql -h 'localhost' -U 'icinga' -p '5432' -d 'icinga' -w -f \"#{ido_pgsql_schema_dir}/pgsql.sql\"", + }, + ) + } end if facts[:kernel] == 'Linux' - context "with manage_packages => false" do + context 'with manage_packages => false' do let(:params) do { - :password => 'foo' + password: 'foo', } end let(:pre_condition) do [ - "class { 'icinga2': features => [], manage_packages => false }" + "class { 'icinga2': features => [], manage_packages => false }", ] end it { is_expected.not_to contain_package('icinga2').with({ 'ensure' => 'installed' }) } it { is_expected.not_to contain_package('icinga2-ido-pgsql').with({ 'ensure' => 'installed' }) } end end end - end end diff --git a/spec/classes/influxdb_spec.rb b/spec/classes/influxdb_spec.rb index 8bca738..1ba8379 100644 --- a/spec/classes/influxdb_spec.rb +++ b/spec/classes/influxdb_spec.rb @@ -1,121 +1,135 @@ require 'spec_helper' -describe('icinga2::feature::influxdb', :type => :class) do +describe('icinga2::feature::influxdb', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }" + "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - @icinga2_pki_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/certs' - @icinga2_sslkey_mode = nil - @icinga2_user = nil - @icinga2_group = nil - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + let(:icinga2_pki_dir) { 'C:/ProgramData/icinga2/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { nil } + let(:icinga2_user) { nil } + let(:icinga2_group) { nil } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { '0600' } + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_sslkey_mode) { '0600' } + case facts[:os]['family'] + when 'Debian' + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } else - @icinga2_conf_dir = '/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_sslkey_mode = '0600' - case facts[:os]['family'] - when 'Debian' - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - else - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - end + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } end end - context "with all defaults" do - it { is_expected.to contain_icinga2__feature('influxdb').with({'ensure' => 'present'}) } - - it { is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/influxdb.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::influxdb') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/influxdb.conf", - 'order' => '05', }) - .with_content(/library \"perfdata\"$/) } + context 'with all defaults' do + it { is_expected.to contain_icinga2__feature('influxdb').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb').with( + { 'target' => "#{icinga2_conf_dir}/features-available/influxdb.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::influxdb').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/influxdb.conf", + 'order' => '05', + }, + ).with_content(%r{library \"perfdata\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('influxdb').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('influxdb').with({ 'ensure' => 'absent' }) } end - context "with enable_ssl = true, ssl_key => foo, ssl_cert => bar, ssl_cacert => baz" do + context "with enable_ssl = true, ssl_key => 'foo', ssl_cert => 'bar', ssl_cacert => 'baz'" do let(:params) do { - :enable_ssl => true, - :ssl_key => 'foo', - :ssl_cert => 'bar', - :ssl_cacert => 'baz' + enable_ssl: true, + ssl_key: 'foo', + ssl_cert: 'bar', + ssl_cacert: 'baz', } end - it { is_expected.to contain_file("#{@icinga2_pki_dir}/InfluxdbWriter_influxdb.key") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - 'mode' => @icinga2_sslkey_mode, }) - .with_content(/^foo$/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/InfluxdbWriter_influxdb.crt") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^bar$/) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/InfluxdbWriter_influxdb_ca.crt") - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .with_content(/^baz$/) } + it { + is_expected.to contain_file("#{icinga2_pki_dir}/InfluxdbWriter_influxdb.key").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + 'mode' => icinga2_sslkey_mode, + }, + ).with_content(%r{^foo$}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/InfluxdbWriter_influxdb.crt").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^bar$}) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/InfluxdbWriter_influxdb_ca.crt").with( + { + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).with_content(%r{^baz$}) + } end - context "with enable_ssl = true, ssl_key_path, ssl_cert_path and ssl_cacert_path set" do + context 'with enable_ssl = true, ssl_key_path, ssl_cert_path and ssl_cacert_path set' do let(:params) do { - :enable_ssl => true, - :ssl_key_path => "#{@icinga2_pki_dir}/InfluxdbWriter_influxdb.key", - :ssl_cert_path => "#{@icinga2_pki_dir}/InfluxdbWriter_influxdb.crt", - :ssl_cacert_path => "#{@icinga2_pki_dir}/InfluxdbWriter_influxdb_ca.crt" + enable_ssl: true, + ssl_key_path: "#{icinga2_pki_dir}/InfluxdbWriter_influxdb.key", + ssl_cert_path: "#{icinga2_pki_dir}/InfluxdbWriter_influxdb.crt", + ssl_cacert_path: "#{icinga2_pki_dir}/InfluxdbWriter_influxdb_ca.crt", } end - it { is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb') - .with_content %r{ssl_key = "#{@icinga2_pki_dir}/InfluxdbWriter_influxdb.key"} } + it { + is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb').with_content(%r{ssl_key = "#{icinga2_pki_dir}/InfluxdbWriter_influxdb.key"}) + } - it { is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb') - .with_content %r{ssl_cert = "#{@icinga2_pki_dir}/InfluxdbWriter_influxdb.crt"} } + it { + is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb').with_content(%r{ssl_cert = "#{icinga2_pki_dir}/InfluxdbWriter_influxdb.crt"}) + } - it { is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb') - .with_content %r{ssl_ca_cert = "#{@icinga2_pki_dir}/InfluxdbWriter_influxdb_ca.crt"} } + it { + is_expected.to contain_concat__fragment('icinga2::object::InfluxdbWriter::influxdb').with_content(%r{ssl_ca_cert = "#{icinga2_pki_dir}/InfluxdbWriter_influxdb_ca.crt"}) + } end end - end end diff --git a/spec/classes/livestatus_spec.rb b/spec/classes/livestatus_spec.rb index deec6d0..7186123 100644 --- a/spec/classes/livestatus_spec.rb +++ b/spec/classes/livestatus_spec.rb @@ -1,53 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::livestatus', :type => :class) do +describe('icinga2::feature::livestatus', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with all defaults" do - it { is_expected.to contain_icinga2__feature('livestatus').with({'ensure' => 'present'}) } - - it { is_expected.to contain_concat__fragment('icinga2::object::LivestatusListener::livestatus') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/livestatus.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::livestatus') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/livestatus.conf", - 'order' => '05', }) - .with_content(/library \"livestatus\"$/) } + context 'with all defaults' do + it { is_expected.to contain_icinga2__feature('livestatus').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_concat__fragment('icinga2::object::LivestatusListener::livestatus').with( + { 'target' => "#{icinga2_conf_dir}/features-available/livestatus.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::livestatus').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/livestatus.conf", + 'order' => '05', + }, + ).with_content(%r{library \"livestatus\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('livestatus').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('livestatus').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/mainlog_spec.rb b/spec/classes/mainlog_spec.rb index e8d3e83..635c80f 100644 --- a/spec/classes/mainlog_spec.rb +++ b/spec/classes/mainlog_spec.rb @@ -1,66 +1,67 @@ require 'spec_helper' -describe('icinga2::feature::mainlog', :type => :class) do +describe('icinga2::feature::mainlog', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do + context 'with defaults' do let(:params) do { - :ensure => 'present' + ensure: 'present', } end - it { is_expected.to contain_icinga2__feature('mainlog').with({'ensure' => 'present'}) } + it { is_expected.to contain_icinga2__feature('mainlog').with({ 'ensure' => 'present' }) } - it { is_expected.to contain_icinga2__object('icinga2::object::FileLogger::mainlog') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/mainlog.conf" }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_icinga2__object('icinga2::object::FileLogger::mainlog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/mainlog.conf" }, + ).that_notifies('Class[icinga2::service]') + } case facts[:os]['family'] when 'windows' - it { is_expected.to contain_concat__fragment('icinga2::object::FileLogger::mainlog') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/mainlog.conf", }) - .with_content(/path = \"C:\/ProgramData\/icinga2\/var\/log\/icinga2\/icinga2.log\"/) } + it { + is_expected.to contain_concat__fragment('icinga2::object::FileLogger::mainlog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/mainlog.conf" }, + ).with_content(%r{path = \"C:\/ProgramData\/icinga2\/var\/log\/icinga2\/icinga2.log\"}) + } else - it { is_expected.to contain_concat__fragment('icinga2::object::FileLogger::mainlog') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/mainlog.conf", }) - .with_content(/path = \"\/var\/log\/icinga2\/icinga2.log\"/) } + it { + is_expected.to contain_concat__fragment('icinga2::object::FileLogger::mainlog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/mainlog.conf" }, + ).with_content(%r{path = \"\/var\/log\/icinga2\/icinga2.log\"}) + } end end context "#{os} with ensure => absent" do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('mainlog').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('mainlog').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/notification_spec.rb b/spec/classes/notification_spec.rb index 7fd6080..d2b1b92 100644 --- a/spec/classes/notification_spec.rb +++ b/spec/classes/notification_spec.rb @@ -1,47 +1,46 @@ require 'spec_helper' -describe('icinga2::feature::notification', :type => :class) do +describe('icinga2::feature::notification', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('notification').with({'ensure' => 'present'}) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('notification').with({ 'ensure' => 'present' }) } - it { is_expected.to contain_icinga2__object('icinga2::object::NotificationComponent::notification') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/notification.conf" }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_icinga2__object('icinga2::object::NotificationComponent::notification').with( + { 'target' => "#{icinga2_conf_dir}/features-available/notification.conf" }, + ).that_notifies('Class[icinga2::service]') + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('notification').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('notification').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/opentsdb_spec.rb b/spec/classes/opentsdb_spec.rb index b394e74..c871fac 100644 --- a/spec/classes/opentsdb_spec.rb +++ b/spec/classes/opentsdb_spec.rb @@ -1,53 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::opentsdb', :type => :class) do +describe('icinga2::feature::opentsdb', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('opentsdb').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::OpenTsdbWriter::opentsdb') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/opentsdb.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::opentsdb') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/opentsdb.conf", - 'order' => '05', }) - .with_content(/library \"perfdata\"$/) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('opentsdb').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::OpenTsdbWriter::opentsdb').with( + { 'target' => "#{icinga2_conf_dir}/features-available/opentsdb.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::opentsdb').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/opentsdb.conf", + 'order' => '05', + }, + ).with_content(%r{library \"perfdata\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('opentsdb').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('opentsdb').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/perfdata_spec.rb b/spec/classes/perfdata_spec.rb index ffab392..4599a95 100644 --- a/spec/classes/perfdata_spec.rb +++ b/spec/classes/perfdata_spec.rb @@ -1,53 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::perfdata', :type => :class) do +describe('icinga2::feature::perfdata', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('perfdata').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::PerfdataWriter::perfdata') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/perfdata.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::perfdata') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/perfdata.conf", - 'order' => '05', }) - .with_content(/library \"perfdata\"$/) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('perfdata').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::PerfdataWriter::perfdata').with( + { 'target' => "#{icinga2_conf_dir}/features-available/perfdata.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::perfdata').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/perfdata.conf", + 'order' => '05', + }, + ).with_content(%r{library \"perfdata\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('perfdata').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('perfdata').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/pki_ca_spec.rb b/spec/classes/pki_ca_spec.rb index b78a1d1..b24155d 100644 --- a/spec/classes/pki_ca_spec.rb +++ b/spec/classes/pki_ca_spec.rb @@ -1,171 +1,199 @@ require 'spec_helper' -describe('icinga2::pki::ca', :type => :class) do +describe('icinga2::pki::ca', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }" + "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do case facts[:kernel] when 'windows' - facts.merge({ - :icinga2_puppet_hostcert => 'C:/ProgramData/PuppetLabs/puppet/ssl/certs/host.example.org.pem', - :icinga2_puppet_hostprivkey => 'C:/ProgramData/PuppetLabs/puppet/ssl/private_keys/host.example.org.pem', - :icinga2_puppet_localcacert => 'C:/ProgramData/PuppetLabs/var/lib/puppet/ssl/certs/ca.pem', - }) + facts.merge( + { + icinga2_puppet_hostcert: 'C:/ProgramData/PuppetLabs/puppet/ssl/certs/host.example.org.pem', + icinga2_puppet_hostprivkey: 'C:/ProgramData/PuppetLabs/puppet/ssl/private_keys/host.example.org.pem', + icinga2_puppet_localcacert: 'C:/ProgramData/PuppetLabs/var/lib/puppet/ssl/certs/ca.pem', + }, + ) else - facts.merge({ - :icinga2_puppet_hostcert => '/etc/puppetlabs/puppet/ssl/certs/host.example.org.pem', - :icinga2_puppet_hostprivkey => '/etc/puppetlabs/puppet/ssl/private_keys/host.example.org.pem', - :icinga2_puppet_localcacert => '/etc/lib/puppetlabs/puppet/ssl/certs/ca.pem', - }) + facts.merge( + { + icinga2_puppet_hostcert: '/etc/puppetlabs/puppet/ssl/certs/host.example.org.pem', + icinga2_puppet_hostprivkey: '/etc/puppetlabs/puppet/ssl/private_keys/host.example.org.pem', + icinga2_puppet_localcacert: '/etc/lib/puppetlabs/puppet/ssl/certs/ca.pem', + }, + ) end end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_bin = 'C:/Program Files/icinga2/sbin/icinga2.exe' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - @icinga2_pki_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/certs' - @icinga2_ca_dir = 'C:/ProgramData/icinga2/var/lib/icinga2/ca' - @icinga2_sslkey_mode = nil - @icinga2_user = nil - @icinga2_group = nil - when 'FreeBSD' - @icinga2_bin = '/usr/local/sbin/icinga2' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_ca_dir = '/var/lib/icinga2/ca' - @icinga2_sslkey_mode = '0600' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' + case facts[:kernel] + when 'windows' + let(:icinga2_bin) { 'C:/Program Files/icinga2/sbin/icinga2.exe' } + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + let(:icinga2_pki_dir) { 'C:/ProgramData/icinga2/var/lib/icinga2/certs' } + let(:icinga2_ca_dir) { 'C:/ProgramData/icinga2/var/lib/icinga2/ca' } + let(:icinga2_sslkey_mode) { nil } + let(:icinga2_user) { nil } + let(:icinga2_group) { nil } + when 'FreeBSD' + let(:icinga2_bin) { '/usr/local/sbin/icinga2' } + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_ca_dir) { '/var/lib/icinga2/ca' } + let(:icinga2_sslkey_mode) { '0600' } + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } + let(:icinga2_pki_dir) { '/var/lib/icinga2/certs' } + let(:icinga2_ca_dir) { '/var/lib/icinga2/ca' } + let(:icinga2_sslkey_mode) { '0600' } + case facts[:os]['family'] + when 'Debian' + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } + let(:icinga2_bin) { '/usr/sbin/icinga2' } else - @icinga2_conf_dir = '/etc/icinga2' - @icinga2_pki_dir = '/var/lib/icinga2/certs' - @icinga2_ca_dir = '/var/lib/icinga2/ca' - @icinga2_sslkey_mode = '0600' - case facts[:os]['family'] - when 'Debian' - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - @icinga2_bin = '/usr/sbin/icinga2' + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + if facts[:os]['family'] != 'RedHat' + let(:icinga2_bin) { '/usr/sbin/icinga2' } else - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - if facts[:os]['family'] != 'RedHat' - @icinga2_bin = '/usr/sbin/icinga2' + case facts[:os]['release']['major'] + when '5' + let(:icinga2_bin) { '/usr/sbin/icinga2' } + when '6' + let(:icinga2_bin) { '/usr/sbin/icinga2' } else - case facts[:os]['release']['major'] - when '5' - @icinga2_bin = '/usr/sbin/icinga2' - when '6' - @icinga2_bin = '/usr/sbin/icinga2' - else - @icinga2_bin = '/sbin/icinga2' - end + let(:icinga2_bin) { '/sbin/icinga2' } end end end end - context "with defaults" do - it { is_expected.to contain_exec('create-icinga2-ca') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki new-ca", - 'creates' => "#{@icinga2_ca_dir}/ca.crt", }) - .that_notifies('Class[icinga2::service]') - .that_comes_before("File[#{@icinga2_pki_dir}/ca.crt]") } - - it { is_expected.to contain_exec('icinga2 pki create certificate signing request') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki new-cert --cn host.example.org --key #{@icinga2_pki_dir}/host.example.org.key --csr #{@icinga2_pki_dir}/host.example.org.csr", - 'creates' => "#{@icinga2_pki_dir}/host.example.org.key", }) - .that_requires("File[#{@icinga2_pki_dir}/ca.crt]") } - - it { is_expected.to contain_exec('icinga2 pki sign certificate') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki sign-csr --csr #{@icinga2_pki_dir}/host.example.org.csr --cert #{@icinga2_pki_dir}/host.example.org.crt", - 'refreshonly' => true, }) - .that_notifies('Class[icinga2::service]') - .that_subscribes_to('Exec[icinga2 pki create certificate signing request]') } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/ca.crt") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/host.example.org.key") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - 'mode' => @icinga2_sslkey_mode, - 'show_diff' => false, - 'backup' => false, }) - .that_requires('Exec[icinga2 pki create certificate signing request]') } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/host.example.org.crt") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, }) - .that_requires('Exec[icinga2 pki sign certificate]') } - - it { is_expected.to contain_file("#{@icinga2_pki_dir}/host.example.org.csr") - .with({ - 'ensure' => 'absent', }) - .that_requires('Exec[icinga2 pki sign certificate]') } + context 'with defaults' do + it { + is_expected.to contain_exec('create-icinga2-ca').with( + { + 'command' => "\"#{icinga2_bin}\" pki new-ca", + 'creates' => "#{icinga2_ca_dir}/ca.crt", + }, + ).that_notifies('Class[icinga2::service]').that_comes_before("File[#{icinga2_pki_dir}/ca.crt]") + } + + it { + is_expected.to contain_exec('icinga2 pki create certificate signing request').with( + { + 'command' => "\"#{icinga2_bin}\" pki new-cert --cn host.example.org --key #{icinga2_pki_dir}/host.example.org.key --csr #{icinga2_pki_dir}/host.example.org.csr", + 'creates' => "#{icinga2_pki_dir}/host.example.org.key", + }, + ).that_requires("File[#{icinga2_pki_dir}/ca.crt]") + } + + it { + is_expected.to contain_exec('icinga2 pki sign certificate').with( + { + 'command' => "\"#{icinga2_bin}\" pki sign-csr --csr #{icinga2_pki_dir}/host.example.org.csr --cert #{icinga2_pki_dir}/host.example.org.crt", + 'refreshonly' => true, + }, + ).that_notifies('Class[icinga2::service]').that_subscribes_to('Exec[icinga2 pki create certificate signing request]') + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/ca.crt").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ) + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/host.example.org.key").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + 'mode' => icinga2_sslkey_mode, + 'show_diff' => false, + 'backup' => false, + }, + ).that_requires('Exec[icinga2 pki create certificate signing request]') + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/host.example.org.crt").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).that_requires('Exec[icinga2 pki sign certificate]') + } + + it { + is_expected.to contain_file("#{icinga2_pki_dir}/host.example.org.csr").with( + { 'ensure' => 'absent' }, + ).that_requires('Exec[icinga2 pki sign certificate]') + } end - context "with ca_cert => 'foo', ca_key => 'bar'" do let(:params) do { - :ca_cert => 'foo', - :ca_key => 'bar' + ca_cert: 'foo', + ca_key: 'bar' } end - it { is_expected.to contain_exec('icinga2 pki create certificate signing request') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki new-cert --cn host.example.org --key #{@icinga2_pki_dir}/host.example.org.key --csr #{@icinga2_pki_dir}/host.example.org.csr", - 'creates' => "#{@icinga2_pki_dir}/host.example.org.key", }) - .that_requires("File[#{@icinga2_pki_dir}/ca.crt]") } - - it { is_expected.to contain_exec('icinga2 pki sign certificate') - .with({ - 'command' => "\"#{@icinga2_bin}\" pki sign-csr --csr #{@icinga2_pki_dir}/host.example.org.csr --cert #{@icinga2_pki_dir}/host.example.org.crt", - 'refreshonly' => true, }) - .that_notifies('Class[icinga2::service]') - .that_subscribes_to('Exec[icinga2 pki create certificate signing request]') } - - it { is_expected.to contain_file("#{@icinga2_ca_dir}/ca.crt") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - 'tag' => 'icinga2::config::file', }) - .with_content(/^foo$/) - .that_comes_before("File[#{@icinga2_pki_dir}/ca.crt]") } - - it { is_expected.to contain_file("#{@icinga2_ca_dir}/ca.key") - .with({ - 'ensure' => 'file', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - 'mode' => @icinga2_sslkey_mode, - 'tag' => 'icinga2::config::file', - 'show_diff' => false, - 'backup' => false, }) - .with_content(/bar/) } + it { + is_expected.to contain_exec('icinga2 pki create certificate signing request').with( + { + 'command' => "\"#{icinga2_bin}\" pki new-cert --cn host.example.org --key #{icinga2_pki_dir}/host.example.org.key --csr #{icinga2_pki_dir}/host.example.org.csr", + 'creates' => "#{icinga2_pki_dir}/host.example.org.key", + }, + ).that_requires("File[#{icinga2_pki_dir}/ca.crt]") + } + + it { + is_expected.to contain_exec('icinga2 pki sign certificate').with( + { + 'command' => "\"#{icinga2_bin}\" pki sign-csr --csr #{icinga2_pki_dir}/host.example.org.csr --cert #{icinga2_pki_dir}/host.example.org.crt", + 'refreshonly' => true, + }, + ).that_notifies('Class[icinga2::service]').that_subscribes_to('Exec[icinga2 pki create certificate signing request]') + } + + it { + is_expected.to contain_file("#{icinga2_ca_dir}/ca.crt").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + 'tag' => 'icinga2::config::file', + }, + ).with_content(%r{^foo$}).that_comes_before("File[#{icinga2_pki_dir}/ca.crt]") + } + + it { + is_expected.to contain_file("#{icinga2_ca_dir}/ca.key").with( + { + 'ensure' => 'file', + 'owner' => icinga2_user, + 'group' => icinga2_group, + 'mode' => icinga2_sslkey_mode, + 'tag' => 'icinga2::config::file', + 'show_diff' => false, + 'backup' => false, + }, + ).with_content(%r{bar}) + } end end - end end diff --git a/spec/classes/statusdata_spec.rb b/spec/classes/statusdata_spec.rb index 87f8777..0283faf 100644 --- a/spec/classes/statusdata_spec.rb +++ b/spec/classes/statusdata_spec.rb @@ -1,53 +1,55 @@ require 'spec_helper' -describe('icinga2::feature::statusdata', :type => :class) do +describe('icinga2::feature::statusdata', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('statusdata').with({'ensure' => 'present'}) } - - it { is_expected.to contain_icinga2__object('icinga2::object::StatusDataWriter::statusdata') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/statusdata.conf" }) - .that_notifies('Class[icinga2::service]') } - - it { is_expected.to contain_concat__fragment('icinga2::feature::statusdata') - .with({ - 'target' => "#{@icinga2_conf_dir}/features-available/statusdata.conf", - 'order' => '05', }) - .with_content(/library \"compat\"$/) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('statusdata').with({ 'ensure' => 'present' }) } + + it { + is_expected.to contain_icinga2__object('icinga2::object::StatusDataWriter::statusdata').with( + { 'target' => "#{icinga2_conf_dir}/features-available/statusdata.conf" }, + ).that_notifies('Class[icinga2::service]') + } + + it { + is_expected.to contain_concat__fragment('icinga2::feature::statusdata').with( + { + 'target' => "#{icinga2_conf_dir}/features-available/statusdata.conf", + 'order' => '05', + }, + ).with_content(%r{library \"compat\"$}) + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('statusdata').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('statusdata').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/classes/syslog_spec.rb b/spec/classes/syslog_spec.rb index c1e95f1..f4a6b26 100644 --- a/spec/classes/syslog_spec.rb +++ b/spec/classes/syslog_spec.rb @@ -1,47 +1,46 @@ require 'spec_helper' -describe('icinga2::feature::syslog', :type => :class) do +describe('icinga2::feature::syslog', type: :class) do let(:pre_condition) do [ - "class { 'icinga2': features => [], }" + "class { 'icinga2': features => [] }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - before(:each) do - case facts[:kernel] - when 'windows' - @icinga2_conf_dir = 'C:/ProgramData/icinga2/etc/icinga2' - when 'FreeBSD' - @icinga2_conf_dir = '/usr/local/etc/icinga2' - else - @icinga2_conf_dir = '/etc/icinga2' - end + case facts[:kernel] + when 'windows' + let(:icinga2_conf_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + when 'FreeBSD' + let(:icinga2_conf_dir) { '/usr/local/etc/icinga2' } + else + let(:icinga2_conf_dir) { '/etc/icinga2' } end - context "with defaults" do - it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) } + context 'with defaults' do + it { is_expected.to contain_icinga2__feature('syslog').with({ 'ensure' => 'present' }) } - it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog') - .with({ 'target' => "#{@icinga2_conf_dir}/features-available/syslog.conf" }) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog').with( + { 'target' => "#{icinga2_conf_dir}/features-available/syslog.conf" }, + ).that_notifies('Class[icinga2::service]') + } end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent' + ensure: 'absent', } end - it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'absent'}) } + it { is_expected.to contain_icinga2__feature('syslog').with({ 'ensure' => 'absent' }) } end end - end end diff --git a/spec/defines/feature_spec.rb b/spec/defines/feature_spec.rb index c5aa9dc..3029cac 100644 --- a/spec/defines/feature_spec.rb +++ b/spec/defines/feature_spec.rb @@ -1,111 +1,103 @@ require 'spec_helper' -describe('icinga2::feature', :type => :define) do - let(:title) do - 'bar' - end +describe('icinga2::feature', type: :define) do + let(:title) { 'bar' } before(:each) do # Fake assert_private function from stdlib to not fail within this test - Puppet::Parser::Functions.newfunction(:assert_private, :type => :rvalue) { |args| } + Puppet::Parser::Functions.newfunction(:assert_private, type: :rvalue) { |args| } end on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do facts end - case facts[:kernel] - when 'Linux' - case facts[:os]['family'] - when 'Debian' - before(:all) do - @icinga2_config_dir = '/etc/icinga2' - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - end - else - before(:all) do - @icinga2_config_dir = '/etc/icinga2' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - end - end - when 'FreeBSD' - before(:all) do - @icinga2_config_dir = '/usr/local/etc/icinga2' - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - end - when 'windows' - before(:all) do - @icinga2_config_dir = 'C:/ProgramData/icinga2/etc/icinga2' - end - end - let(:pre_condition) do [ "class { 'icinga2': features => [] }", "icinga2::object { 'icinga2::object::FooComponent::foo': object_name => 'foo', object_type => 'FooComponent', - target => '#{@icinga2_config_dir}/features-available/foo.conf', + target => '#{icinga2_config_dir}/features-available/foo.conf', order => 10, - }" + }", ] end case facts[:kernel] - when 'windows' - context "with ensure => present" do - let(:params) do - { - :ensure => 'present', - :feature => 'foo' - } - end + when 'Linux' + let(:icinga2_config_dir) { '/etc/icinga2' } + case facts[:os]['family'] + when 'Debian' + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } + else + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + end + when 'FreeBSD' + let(:icinga2_config_dir) { '/usr/local/etc/icinga2' } + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } + when 'windows' + let(:icinga2_config_dir) { 'C:/ProgramData/icinga2/etc/icinga2' } + end - it { is_expected.to contain_file("#{@icinga2_config_dir}/features-enabled/foo.conf") - .with({ 'ensure' => 'file' }) - .that_notifies('Class[icinga2::service]') } + case facts[:kernel] + when 'windows' + context 'with ensure => present' do + let(:params) do + { + ensure: 'present', + feature: 'foo', + } + end + + it { is_expected.to contain_file("#{icinga2_config_dir}/features-enabled/foo.conf").with({ 'ensure' => 'file' }).that_notifies('Class[icinga2::service]') } - it { should compile } + it { is_expected.to compile } + end + else + context 'with ensure => present' do + let(:params) do + { + ensure: 'present', + feature: 'foo', + } end - else - context "with ensure => present" do - let(:params) do - { - :ensure => 'present', - :feature => 'foo' - } - end - it { is_expected.to contain_file("#{@icinga2_config_dir}/features-enabled/foo.conf") - .with({ + it { + is_expected.to contain_file("#{icinga2_config_dir}/features-enabled/foo.conf").with( + { 'ensure' => 'link', - 'owner' => @icinga2_user, - 'group' => @icinga2_group, - }).that_notifies('Class[icinga2::service]') } + 'owner' => icinga2_user, + 'group' => icinga2_group, + }, + ).that_notifies('Class[icinga2::service]') + } - it { should compile } - end + it { is_expected.to compile } + end end - context "with ensure => absent" do + context 'with ensure => absent' do let(:params) do { - :ensure => 'absent', - :feature => 'foo' + ensure: 'absent', + feature: 'foo', } end - it { is_expected.to contain_file("#{@icinga2_config_dir}/features-enabled/foo.conf") - .with({ 'ensure' => 'absent'}) - .that_notifies('Class[icinga2::service]') } + it { + is_expected.to contain_file("#{icinga2_config_dir}/features-enabled/foo.conf") + .with({ 'ensure' => 'absent' }) + .that_notifies('Class[icinga2::service]') + } - it { should compile } + it { is_expected.to compile } end end end end diff --git a/spec/defines/fragment_spec.rb b/spec/defines/fragment_spec.rb index 5a0ca27..f732f43 100644 --- a/spec/defines/fragment_spec.rb +++ b/spec/defines/fragment_spec.rb @@ -1,37 +1,31 @@ require 'spec_helper' -describe('icinga2::config::fragment', :type => :define) do - let(:title) do - 'bar' - end +describe('icinga2::config::fragment', type: :define) do + let(:title) { 'bar' } let(:pre_condition) do [ - "class { 'icinga2': }" + "class { 'icinga2': }", ] end on_supported_os.each do |os, facts| let(:facts) do facts - end + end - context "#{os} with content => foo, target => /bar/baz, order => 10" do + context "#{os} with content => 'foo, target => '/bar/baz', order => 10" do let(:params) do { - :content => 'foo', - :target => '/bar/baz', - :order => '10' + content: 'foo', + target: '/bar/baz', + order: '10', } end it { is_expected.to contain_concat('/bar/baz') } - it { is_expected.to contain_concat__fragment('icinga2::config::bar') - .with({ - 'target' => '/bar/baz', - 'order' => '10' - }).with_content(/^foo$/) } + it { is_expected.to contain_concat__fragment('icinga2::config::bar').with({ 'target' => '/bar/baz', 'order' => '10' }).with_content(%r{^foo$}) } end end end diff --git a/spec/defines/objects_spec.rb b/spec/defines/objects_spec.rb index e0bdb05..04150f3 100644 --- a/spec/defines/objects_spec.rb +++ b/spec/defines/objects_spec.rb @@ -1,228 +1,201 @@ require 'spec_helper' facts = { - :kernel => 'Linux', - :os => {'family' => 'Debian', 'name' => 'Debian'}, + kernel: 'Linux', + os: { family: 'Debian', name: 'Debian' }, } - -describe('icinga2::object', :type => :define) do +describe('icinga2::object', type: :define) do let(:title) do 'foo' end let(:pre_condition) do [ - "class { 'icinga2': }" + "class { 'icinga2': }", ] end before(:each) do # Fake assert_private function from stdlib to not fail within this test - Puppet::Parser::Functions.newfunction(:assert_private, :type => :rvalue) { |args| } + Puppet::Parser::Functions.newfunction(:assert_private, type: :rvalue) { |args| } end on_supported_os.each do |os, complete_facts| let(:facts) do complete_facts end context "#{os} with object_type => 'foobar'" do let(:params) do { - :object_type => 'foobar', - :target => '/bar/baz', - :order => '10' + object_type: 'foobar', + target: '/bar/baz', + order: '10', } end case facts[:os]['family'] when 'Debian' - before(:each) do - @icinga2_user = 'nagios' - @icinga2_group = 'nagios' - end + let(:icinga2_user) { 'nagios' } + let(:icinga2_group) { 'nagios' } when 'Windows' - before(:each) do - @icinga2_user = null - @icinga2_group = null - end + let(:icinga2_user) { null } + let(:icinga2_group) { null } else - before(:each) do - @icinga2_user = 'icinga' - @icinga2_group = 'icinga' - end + let(:icinga2_user) { 'icinga' } + let(:icinga2_group) { 'icinga' } end - it { is_expected.to contain_concat('/bar/baz') - .with({ - 'owner' => @icinga2_user, - 'group' => @icinga2_group - }).that_notifies('Class[icinga2::service]') } + it { is_expected.to contain_concat('/bar/baz').with({ 'owner' => icinga2_user, 'group' => icinga2_group }).that_notifies('Class[icinga2::service]') } - it { is_expected.to contain_concat__fragment('foo') - .with({ - 'target' => '/bar/baz', - 'order' => '10' - }).with_content(/object foobar "foo" \{/) } + it { is_expected.to contain_concat__fragment('foo').with({ 'target' => '/bar/baz', 'order' => '10' }).with_content(%r{object foobar "foo" \{}) } - it { should compile } + it { is_expected.to compile } end end - let(:facts) do - facts - end - - context "with template => true" do + context 'with template => true' do let(:params) do { - :template => true, - :object_type => 'foobar', - :target => '/bar/baz', - :order => '10' + template: true, + object_type: 'foobar', + target: '/bar/baz', + order: '10', } end - it { is_expected.to contain_concat__fragment('foo') - .with_content(/template foobar "foo" \{/) } + it { is_expected.to contain_concat__fragment('foo').with_content(%r{template foobar "foo" \{}) } end context "with import => ['bar', 'baz']" do let(:params) do { - :import => ['bar', 'baz'], - :object_type => 'foobar', - :target => '/bar/baz', - :order => '10' + import: ['bar', 'baz'], + object_type: 'foobar', + target: '/bar/baz', + order: '10', } end - it { is_expected.to contain_concat__fragment('foo') - .with_content(/import "bar"\n import "baz"\n/) } + it { is_expected.to contain_concat__fragment('foo').with_content(%r{import "bar"\n import "baz"\n}) } end context "with apply_target => 'Service', object_type => 'Service' (same value)" do let(:params) do { - :apply_target => 'Service', - :object_type => 'Service', - :target => '/bar/baz', - :order => '10' + apply_target: 'Service', + object_type: 'Service', + target: '/bar/baz', + order: '10', } end - it { is_expected.to raise_error(Puppet::Error, /must be different/) } + it { is_expected.to raise_error(Puppet::Error, %r{must be different}) } end context "with apply => true, apply_target => 'Host'" do let(:params) do { - :apply => true, - :apply_target => 'Host', - :object_type => 'foobar', - :target => '/bar/baz', - :order => '10' + apply: true, + apply_target: 'Host', + object_type: 'foobar', + target: '/bar/baz', + order: '10', } end - it { is_expected.to contain_concat__fragment('foo') - .with_content(/apply foobar \"foo\" to Host \{/) } + it { is_expected.to contain_concat__fragment('foo').with_content(%r{apply foobar \"foo\" to Host \{}) } end context "with apply => true, apply_target => 'Service'" do let(:params) do { - :apply => true, - :apply_target => 'Service', - :object_type => 'foobar', - :target => '/bar/baz', - :order => '10' + apply: true, + apply_target: 'Service', + object_type: 'foobar', + target: '/bar/baz', + order: '10', } end - it { is_expected.to contain_concat__fragment('foo') - .with_content(/apply foobar \"foo\" to Service \{/) } + it { is_expected.to contain_concat__fragment('foo').with_content(%r{apply foobar \"foo\" to Service \{}) } end context "with apply => 'item in array', prefix => true" do let(:params) do { - :apply => 'item in array', - :prefix => true, - :object_type => 'foobar', - :target => '/bar/baz', - :order => '10' + apply: 'item in array', + prefix: true, + object_type: 'foobar', + target: '/bar/baz', + order: '10', } end - it { is_expected.to contain_concat__fragment('foo') - .with_content(/apply foobar \"foo\" for \(item in array\) \{/) } + it { is_expected.to contain_concat__fragment('foo').with_content(%r{apply foobar \"foo\" for \(item in array\) \{}) } end context "with apply => 'key => value in hash', prefix => 'some string'" do let(:params) do { - :apply => 'key => value in hash', - :prefix => 'some string', - :object_type => 'foobar', - :target => '/bar/baz', - :order => '10' + apply: 'key => value in hash', + prefix: 'some string', + object_type: 'foobar', + target: '/bar/baz', + order: '10', } end - it { is_expected.to contain_concat__fragment('foo') - .with_content(/apply foobar \"some string\" for \(key => value in hash\) \{/) } + it { is_expected.to contain_concat__fragment('foo').with_content(%r{apply foobar \"some string\" for \(key => value in hash\) \{}) } end end - on_icinga_objects = { - 'ApiUser' => 'icinga2::object::apiuser', - 'CheckCommand' => 'icinga2::object::checkcommand', - 'Dependency' => 'icinga2::object::dependency', - 'Endpoint' => 'icinga2::object::endpoint', - 'EventCommand' => 'icinga2::object::eventcommand', - 'Host' => 'icinga2::object::host', - 'HostGroup' => 'icinga2::object::hostgroup', - 'Notification' => 'icinga2::object::notification', - 'NotificationCommand' => 'icinga2::object::notificationcommand', - 'ScheduledDowntime' => 'icinga2::object::scheduleddowntime', - 'Service' => 'icinga2::object::service', - 'ServiceGroup' => 'icinga2::object::servicegroup', - 'TimePeriod' => 'icinga2::object::timeperiod', - 'User' => 'icinga2::object::user', - 'UserGroup' => 'icinga2::object::usergroup', - 'Zone' => 'icinga2::object::zone', + ApiUser: 'icinga2::object::apiuser', + CheckCommand: 'icinga2::object::checkcommand', + Dependency: 'icinga2::object::dependency', + Endpoint: 'icinga2::object::endpoint', + EventCommand: 'icinga2::object::eventcommand', + Host: 'icinga2::object::host', + HostGroup: 'icinga2::object::hostgroup', + Notification: 'icinga2::object::notification', + NotificationCommand: 'icinga2::object::notificationcommand', + ScheduledDowntime: 'icinga2::object::scheduleddowntime', + Service: 'icinga2::object::service', + ServiceGroup: 'icinga2::object::servicegroup', + TimePeriod: 'icinga2::object::timeperiod', + User: 'icinga2::object::user', + UserGroup: 'icinga2::object::usergroup', + Zone: 'icinga2::object::zone', } on_icinga_objects.each do |otype, rtype| - describe(rtype, :type => :define) do + describe(rtype, type: :define) do let(:title) do 'foo' end let(:pre_condition) do [ - "class { 'icinga2': }" + "class { 'icinga2': }", ] end let(:facts) do facts end - context "with all defaults" do + context 'with all defaults' do let(:params) do { - :target => '/bar/baz' + target: '/bar/baz', } end - it { is_expected.to contain_icinga2__object("icinga2::object::#{otype}::foo") - .with_object_type(otype) } + it { is_expected.to contain_icinga2__object("icinga2::object::#{otype}::foo").with_object_type(otype) } - it { should compile } + it { is_expected.to compile } end end end diff --git a/spec/functions/attributes_spec.rb b/spec/functions/attributes_spec.rb index be3f610..6f6445b 100644 --- a/spec/functions/attributes_spec.rb +++ b/spec/functions/attributes_spec.rb @@ -1,604 +1,734 @@ require 'spec_helper' describe 'icinga2_attributes' do let(:pre_condition) do [ - "class { 'icinga2': }" + "class { 'icinga2': }", ] end let(:facts) do { - :kernel => 'Linux', - :os => { - 'family' => 'Debian', - 'name' => 'Debian' + kernel: 'Linux', + os: { + family: 'Debian', + name: 'Debian', }, } end it 'raises a ArgumentError if there is less than 1 arguments' do is_expected.to run.with_params.and_raise_error(Puppet::ParseError) end - it 'raises a ArgumentError if there are more than 4 arguments' do - is_expected.to run.with_params('one','two','three','four','five').and_raise_error(Puppet::ParseError) + is_expected.to run.with_params('one', 'two', 'three', 'four', 'five').and_raise_error(Puppet::ParseError) end - it 'assign a string' do - # foo = "some string, connected to another. Yeah!" - is_expected.to run.with_params({ - 'foo' => 'some string, connected to another. Yeah!' - }).and_return("foo = \"some string, connected to another. Yeah!\"\n") + is_expected.to run.with_params( + { + 'foo' => 'some string, connected to another. Yeah!', + }, + ).and_return("foo = \"some string, connected to another. Yeah!\"\n") # foo += "some string" - is_expected.to run.with_params({ - 'foo' => '+ some string, connected to another. Yeah!' - }).and_return("foo += \"some string, connected to another. Yeah!\"\n") + is_expected.to run.with_params( + { + 'foo' => '+ some string, connected to another. Yeah!', + }, + ).and_return("foo += \"some string, connected to another. Yeah!\"\n") # vars.foo = "some string" - is_expected.to run.with_params({ - 'vars' => { - 'foo' => 'some string, connected to another. Yeah!' - } - }).and_return("vars.foo = \"some string, connected to another. Yeah!\"\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => 'some string, connected to another. Yeah!', + }, + }, + ).and_return("vars.foo = \"some string, connected to another. Yeah!\"\n") # vars.foo += "some string" - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '+ some string, connected to another. Yeah!' - } - }).and_return("vars.foo += \"some string, connected to another. Yeah!\"\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '+ some string, connected to another. Yeah!', + }, + }, + ).and_return("vars.foo += \"some string, connected to another. Yeah!\"\n") # foo = "some string" + [ "bar", "baz", ] - is_expected.to run.with_params({ - 'foo' => 'some string + [ bar, baz ]' - }).and_return("foo = \"some string\" + [ \"bar\", \"baz\", ]\n") + is_expected.to run.with_params( + { + 'foo' => 'some string + [ bar, baz ]', + }, + ).and_return("foo = \"some string\" + [ \"bar\", \"baz\", ]\n") # foo = "[ "bar", "baz", ] + "other string" - is_expected.to run.with_params({ - 'foo' => '[ bar, baz ] + other string' - }).and_return("foo = [ \"bar\", \"baz\", ] + \"other string\"\n") + is_expected.to run.with_params( + { + 'foo' => '[ bar, baz ] + other string', + }, + ).and_return("foo = [ \"bar\", \"baz\", ] + \"other string\"\n") # foo = "[ "bar", "baz", ] + [ "barbaz", ] - is_expected.to run.with_params({ - 'foo' => '[ bar, baz ] + [ barbaz ]' - }).and_return("foo = [ \"bar\", \"baz\", ] + [ \"barbaz\", ]\n") + is_expected.to run.with_params( + { + 'foo' => '[ bar, baz ] + [ barbaz ]', + }, + ).and_return("foo = [ \"bar\", \"baz\", ] + [ \"barbaz\", ]\n") # foo = "[ "bar", [ "baz", ], ] - is_expected.to run.with_params({ - 'foo' => '[ bar, [ baz ] ]' - }).and_return("foo = [ \"bar\", [ \"baz\", ], ]\n") + is_expected.to run.with_params( + { + 'foo' => '[ bar, [ baz ] ]', + }, + ).and_return("foo = [ \"bar\", [ \"baz\", ], ]\n") # result = "some string" + { # foo = "baz" # bar = "baz" # } - is_expected.to run.with_params({ - 'result' => '{ foo => baz, bar => baz }' - }).and_return("result = {\n foo = \"baz\"\n bar = \"baz\"\n}\n") + is_expected.to run.with_params( + { + 'result' => '{ foo => baz, bar => baz }', + }, + ).and_return("result = {\n foo = \"baz\"\n bar = \"baz\"\n}\n") end - it 'assign a boolean' do - # foo = false - is_expected.to run.with_params({ - 'foo' => 'false' - }).and_return("foo = false\n") + is_expected.to run.with_params( + { + 'foo' => 'false', + }, + ).and_return("foo = false\n") # foo = true - is_expected.to run.with_params({ - 'foo' => 'true' - }).and_return("foo = true\n") + is_expected.to run.with_params( + { + 'foo' => 'true', + }, + ).and_return("foo = true\n") # foo = null - is_expected.to run.with_params({ - 'foo' => 'null' - }).and_return("foo = null\n") + is_expected.to run.with_params( + { + 'foo' => 'null', + }, + ).and_return("foo = null\n") # vars.foo = false - is_expected.to run.with_params({ - 'vars' => { - 'foo' => 'false' - } - }).and_return("vars.foo = false\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => 'false', + }, + }, + ).and_return("vars.foo = false\n") # vars.foo = true - is_expected.to run.with_params({ - 'vars' => { - 'foo' => 'true' - } - }).and_return("vars.foo = true\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => 'true', + }, + }, + ).and_return("vars.foo = true\n") # vars.foo = null - is_expected.to run.with_params({ - 'vars' => { - 'foo' => 'null' - } - }).and_return("vars.foo = null\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => 'null', + }, + }, + ).and_return("vars.foo = null\n") end - it 'assign a number' do - # foo = 42 - is_expected.to run.with_params({ - 'foo' => '42' - }).and_return("foo = 42\n") + is_expected.to run.with_params( + { + 'foo' => '42', + }, + ).and_return("foo = 42\n") # foo += 42 - is_expected.to run.with_params({ - 'foo' => '+ 42' - }).and_return("foo += 42\n") + is_expected.to run.with_params( + { + 'foo' => '+ 42', + }, + ).and_return("foo += 42\n") # foo -= 42 - is_expected.to run.with_params({ - 'foo' => '- 42' - }).and_return("foo -= 42\n") + is_expected.to run.with_params( + { + 'foo' => '- 42', + }, + ).and_return("foo -= 42\n") # foo = -42 - is_expected.to run.with_params({ - 'foo' => '-42' - }).and_return("foo = -42\n") + is_expected.to run.with_params( + { + 'foo' => '-42', + }, + ).and_return("foo = -42\n") # foo += -42 - is_expected.to run.with_params({ - 'foo' => '+ -42' - }).and_return("foo += -42\n") + is_expected.to run.with_params( + { + 'foo' => '+ -42', + }, + ).and_return("foo += -42\n") # foo -= -42 - is_expected.to run.with_params({ - 'foo' => '- -42' - }).and_return("foo -= -42\n") + is_expected.to run.with_params( + { + 'foo' => '- -42', + }, + ).and_return("foo -= -42\n") # vars.foo = 42 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '42' - } - }).and_return("vars.foo = 42\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '42', + }, + }, + ).and_return("vars.foo = 42\n") # vars.foo += 42 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '+ 42' - } - }).and_return("vars.foo += 42\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '+ 42', + }, + }, + ).and_return("vars.foo += 42\n") # vars.foo -= 42 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '- 42' - } - }).and_return("vars.foo -= 42\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '- 42', + }, + }, + ).and_return("vars.foo -= 42\n") # vars.foo = -42 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '-42' - } - }).and_return("vars.foo = -42\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '-42', + }, + }, + ).and_return("vars.foo = -42\n") # vars.foo += -42 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '+ -42' - } - }).and_return("vars.foo += -42\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '+ -42', + }, + }, + ).and_return("vars.foo += -42\n") # vars.foo -= -42 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '- -42' - } - }).and_return("vars.foo -= -42\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '- -42', + }, + }, + ).and_return("vars.foo -= -42\n") end - it 'assign a floating point number' do - # foo = 3.141 - is_expected.to run.with_params({ - 'foo' => '3.141' - }).and_return("foo = 3.141\n") + is_expected.to run.with_params( + { + 'foo' => '3.141', + }, + ).and_return("foo = 3.141\n") # foo += 3.141 - is_expected.to run.with_params({ - 'foo' => '+ 3.141' - }).and_return("foo += 3.141\n") + is_expected.to run.with_params( + { + 'foo' => '+ 3.141', + }, + ).and_return("foo += 3.141\n") # foo -= 3.141 - is_expected.to run.with_params({ - 'foo' => '- 3.141' - }).and_return("foo -= 3.141\n") + is_expected.to run.with_params( + { + 'foo' => '- 3.141', + }, + ).and_return("foo -= 3.141\n") # foo = -3.141 - is_expected.to run.with_params({ - 'foo' => '-3.141' - }).and_return("foo = -3.141\n") + is_expected.to run.with_params( + { + 'foo' => '-3.141', + }, + ).and_return("foo = -3.141\n") # foo += -3.141 - is_expected.to run.with_params({ - 'foo' => '+ -3.141' - }).and_return("foo += -3.141\n") + is_expected.to run.with_params( + { + 'foo' => '+ -3.141', + }, + ).and_return("foo += -3.141\n") # foo -= -3.141 - is_expected.to run.with_params({ - 'foo' => '- -3.141' - }).and_return("foo -= -3.141\n") + is_expected.to run.with_params( + { + 'foo' => '- -3.141', + }, + ).and_return("foo -= -3.141\n") # vars.foo = 3.141 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '3.141' - } - }).and_return("vars.foo = 3.141\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '3.141', + }, + }, + ).and_return("vars.foo = 3.141\n") # vars.foo += 3.141 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '+ 3.141' - } - }).and_return("vars.foo += 3.141\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '+ 3.141', + }, + }, + ).and_return("vars.foo += 3.141\n") # vars.foo -= 3.141 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '- 3.141' - } - }).and_return("vars.foo -= 3.141\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '- 3.141', + }, + }, + ).and_return("vars.foo -= 3.141\n") # vars.foo = -3.141 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '-3.141' - } - }).and_return("vars.foo = -3.141\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '-3.141', + }, + }, + ).and_return("vars.foo = -3.141\n") # vars.foo += -3.141 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '+ -3.141' - } - }).and_return("vars.foo += -3.141\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '+ -3.141', + }, + }, + ).and_return("vars.foo += -3.141\n") # vars.foo -= -3.141 - is_expected.to run.with_params({ - 'vars' => { - 'foo' => '- -3.141' - } - }).and_return("vars.foo -= -3.141\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => '- -3.141', + }, + }, + ).and_return("vars.foo -= -3.141\n") end - it 'assign numbers with time units' do - # foo_s = 60s # foo_m = 5m # foo_h = 2.5h # foo_d = 2d - is_expected.to run.with_params({ - 'foo_s' => '60s', - 'foo_m' => '5m', - 'foo_h' => '2.5h', - 'foo_d' => '2d' - }).and_return("foo_s = 60s\nfoo_m = 5m\nfoo_h = 2.5h\nfoo_d = 2d\n") + is_expected.to run.with_params( + { + 'foo_s' => '60s', + 'foo_m' => '5m', + 'foo_h' => '2.5h', + 'foo_d' => '2d', + }, + ).and_return("foo_s = 60s\nfoo_m = 5m\nfoo_h = 2.5h\nfoo_d = 2d\n") # vars.foo_s = 60s # vars.foo_m = 5m # vars.foo_h = 2.5h # vars.foo_d = 2d - is_expected.to run.with_params({ - 'vars' => { - 'foo_s' => '60s', - 'foo_m' => '5m', - 'foo_h' => '2.5h', - 'foo_d' => '2d' - } - }).and_return("vars.foo_s = 60s\nvars.foo_m = 5m\nvars.foo_h = 2.5h\nvars.foo_d = 2d\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo_s' => '60s', + 'foo_m' => '5m', + 'foo_h' => '2.5h', + 'foo_d' => '2d', + }, + }, + ).and_return("vars.foo_s = 60s\nvars.foo_m = 5m\nvars.foo_h = 2.5h\nvars.foo_d = 2d\n") end - it 'assign an array' do - # foo = [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ] - is_expected.to run.with_params({ - 'foo' => ['some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'] - }).and_return("foo = [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") + is_expected.to run.with_params( + { + 'foo' => ['some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'], + }, + ).and_return("foo = [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") # foo += [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ] - is_expected.to run.with_params({ - 'foo' => ['+', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'] - }).and_return("foo += [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") + is_expected.to run.with_params( + { + 'foo' => ['+', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'], + }, + ).and_return("foo += [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") # foo -= [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ] - is_expected.to run.with_params({ - 'foo' => ['-', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'] - }).and_return("foo -= [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") + is_expected.to run.with_params( + { + 'foo' => ['-', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'], + }, + ).and_return("foo -= [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") # vars.foo = [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ] - is_expected.to run.with_params({ - 'vars' => { - 'foo' => ['some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'] - } - }).and_return("vars.foo = [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => ['some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'], + }, + }, + ).and_return("vars.foo = [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") # vars.foo += [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ] - is_expected.to run.with_params({ - 'vars' => { - 'foo' => ['+', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'] - } - }).and_return("vars.foo += [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => ['+', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'], + }, + }, + ).and_return("vars.foo += [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") # vars.foo -= [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ] - is_expected.to run.with_params({ - 'vars' => { - 'foo' => ['-', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'] - } - }).and_return("vars.foo -= [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => ['-', 'some string, connected to another. Yeah!', 'NodeName', '42', '3.141', '2.5d', 'true'], + }, + }, + ).and_return("vars.foo -= [ \"some string, connected to another. Yeah!\", NodeName, 42, 3.141, 2.5d, true, ]\n") end - it 'assign a hash' do - # foo = {} - is_expected.to run.with_params({ - 'foo' => {} - }).and_return("foo = {}\n") + is_expected.to run.with_params( + { + 'foo' => {}, + }, + ).and_return("foo = {}\n") # foo += {} - is_expected.to run.with_params({ - 'foo' => { - '+' => true, - } - }).and_return("foo += {}\n") + is_expected.to run.with_params( + { + 'foo' => { + '+' => true, + }, + }, + ).and_return("foo += {}\n") # foo = { # string = "some string, connected to another. Yeah!" # constant = NodeName # numbers = [ 42, 3.141, -42, -3.141, ] # time = 2.5d # bool = true # } - is_expected.to run.with_params({ - 'foo' => { - 'string' => 'some string, connected to another. Yeah!', - 'constant' => 'NodeName', - 'numbers' => ['42', '3.141', '-42', '-3.141'], - 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], - 'time' => '2.5d', - 'bool' => 'true', - } - }).and_return("foo = {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n numbers = [ 42, 3.141, -42, -3.141, ]\n merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n bool = true\n}\n") + is_expected.to run.with_params( + { + 'foo' => { + 'string' => 'some string, connected to another. Yeah!', + 'constant' => 'NodeName', + 'numbers' => ['42', '3.141', '-42', '-3.141'], + 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], + 'time' => '2.5d', + 'bool' => 'true', + }, + }, + ).and_return( + "foo = {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n" \ + " numbers = [ 42, 3.141, -42, -3.141, ]\n merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n bool = true\n}\n", + ) # foo += { # string = "some string, connected to another. Yeah!" # constant = NodeName # numbers = [ 42, 3.141, -42, -3.141, ] # time = 2.5d # bool = true # } - is_expected.to run.with_params({ - 'foo' => { - '+' => true, - 'string' => 'some string, connected to another. Yeah!', - 'constant' => 'NodeName', - 'numbers' => ['42', '3.141', '-42', '-3.141'], - 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], - 'time' => '2.5d', - 'bool' => 'true', - } - }).and_return("foo += {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n numbers = [ 42, 3.141, -42, -3.141, ]\n merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n bool = true\n}\n") + is_expected.to run.with_params( + { + 'foo' => { + '+' => true, + 'string' => 'some string, connected to another. Yeah!', + 'constant' => 'NodeName', + 'numbers' => ['42', '3.141', '-42', '-3.141'], + 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], + 'time' => '2.5d', + 'bool' => 'true', + }, + }, + ).and_return( + "foo += {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n numbers = [ 42, 3.141, -42, -3.141, ]\n" \ + " merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n bool = true\n}\n", + ) # vars.foo["string"] = "some string, connected to another. Yeah!" # vars.foo["constant"] = NodeName # vars.foo["numbers"] = [ 42, 3.141, -42, -3.141, ] # vars.foo["merge_array"] += [ 42, 3.141, -42, -3.141, ] # vars.foo["time"] = 2.5d # vars.foo["bool"] = true - is_expected.to run.with_params({ - 'vars' => { - 'foo' => { - 'string' => 'some string, connected to another. Yeah!', - 'constant' => 'NodeName', - 'numbers' => ['42', '3.141', '-42', '-3.141'], - 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], - 'time' => '2.5d', - 'bool' => 'true' - } - } - }).and_return("vars.foo[\"string\"] = \"some string, connected to another. Yeah!\"\nvars.foo[\"constant\"] = NodeName\nvars.foo[\"numbers\"] = [ 42, 3.141, -42, -3.141, ]\nvars.foo[\"merge_array\"] += [ 42, 3.141, -42, -3.141, ]\nvars.foo[\"time\"] = 2.5d\nvars.foo[\"bool\"] = true\n") + is_expected.to run.with_params( + { + 'vars' => { + 'foo' => { + 'string' => 'some string, connected to another. Yeah!', + 'constant' => 'NodeName', + 'numbers' => ['42', '3.141', '-42', '-3.141'], + 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], + 'time' => '2.5d', + 'bool' => 'true', + }, + }, + }, + ).and_return( + "vars.foo[\"string\"] = \"some string, connected to another. Yeah!\"\nvars.foo[\"constant\"] = NodeName\nvars.foo[\"numbers\"] = [ 42, 3.141, -42, -3.141, ]\n" \ + "vars.foo[\"merge_array\"] += [ 42, 3.141, -42, -3.141, ]\nvars.foo[\"time\"] = 2.5d\nvars.foo[\"bool\"] = true\n", + ) end - it 'assign a nested hash' do - # foobar = { # foo += { # string = "some string, connected to another. Yeah!" # constant = NodeName # bool = true # } # fooz += {} # bar = { # numbers = [ 42, 3.141, -42, -3,141, ] # merge_array += [ 42, 3.141, -42, -3,141, ] # time = 2.5d # } # baz = {} # } - is_expected.to run.with_params({ - 'foobar' => { - 'foo' => { - '+' => true, - 'string' => 'some string, connected to another. Yeah!', - 'constant' => 'NodeName', - 'bool' => 'true' - }, - 'fooz' => { - '+' => true, - }, - 'bar' => { - 'numbers' => ['42', '3.141', '-42', '-3.141'], - 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], - 'time' => '2.5d' + is_expected.to run.with_params( + { + 'foobar' => { + 'foo' => { + '+' => true, + 'string' => 'some string, connected to another. Yeah!', + 'constant' => 'NodeName', + 'bool' => 'true', + }, + 'fooz' => { + '+' => true, + }, + 'bar' => { + 'numbers' => ['42', '3.141', '-42', '-3.141'], + 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], + 'time' => '2.5d', + }, + 'baz' => {}, }, - 'baz' => {}, - } - }).and_return("foobar = {\n foo += {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n bool = true\n }\n fooz += {}\n bar = {\n numbers = [ 42, 3.141, -42, -3.141, ]\n merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n }\n baz = {}\n}\n") + }, + ).and_return( + "foobar = {\n foo += {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n bool = true\n }\n fooz += {}\n" \ + " bar = {\n numbers = [ 42, 3.141, -42, -3.141, ]\n merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n }\n baz = {}\n}\n", + ) # vars.foobar["foo"] += { # string = "some string, connected to another. Yeah!" # constant = NodeName # bool = true # } # vars.foobar["fooz"] += {} # vars.foobar["bar"] = { # numbers = [ 42, 3.141, -42, -3,141, ] # merge_array += [ 42, 3.141, -42, -3,141, ] # time = 2.5d # } # vars.foobar["baz"] = {} - is_expected.to run.with_params({ - 'vars' => { - 'foobar' => { - 'foo' => { - '+' => true, - 'string' => 'some string, connected to another. Yeah!', - 'constant' => 'NodeName', - 'bool' => 'true' - }, - 'fooz' => { - '+' => true, + is_expected.to run.with_params( + { + 'vars' => { + 'foobar' => { + 'foo' => { + '+' => true, + 'string' => 'some string, connected to another. Yeah!', + 'constant' => 'NodeName', + 'bool' => 'true', + }, + 'fooz' => { + '+' => true, + }, + 'bar' => { + 'numbers' => ['42', '3.141', '-42', '-3.141'], + 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], + 'time' => '2.5d', + }, + 'baz' => {}, }, - 'bar' => { - 'numbers' => ['42', '3.141', '-42', '-3.141'], - 'merge_array' => ['+', '42', '3.141', '-42', '-3.141'], - 'time' => '2.5d' - }, - 'baz' => {}, - } - } - }).and_return("vars.foobar[\"foo\"] += {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n bool = true\n}\nvars.foobar[\"fooz\"] += {}\nvars.foobar[\"bar\"] = {\n numbers = [ 42, 3.141, -42, -3.141, ]\n merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n}\nvars.foobar[\"baz\"] = {}\n") + }, + }, + ).and_return( + "vars.foobar[\"foo\"] += {\n string = \"some string, connected to another. Yeah!\"\n constant = NodeName\n bool = true\n}\n" \ + "vars.foobar[\"fooz\"] += {}\nvars.foobar[\"bar\"] = {\n numbers = [ 42, 3.141, -42, -3.141, ]\n merge_array += [ 42, 3.141, -42, -3.141, ]\n time = 2.5d\n}\nvars.foobar[\"baz\"] = {}\n", + ) end - it 'assign multiple custom attributes' do # vars += config1 - is_expected.to run.with_params({ - 'vars' => '+ config', - }, 0, ['config']).and_return("vars += config\n") + is_expected.to run.with_params( + { + 'vars' => '+ config', + }, + 0, + ['config'], + ).and_return("vars += config\n") # vars = vars + config1 - is_expected.to run.with_params({ - 'vars' => 'vars + config', - }, 0, ['vars','config']).and_return("vars = vars + config\n") + is_expected.to run.with_params( + { + 'vars' => 'vars + config', + }, + 0, + [ 'vars', 'config' ], + ).and_return("vars = vars + config\n") # vars += config1 # vars += {} # vars.foo = "some string" # vars.bar += [ 42, 3.141, -42, -3.141, ] # vars.baz["number"] -= 42 # vars.baz["floating"] += 3.141 # vars += config2 - is_expected.to run.with_params({ - 'vars' => [ - '+ config1', - {}, - { - 'foo' => 'some string', - 'bar' => [ '+', '42', '3.141', '-42', '-3.141' ], - 'baz' => { - '+' => true, - 'number' => '- 42', - 'floating' => '+ 3.141', + is_expected.to run.with_params( + { + 'vars' => [ + '+ config1', + {}, + { + 'foo' => 'some string', + 'bar' => [ '+', '42', '3.141', '-42', '-3.141' ], + 'baz' => { + '+' => true, + 'number' => '- 42', + 'floating' => '+ 3.141', + }, }, - }, - '+ config2', - ], - }).and_return("vars += config1\nvars += {}\nvars.foo = \"some string\"\nvars.bar += [ 42, 3.141, -42, -3.141, ]\nvars.baz[\"number\"] -= 42\nvars.baz[\"floating\"] += 3.141\nvars += config2\n") + '+ config2', + ], + }, + ).and_return("vars += config1\nvars += {}\nvars.foo = \"some string\"\nvars.bar += [ 42, 3.141, -42, -3.141, ]\nvars.baz[\"number\"] -= 42\nvars.baz[\"floating\"] += 3.141\nvars += config2\n") end - it 'arithmetic and logical expressions' do - # result = 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string") - is_expected.to run.with_params({ - 'result' => '3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)' - }).and_return("result = 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\")\n") + is_expected.to run.with_params( + { + 'result' => '3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)', + }, + ).and_return("result = 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\")\n") # result += 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string") - is_expected.to run.with_params({ - 'result' => '+ 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)' - }).and_return("result += 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\")\n") + is_expected.to run.with_params( + { + 'result' => '+ 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)', + }, + ).and_return("result += 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\")\n") # result = [ 3 + 4, 4 - (4 + (-2.5)) * 8, func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string"), ] - is_expected.to run.with_params({ - 'result' => [ - '3 + 4', - '4 - (4 + (-2.5)) * 8', - 'func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)' - ] - }).and_return("result = [ 3 + 4, 4 - (4 + (-2.5)) * 8, func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\"), ]\n") + is_expected.to run.with_params( + { + 'result' => [ + '3 + 4', + '4 - (4 + (-2.5)) * 8', + 'func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)', + ], + }, + ).and_return("result = [ 3 + 4, 4 - (4 + (-2.5)) * 8, func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\"), ]\n") # result = { # add = 3 + 4 # expr = 4 - (4 + (-2.5)) * 8 # func = func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string") # } - is_expected.to run.with_params({ - 'result' => { - 'add' => '3 + 4', - 'expr' => '4 - (4 + (-2.5)) * 8', - 'func' => 'func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)' - } - }).and_return("result = {\n add = 3 + 4\n expr = 4 - (4 + (-2.5)) * 8\n func = func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\")\n}\n") + is_expected.to run.with_params( + { + 'result' => { + 'add' => '3 + 4', + 'expr' => '4 - (4 + (-2.5)) * 8', + 'func' => 'func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)', + }, + }, + ).and_return("result = {\n add = 3 + 4\n expr = 4 - (4 + (-2.5)) * 8\n func = func(3 * 2 + 1, funcN(-42)) + str(NodeName, \"some string\", \"another string\")\n}\n") # result = get_object("Endpoint", host.name).host + "host.example.org" - is_expected.to run.with_params({ - 'result' => 'get_object(Endpoint, host.name).attribute + string', - }).and_return("result = get_object(\"Endpoint\", host.name).attribute + \"string\"\n") + is_expected.to run.with_params( + { + 'result' => 'get_object(Endpoint, host.name).attribute + string', + }, + ).and_return("result = get_object(\"Endpoint\", host.name).attribute + \"string\"\n") # assign where (host.address || host.address6) && host.vars.os == "Linux" # assign where get_object("Endpoint", host.name) - is_expected.to run.with_params({ - 'assign where' => [ - '(host.address || host.address6) && host.vars.os == Linux', - 'get_object(Endpoint, host.name)' - ] - }).and_return("assign where (host.address || host.address6) && host.vars.os == \"Linux\"\nassign where get_object(\"Endpoint\", host.name)\n") + is_expected.to run.with_params( + { + 'assign where' => [ + '(host.address || host.address6) && host.vars.os == Linux', + 'get_object(Endpoint, host.name)', + ], + }, + ).and_return("assign where (host.address || host.address6) && host.vars.os == \"Linux\"\nassign where get_object(\"Endpoint\", host.name)\n") # ignore where get_object("Endpoint", host.name) || host.vars.os != "Windows" - is_expected.to run.with_params({ - 'ignore where' => [ - 'get_object(Endpoint, host.name) || host.vars.os != Windows' - ] - }).and_return("ignore where get_object(\"Endpoint\", host.name) || host.vars.os != \"Windows\"\n") + is_expected.to run.with_params( + { + 'ignore where' => [ + 'get_object(Endpoint, host.name) || host.vars.os != Windows', + ], + }, + ).and_return("ignore where get_object(\"Endpoint\", host.name) || host.vars.os != \"Windows\"\n") end it 'disable parsing' do - # result = "unparsed string NodeName with quotes" - is_expected.to run.with_params({ - 'result' => '-:"unparsed string NodeName with quotes"' - }).and_return("result = \"unparsed string NodeName with quotes\"\n") + is_expected.to run.with_params( + { + 'result' => '-:"unparsed string NodeName with quotes"', + }, + ).and_return("result = \"unparsed string NodeName with quotes\"\n") # result = "unparsed string NodeName with quotes", ] - is_expected.to run.with_params({ - 'result' => [ '-:"unparsed string NodeName with quotes"' ] - }).and_return("result = [ \"unparsed string NodeName with quotes\", ]\n") + is_expected.to run.with_params( + { + 'result' => [ '-:"unparsed string NodeName with quotes"' ], + }, + ).and_return("result = [ \"unparsed string NodeName with quotes\", ]\n") # result = { # string = "unparsed string NodeName with quotes", # } - is_expected.to run.with_params({ - 'result' => { 'string' => '-:"unparsed string NodeName with quotes"' } - }).and_return("result = {\n string = \"unparsed string NodeName with quotes\"\n}\n") - + is_expected.to run.with_params( + { + 'result' => { 'string' => '-:"unparsed string NodeName with quotes"' }, + }, + ).and_return("result = {\n string = \"unparsed string NodeName with quotes\"\n}\n") end - end diff --git a/spec/functions/icinga2_icinga2_attributes_spec.rb b/spec/functions/icinga2_icinga2_attributes_spec.rb index 68d80db..f82508f 100644 --- a/spec/functions/icinga2_icinga2_attributes_spec.rb +++ b/spec/functions/icinga2_icinga2_attributes_spec.rb @@ -1,41 +1,40 @@ require 'spec_helper' describe 'icinga2::icinga2_attributes' do # without knowing details about the implementation, this is the only test # case that we can autogenerate. You should add more examples below! it { is_expected.not_to eq(nil) } -################################# -# Below are some example test cases. You may uncomment and modify them to match -# your needs. Notice that they all expect the base error class of `StandardError`. -# This is because the autogenerated function uses an untyped array for parameters -# and relies on your implementation to do the validation. As you convert your -# function to proper dispatches and typed signatures, you should change the -# expected error of the argument validation examples to `ArgumentError`. -# -# Other error types you might encounter include -# -# * StandardError -# * ArgumentError -# * Puppet::ParseError -# -# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ -# -# it 'raises an error if called with no argument' do -# is_expected.to run.with_params.and_raise_error(StandardError) -# end -# -# it 'raises an error if there is more than 1 arguments' do -# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) -# end -# -# it 'raises an error if argument is not the proper type' do -# is_expected.to run.with_params('foo').and_raise_error(StandardError) -# end -# -# it 'returns the proper output' do -# is_expected.to run.with_params(123).and_return('the expected output') -# end -################################# - + ################################# + # Below are some example test cases. You may uncomment and modify them to match + # your needs. Notice that they all expect the base error class of `StandardError`. + # This is because the autogenerated function uses an untyped array for parameters + # and relies on your implementation to do the validation. As you convert your + # function to proper dispatches and typed signatures, you should change the + # expected error of the argument validation examples to `ArgumentError`. + # + # Other error types you might encounter include + # + # * StandardError + # * ArgumentError + # * Puppet::ParseError + # + # Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ + # + # it 'raises an error if called with no argument' do + # is_expected.to run.with_params.and_raise_error(StandardError) + # end + # + # it 'raises an error if there is more than 1 arguments' do + # is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) + # end + # + # it 'raises an error if argument is not the proper type' do + # is_expected.to run.with_params('foo').and_raise_error(StandardError) + # end + # + # it 'returns the proper output' do + # is_expected.to run.with_params(123).and_return('the expected output') + # end + ################################# end diff --git a/spec/functions/icinga2_icinga2_ticket_id_spec.rb b/spec/functions/icinga2_icinga2_ticket_id_spec.rb index ab37b93..9736015 100644 --- a/spec/functions/icinga2_icinga2_ticket_id_spec.rb +++ b/spec/functions/icinga2_icinga2_ticket_id_spec.rb @@ -1,41 +1,40 @@ require 'spec_helper' describe 'icinga2::icinga2_ticket_id' do # without knowing details about the implementation, this is the only test # case that we can autogenerate. You should add more examples below! it { is_expected.not_to eq(nil) } -################################# -# Below are some example test cases. You may uncomment and modify them to match -# your needs. Notice that they all expect the base error class of `StandardError`. -# This is because the autogenerated function uses an untyped array for parameters -# and relies on your implementation to do the validation. As you convert your -# function to proper dispatches and typed signatures, you should change the -# expected error of the argument validation examples to `ArgumentError`. -# -# Other error types you might encounter include -# -# * StandardError -# * ArgumentError -# * Puppet::ParseError -# -# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ -# -# it 'raises an error if called with no argument' do -# is_expected.to run.with_params.and_raise_error(StandardError) -# end -# -# it 'raises an error if there is more than 1 arguments' do -# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) -# end -# -# it 'raises an error if argument is not the proper type' do -# is_expected.to run.with_params('foo').and_raise_error(StandardError) -# end -# -# it 'returns the proper output' do -# is_expected.to run.with_params(123).and_return('the expected output') -# end -################################# - + ################################# + # Below are some example test cases. You may uncomment and modify them to match + # your needs. Notice that they all expect the base error class of `StandardError`. + # This is because the autogenerated function uses an untyped array for parameters + # and relies on your implementation to do the validation. As you convert your + # function to proper dispatches and typed signatures, you should change the + # expected error of the argument validation examples to `ArgumentError`. + # + # Other error types you might encounter include + # + # * StandardError + # * ArgumentError + # * Puppet::ParseError + # + # Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ + # + # it 'raises an error if called with no argument' do + # is_expected.to run.with_params.and_raise_error(StandardError) + # end + # + # it 'raises an error if there is more than 1 arguments' do + # is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) + # end + # + # it 'raises an error if argument is not the proper type' do + # is_expected.to run.with_params('foo').and_raise_error(StandardError) + # end + # + # it 'returns the proper output' do + # is_expected.to run.with_params(123).and_return('the expected output') + # end + ################################# end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d3778ca..9b1fa6f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,57 +1,73 @@ # 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 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), [], [], true)) rescue => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end # read default_facts and merge them over what is provided by facterdb default_facts.each do |fact, value| add_custom_fact fact, value end 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 end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end end # 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) end end # 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e01a077..386093d 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,48 +1,48 @@ require 'beaker-rspec' require 'beaker/puppet_install_helper' # Install Puppet on all hosts -install_puppet_agent_on(hosts, :puppet_collection => 'puppet5') +install_puppet_agent_on(hosts, puppet_collection: 'puppet5') RSpec.configure do |c| module_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) c.formatter = :documentation c.before :suite do # Install module to all hosts hosts.each do |host| - install_dev_puppet_module_on(host, :source => module_root, :module_name => 'icinga2', - :target_module_path => '/etc/puppetlabs/code/modules') + install_dev_puppet_module_on(host, source: module_root, module_name: 'icinga2', + target_module_path: '/etc/puppetlabs/code/modules') # Install dependencies on(host, puppet('module', 'install', 'icinga-icinga')) on(host, puppet('module', 'install', 'puppetlabs-stdlib')) on(host, puppet('module', 'install', 'puppetlabs-concat')) # Install additional modules on(host, puppet('module', 'install', 'puppetlabs-mysql')) on(host, puppet('module', 'install', 'puppetlabs-postgresql')) if fact('os.family') == 'Debian' on(host, puppet('module', 'install', 'puppetlabs-apt')) end if fact('os.family') == 'Suse' on(host, puppet('module', 'install', 'puppet-zypprepo')) end # Add more setup code as needed end end end shared_examples 'a idempotent resource' do it 'applies with no errors' do apply_manifest(pp, catch_failures: true) end it 'applies a second time without changes', :skip_pup_5016 do apply_manifest(pp, catch_changes: true) end end diff --git a/spec/type_aliases/logserverity.rb b/spec/type_aliases/logserverity.rb deleted file mode 100644 index 1ee6573..0000000 --- a/spec/type_aliases/logserverity.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'spec_helper' - -if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 - - describe 'Icinga2::LogSeverity' do - describe 'valid handling' do - [ - 'LOG_AUTH', - 'LOG_AUTHPRIV', - 'LOG_CRON', - 'LOG_DAEMON', - 'LOG_FTP', - 'LOG_KERN', - 'LOG_LPR', - 'LOG_MAIL', - 'LOG_NEWS', - 'LOG_SYSLOG', - 'LOG_USER', - 'LOG_UUCP', - 'LOG_LOCAL0', - 'LOG_LOCAL1', - 'LOG_LOCAL2', - 'LOG_LOCAL3', - 'LOG_LOCAL4', - 'LOG_LOCAL5', - 'LOG_LOCAL6', - 'LOG_LOCAL7', - ].each do |value| - describe value.inspect do - it { is_expected.to allow_value(value) } - end - end - end - - describe 'invalid path handling' do - context 'garbage inputs' do - [nil, '', 'foo'].each do |value| - describe value.inspect do - it { is_expected.not_to allow_value(value) } - end - end - end - end - end - -end diff --git a/spec/type_aliases/logseverity.rb b/spec/type_aliases/logseverity_spec.rb similarity index 89% rename from spec/type_aliases/logseverity.rb rename to spec/type_aliases/logseverity_spec.rb index f0d28ad..be9f757 100644 --- a/spec/type_aliases/logseverity.rb +++ b/spec/type_aliases/logseverity_spec.rb @@ -1,27 +1,27 @@ require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 describe 'Icinga2::LogSeverity' do describe 'valid handling' do [ - 'debug', 'information', 'notice', 'warning', 'critical', + 'debug', 'information', 'notice', 'warning', 'critical' ].each do |value| describe value.inspect do it { is_expected.to allow_value(value) } end end end describe 'invalid path handling' do context 'garbage inputs' do [nil, '', 'foo'].each do |value| describe value.inspect do it { is_expected.not_to allow_value(value) } end end end end end end diff --git a/spec/unit/facter/util/fact_icinga2_puppet_hostcert_spec.rb b/spec/unit/facter/util/fact_icinga2_puppet_hostcert_spec.rb deleted file mode 100644 index 62570cc..0000000 --- a/spec/unit/facter/util/fact_icinga2_puppet_hostcert_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'spec_helper' - -describe Facter::Util::Fact do - on_supported_os.each do |os, facts| - let(:facts) do - facts - end - - context "#{os} icinga2_puppet_hostcert fact" do - it { expect(Facter.fact(:icinga2_puppet_hostcert).value).to match(/\/ssl\/certs\/.*.pem/) } - end - end -end - -describe('icinga2::feature::gelf', :type => :class) do - let(:facts) do - { - :kernel => 'Windows', - :os => { - 'architecture' => 'x86_64', - 'family' => 'Windows', - 'name' => 'Windows', - 'release' => {'major' => '2012 R2'} - }, - :path => 'C:\Program Files\Puppet Labs\Puppet\puppet\bin; - C:\Program Files\Puppet Labs\Puppet\facter\bin; - C:\Program Files\Puppet Labs\Puppet\hiera\bin; - C:\Program Files\Puppet Labs\Puppet\mcollective\bin; - C:\Program Files\Puppet Labs\Puppet\bin; - C:\Program Files\Puppet Labs\Puppet\sys\ruby\bin; - C:\Program Files\Puppet Labs\Puppet\sys\tools\bin; - C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem; - C:\Windows\System32\WindowsPowerShell\v1.0\; - C:\ProgramData\chocolatey\bin;', - } - end - - context "Windows 2012 R2 icinga2_puppet_hostcert fact" do - it { expect(Facter.fact(:icinga2_puppet_hostcert).value).to match(/\/ssl\/certs\/.*.pem/) } - end - -end diff --git a/spec/unit/facter/util/fact_icinga2_puppet_hostprivkey_spec.rb b/spec/unit/facter/util/fact_icinga2_puppet_hostprivkey_spec.rb deleted file mode 100644 index bada001..0000000 --- a/spec/unit/facter/util/fact_icinga2_puppet_hostprivkey_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'spec_helper' - -describe Facter::Util::Fact do - on_supported_os.each do |os, facts| - let :facts do - facts - end - - context "#{os} icinga2_puppet_hostprivkey fact" do - it { expect(Facter.fact(:icinga2_puppet_hostprivkey).value).to match(/\/ssl\/private_keys\/.*.pem/) } - end - end -end - -describe('icinga2::feature::gelf', :type => :class) do - let(:facts) do - { - :kernel => 'Windows', - :os => { - 'architecture' => 'x86_64', - 'family' => 'Windows', - 'name' => 'Windows', - 'release' => {'major' => '2012 R2'} - }, - :path => 'C:\Program Files\Puppet Labs\Puppet\puppet\bin; - C:\Program Files\Puppet Labs\Puppet\facter\bin; - C:\Program Files\Puppet Labs\Puppet\hiera\bin; - C:\Program Files\Puppet Labs\Puppet\mcollective\bin; - C:\Program Files\Puppet Labs\Puppet\bin; - C:\Program Files\Puppet Labs\Puppet\sys\ruby\bin; - C:\Program Files\Puppet Labs\Puppet\sys\tools\bin; - C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem; - C:\Windows\System32\WindowsPowerShell\v1.0\; - C:\ProgramData\chocolatey\bin;', - } - end - - context "Windows 2012 R2 icinga2_puppet_hostprivkey fact" do - it { expect(Facter.fact(:icinga2_puppet_hostprivkey).value).to match(/\/ssl\/private_keys\/.*.pem/) } - end - -end diff --git a/spec/unit/facter/util/fact_icinga2_puppet_localcacert_spec.rb b/spec/unit/facter/util/fact_icinga2_puppet_localcacert_spec.rb deleted file mode 100644 index 06e5857..0000000 --- a/spec/unit/facter/util/fact_icinga2_puppet_localcacert_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'spec_helper' - -describe Facter::Util::Fact do - on_supported_os.each do |os, facts| - let :facts do - facts - end - - context "#{os} icinga2_puppet_localcacert fact" do - it { expect(Facter.fact(:icinga2_puppet_localcacert).value).to match(/\/ssl\/certs\/.*.pem/) } - end - end -end - -describe('icinga2::feature::gelf', :type => :class) do - let(:facts) do - { - :kernel => 'Windows', - :os => { - 'architecture' => 'x86_64', - 'family' => 'Windows', - 'name' => 'Windows', - 'release' => {'major' => '2012 R2'} - }, - :path => 'C:\Program Files\Puppet Labs\Puppet\puppet\bin; - C:\Program Files\Puppet Labs\Puppet\facter\bin; - C:\Program Files\Puppet Labs\Puppet\hiera\bin; - C:\Program Files\Puppet Labs\Puppet\mcollective\bin; - C:\Program Files\Puppet Labs\Puppet\bin; - C:\Program Files\Puppet Labs\Puppet\sys\ruby\bin; - C:\Program Files\Puppet Labs\Puppet\sys\tools\bin; - C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem; - C:\Windows\System32\WindowsPowerShell\v1.0\; - C:\ProgramData\chocolatey\bin;', - } - end - - context "Windows 2012 R2 icinga2_puppet_localcacert fact" do - it { expect(Facter.fact(:icinga2_puppet_localcacert).value).to match(/\/ssl\/certs\/.*.pem/) } - end - -end diff --git a/spec/unit/facter/util/fact_icinga2_puppet_spec.rb b/spec/unit/facter/util/fact_icinga2_puppet_spec.rb new file mode 100644 index 0000000..69f311f --- /dev/null +++ b/spec/unit/facter/util/fact_icinga2_puppet_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Facter::Util::Fact do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context "#{os} icinga2_puppet_hostcert fact" do + it { expect(Facter.fact(:icinga2_puppet_hostcert).value).to match(%r{/ssl/certs/.*.pem}) } + end + + context "#{os} icinga2_puppet_hostprivkey fact" do + it { expect(Facter.fact(:icinga2_puppet_hostprivkey).value).to match(%r{/ssl/private_keys/.*.pem}) } + end + + context "#{os} icinga2_puppet_localcacert fact" do + it { expect(Facter.fact(:icinga2_puppet_localcacert).value).to match(%r{/ssl/certs/.*.pem}) } + end + end + end +end