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..8f782e7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,137 +1,519 @@ --- require: +- rubocop-performance - rubocop-rspec -- rubocop-i18n AllCops: DisplayCopNames: true - TargetRubyVersion: '2.1' + TargetRubyVersion: '2.4' Include: - - "./**/*.rb" + - "**/*.rb" Exclude: - bin/* - ".vendor/**/*" - "**/Gemfile" - "**/Rakefile" - pkg/**/* - spec/fixtures/**/* - vendor/**/* - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" -Metrics/LineLength: +Layout/LineLength: Description: People have wide screens, use them. Max: 200 -GetText: - Enabled: false -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. Exclude: - spec/acceptance/**/*.rb RSpec/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each +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/AUTHORS b/AUTHORS index b6b1b17..bc31d93 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,50 +1,53 @@ Alexandre Beche Alexandre R Gomes Andrew Choo Benjamin Krein Bill Scheidegger Blerim Sheqa Bram Vogelaar Bram Vogelaar CV Dennis Hoppe Devin Christensen Eric Lippmann Eric Zounes Florian Baumann James Weakly Jan Collijs Johan Fleury Jonas Verhofsté Josh Beard Joshua Hoblitt Khanh Ngo Lennart Betz Leo Antunes Lorenz Bischof Markus Frosch +Markus Zilch Martin Jansen Matthias Baur Michael Friedrich Nicolas Dandrimont Ott, Jörn WI (Fa. Goetzfried) Paolo Schiro Pavel Pulec Peter Souter Robert Waffen +Ruben Bosch Rudy Gevaert Sebastian Brückner Stefan Kleindl +Steffen Zieger Steffen Zieger Steven Bambling Tim Bishop Timo Goebel Tokynet Tom De Vylder Tomislav Dukaric Vladimir Smirnov XnS Zach Leslie david.leib@barzahlen.de marco.fretz plarivee diff --git a/Gemfile b/Gemfile index 77ff14c..a167b88 100644 --- a/Gemfile +++ b/Gemfile @@ -1,73 +1,62 @@ 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 "github_changelog_generator", '~> 1.15', require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') + 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] +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 0f8d7cd..2906c15 100644 --- a/Rakefile +++ b/Rakefile @@ -1,87 +1,88 @@ # 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 = "Icinga" || JSON.load(File.read('metadata.json'))['author'] + 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_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/data/common.yaml b/data/common.yaml index 019390a..3ecfe5a 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,24 +1,24 @@ --- icingaweb2::conf_group: icingaweb2 icingaweb2::admin_role: - name: default admin users + name: default admin user users: - icingaadmin icingaweb2::default_admin_username: icingaadmin icingaweb2::default_admin_password: icinga icingaweb2::module::businessprocess::git_repository: https://github.com/Icinga/icingaweb2-module-businessprocess.git icingaweb2::module::cube::git_repository: https://github.com/Icinga/icingaweb2-module-cube.git icingaweb2::module::director::git_repository: https://github.com/Icinga/icingaweb2-module-director.git icingaweb2::module::elasticsearch::git_repository: https://github.com/Icinga/icingaweb2-module-elasticsearch.git icingaweb2::module::fileshipper::git_repository: https://github.com/Icinga/icingaweb2-module-fileshipper.git icingaweb2::module::generictts::git_repository: https://github.com/Icinga/icingaweb2-module-generictts.git icingaweb2::module::graphite::git_repository: https://github.com/Icinga/icingaweb2-module-graphite.git icingaweb2::module::incubator::git_repository: https://github.com/Icinga/icingaweb2-module-incubator.git icingaweb2::module::incubator::git_revision: v0.5.0 icingaweb2::module::ipl::git_repository: https://github.com/Icinga/icingaweb2-module-ipl.git icingaweb2::module::ipl::git_revision: v0.5.0 icingaweb2::module::puppetdb::git_repository: https://github.com/Icinga/icingaweb2-module-puppetdb.git icingaweb2::module::reactbundle::git_repository: https://github.com/Icinga/icingaweb2-module-reactbundle.git icingaweb2::module::reactbundle::git_revision: v0.7.0 icingaweb2::module::vsphere::git_repository: https://github.com/Icinga/icingaweb2-module-vsphere.git icingaweb2::module::vspheredb::git_repository: https://github.com/Icinga/icingaweb2-module-vspheredb.git diff --git a/manifests/config.pp b/manifests/config.pp index ea06992..8069fdb 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,194 +1,195 @@ # @summary # Configures Icinga Web 2. # # @api private # class icingaweb2::config { $conf_dir = $::icingaweb2::globals::conf_dir $conf_user = $::icingaweb2::conf_user $conf_group = $::icingaweb2::conf_group $logging = $::icingaweb2::logging $logging_file = $::icingaweb2::logging_file $logging_dir = dirname($::icingaweb2::logging_file) $logging_level = $::icingaweb2::logging_level $logging_facility = $::icingaweb2::logging_facility $logging_application = $::icingaweb2::logging_application $show_stacktraces = $::icingaweb2::show_stacktraces $module_path = $::icingaweb2::module_path $theme = $::icingaweb2::theme $theme_disabled = $::icingaweb2::theme_disabled $cookie_path = $::icingaweb2::cookie_path $import_schema = $::icingaweb2::import_schema $mysql_db_schema = $::icingaweb2::globals::mysql_db_schema $pgsql_db_schema = $::icingaweb2::globals::pgsql_db_schema $db_name = $::icingaweb2::db_name $db_host = $::icingaweb2::db_host $db_port = $::icingaweb2::db_port $db_type = $::icingaweb2::db_type $db_username = $::icingaweb2::db_username $db_password = $::icingaweb2::db_password $default_domain = $::icingaweb2::default_domain $admin_role = $::icingaweb2::admin_role $admin_username = $::icingaweb2::default_admin_username $admin_password = $::icingaweb2::default_admin_password $config_backend = $::icingaweb2::config_backend $config_resource = $::icingaweb2::config_backend ? { 'ini' => undef, 'db' => "${db_type}-icingaweb2", } File { mode => '0660', owner => $conf_user, group => $conf_group } Exec { user => 'root', path => $::path, } file { $logging_dir: ensure => directory, mode => '0750', } file { $logging_file: ensure => file, mode => '0640', } icingaweb2::inisection { 'config-logging': section_name => 'logging', target => "${conf_dir}/config.ini", settings => { 'log' => $logging, 'file' => $logging_file, 'level' => $logging_level, 'facility' => $logging_facility, 'application' => $logging_application, }, } $settings = { 'show_stacktraces' => $show_stacktraces, 'module_path' => $module_path, 'config_backend' => $config_backend, 'config_resource' => $config_resource, } icingaweb2::inisection { 'config-global': section_name => 'global', target => "${conf_dir}/config.ini", settings => delete_undef_values($settings), } if $default_domain { icingaweb2::inisection { 'config-authentication': section_name => 'authentication', target => "${conf_dir}/config.ini", settings => { 'default_domain' => $default_domain, } } } icingaweb2::inisection { 'config-themes': section_name => 'themes', target => "${conf_dir}/config.ini", settings => { 'default' => $theme, 'disabled' => $theme_disabled, }, } if $cookie_path { icingaweb2::inisection {'config-cookie': section_name => 'cookie', target => "${conf_dir}/config.ini", settings => { 'path' => $cookie_path, }, } } file { "${conf_dir}/modules": ensure => 'directory', mode => '2770', } file { "${conf_dir}/enabledModules": ensure => 'directory', mode => '2770', } if $import_schema or $config_backend == 'db' { icingaweb2::config::resource { "${db_type}-icingaweb2": type => 'db', host => $db_host, port => $db_port, db_type => $db_type, db_name => $db_name, db_username => $db_username, db_password => $db_password, } icingaweb2::config::groupbackend { "${db_type}-group": backend => 'db', resource => "${db_type}-icingaweb2" } - + icingaweb2::config::authmethod { "${db_type}-auth": backend => 'db', resource => "${db_type}-icingaweb2" } } - if $admin_role { - icingaweb2::config::role { $admin_role['name']: - users => if $admin_role['users'] { join(union([$admin_username], $admin_role['users'])) } else { $admin_username }, - groups => if $admin_role['groups'] { join($admin_role['groups']) } else { undef }, - permissions => '*', + if $import_schema { + + if $admin_role { + icingaweb2::config::role { $admin_role['name']: + users => if $admin_role['users'] { join(union([$admin_username], $admin_role['users'])) } else { $admin_username }, + groups => if $admin_role['groups'] { join($admin_role['groups']) } else { undef }, + permissions => '*', + } } - } - if $import_schema { case $db_type { 'mysql': { exec { 'import schema': command => "mysql -h '${db_host}' -P '${db_port}' -u '${db_username}' -p'${db_password}' '${db_name}' < '${mysql_db_schema}'", unless => "mysql -h '${db_host}' -P '${db_port}' -u '${db_username}' -p'${db_password}' '${db_name}' -Ns -e 'SELECT 1 FROM icingaweb_user'", notify => Exec['create default admin user'], } exec { 'create default admin user': command => "echo \"INSERT INTO icingaweb_user (name, active, password_hash) VALUES (\\\"${admin_username}\\\", 1, \\\"`php -r 'echo password_hash(\"${admin_password}\", PASSWORD_DEFAULT);'`\\\")\" | mysql -h '${db_host}' -P '${db_port}' -u '${db_username}' -p'${db_password}' '${db_name}' -Ns", refreshonly => true, } } 'pgsql': { exec { 'import schema': environment => ["PGPASSWORD=${db_password}"], command => "psql -h '${db_host}' -p '${db_port}' -U '${db_username}' -d '${db_name}' -w -f ${pgsql_db_schema}", unless => "echo \"INSERT INTO icingaweb_user (name, active, password_hash) VALUES (\\\"${admin_username}\\\", 1, \\\"`php -r 'echo password_hash(\"${admin_password}\", PASSWORD_DEFAULT);'`\\\")\" | psql -h '${db_host}' -p '${db_port}' -U '${db_username}' -d '${db_name}' -w", notify => Exec['create default admin user'], } exec { 'create default admin user': environment => ["PGPASSWORD=${db_password}"], command => "psql -h '${db_host}' -p '${db_port}' -U '${db_username}' -d '${db_name}' -w -c \"INSERT INTO icingaweb_user(name, active, password_hash) VALUES ('icingaadmin', 1, '\\\$1\\\$3no6eqZp\\\$FlcHQDdnxGPqKadmfVcCU.')\"", refreshonly => true, } } default: { fail('The database type you provided is not supported.') } } } } diff --git a/manifests/init.pp b/manifests/init.pp index e5ceeea..3b8cf86 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,190 +1,190 @@ # @summary # Installs and configures Icinga Web 2. # # @param [Enum['file', 'syslog', 'php', 'none']] logging # Whether Icinga Web 2 should log to 'file', 'syslog' or 'php' (web server's error log). Setting 'none' disables logging. # # @param [Stdlib::Absolutepath] logging_file # If 'logging' is set to 'file', this is the target log file. # # @param [Enum['ERROR', 'WARNING', 'INFO', 'DEBUG']] logging_level # Logging verbosity. Possible values are 'ERROR', 'WARNING', 'INFO' and 'DEBUG'. # # @param [Pattern[/user|local[0-7]/]] logging_facility # Logging facility when using syslog. Possible values are 'user' or 'local0' up to 'local7'. # # @param [String] logging_application # Logging application name when using syslog. # # @param [Boolean] show_stacktraces # Whether to display stacktraces in the web interface or not. # # @param [Stdlib::Absolutepath] module_path # Path to module sources. Multiple paths must be separated by colon. # # @param [String] theme # The default theme setting. Users may override this settings. # # @param [Boolean] theme_disabled # Whether users can change themes or not. # # @param [Boolean] manage_repo # Deprecated, use manage_repos. # # @param [Boolean] manage_repos # When set to true this module will use the module icinga/puppet-icinga to manage repositories, # e.g. the release repo on packages.icinga.com repository by default, the EPEL repository or Backports. # For more information, see http://github.com/icinga/puppet-icinga. # # @param [Boolean] manage_package # If set to `false` packages aren't managed. # # @param [Optional[Array[String]]] extra_packages # An array of packages to install additionally. # # @param [Boolean] import_schema # Import database scheme. Make sure you have an existing database if you use this option. # # @param [Enum['mysql', 'pgsql']] db_type # Database type, can be either `mysql` or `pgsql`. This parameter is only used if `import_schema` is `true` or # `config_backend` is `db`. # # @param [Stdlib::Host] db_host # Database hostname. This parameter is only used if `import_schema` is `true` or # `config_backend` is `db`. # # @param [Stdlib::Port] db_port # Port of database host. This parameter is only used if `import_schema` is `true` or # `config_backend` is `db`. # # @param [String] db_name # Database name. This parameter is only used if `import_schema` is `true` or # `config_backend` is `db`. # # @param [Optional[String]] db_username # Username for database access. This parameter is only used if `import_schema` is `true` or # `config_backend` is `db`. # # @param [Optional[String]] db_password # Password for database access. This parameter is only used if `import_schema` is `true` or # `config_backend` is `db`. # # @param [Enum['ini', 'db']] config_backend # The global Icinga Web 2 preferences can either be stored in a database or in ini files. This parameter can either # be set to `db` or `ini`. # # @param [String] conf_user # By default this module expects Apache2 on the server. You can change the owner of the config files with this # parameter. # # @param [String] conf_group # Group membership of config files. # # @param [Optional[String]] default_domain # When using domain-aware authentication, you can set a default domain here. # # @param [Optional[Stdlib::Absolutepath]] cookie_path # Path to where cookies are stored. # # @param [Variant[Struct[{name => String, users => Optional[Array[String]], groups => Optional[Array[String]]}], Boolean[false]]] admin_role # Manage a role for admin access. # # @param String default_admin_username # Default username for initial admin access. This parameter is only used # if `import_schema` is set to `true` and only during the import itself. # # @param String default_admin_password # Default password for initial admin access. This parameter is only used # if `import_schema` is set to `true` and only during the import itself. # # @example Use MySQL as backend for user authentication: # include ::mysql::server # # mysql::db { 'icingaweb2': # user => 'icingaweb2', # password => 'supersecret', # host => 'localhost', # grant => [ 'ALL' ], # } # # class {'icingaweb2': # manage_repos => true, # import_schema => true, # db_type => 'mysql', # db_host => 'localhost', # db_port => 3306, # db_username => 'icingaweb2', # db_password => 'supersecret', # require => Mysql::Db['icingaweb2'], # } # # @example Use PostgreSQL as backend for user authentication: # include ::postgresql::server # # postgresql::server::db { 'icingaweb2': # user => 'icingaweb2', # password => postgresql_password('icingaweb2', 'icingaweb2'), # } # # class {'icingaweb2': # manage_repos => true, # import_schema => true, # db_type => 'pgsql', # db_host => 'localhost', # db_port => 5432, # db_username => 'icingaweb2', # db_password => 'icingaweb2', # require => Postgresql::Server::Db['icingaweb2'], # } # class icingaweb2 ( Stdlib::Absolutepath $module_path, Stdlib::Absolutepath $logging_file, String $conf_user, String $conf_group, + Variant[ + Struct[{ + name => String, + users => Optional[Array[String]], + groups => Optional[Array[String]] + }], Boolean[false]] $admin_role, + String $default_admin_username, + String $default_admin_password, Enum['file', 'syslog', 'php', 'none'] $logging = 'file', Enum['ERROR', 'WARNING', 'INFO', 'DEBUG'] $logging_level = 'INFO', Pattern[/user|local[0-7]/] $logging_facility = 'user', String $logging_application = 'icingaweb2', Boolean $show_stacktraces = false, String $theme = 'Icinga', Boolean $theme_disabled = false, Boolean $manage_repo = false, Boolean $manage_repos = false, Boolean $manage_package = true, Optional[Array[String]] $extra_packages = undef, Boolean $import_schema = false, Enum['mysql', 'pgsql'] $db_type = 'mysql', Stdlib::Host $db_host = 'localhost', Stdlib::Port $db_port = 3306, String $db_name = 'icingaweb2', Optional[String] $db_username = undef, Optional[String] $db_password = undef, Enum['ini', 'db'] $config_backend = 'ini', Optional[String] $default_domain = undef, Optional[Stdlib::Absolutepath] $cookie_path = undef, - Variant[ - Struct[{ - name => String, - users => Optional[Array[String]], - groups => Optional[Array[String]] - }], Boolean[false]] $admin_role, - String $default_admin_username, - String $default_admin_password, ) { require ::icingaweb2::globals if $manage_repos or $manage_repo { require ::icinga::repos if $manage_repo { deprecation('manage_repo', 'manage_repo is deprecated and will be replaced by manage_repos in the future.') } } class { '::icingaweb2::install': } -> class { '::icingaweb2::config': } contain ::icingaweb2::install contain ::icingaweb2::config } diff --git a/manifests/module/director/service.pp b/manifests/module/director/service.pp index 821916e..80b7d83 100644 --- a/manifests/module/director/service.pp +++ b/manifests/module/director/service.pp @@ -1,57 +1,57 @@ # @summary # Installs and configures the director service. # # @note Only systemd is supported by the Icinga Team and this module. # # @param [Stdlib::Ensure::Service] ensure # Whether the director service should be running. # # @param [Boolean] enable # Enable or disable the service. # # @param [String] user # Specifies user to run director service daemon. Only available if # install_method package is not used. # # @param [String] group # Specifies primary group for user to run director service daemon. # Only available if install_method package is not used. # # @param [Boolean] manage_user # Whether to manage the server user resource. Only available if # install_method package is not used. # class icingaweb2::module::director::service( Stdlib::Ensure::Service $ensure = 'running', Boolean $enable = true, String $user = 'icingadirector', String $group = 'icingaweb2', Boolean $manage_user = true, ) { require ::icingaweb2::module::director $icingacli_bin = $::icingaweb2::globals::icingacli_bin $install_method = $::icingaweb2::module::director::install_method if $install_method != 'package' { if $manage_user { user { $user: ensure => present, gid => $group, shell => '/bin/false', before => Systemd::Unit_file['icinga-director.service'], } } - + systemd::unit_file { 'icinga-director.service': content => template('icingaweb2/icinga-director.service.erb'), notify => Service['icinga-director'], } } service {'icinga-director': ensure => $ensure, enable => $enable, } } diff --git a/metadata.json b/metadata.json index 31ff39e..436d0f8 100644 --- a/metadata.json +++ b/metadata.json @@ -1,87 +1,87 @@ { "name": "icinga-icingaweb2", "version": "3.1.0", "author": "Icinga Team", "summary": "Icinga Web 2 Puppet Module", "license": "Apache-2.0", "source": "git://github.com/Icinga/puppet-icingaweb2", "project_page": "https://github.com/Icinga/puppet-icingaweb2", "issues_url": "https://github.com/Icinga/puppet-icingaweb2/issues", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.25.0 < 9.0.0" }, { "name": "puppetlabs/concat", "version_requirement": ">= 2.0.1 < 8.0.0" }, { "name": "icinga/icinga", "version_requirement": ">= 1.0.0 < 3.0.0" }, { "name": "puppetlabs/vcsrepo", "version_requirement": ">= 1.3.0 < 6.0.0" }, { "name": "puppet/systemd", "version_requirement": ">= 1.1.1 < 4.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Debian", "operatingsystemrelease": [ "9", "10" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ "6", "7", "8" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "6", "7", "8" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "16.04", "18.04", "20.04" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "12", "15" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 4.7.0 < 8.0.0" } ], "tags": [ "icinga", "icinga2", "icingaweb2", "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/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 747d05b..bb04ae6 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,109 +1,120 @@ require 'spec_helper' describe('icingaweb2::config', type: :class) do on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context 'with default parameters' do let :pre_condition do "class { 'icingaweb2': }" end it { is_expected.to contain_icingaweb2__inisection('config-logging') } it { is_expected.to contain_icingaweb2__inisection('config-global') .with_settings('show_stacktraces' => false, 'module_path' => '/usr/share/icingaweb2/modules', 'config_backend' => 'ini') } it { is_expected.to contain_icingaweb2__inisection('config-themes') } it { is_expected.not_to contain_icingaweb2__inisection('config-cookie') } it { is_expected.to contain_file('/var/log/icingaweb2') .with_ensure('directory') .with_mode('0750') } it { is_expected.to contain_file('/var/log/icingaweb2/icingaweb2.log') .with_ensure('file') .with_mode('0640') } + it { is_expected.not_to contain_exec('import schema') } + it { is_expected.not_to contain_exec('create default admin user') } + it { is_expected.not_to contain_icingaweb2__config__role('default admin user') } end context 'with import_schema => true and db_type => mysql' do let :pre_condition do "class { 'icingaweb2': import_schema => true, db_type => 'mysql'}" end it { is_expected.to contain_icingaweb2__config__resource('mysql-icingaweb2') } it { is_expected.to contain_icingaweb2__config__authmethod('mysql-auth') } it { is_expected.to contain_icingaweb2__config__role('default admin user') } it { is_expected.to contain_exec('import schema') } - it { is_expected.to contain_exec('create default user') } + it { is_expected.to contain_exec('create default admin user') } end context 'with import_schema => true and db_type => pgsql' do let :pre_condition do "class { 'icingaweb2': import_schema => true, db_type => 'pgsql'}" end it { is_expected.to contain_icingaweb2__config__resource('pgsql-icingaweb2') } it { is_expected.to contain_icingaweb2__config__authmethod('pgsql-auth') } it { is_expected.to contain_icingaweb2__config__role('default admin user') } it { is_expected.to contain_exec('import schema') } - it { is_expected.to contain_exec('create default user') } + it { is_expected.to contain_exec('create default admin user') } end context 'with import_schema => true and invalid db_type' do let :pre_condition do "class { 'icingaweb2': import_schema => true, db_type => 'foobar'}" end it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['mysql', 'pgsql'\]}) } end - context 'with import_schema => false' do +# context 'with import_schema => false' do +# let :pre_condition do +# "class { 'icingaweb2': import_schema => false }" +# end +# +# it { is_expected.not_to contain_exec('import schema') } +# it { is_expected.not_to contain_exec('create default admin user') } +# it { is_expected.to contain_icingaweb2__config__role('default admin user') } +# end + + context 'with import_schema => true and admin_role => false' do let :pre_condition do - "class { 'icingaweb2': import_schema => false }" + "class { 'icingaweb2': import_schema => true, admin_role => false }" end - it { is_expected.not_to contain_exec('import schema') } - it { is_expected.not_to contain_exec('create default user') } it { is_expected.not_to contain_icingaweb2__config__role('default admin user') } end context 'with config_backend => db' do let :pre_condition do "class { 'icingaweb2': config_backend => 'db' }" end it { is_expected.to contain_icingaweb2__inisection('config-global') .with_settings('show_stacktraces' => false, 'module_path' => '/usr/share/icingaweb2/modules', 'config_backend' => 'db', 'config_resource' => 'mysql-icingaweb2') } it { is_expected.to contain_icingaweb2__config__resource('mysql-icingaweb2') } end context 'with cookie_path => /' do let :pre_condition do "class { 'icingaweb2': cookie_path => '/' }" end it { is_expected.to contain_icingaweb2__inisection('config-cookie') .with_settings('path' => '/') } end context 'with invalid config_backend' do let :pre_condition do "class { 'icingaweb2': config_backend => 'foobar' }" end it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['db', 'ini'\]}) } end end end end diff --git a/spec/classes/monitoring_spec.rb b/spec/classes/monitoring_spec.rb index c9f8391..66b506d 100644 --- a/spec/classes/monitoring_spec.rb +++ b/spec/classes/monitoring_spec.rb @@ -1,178 +1,180 @@ require 'spec_helper' describe('icingaweb2::module::monitoring', type: :class) do let(:pre_condition) do [ "class { 'icingaweb2': }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end case facts[:osfamily] when 'Debian' let(:install_method) { 'package' } let(:package_name) { 'icingaweb2-module-monitoring' } else let(:install_method) { 'none' } let(:package_name) { nil } end context "#{os} with ido_type 'mysql' and commandtransport 'api'" do let(:params) do { ido_type: 'mysql', ido_host: 'localhost', ido_db_name: 'icinga2', ido_db_username: 'icinga2', ido_db_password: 'icinga2', commandtransports: { 'foo' => { 'username' => 'root', 'password' => 'foobar', }, } } end it { is_expected.to contain_icingaweb2__module('monitoring') .with_install_method(install_method) .with_package_name(package_name) .with_module_dir('/usr/share/icingaweb2/modules/monitoring') .with_settings('module-monitoring-backends' => { 'section_name' => 'backends', 'target' => '/etc/icingaweb2/modules/monitoring/backends.ini', 'settings' => { 'type' => 'ido', 'resource' => 'icingaweb2-module-monitoring', }, }, 'module-monitoring-security' => { 'section_name' => 'security', 'target' => '/etc/icingaweb2/modules/monitoring/config.ini', 'settings' => { 'protected_customvars' => '*pw*,*pass*,community', }, - }) } + }) + } it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring') .with_type('db') .with_db_type('mysql') .with_host('localhost') .with_port('3306') .with_db_name('icinga2') .with_db_username('icinga2') .with_db_password('icinga2') } it { is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo') .with_username('root') .with_password('foobar') } end context "#{os} with ido_type 'pgsql' and commandtransport 'local'" do let(:params) do { ido_type: 'pgsql', ido_host: 'localhost', ido_port: 5432, ido_db_name: 'icinga2', ido_db_username: 'icinga2', ido_db_password: 'icinga2', commandtransports: { 'foo' => { 'transport' => 'local', }, } } end it do is_expected.to contain_icingaweb2__module('monitoring') .with_install_method(install_method) .with_package_name(package_name) .with_module_dir('/usr/share/icingaweb2/modules/monitoring') .with_settings('module-monitoring-backends' => { 'section_name' => 'backends', 'target' => '/etc/icingaweb2/modules/monitoring/backends.ini', 'settings' => { 'type' => 'ido', 'resource' => 'icingaweb2-module-monitoring', }, }, 'module-monitoring-security' => { 'section_name' => 'security', 'target' => '/etc/icingaweb2/modules/monitoring/config.ini', 'settings' => { 'protected_customvars' => '*pw*,*pass*,community', }, }) end it { is_expected.to contain_icingaweb2__config__resource('icingaweb2-module-monitoring') .with_type('db') .with_db_type('pgsql') .with_host('localhost') .with_port(5432) .with_db_name('icinga2') .with_db_username('icinga2') .with_db_password('icinga2') } if facts[:osfamily] == 'Debian' it { is_expected.to contain_package('icingaweb2-module-monitoring').with('ensure' => 'present') } end it { is_expected.to contain_icingaweb2__module__monitoring__commandtransport('foo') .with_transport('local') } end context "#{os} with invalid ido_type" do let(:params) { { ido_type: 'foobar' } } it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['mysql', 'pgsql'\]}) } end context "#{os} with array protected_customvars" do let(:params) do { ido_type: 'mysql', ido_host: 'localhost', ido_db_name: 'icinga2', ido_db_username: 'icinga2', ido_db_password: 'icinga2', commandtransports: { 'foo' => { 'transport' => 'local', }, }, protected_customvars: ['foo', 'bar', '*baz*'] } end it { is_expected.to contain_icingaweb2__module('monitoring') .with_settings('module-monitoring-backends' => { 'section_name' => 'backends', 'target' => '/etc/icingaweb2/modules/monitoring/backends.ini', 'settings' => { 'type' => 'ido', 'resource' => 'icingaweb2-module-monitoring', }, }, 'module-monitoring-security' => { 'section_name' => 'security', 'target' => '/etc/icingaweb2/modules/monitoring/config.ini', 'settings' => { 'protected_customvars' => 'foo,bar,*baz*', }, - }) } + }) + } end end end end diff --git a/spec/classes/translation_spec.rb b/spec/classes/translation_spec.rb index f9b8256..03a05c3 100644 --- a/spec/classes/translation_spec.rb +++ b/spec/classes/translation_spec.rb @@ -1,67 +1,68 @@ require 'spec_helper' describe('icingaweb2::module::translation', type: :class) do let(:pre_condition) do [ "class { 'icingaweb2': }", ] end on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context 'with ensure present' do let(:params) { { ensure: 'present' } } it { is_expected.to contain_icingaweb2__module('translation') .with_ensure('present') .with_install_method('none') .with_module_dir('/usr/share/icingaweb2/modules/translation') .with_settings('module-translation' => { 'section_name' => 'translation', 'target' => '/etc/icingaweb2/modules/translation/config.ini', 'settings' => { 'msgmerge' => '/usr/bin/msgmerge', 'xgettext' => '/usr/bin/xgettext', 'msgfmt' => '/usr/bin/msgfmt', }, - }) } + }) + } case facts[:osfamily] when 'Debian', 'RedHat' it { is_expected.to contain_package('gettext').with('ensure' => 'present') } when 'Suse' it { is_expected.to contain_package('gettext-tools').with('ensure' => 'present') } end end context 'with ensure absent' do let(:params) { { ensure: 'absent' } } it { is_expected.to contain_icingaweb2__module('translation') .with_ensure('absent') .with_install_method('none') .with_module_dir('/usr/share/icingaweb2/modules/translation') } case facts[:osfamily] when 'Debian', 'RedHat' it { is_expected.to contain_package('gettext').with('ensure' => 'absent') } when 'Suse' it { is_expected.to contain_package('gettext-tools').with('ensure' => 'absent') } end end context 'with ensure foobar' do let(:params) { { ensure: 'foobar' } } it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Enum\['absent', 'present'\]}) } end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b367fde..9b1fa6f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,61 +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