diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..72f5f42 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,7 @@ +# This file can be used to install module dependencies for unit testing +# See https://github.com/puppetlabs/puppetlabs_spec_helper#using-fixtures for details +--- +fixtures: + forge_modules: + stdlib: "puppetlabs/stdlib" + apt: "puppetlabs/apt" diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2803e56 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +.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/ +/.vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml +/spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..84684be --- /dev/null +++ b/.pdkignore @@ -0,0 +1,51 @@ +.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/ +/.vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml +/spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log +/.fixtures.yml +/Gemfile +/.gitattributes +/.github/ +/.gitignore +/.pdkignore +/.puppet-lint.rc +/Rakefile +/rakelib/ +/.rspec +/..yml +/.yardopts +/spec/ +/.vscode/ +/.sync.yml +/.devcontainer/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..9e15c6e --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,9 @@ +--fail-on-warnings +--relative +--no-80chars-check +--no-140chars-check +--no-class_inherits_from_params_class-check +--no-autoloader_layout-check +--no-documentation-check +--no-single_quote_string_with_variables-check +--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..16f9cdb --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..21b82b9 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,730 @@ +--- +require: +- rubocop-performance +- rubocop-rspec +AllCops: + NewCops: enable + DisplayCopNames: true + TargetRubyVersion: '2.6' + Include: + - "**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Layout/LineLength: + Description: People have wide screens, use them. + Max: 200 +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +RSpec/DescribeSymbol: + Exclude: + - spec/unit/facter/**/*.rb +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInArrayLiteral: + Description: Prefer always trailing comma on multiline literals. This makes diffs, + and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/SymbolArray: + Description: Using percent style obscures symbolic intent of array's contents. + EnforcedStyle: brackets +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* + - spec/**/* +Style/WordArray: + EnforcedStyle: brackets +Performance/AncestorsInclude: + Enabled: true +Performance/BigDecimalWithNumericArgument: + Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true +Performance/CaseWhenSplat: + Enabled: true +Performance/ConstantRegexp: + Enabled: true +Performance/MethodObjectAsBlock: + Enabled: true +Performance/RedundantSortBlock: + Enabled: true +Performance/RedundantStringChars: + Enabled: true +Performance/ReverseFirst: + Enabled: true +Performance/SortReverse: + Enabled: true +Performance/Squeeze: + Enabled: true +Performance/StringInclude: + Enabled: true +Performance/Sum: + Enabled: true +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +Bundler/GemFilename: + Enabled: false +Bundler/InsecureProtocolSource: + Enabled: false +Capybara/CurrentPathExpectation: + Enabled: false +Capybara/VisibilityMatcher: + Enabled: false +Gemspec/DuplicatedAssignment: + Enabled: false +Gemspec/OrderedDependencies: + Enabled: false +Gemspec/RequiredRubyVersion: + Enabled: false +Gemspec/RubyVersionGlobalsUsage: + Enabled: false +Layout/ArgumentAlignment: + Enabled: false +Layout/BeginEndAlignment: + Enabled: false +Layout/ClosingHeredocIndentation: + Enabled: false +Layout/EmptyComment: + Enabled: false +Layout/EmptyLineAfterGuardClause: + Enabled: false +Layout/EmptyLinesAroundArguments: + Enabled: false +Layout/EmptyLinesAroundAttributeAccessor: + Enabled: false +Layout/EndOfLine: + Enabled: false +Layout/FirstArgumentIndentation: + Enabled: false +Layout/HashAlignment: + Enabled: false +Layout/HeredocIndentation: + Enabled: false +Layout/LeadingEmptyLines: + Enabled: false +Layout/SpaceAroundMethodCallOperator: + Enabled: false +Layout/SpaceInsideArrayLiteralBrackets: + Enabled: false +Layout/SpaceInsideReferenceBrackets: + Enabled: false +Lint/BigDecimalNew: + Enabled: false +Lint/BooleanSymbol: + Enabled: false +Lint/ConstantDefinitionInBlock: + Enabled: false +Lint/DeprecatedOpenSSLConstant: + Enabled: false +Lint/DisjunctiveAssignmentInConstructor: + Enabled: false +Lint/DuplicateElsifCondition: + Enabled: false +Lint/DuplicateRequire: + Enabled: false +Lint/DuplicateRescueException: + Enabled: false +Lint/EmptyConditionalBody: + Enabled: false +Lint/EmptyFile: + Enabled: false +Lint/ErbNewArguments: + Enabled: false +Lint/FloatComparison: + Enabled: false +Lint/HashCompareByIdentity: + Enabled: false +Lint/IdentityComparison: + Enabled: false +Lint/InterpolationCheck: + Enabled: false +Lint/MissingCopEnableDirective: + Enabled: false +Lint/MixedRegexpCaptureTypes: + Enabled: false +Lint/NestedPercentLiteral: + Enabled: false +Lint/NonDeterministicRequireOrder: + Enabled: false +Lint/OrderedMagicComments: + Enabled: false +Lint/OutOfRangeRegexpRef: + Enabled: false +Lint/RaiseException: + Enabled: false +Lint/RedundantCopEnableDirective: + Enabled: false +Lint/RedundantRequireStatement: + Enabled: false +Lint/RedundantSafeNavigation: + Enabled: false +Lint/RedundantWithIndex: + Enabled: false +Lint/RedundantWithObject: + Enabled: false +Lint/RegexpAsCondition: + Enabled: false +Lint/ReturnInVoidContext: + Enabled: false +Lint/SafeNavigationConsistency: + Enabled: false +Lint/SafeNavigationWithEmpty: + Enabled: false +Lint/SelfAssignment: + Enabled: false +Lint/SendWithMixinArgument: + Enabled: false +Lint/ShadowedArgument: + Enabled: false +Lint/StructNewOverride: + Enabled: false +Lint/ToJSON: + Enabled: false +Lint/TopLevelReturnWithArgument: + Enabled: false +Lint/TrailingCommaInAttributeDeclaration: + Enabled: false +Lint/UnreachableLoop: + Enabled: false +Lint/UriEscapeUnescape: + Enabled: false +Lint/UriRegexp: + Enabled: false +Lint/UselessMethodDefinition: + Enabled: false +Lint/UselessTimes: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/BlockNesting: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false +Metrics/PerceivedComplexity: + Enabled: false +Migration/DepartmentName: + Enabled: false +Naming/AccessorMethodName: + Enabled: false +Naming/BlockParameterName: + Enabled: false +Naming/HeredocDelimiterCase: + Enabled: false +Naming/HeredocDelimiterNaming: + Enabled: false +Naming/MemoizedInstanceVariableName: + Enabled: false +Naming/MethodParameterName: + Enabled: false +Naming/RescuedExceptionsVariableName: + Enabled: false +Naming/VariableNumber: + Enabled: false +Performance/BindCall: + Enabled: false +Performance/DeletePrefix: + Enabled: false +Performance/DeleteSuffix: + Enabled: false +Performance/InefficientHashSearch: + Enabled: false +Performance/UnfreezeString: + Enabled: false +Performance/UriDefaultParser: + Enabled: false +RSpec/Be: + Enabled: false +RSpec/Capybara/FeatureMethods: + Enabled: false +RSpec/ContainExactly: + Enabled: false +RSpec/ContextMethod: + Enabled: false +RSpec/ContextWording: + Enabled: false +RSpec/DescribeClass: + Enabled: false +RSpec/EmptyHook: + Enabled: false +RSpec/EmptyLineAfterExample: + Enabled: false +RSpec/EmptyLineAfterExampleGroup: + Enabled: false +RSpec/EmptyLineAfterHook: + Enabled: false +RSpec/ExampleLength: + Enabled: false +RSpec/ExampleWithoutDescription: + Enabled: false +RSpec/ExpectChange: + Enabled: false +RSpec/ExpectInHook: + Enabled: false +RSpec/FactoryBot/AttributeDefinedStatically: + Enabled: false +RSpec/FactoryBot/CreateList: + Enabled: false +RSpec/FactoryBot/FactoryClassName: + Enabled: false +RSpec/HooksBeforeExamples: + Enabled: false +RSpec/ImplicitBlockExpectation: + Enabled: false +RSpec/ImplicitSubject: + Enabled: false +RSpec/LeakyConstantDeclaration: + Enabled: false +RSpec/LetBeforeExamples: + Enabled: false +RSpec/MatchArray: + Enabled: false +RSpec/MissingExampleGroupArgument: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/MultipleSubjects: + Enabled: false +RSpec/NestedGroups: + Enabled: false +RSpec/PredicateMatcher: + Enabled: false +RSpec/ReceiveCounts: + Enabled: false +RSpec/ReceiveNever: + Enabled: false +RSpec/RepeatedExampleGroupBody: + Enabled: false +RSpec/RepeatedExampleGroupDescription: + Enabled: false +RSpec/RepeatedIncludeExample: + Enabled: false +RSpec/ReturnFromStub: + Enabled: false +RSpec/SharedExamples: + Enabled: false +RSpec/StubbedMock: + Enabled: false +RSpec/UnspecifiedException: + Enabled: false +RSpec/VariableDefinition: + Enabled: false +RSpec/VoidExpect: + Enabled: false +RSpec/Yield: + Enabled: false +Security/Open: + Enabled: false +Style/AccessModifierDeclarations: + Enabled: false +Style/AccessorGrouping: + Enabled: false +Style/BisectedAttrAccessor: + Enabled: false +Style/CaseLikeIf: + Enabled: false +Style/ClassEqualityComparison: + Enabled: false +Style/ColonMethodDefinition: + Enabled: false +Style/CombinableLoops: + Enabled: false +Style/CommentedKeyword: + Enabled: false +Style/Dir: + Enabled: false +Style/DoubleCopDisableDirective: + Enabled: false +Style/EmptyBlockParameter: + Enabled: false +Style/EmptyLambdaParameter: + Enabled: false +Style/Encoding: + Enabled: false +Style/EvalWithLocation: + Enabled: false +Style/ExpandPathArguments: + Enabled: false +Style/ExplicitBlockArgument: + Enabled: false +Style/ExponentialNotation: + Enabled: false +Style/FloatDivision: + Enabled: false +Style/FrozenStringLiteralComment: + Enabled: false +Style/GlobalStdStream: + Enabled: false +Style/HashAsLastArrayItem: + Enabled: false +Style/HashLikeCase: + Enabled: false +Style/HashTransformKeys: + Enabled: false +Style/HashTransformValues: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/KeywordParametersOrder: + Enabled: false +Style/MinMax: + Enabled: false +Style/MixinUsage: + Enabled: false +Style/MultilineWhenThen: + Enabled: false +Style/NegatedUnless: + Enabled: false +Style/NumericPredicate: + Enabled: false +Style/OptionalBooleanParameter: + Enabled: false +Style/OrAssignment: + Enabled: false +Style/RandomWithOffset: + Enabled: false +Style/RedundantAssignment: + Enabled: false +Style/RedundantCondition: + Enabled: false +Style/RedundantConditional: + Enabled: false +Style/RedundantFetchBlock: + Enabled: false +Style/RedundantFileExtensionInRequire: + Enabled: false +Style/RedundantRegexpCharacterClass: + Enabled: false +Style/RedundantRegexpEscape: + Enabled: false +Style/RedundantSelfAssignment: + Enabled: false +Style/RedundantSort: + Enabled: false +Style/RescueStandardError: + Enabled: false +Style/SingleArgumentDig: + Enabled: false +Style/SlicingWithRange: + Enabled: false +Style/SoleNestedConditional: + Enabled: false +Style/StderrPuts: + Enabled: false +Style/StringConcatenation: + Enabled: false +Style/Strip: + Enabled: false +Style/SymbolProc: + Enabled: false +Style/TrailingBodyOnClass: + Enabled: false +Style/TrailingBodyOnMethodDefinition: + Enabled: false +Style/TrailingBodyOnModule: + Enabled: false +Style/TrailingCommaInHashLiteral: + Enabled: false +Style/TrailingMethodEndStatement: + Enabled: false +Style/UnpackFirst: + Enabled: false +Capybara/MatchStyle: + Enabled: false +Capybara/NegationMatcher: + Enabled: false +Capybara/SpecificActions: + Enabled: false +Capybara/SpecificFinders: + Enabled: false +Capybara/SpecificMatcher: + Enabled: false +Gemspec/DeprecatedAttributeAssignment: + Enabled: false +Gemspec/DevelopmentDependencies: + Enabled: false +Gemspec/RequireMFA: + Enabled: false +Layout/LineContinuationLeadingSpace: + Enabled: false +Layout/LineContinuationSpacing: + Enabled: false +Layout/LineEndStringConcatenationIndentation: + Enabled: false +Layout/SpaceBeforeBrackets: + Enabled: false +Lint/AmbiguousAssignment: + Enabled: false +Lint/AmbiguousOperatorPrecedence: + Enabled: false +Lint/AmbiguousRange: + Enabled: false +Lint/ConstantOverwrittenInRescue: + Enabled: false +Lint/DeprecatedConstants: + Enabled: false +Lint/DuplicateBranch: + Enabled: false +Lint/DuplicateMagicComment: + Enabled: false +Lint/DuplicateMatchPattern: + Enabled: false +Lint/DuplicateRegexpCharacterClassElement: + Enabled: false +Lint/EmptyBlock: + Enabled: false +Lint/EmptyClass: + Enabled: false +Lint/EmptyInPattern: + Enabled: false +Lint/IncompatibleIoSelectWithFiberScheduler: + Enabled: false +Lint/LambdaWithoutLiteralBlock: + Enabled: false +Lint/NoReturnInBeginEndBlocks: + Enabled: false +Lint/NonAtomicFileOperation: + Enabled: false +Lint/NumberedParameterAssignment: + Enabled: false +Lint/OrAssignmentToConstant: + Enabled: false +Lint/RedundantDirGlobSort: + Enabled: false +Lint/RefinementImportMethods: + Enabled: false +Lint/RequireRangeParentheses: + Enabled: false +Lint/RequireRelativeSelfPath: + Enabled: false +Lint/SymbolConversion: + Enabled: false +Lint/ToEnumArguments: + Enabled: false +Lint/TripleQuotes: + Enabled: false +Lint/UnexpectedBlockArity: + Enabled: false +Lint/UnmodifiedReduceAccumulator: + Enabled: false +Lint/UselessRescue: + Enabled: false +Lint/UselessRuby2Keywords: + Enabled: false +Metrics/CollectionLiteralLength: + Enabled: false +Naming/BlockForwarding: + Enabled: false +Performance/CollectionLiteralInLoop: + Enabled: false +Performance/ConcurrentMonotonicTime: + Enabled: false +Performance/MapCompact: + Enabled: false +Performance/RedundantEqualityComparisonBlock: + Enabled: false +Performance/RedundantSplitRegexpArgument: + Enabled: false +Performance/StringIdentifierArgument: + Enabled: false +RSpec/BeEq: + Enabled: false +RSpec/BeNil: + Enabled: false +RSpec/ChangeByZero: + Enabled: false +RSpec/ClassCheck: + Enabled: false +RSpec/DuplicatedMetadata: + Enabled: false +RSpec/ExcessiveDocstringSpacing: + Enabled: false +RSpec/FactoryBot/ConsistentParenthesesStyle: + Enabled: false +RSpec/FactoryBot/FactoryNameStyle: + Enabled: false +RSpec/FactoryBot/SyntaxMethods: + Enabled: false +RSpec/IdenticalEqualityAssertion: + Enabled: false +RSpec/NoExpectationExample: + Enabled: false +RSpec/PendingWithoutReason: + Enabled: false +RSpec/Rails/AvoidSetupHook: + Enabled: false +RSpec/Rails/HaveHttpStatus: + Enabled: false +RSpec/Rails/InferredSpecType: + Enabled: false +RSpec/Rails/MinitestAssertions: + Enabled: false +RSpec/Rails/TravelAround: + Enabled: false +RSpec/RedundantAround: + Enabled: false +RSpec/SkipBlockInsideExample: + Enabled: false +RSpec/SortMetadata: + Enabled: false +RSpec/SubjectDeclaration: + Enabled: false +RSpec/VerifiedDoubleReference: + Enabled: false +Security/CompoundHash: + Enabled: false +Security/IoMethods: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false +Style/ArrayIntersect: + Enabled: false +Style/CollectionCompact: + Enabled: false +Style/ComparableClamp: + Enabled: false +Style/ConcatArrayLiterals: + Enabled: false +Style/DataInheritance: + Enabled: false +Style/DirEmpty: + Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false +Style/EmptyHeredoc: + Enabled: false +Style/EndlessMethod: + Enabled: false +Style/EnvHome: + Enabled: false +Style/FetchEnvVar: + Enabled: false +Style/FileEmpty: + Enabled: false +Style/FileRead: + Enabled: false +Style/FileWrite: + Enabled: false +Style/HashConversion: + Enabled: false +Style/HashExcept: + Enabled: false +Style/IfWithBooleanLiteralBranches: + Enabled: false +Style/InPatternThen: + Enabled: false +Style/MagicCommentFormat: + Enabled: false +Style/MapCompactWithConditionalBlock: + Enabled: false +Style/MapToHash: + Enabled: false +Style/MapToSet: + Enabled: false +Style/MinMaxComparison: + Enabled: false +Style/MultilineInPatternThen: + Enabled: false +Style/NegatedIfElseCondition: + Enabled: false +Style/NestedFileDirname: + Enabled: false +Style/NilLambda: + Enabled: false +Style/NumberedParameters: + Enabled: false +Style/NumberedParametersLimit: + Enabled: false +Style/ObjectThen: + Enabled: false +Style/OpenStructUse: + Enabled: false +Style/OperatorMethodCall: + Enabled: false +Style/QuotedSymbols: + Enabled: false +Style/RedundantArgument: + Enabled: false +Style/RedundantConstantBase: + Enabled: false +Style/RedundantDoubleSplatHashBraces: + Enabled: false +Style/RedundantEach: + Enabled: false +Style/RedundantHeredocDelimiterQuotes: + Enabled: false +Style/RedundantInitialize: + Enabled: false +Style/RedundantLineContinuation: + Enabled: false +Style/RedundantSelfAssignmentBranch: + Enabled: false +Style/RedundantStringEscape: + Enabled: false +Style/SelectByRegexp: + Enabled: false +Style/StringChars: + Enabled: false +Style/SwapValues: + Enabled: false diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..8c2c98e --- /dev/null +++ b/.sync.yml @@ -0,0 +1,8 @@ +# This file can be used to customize the files managed by PDK. +# +# See https://github.com/puppetlabs/pdk-templates/blob/main/README.md +# for more information. +# +# See https://github.com/puppetlabs/pdk-templates/blob/main/config_defaults.yml +# for the default values. +--- {} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..6da8d47 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "puppet.puppet-vscode", + "Shopify.ruby-lsp" + ] +} diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..29c933b --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +--markup markdown diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e310aa5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## Release 1.4.4 + +**Features** + +**Bugfixes** + +**Known Issues** diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f84ea87 --- /dev/null +++ b/Gemfile @@ -0,0 +1,79 @@ +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 + +group :development do + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "deep_merge", '~> 1.2.2', require: false + gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false + gem "facterdb", '~> 2.1', require: false + gem "metadata-json-lint", '~> 4.0', require: false + gem "rspec-puppet-facts", '~> 4.0', require: false + gem "dependency_checker", '~> 1.0.0', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.9', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '~> 1.50.0', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "rexml", '>= 3.0.0', '< 3.2.7', require: false +end +group :development, :release_prep do + gem "puppet-strings", '~> 4.0', require: false + gem "puppetlabs_spec_helper", '~> 8.0', require: false + gem "puppet-blacksmith", '~> 7.0', require: false +end +group :system_tests do + gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] + gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "serverspec", '~> 2.41', require: false +end + +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables + +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version + +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params +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 new file mode 100644 index 0000000..31b5930 --- /dev/null +++ b/Rakefile @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'bundler' +require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus' +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' + +PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] + diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..2fbf0ff --- /dev/null +++ b/data/common.yaml @@ -0,0 +1 @@ +--- {} diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..545fff3 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,21 @@ +--- +version: 5 + +defaults: # Used for any hierarchy level that omits these keys. + datadir: data # This path is relative to hiera.yaml's directory. + data_hash: yaml_data # Use the built-in YAML backend. + +hierarchy: + - name: "osfamily/major release" + paths: + # Used to distinguish between Debian and Ubuntu + - "os/%{facts.os.name}/%{facts.os.release.major}.yaml" + - "os/%{facts.os.family}/%{facts.os.release.major}.yaml" + # Used for Solaris + - "os/%{facts.os.family}/%{facts.kernelrelease}.yaml" + - name: "osfamily" + paths: + - "os/%{facts.os.name}.yaml" + - "os/%{facts.os.family}.yaml" + - name: 'common' + path: 'common.yaml' diff --git a/lib/facter/keepup_package_versions.rb b/lib/facter/keepup_package_versions.rb old mode 100644 new mode 100755 index c661be2..a5fa2e1 --- a/lib/facter/keepup_package_versions.rb +++ b/lib/facter/keepup_package_versions.rb @@ -1,6 +1,7 @@ #!/usr/bin/env ruby require 'facter' +require 'English' packages = { 'mongodb' => { @@ -13,7 +14,7 @@ }, 'mysql' => { host_package: 'percona-server-server', - host_version_command: "dpkg-query -W -f='\${Package} \${Version}\n' percona-server-server 2>/dev/null || true", + host_version_command: "dpkg-query -W -f='\${Package} \${Version}\n' percona-server-server percona-xtradb-cluster-server 2>/dev/null || true", }, 'rabbitmq' => { host_package: 'rabbitmq-server', @@ -28,7 +29,7 @@ host_version_command: "dpkg-query -W -f='\${Package} \${Version}\n' envoy 2>/dev/null || true", }, 'postgresql' => { - host_package: 'postgresql', + host_package: 'postgresql', host_version_command: "psql --version 2>/dev/null | cut -d ' ' -f3 | sed 's/^/postgresql /' || true", }, 'elasticsearch' => { @@ -52,7 +53,7 @@ def process_running?(package) def package_version(command) output = Facter::Util::Resolution.exec(command) - return nil unless $?.success? && output + return nil unless $CHILD_STATUS.success? && output version = output.strip.split(' ')[1] version @@ -66,13 +67,13 @@ def package_version(command) if process_check version = package_version(config[:host_version_command]) - if version - package_versions[package_name] = { 'version' => version } - else - package_versions[package_name] = { 'version' => 'unknown'} - end + package_versions[package_name] = if version + { 'version' => version } + else + { 'version' => 'unknown' } + end else - package_versions[package_name] = { 'version' => 'unknown'} + package_versions[package_name] = { 'version' => 'unknown' } end end diff --git a/manifests/config.pp b/manifests/config.pp index 0d87da3..dfa1858 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -30,11 +30,12 @@ owner => 'root', group => 'root', mode => '0750', - } -> + } # ensure old data file is absent file { '/opt/keepup/data.json': ensure => 'absent', + require => File['/opt/keepup'], } file { '/opt/keepup/pkg.json': @@ -64,19 +65,21 @@ $persistent_random_minute = $facts['keepup_random_minute'] # for example: 'RANDOM */3 * * *' will be replaced to rndomized persistent value + # lint:ignore:only_variable_string $crontabtime = regsubst($crontimetpl, 'RANDOM', "${persistent_random_minute}", 'G') + # lint:endignore $systemd_calendar = "*-*-* 00/3:${persistent_random_minute}:00" + exec { 'keepup-systemd-daemon-reload': + command => '/bin/systemctl daemon-reload', + refreshonly => true, + } + if $systemd_timer { file { '/etc/cron.d/keepup': ensure => absent, } - exec { 'keepup-systemd-daemon-reload': - command => '/bin/systemctl daemon-reload', - refreshonly => true, - } - file { '/etc/systemd/system/keepup.service': ensure => file, owner => 'root', @@ -121,15 +124,7 @@ onlyif => '/bin/systemctl list-unit-files keepup.timer --no-legend | /bin/grep -q "^keepup.timer"', } - exec { 'keepup-systemd-daemon-reload': - command => '/bin/systemctl daemon-reload', - refreshonly => true, - } - - file { [ - '/etc/systemd/system/keepup.service', - '/etc/systemd/system/keepup.timer', - ]: + file { ['/etc/systemd/system/keepup.service', '/etc/systemd/system/keepup.timer']: ensure => absent, require => Exec['keepup-systemd-disable-timer'], notify => Exec['keepup-systemd-daemon-reload'], diff --git a/manifests/init.pp b/manifests/init.pp index 03ecc0a..3a6fc1f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,6 +3,19 @@ # This module installs and configures keepup # # === Parameters +# @param key +# @param pkg_path +# @param server +# @param crontimetpl +# @param manage_package +# @param package_name +# @param config_manage +# @param use_defaults +# @param systemd_timer +# @param info_defaults +# @param package_defaults +# @param info + class keepup ( String $key = $keepup::params::key, String $pkg_path = $keepup::params::pkg_path, @@ -20,6 +33,6 @@ contain keepup::install contain keepup::config - Class['keepup::install'] -> - Class['keepup::config'] + Class['keepup::install'] + -> Class['keepup::config'] } diff --git a/manifests/params.pp b/manifests/params.pp index 04d15e6..050b79b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,7 +5,7 @@ class keepup::params { $key = 'secret' $pkg_path = '/package-version' - $server_name = 'keepup.exampel.com' + $server = 'keepup.example.com' # will be replaced to randomized minute $crontimetpl = 'RANDOM */3 * * *' $package_ensure = 'installed' diff --git a/metadata.json b/metadata.json index bba53b1..b9c72a2 100644 --- a/metadata.json +++ b/metadata.json @@ -1,30 +1,38 @@ { - "name": "code_tool-keepup", + "name": "codetool-keepup", "version": "1.4.4", "author": "code_tool", - "license": "MIT", "summary": "Installs and configures keepup - a package version monitoring agent", + "license": "MIT", "source": "https://github.com/code-tool/puppet-keepup", - "issues_url": "https://github.com/code-tool/puppet-keepup/issues", "project_page": "https://github.com/code-tool/puppet-keepup", + "issues_url": "https://github.com/code-tool/puppet-keepup/issues", "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.25.0 < 10.0.0" + "version_requirement": ">= 4.25.0 < 11.0.0" }, { "name": "puppetlabs/apt", - "version_requirement": ">= 6.0.0 < 10.0.0" + "version_requirement": ">= 6.0.0 < 12.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Debian", - "operatingsystemrelease": ["10", "11", "12", "13"] + "operatingsystemrelease": [ + "11", + "12", + "13" + ] }, { "operatingsystem": "Ubuntu", - "operatingsystemrelease": ["20.04", "22.04", "24.04"] + "operatingsystemrelease": [ + "22.04", + "24.04", + "26.04" + ] } ], "requirements": [ @@ -32,5 +40,8 @@ "name": "puppet", "version_requirement": ">= 6.0.0 < 9.0.0" } - ] + ], + "pdk-version": "3.4.0", + "template-url": "pdk-default#3.4.0", + "template-ref": "tags/3.4.0-0-gd3cc13f" } 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/classes/keepup_spec.rb b/spec/classes/keepup_spec.rb new file mode 100644 index 0000000..ea0d18b --- /dev/null +++ b/spec/classes/keepup_spec.rb @@ -0,0 +1,194 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'keepup' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) do + os_facts + end + + let(:params) do + {} + end + + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_class('keepup::config') } + it { is_expected.to contain_class('keepup::install') } + it { is_expected.to contain_class('keepup::params') } + + it { + is_expected.to contain_file('/opt/keepup').with( + { + ensure: 'directory', + owner: 'root', + group: 'root', + mode: '0750', + }, + ) + } + + it { + is_expected.to contain_file('/opt/keepup/data.json').with( + { + ensure: 'absent', + require: 'File[/opt/keepup]' + }, + ) + } + + it { + is_expected.to contain_file('/opt/keepup/pkg.json').with( + { + ensure: 'file', + owner: 'root', + group: 'root', + mode: '0640', + content: File.read(File.expand_path("../../fixtures/files//opt/keepup/pkg-defaults-#{facts[:os]['distro']['id']}-#{facts[:os]['distro']['release']['major']}.json", __FILE__)), + replace: true, + }, + ) + } + + it { + is_expected.to contain_file('/opt/keepup/run.sh').with( + { + ensure: 'file', + owner: 'root', + group: 'root', + mode: '0750', + content: File.read(File.expand_path('../../fixtures/files/opt/keepup/run.sh', __FILE__)), + }, + ) + } + + it { + is_expected.to contain_exec('keepup-systemd-daemon-reload').with( + { + command: '/bin/systemctl daemon-reload', + refreshonly: true + }, + ) + } + + it { + is_expected.to contain_exec('keepup-systemd-disable-timer').with( + { + command: '/bin/systemctl disable --now keepup.timer', + onlyif: '/bin/systemctl list-unit-files keepup.timer --no-legend | /bin/grep -q "^keepup.timer"' + }, + ) + } + + context 'with manage_package=true' do + let(:params) do + super().merge( + manage_package: true, + ) + end + + it { is_expected.to compile.with_all_deps } + + it { + is_expected.to contain_package('curl').with( + 'ensure' => 'installed', + ) + } + end + + context 'with use_defaults=false' do + let(:params) do + super().merge( + use_defaults: false, + ) + end + + it { is_expected.to compile.with_all_deps } + + it { + is_expected.to contain_file('/opt/keepup/pkg.json').with( + { + ensure: 'file', + owner: 'root', + group: 'root', + mode: '0640', + content: File.read(File.expand_path('../../fixtures/files//opt/keepup/pkg-no-defaults.json', __FILE__)), + replace: true, + }, + ) + } + end + + context 'with systemd_timer=true' do + let(:params) do + super().merge( + systemd_timer: true, + ) + end + + it { is_expected.to compile.with_all_deps } + + it { + is_expected.to contain_file('/etc/cron.d/keepup').with({ ensure: 'absent' }) + } + + it { + is_expected.to contain_file('/etc/systemd/system/keepup.service').with( + { + ensure: 'file', + owner: 'root', + group: 'root', + mode: '0644', + content: File.read(File.expand_path('../../fixtures/files/etc/systemd/system/keepup.service', __FILE__)), + notify: 'Exec[keepup-systemd-daemon-reload]' + }, + ) + } + + it { + is_expected.to contain_file('/etc/systemd/system/keepup.timer').with( + { + ensure: 'file', + owner: 'root', + group: 'root', + mode: '0644', + content: File.read(File.expand_path('../../fixtures/files/etc/systemd/system/keepup.timer', __FILE__)), + notify: 'Exec[keepup-systemd-daemon-reload]' + }, + ) + } + + it { + is_expected.to contain_service('keepup.timer').with( + { + ensure: 'running', + enable: true, + require: 'Exec[keepup-systemd-daemon-reload]', + subscribe: 'File[/etc/systemd/system/keepup.timer]' + }, + ) + } + end + + context 'with config_manage=false' do + let(:params) do + super().merge( + config_manage: false, + ) + end + + it { is_expected.to compile.with_all_deps } + + it { + is_expected.to contain_file('/opt/keepup/pkg.json').with({ ensure: 'absent' }) + is_expected.to contain_file('/opt/keepup/run.sh').with({ ensure: 'absent' }) + is_expected.to contain_file('/etc/cron.d/keepup').with({ ensure: 'absent' }) + is_expected.to contain_file('/etc/systemd/system/keepup.service').with({ ensure: 'absent' }) + is_expected.to contain_file('/etc/systemd/system/keepup.timer').with({ ensure: 'absent' }) + } + end + end + end +end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..cbf7d00 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,32 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +networking: + ip: "172.16.254.254" + ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" + mac: "AA:AA:AA:AA:AA:AA" +is_pe: false + +keepup_random_minute: 30 +package_versions: + mongodb: + version: 0.0.0 + redis: + version: 0.0.0 + mysql: + version: 0.0.0 + rabbitmq: + version: 0.0.0 + memcached: + version: 0.0.0 + envoy: + version: 0.0.0 + postgresql: + version: 0.0.0 + elasticsearch: + version: 0.0.0 + php: + version: 0.0.0 + linux: + version: 0.0.0 diff --git a/spec/fixtures/files/etc/systemd/system/keepup.service b/spec/fixtures/files/etc/systemd/system/keepup.service new file mode 100644 index 0000000..d30a899 --- /dev/null +++ b/spec/fixtures/files/etc/systemd/system/keepup.service @@ -0,0 +1,6 @@ +[Unit] +Description=Send keepup package versions + +[Service] +Type=oneshot +ExecStart=/opt/keepup/run.sh diff --git a/spec/fixtures/files/etc/systemd/system/keepup.timer b/spec/fixtures/files/etc/systemd/system/keepup.timer new file mode 100644 index 0000000..946a5a3 --- /dev/null +++ b/spec/fixtures/files/etc/systemd/system/keepup.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run keepup periodically + +[Timer] +OnCalendar=*-*-* 00/3:30:00 +Persistent=true +AccuracySec=1min + +[Install] +WantedBy=timers.target diff --git a/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-11.json b/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-11.json new file mode 100644 index 0000000..cd5b0dd --- /dev/null +++ b/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-11.json @@ -0,0 +1,18 @@ +{ + "packages": { + "debian": "11", + "mongodb": "0.0.0", + "redis": "0.0.0", + "mysql": "0.0.0", + "rabbitmq": "0.0.0", + "memcached": "0.0.0", + "envoy": "0.0.0", + "postgresql": "0.0.0", + "elasticsearch": "0.0.0", + "php": "0.0.0", + "linux": "0.0.0", + "host_ip": "foo", + "data_center": "unknown", + "team": "unknown" + } +} diff --git a/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-12.json b/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-12.json new file mode 100644 index 0000000..3a5d870 --- /dev/null +++ b/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-12.json @@ -0,0 +1,18 @@ +{ + "packages": { + "debian": "12", + "mongodb": "0.0.0", + "redis": "0.0.0", + "mysql": "0.0.0", + "rabbitmq": "0.0.0", + "memcached": "0.0.0", + "envoy": "0.0.0", + "postgresql": "0.0.0", + "elasticsearch": "0.0.0", + "php": "0.0.0", + "linux": "0.0.0", + "host_ip": "foo", + "data_center": "unknown", + "team": "unknown" + } +} diff --git a/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-13.json b/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-13.json new file mode 100644 index 0000000..95e8ae1 --- /dev/null +++ b/spec/fixtures/files/opt/keepup/pkg-defaults-Debian-13.json @@ -0,0 +1,18 @@ +{ + "packages": { + "debian": "13", + "mongodb": "0.0.0", + "redis": "0.0.0", + "mysql": "0.0.0", + "rabbitmq": "0.0.0", + "memcached": "0.0.0", + "envoy": "0.0.0", + "postgresql": "0.0.0", + "elasticsearch": "0.0.0", + "php": "0.0.0", + "linux": "0.0.0", + "host_ip": "foo", + "data_center": "unknown", + "team": "unknown" + } +} diff --git a/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-22.04.json b/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-22.04.json new file mode 100644 index 0000000..f7f3010 --- /dev/null +++ b/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-22.04.json @@ -0,0 +1,18 @@ +{ + "packages": { + "debian": "22.04", + "mongodb": "0.0.0", + "redis": "0.0.0", + "mysql": "0.0.0", + "rabbitmq": "0.0.0", + "memcached": "0.0.0", + "envoy": "0.0.0", + "postgresql": "0.0.0", + "elasticsearch": "0.0.0", + "php": "0.0.0", + "linux": "0.0.0", + "host_ip": "foo", + "data_center": "unknown", + "team": "unknown" + } +} diff --git a/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-24.04.json b/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-24.04.json new file mode 100644 index 0000000..1cd939a --- /dev/null +++ b/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-24.04.json @@ -0,0 +1,18 @@ +{ + "packages": { + "debian": "24.04", + "mongodb": "0.0.0", + "redis": "0.0.0", + "mysql": "0.0.0", + "rabbitmq": "0.0.0", + "memcached": "0.0.0", + "envoy": "0.0.0", + "postgresql": "0.0.0", + "elasticsearch": "0.0.0", + "php": "0.0.0", + "linux": "0.0.0", + "host_ip": "foo", + "data_center": "unknown", + "team": "unknown" + } +} diff --git a/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-26.04.json b/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-26.04.json new file mode 100644 index 0000000..657729b --- /dev/null +++ b/spec/fixtures/files/opt/keepup/pkg-defaults-Ubuntu-26.04.json @@ -0,0 +1,18 @@ +{ + "packages": { + "debian": "26.04", + "mongodb": "0.0.0", + "redis": "0.0.0", + "mysql": "0.0.0", + "rabbitmq": "0.0.0", + "memcached": "0.0.0", + "envoy": "0.0.0", + "postgresql": "0.0.0", + "elasticsearch": "0.0.0", + "php": "0.0.0", + "linux": "0.0.0", + "host_ip": "foo", + "data_center": "unknown", + "team": "unknown" + } +} diff --git a/spec/fixtures/files/opt/keepup/pkg-no-defaults.json b/spec/fixtures/files/opt/keepup/pkg-no-defaults.json new file mode 100644 index 0000000..100dd66 --- /dev/null +++ b/spec/fixtures/files/opt/keepup/pkg-no-defaults.json @@ -0,0 +1,18 @@ +{ + "packages": { + "debian": "", + "mongodb": "", + "redis": "", + "mysql": "", + "rabbitmq": "", + "memcached": "", + "envoy": "", + "postgresql": "", + "elasticsearch": "", + "php": "", + "linux": "", + "host_ip": "", + "data_center": "", + "team": "" + } +} diff --git a/spec/fixtures/files/opt/keepup/run.sh b/spec/fixtures/files/opt/keepup/run.sh new file mode 100644 index 0000000..c28caea --- /dev/null +++ b/spec/fixtures/files/opt/keepup/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +set -e +curl -s -XPUT -H "x-api-token: secret" https://keepup.example.com/package-version -d @/opt/keepup/pkg.json diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..ae7c1f6 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,75 @@ +# 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 + require 'deep_merge' + default_facts.deep_merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) + rescue StandardError => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end + +# read default_facts and merge them over what is provided by facterdb +default_facts.each do |fact, value| + add_custom_fact fact, value, merge_facts: true +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 + RSpec::Puppet::Coverage.report!(0) + end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end +end + +# 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