From 59b635cf8dc650957d82ce12fe356f2df86ee685 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Wed, 5 Apr 2023 12:48:05 +0000 Subject: [PATCH 01/17] Convert to PDK 2.7.1 --- .devcontainer/Dockerfile | 6 + .devcontainer/README.md | 38 +++ .devcontainer/devcontainer.json | 17 ++ .gitattributes | 5 + .gitignore | 58 ++-- .gitlab-ci.yml | 53 ++++ .pdkignore | 46 +++ .puppet-lint.rc | 1 + .rspec | 2 + .rubocop.yml | 519 ++++++++++++++++++++++++++++++++ .sync.yml | 8 + .vscode/extensions.json | 6 + .yardopts | 1 + Gemfile | 100 ++++-- Rakefile | 97 +++++- appveyor.yml | 49 +++ data/common.yaml | 1 + hiera.yaml | 21 ++ metadata.json | 43 ++- pdk.yaml | 2 + spec/default_facts.yml | 8 + spec/spec_helper.rb | 81 ++++- 22 files changed, 1062 insertions(+), 100 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/README.md create mode 100644 .devcontainer/devcontainer.json create mode 100644 .gitattributes create mode 100644 .gitlab-ci.yml create mode 100644 .pdkignore create mode 100644 .puppet-lint.rc create mode 100644 .rspec create mode 100644 .rubocop.yml create mode 100644 .sync.yml create mode 100644 .vscode/extensions.json create mode 100644 .yardopts create mode 100644 appveyor.yml create mode 100644 data/common.yaml create mode 100644 hiera.yaml create mode 100644 pdk.yaml create mode 100644 spec/default_facts.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..12ed4ff --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM puppet/pdk:latest + +# [Optional] Uncomment this section to install additional packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000..a719361 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,38 @@ +# devcontainer + + +For format details, see https://aka.ms/devcontainer.json. + +For config options, see the README at: +https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet + +``` json +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "bash", + } + } + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "pdk --version", +} +``` + + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..cdd65d2 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "Puppet Development Kit (Community)", + "dockerFile": "Dockerfile", + + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "bash" + } + } + }, + + "extensions": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/.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 index 222e35e..988dcbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,28 @@ -# Default .gitignore for Ruby -*.gem -*.rbc -.bundle -.config -coverage -InstalledFiles -lib/bundler/man -pkg -rdoc -spec/reports -test/tmp -test/version_tmp -tmp - -# YARD artifacts +.git/ +.*.sw[op] +.metadata .yardoc -_yardoc -doc/ - -# Vim -*.swp - -# Eclipse -.project - -# OS X +.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 - -# Puppet -coverage/ -spec/fixtures/manifests/* -spec/fixtures/modules/* -Gemfile.lock +.project +.envrc +/inventory.yaml +/spec/fixtures/litmus_inventory.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..6d5e786 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,53 @@ +--- +stages: + - syntax + - unit + +default: + cache: + paths: + - vendor/bundle + + 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) + +validate lint check rubocop-Ruby 2.5.7-Puppet ~> 6: + stage: syntax + image: ruby:2.5.7 + script: + - 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' + +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.7.2 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 7' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..a956c8f --- /dev/null +++ b/.pdkignore @@ -0,0 +1,46 @@ +.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 +/.yardopts +/spec/ +/.vscode/ +/.sync.yml +/.devcontainer/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..cc96ece --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--relative 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..31e8248 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,519 @@ +--- +require: +- rubocop-performance +- rubocop-rspec +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.5' + 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/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 +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/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/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/.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..2f1e4f7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} 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/Gemfile b/Gemfile index f8bdb02..4eaa0c3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,38 +1,72 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' -if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false -else - gem 'puppet', :require => false +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 "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false + gem "puppetlabs_spec_helper", '~> 5.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 0.2', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.6.1', require: false + gem "rubocop-performance", '= 1.9.1', require: false + gem "rubocop-rspec", '= 2.0.1', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] +end +group :system_tests do + gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :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 -gem 'facter', '>= 1.7.0', :require => false -gem 'rspec-puppet', '>= 2.4.0', :require => false -gem 'puppet-lint', '~> 2.0', :require => false -gem 'puppet-lint-absolute_classname-check', :require => false -gem 'puppet-lint-alias-check', :require => false -gem 'puppet-lint-empty_string-check', :require => false -gem 'puppet-lint-file_ensure-check', :require => false -gem 'puppet-lint-file_source_rights-check', :require => false -gem 'puppet-lint-leading_zero-check', :require => false -gem 'puppet-lint-spaceship_operator_without_tag-check', :require => false -gem 'puppet-lint-trailing_comma-check', :require => false -gem 'puppet-lint-undef_in_function-check', :require => false -gem 'puppet-lint-unquoted_string-check', :require => false -gem 'puppet-lint-variable_contains_upcase', :require => false - -gem 'rspec', '~> 2.0', :require => false if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' -gem 'rake', '~> 10.0', :require => false if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' -gem 'json', '<= 1.8', :require => false if RUBY_VERSION < '2.0.0' -gem 'json_pure', '<= 2.0.1', :require => false if RUBY_VERSION < '2.0.0' -gem 'metadata-json-lint', '0.0.11' if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' -gem 'metadata-json-lint', '1.0.0' if RUBY_VERSION >= '1.9' && RUBY_VERSION < '2.0' -gem 'metadata-json-lint' if RUBY_VERSION >= '2.0' - -gem 'puppetlabs_spec_helper', '2.0.2', :require => false if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' -gem 'puppetlabs_spec_helper', '>= 2.0.0', :require => false if RUBY_VERSION >= '1.9' -gem 'parallel_tests', '<= 2.9.0', :require => false if RUBY_VERSION < '2.0.0' - -if puppetversion && puppetversion < '5.0' - gem 'semantic_puppet', :require => false +# 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 5fe42a7..0f8754e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,16 +1,89 @@ +# frozen_string_literal: true + +require 'bundler' +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.send('disable_140chars') -PuppetLint.configuration.relative = true -PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp', 'vendor/**/*.pp'] - -desc 'Validate manifests, templates, ruby files and shell scripts' -task :validate do - Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| - sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ +require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? +require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? +require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? + +def changelog_user + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = nil || JSON.load(File.read('metadata.json'))['author'] + raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator user:#{returnVal}" + returnVal +end + +def changelog_project + return unless Rake.application.top_level_tasks.include? "changelog" + + returnVal = nil + returnVal ||= begin + metadata_source = JSON.load(File.read('metadata.json'))['source'] + metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) + + metadata_source_match && metadata_source_match[1] + end + + raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? + + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal +end + +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] + raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator future_release:#{returnVal}" + returnVal +end + +PuppetLint.configuration.send('disable_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 - Dir['files/**/*.sh'].each do |shell_script| - sh "bash -n #{shell_script}" +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 new file mode 100644 index 0000000..a70c01e --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,49 @@ +--- +version: 1.1.x.{build} +skip_branch_with_pr: true +branches: + only: + - 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: 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 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/metadata.json b/metadata.json index 1b09baa..cc8ce79 100644 --- a/metadata.json +++ b/metadata.json @@ -3,20 +3,31 @@ "version": "1.13.0", "author": "ghoneycutt", "summary": "Puppet module to manage default types through hashes in Hiera", - "description": "Puppet module to manage default types through hashes in Hiera with the\ncreate_resources() function. This module adds validation and helper functions,\nsuch as ensuring directories. Without specifying any hashes, this module will take no action.", "license": "Apache-2.0", - "source": "git://github.com/ghoneycutt/puppet-module-types.git", + "source": "git://github.com:ghoneycutt/puppet-module-types.git", "project_page": "https://github.com/ghoneycutt/puppet-module-types", "issues_url": "https://github.com/ghoneycutt/puppet-module-types/issues", - "requirements": [ - {"name":"puppet","version_requirement":">= 3.2.0 < 7.0.0"} - ], "dependencies": [ - {"name":"puppetlabs/stdlib","version_requirement":">= 4.6.0 < 7.0.0"}, - {"name":"ghoneycutt/common","version_requirement":">= 1.7.0 < 2.0.0"}, - {"name":"puppetlabs/cron_core","version_requirement":">= 1.0.0 <2.0.0"}, - {"name":"puppetlabs/mount_core","version_requirement":">= 1.0.2 <2.0.0"}, - {"name":"puppetlabs/selinux_core","version_requirement":">= 1.0.1 <2.0.0"} + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.6.0 < 7.0.0" + }, + { + "name": "ghoneycutt/common", + "version_requirement": ">= 1.7.0 < 2.0.0" + }, + { + "name": "puppetlabs/cron_core", + "version_requirement": ">= 1.0.0 < 2.0.0" + }, + { + "name": "puppetlabs/mount_core", + "version_requirement": ">= 1.0.2 < 2.0.0" + }, + { + "name": "puppetlabs/selinux_core", + "version_requirement": ">= 1.0.1 < 2.0.0" + } ], "operatingsystem_support": [ { @@ -49,5 +60,15 @@ { "operatingsystem": "Ubuntu" } - ] + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 6.0.0 < 8.0.0" + } + ], + "description": "Puppet module to manage default types through hashes in Hiera with the\ncreate_resources() function. This module adds validation and helper functions,\nsuch as ensuring directories. Without specifying any hashes, this module will take no action.", + "pdk-version": "2.7.1", + "template-url": "pdk-default#2.7.4", + "template-ref": "tags/2.7.4-0-g58edf57" } 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/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..f777abf --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,8 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +ipaddress: "172.16.254.254" +ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 74f727d..9b1fa6f 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,16 +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, +} -RSpec.configure do |config| - config.hiera_config = 'spec/fixtures/hiera/hiera.yaml' - config.before :each do - # Ensure that we don't accidentally cache facts and environment between - # test cases. This requires each example group to explicitly load the - # facts being exercised with something like - # Facter.collection.loader.load(:ipaddress) - Facter.clear - Facter.clear_messages +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 - config.default_facts = { - :environment => 'rp_env', - } 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 From 8b39ed166d87bf13b6de4df3a33e05bf2ccf8140 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Tue, 4 Apr 2023 15:10:51 +0000 Subject: [PATCH 02/17] Satisfy rubocop --- spec/classes/init_spec.rb | 706 +++++++++++++++++--------------- spec/defines/cron_spec.rb | 95 +++-- spec/defines/exec_spec.rb | 126 +++--- spec/defines/file_line_spec.rb | 106 ++--- spec/defines/file_spec.rb | 165 ++++---- spec/defines/mount_spec.rb | 167 ++++---- spec/defines/package_spec.rb | 88 ++-- spec/defines/selboolean_spec.rb | 66 +-- spec/defines/service_spec.rb | 122 +++--- 9 files changed, 877 insertions(+), 764 deletions(-) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 504bba8..26923fc 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,73 +1,84 @@ require 'spec_helper' describe 'types' do - - it { should compile.with_all_deps } + it { is_expected.to compile.with_all_deps } context 'with default options' do - it { should contain_class('types') } + it { is_expected.to contain_class('types') } end context 'with mounts specified as a hash' do - let(:facts) { { :osfamily => 'RedHat' } } - let(:params) { { :mounts => { - '/mnt' => { - 'device' => '/dev/dvd', - 'fstype' => 'iso9660', - 'atboot' => 'no', - 'remounts' => 'true', - }, - '/srv/nfs/home' => { - 'device' => 'nfsserver:/export/home', - 'fstype' => 'nfs', - 'options' => 'rw,rsize=8192,wsize=8192', - 'remounts' => 'true', - 'blockdevice' => '-', + let(:facts) { { osfamily: 'RedHat' } } + let(:params) do + { + mounts: { + '/mnt' => { + 'device' => '/dev/dvd', + 'fstype' => 'iso9660', + 'atboot' => 'no', + 'remounts' => 'true', + }, + '/srv/nfs/home' => { + 'device' => 'nfsserver:/export/home', + 'fstype' => 'nfs', + 'options' => 'rw,rsize=8192,wsize=8192', + 'remounts' => 'true', + 'blockdevice' => '-', + } + } } - } } } - - it { should contain_class('types') } - - it { - should contain_mount('/mnt').with({ - 'ensure' => 'mounted', - 'device' => '/dev/dvd', - 'fstype' => 'iso9660', - 'atboot' => 'no', - 'remounts' => 'true', - }) - } - - it { - should contain_exec('mkdir_p-/mnt').with({ - 'command' => 'mkdir -p /mnt', - 'unless' => 'test -d /mnt', - }) - } - - it { - should contain_mount('/srv/nfs/home').with({ - 'device' => 'nfsserver:/export/home', - 'fstype' => 'nfs', - 'options' => 'rw,rsize=8192,wsize=8192', - 'remounts' => 'true', - 'blockdevice' => '-', - }) - } - - it { - should contain_exec('mkdir_p-/srv/nfs/home').with({ - 'command' => 'mkdir -p /srv/nfs/home', - 'unless' => 'test -d /srv/nfs/home', - }) - } + end + + it { is_expected.to contain_class('types') } + + it do + is_expected.to contain_mount('/mnt').with( + { + 'ensure' => 'mounted', + 'device' => '/dev/dvd', + 'fstype' => 'iso9660', + 'atboot' => 'no', + 'remounts' => 'true', + }, + ) + end + + it do + is_expected.to contain_exec('mkdir_p-/mnt').with( + { + 'command' => 'mkdir -p /mnt', + 'unless' => 'test -d /mnt', + }, + ) + end + + it do + is_expected.to contain_mount('/srv/nfs/home').with( + { + 'device' => 'nfsserver:/export/home', + 'fstype' => 'nfs', + 'options' => 'rw,rsize=8192,wsize=8192', + 'remounts' => 'true', + 'blockdevice' => '-', + }, + ) + end + + it do + is_expected.to contain_exec('mkdir_p-/srv/nfs/home').with( + { + 'command' => 'mkdir -p /srv/nfs/home', + 'unless' => 'test -d /srv/nfs/home', + }, + ) + end end context 'with file_lines specified as a hash' do - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } let :params do { - :file_lines_hiera_merge => 'false', - :file_lines => { + file_lines_hiera_merge: 'false', + file_lines: { 'some_file' => { 'path' => '/tmp/foo', 'line' => 'option=asdf', @@ -86,145 +97,163 @@ } end - it { should contain_class('types') } - - it { - should contain_file_line('some_file').with({ - 'path' => '/tmp/foo', - 'line' => 'option=asdf', - 'match' => nil, - }) - } - - it { - should contain_file_line('some_other_file').with({ - 'path' => '/tmp/bar', - 'line' => 'option=asdf', - 'match' => '^option', - }) - } - - it { - should contain_file_line('another_line').with({ - 'ensure' => 'absent', - 'path' => '/tmp/bar', - 'line' => 'param=x', - }) - } + it { is_expected.to contain_class('types') } + + it do + is_expected.to contain_file_line('some_file').with( + { + 'path' => '/tmp/foo', + 'line' => 'option=asdf', + 'match' => nil, + }, + ) + end + + it do + is_expected.to contain_file_line('some_other_file').with( + { + 'path' => '/tmp/bar', + 'line' => 'option=asdf', + 'match' => '^option', + }, + ) + end + + it do + is_expected.to contain_file_line('another_line').with( + { + 'ensure' => 'absent', + 'path' => '/tmp/bar', + 'line' => 'param=x', + }, + ) + end end context 'with files specified as a hash' do - let(:facts) { { :osfamily => 'RedHat' } } - let(:params) { { :files => { - '/localdisk' => { - 'ensure' => 'directory', - 'mode' => '0755', - 'owner' => 'root', - 'group' => 'root', - }, - '/tmp/file1' => { - 'ensure' => 'present', - 'mode' => '0777', - 'owner' => 'root', - 'group' => 'root', - 'content' => 'This is the content', - 'backup' => 'foobucket', - 'checksum' => 'none', - 'force' => 'purge', - 'ignore' => ['.svn', '.foo'], - 'links' => 'follow', - 'provider' => 'posix', - 'purge' => true, - 'recurse' => true, - 'recurselimit' => 2, - 'replace' => false, - 'selinux_ignore_defaults' => false, - 'selrange' => 's0', - 'selrole' => 'object_r', - 'seltype' => 'var_t', - 'seluser' => 'system_u', - 'show_diff' => false, - 'source' => 'puppet://modules/types/mydir', - 'sourceselect' => 'first', - }, - '/tmp/file2' => { - }, - '/softlink' => { - 'ensure' => 'link', - 'target' => '/etc/motd', - }, - '/tmp/dir' => { - 'ensure' => 'directory', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0777', - }, - } } } - - it { should contain_class('types') } - - it { - should contain_file('/localdisk').with({ - 'ensure' => 'directory', - 'mode' => '0755', - 'owner' => 'root', - 'group' => 'root', - }) - } - - it { - should contain_file('/tmp/file1').with({ - 'ensure' => 'present', - 'mode' => '0777', - 'owner' => 'root', - 'group' => 'root', - 'content' => 'This is the content', - 'backup' => 'foobucket', - 'checksum' => 'none', - 'force' => 'purge', - 'ignore' => ['.svn', '.foo'], - 'links' => 'follow', - 'provider' => 'posix', - 'purge' => true, - 'recurse' => true, - 'recurselimit' => 2, - 'replace' => false, - 'selinux_ignore_defaults' => false, - 'selrange' => 's0', - 'selrole' => 'object_r', - 'seltype' => 'var_t', - 'seluser' => 'system_u', - 'show_diff' => false, - 'source' => 'puppet://modules/types/mydir', - 'sourceselect' => 'first', - }) - } - - it { - should contain_file('/tmp/file2').with({ - 'ensure' => 'present', - 'mode' => '0644', - 'owner' => 'root', - 'group' => 'root', - }) - } - - it { - should contain_file('/tmp/dir').with({ - 'ensure' => 'directory', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0777', - }) - } + let(:facts) { { osfamily: 'RedHat' } } + let(:params) do + { + files: { + '/localdisk' => { + 'ensure' => 'directory', + 'mode' => '0755', + 'owner' => 'root', + 'group' => 'root', + }, + '/tmp/file1' => { + 'ensure' => 'present', + 'mode' => '0777', + 'owner' => 'root', + 'group' => 'root', + 'content' => 'This is the content', + 'backup' => 'foobucket', + 'checksum' => 'none', + 'force' => 'purge', + 'ignore' => ['.svn', '.foo'], + 'links' => 'follow', + 'provider' => 'posix', + 'purge' => true, + 'recurse' => true, + 'recurselimit' => 2, + 'replace' => false, + 'selinux_ignore_defaults' => false, + 'selrange' => 's0', + 'selrole' => 'object_r', + 'seltype' => 'var_t', + 'seluser' => 'system_u', + 'show_diff' => false, + 'source' => 'puppet://modules/types/mydir', + 'sourceselect' => 'first', + }, + '/tmp/file2' => { + }, + '/softlink' => { + 'ensure' => 'link', + 'target' => '/etc/motd', + }, + '/tmp/dir' => { + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0777', + }, + } + } + end + + it { is_expected.to contain_class('types') } + + it do + is_expected.to contain_file('/localdisk').with( + { + 'ensure' => 'directory', + 'mode' => '0755', + 'owner' => 'root', + 'group' => 'root', + }, + ) + end + + it do + is_expected.to contain_file('/tmp/file1').with( + { + 'ensure' => 'present', + 'mode' => '0777', + 'owner' => 'root', + 'group' => 'root', + 'content' => 'This is the content', + 'backup' => 'foobucket', + 'checksum' => 'none', + 'force' => 'purge', + 'ignore' => ['.svn', '.foo'], + 'links' => 'follow', + 'provider' => 'posix', + 'purge' => true, + 'recurse' => true, + 'recurselimit' => 2, + 'replace' => false, + 'selinux_ignore_defaults' => false, + 'selrange' => 's0', + 'selrole' => 'object_r', + 'seltype' => 'var_t', + 'seluser' => 'system_u', + 'show_diff' => false, + 'source' => 'puppet://modules/types/mydir', + 'sourceselect' => 'first', + }, + ) + end + + it do + is_expected.to contain_file('/tmp/file2').with( + { + 'ensure' => 'present', + 'mode' => '0644', + 'owner' => 'root', + 'group' => 'root', + }, + ) + end + + it do + is_expected.to contain_file('/tmp/dir').with( + { + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0777', + }, + ) + end end context 'with packages specified as a hash' do - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } let :params do { - :packages_hiera_merge => 'false', - :packages => { + packages_hiera_merge: 'false', + packages: { 'pkg1' => { 'ensure' => 'present', }, @@ -238,34 +267,39 @@ } end - it { should contain_class('types') } - - it { - should contain_package('pkg1').with({ - 'ensure' => 'present', - }) - } + it { is_expected.to contain_class('types') } - it { - should contain_package('pkg2').with({ - 'ensure' => 'absent', - }) - } + it do + is_expected.to contain_package('pkg1').with( + { + 'ensure' => 'present', + }, + ) + end - it { - should contain_package('pkg3').with({ - 'ensure' => 'latest', - }) - } + it do + is_expected.to contain_package('pkg2').with( + { + 'ensure' => 'absent', + }, + ) + end + it do + is_expected.to contain_package('pkg3').with( + { + 'ensure' => 'latest', + }, + ) + end end context 'with selboolean specified as a hash' do - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } let :params do { - :selbooleans_hiera_merge => 'false', - :selbooleans => { + selbooleans_hiera_merge: 'false', + selbooleans: { 'nfs_export_all_ro' => { 'value' => 'on', }, @@ -277,125 +311,139 @@ } end - it { should contain_class('types') } - it { - should contain_selboolean('nfs_export_all_ro').with({ - 'value' => 'on', - }) - } - it { - should contain_selboolean('nfs_export_all_rw').with({ - 'persistent' => true, - 'value' => 'on', - }) - } + it { is_expected.to contain_class('types') } + it do + is_expected.to contain_selboolean('nfs_export_all_ro').with( + { + 'value' => 'on', + }, + ) + end + + it do + is_expected.to contain_selboolean('nfs_export_all_rw').with( + { + 'persistent' => true, + 'value' => 'on', + }, + ) + end end context 'with selboolean specified as an invalid type' do - let(:facts) { { :osfamily => 'RedHat' } } - let(:params) { { :selbooleans => ['not','a','hash'] } } + let(:facts) { { osfamily: 'RedHat' } } + let(:params) { { selbooleans: ['not', 'a', 'hash'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end context 'with mounts specified as an invalid type' do - let(:params) { { :mounts => ['not','a','hash'] } } + let(:params) { { mounts: ['not', 'a', 'hash'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/\["not", "a", "hash"\] is not a Hash\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{\["not", "a", "hash"\] is not a Hash\.}) end end context 'with packages specified as an invalid type' do - let(:params) { { :packages => ['not','a','hash'] } } + let(:params) { { packages: ['not', 'a', 'hash'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end context 'with file_lines specified as an invalid type' do - let(:params) { { :file_lines => ['not','a','hash'] } } + let(:params) { { file_lines: ['not', 'a', 'hash'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end context 'with files specified as an invalid type' do - let(:params) { { :files => ['not','a','hash'] } } + let(:params) { { files: ['not', 'a', 'hash'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/\["not", "a", "hash"\] is not a Hash\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{\["not", "a", "hash"\] is not a Hash\.}) end end context 'with cron specified as a hash' do - let(:facts) { { :osfamily => 'RedHat' } } - let(:params) { { :crons => { - 'cronjob-1' => { - 'command' => '/usr/local/bin/some-script.sh', - 'hour' => '0', - 'minute' => '10', - 'weekday' => '0', - }, - 'cronjob-2' => { - 'command' => '/usr/local/bin/script.sh', - 'hour' => '23', - 'minute' => '0', - 'user' => 'www-user', + let(:facts) { { osfamily: 'RedHat' } } + let(:params) do + { + crons: { + 'cronjob-1' => { + 'command' => '/usr/local/bin/some-script.sh', + 'hour' => '0', + 'minute' => '10', + 'weekday' => '0', + }, + 'cronjob-2' => { + 'command' => '/usr/local/bin/script.sh', + 'hour' => '23', + 'minute' => '0', + 'user' => 'www-user', + } + } } - } } } - - it { should contain_class('types') } - - it { - should contain_cron('cronjob-1').with({ - 'ensure' => 'present', - 'command' => '/usr/local/bin/some-script.sh', - 'hour' => '0', - 'minute' => '10', - 'weekday' => '0', - }) - } - it { - should contain_cron('cronjob-2').with({ - 'ensure' => 'present', - 'command' => '/usr/local/bin/script.sh', - 'hour' => '23', - 'minute' => '0', - 'user' => 'www-user', - }) - } + end + + it { is_expected.to contain_class('types') } + + it do + is_expected.to contain_cron('cronjob-1').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/some-script.sh', + 'hour' => '0', + 'minute' => '10', + 'weekday' => '0', + }, + ) + end + + it do + is_expected.to contain_cron('cronjob-2').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/script.sh', + 'hour' => '23', + 'minute' => '0', + 'user' => 'www-user', + }, + ) + end end context 'with cron specified as an invalid type' do - let(:params) { { :crons => ['not','a','hash'] } } + let(:params) { { crons: ['not', 'a', 'hash'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/\["not", "a", "hash"\] is not a Hash\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{\["not", "a", "hash"\] is not a Hash\.}) end end context 'with exec specified as a hash' do - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } let(:params) do { - :execs => { + execs: { 'exec-1' => { 'command' => '/usr/local/bin/some-script.sh', 'creates' => '/tmp/touch', @@ -422,41 +470,46 @@ } end - it { should contain_class('types') } + it { is_expected.to contain_class('types') } it do - should contain_types__exec('exec-1').with({ - 'command' => '/usr/local/bin/some-script.sh', - 'creates' => '/tmp/touch', - 'cwd' => '/tmp', - 'environment' => 'var=value', - 'group' => 'group-1', - 'logoutput' => true, - 'onlyif' => '/onlyif.sh', - 'path' => '/tmp', - 'provider' => 'shell', - }) - end - it { - should contain_types__exec('exec-2').with({ - 'command' => '/usr/local/bin/script.sh', - 'refresh' => '/refresh.sh', - 'refreshonly' => true, - 'returns' => 242, - 'timeout' => 3, - 'tries' => 3, - 'try_sleep' => 3, - 'unless' => '/unless.sh', - 'user' => 'tester', - }) - } + is_expected.to contain_types__exec('exec-1').with( + { + 'command' => '/usr/local/bin/some-script.sh', + 'creates' => '/tmp/touch', + 'cwd' => '/tmp', + 'environment' => 'var=value', + 'group' => 'group-1', + 'logoutput' => true, + 'onlyif' => '/onlyif.sh', + 'path' => '/tmp', + 'provider' => 'shell', + }, + ) + end + + it do + is_expected.to contain_types__exec('exec-2').with( + { + 'command' => '/usr/local/bin/script.sh', + 'refresh' => '/refresh.sh', + 'refreshonly' => true, + 'returns' => 242, + 'timeout' => 3, + 'tries' => 3, + 'try_sleep' => 3, + 'unless' => '/unless.sh', + 'user' => 'tester', + }, + ) + end end context 'with services specified as a hash' do let :params do { - :services_hiera_merge => 'false', - :services => { + services_hiera_merge: 'false', + services: { 'service-stopped' => { 'ensure' => 'stopped', 'enable' => 'false', @@ -469,28 +522,33 @@ } end - it { should contain_class('types') } - - it { - should contain_service('service-stopped').with({ - 'ensure' => 'stopped', - 'enable' => 'false', - }) - } - it { - should contain_service('service-running').with({ - 'ensure' => 'running', - 'enable' => 'true', - }) - } + it { is_expected.to contain_class('types') } + + it do + is_expected.to contain_service('service-stopped').with( + { + 'ensure' => 'stopped', + 'enable' => 'false', + }, + ) + end + + it do + is_expected.to contain_service('service-running').with( + { + 'ensure' => 'running', + 'enable' => 'true', + }, + ) + end end context 'with service specified as an invalid type' do - let(:params) { { :services => ['not','a','hash'] } } + let(:params) { { services: ['not', 'a', 'hash'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 970e0f6..c6bd3c2 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -1,72 +1,77 @@ require 'spec_helper' describe 'types::cron' do - context 'cron with bare minimum specified' do let(:title) { 'cronjob-1' } let(:params) do - { :command => '/usr/local/bin/script.sh' } + { command: '/usr/local/bin/script.sh' } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it { - should contain_cron('cronjob-1').with({ - 'ensure' => 'present', - 'command' => '/usr/local/bin/script.sh', - }) - } + it do + is_expected.to contain_cron('cronjob-1').with( + { + 'ensure' => 'present', + 'command' => '/usr/local/bin/script.sh', + }, + ) + end end context 'cron with all options specified' do let(:title) { 'cronjob-1' } let(:params) do - { :command => '/usr/local/bin/script.sh', - :ensure => 'absent', - :environment => '/bin:/usr/bin', - :hour => '1', - :minute => '10', - :month => 'Jan', - :monthday => '1', - :provider => 'crontab', - :special => 'absent', - :target => 'root', - :user => 'root', - :weekday => '6', + { + command: '/usr/local/bin/script.sh', + ensure: 'absent', + environment: '/bin:/usr/bin', + hour: '1', + minute: '10', + month: 'Jan', + monthday: '1', + provider: 'crontab', + special: 'absent', + target: 'root', + user: 'root', + weekday: '6', } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it { - should contain_cron('cronjob-1').with({ - 'ensure' => 'absent', - 'command' => '/usr/local/bin/script.sh', - 'environment' => '/bin:/usr/bin', - 'hour' => '1', - 'minute' => '10', - 'month' => 'Jan', - 'monthday' => '1', - 'provider' => 'crontab', - 'special' => 'absent', - 'target' => 'root', - 'user' => 'root', - 'weekday' => '6', - }) - } + it do + is_expected.to contain_cron('cronjob-1').with( + { + 'ensure' => 'absent', + 'command' => '/usr/local/bin/script.sh', + 'environment' => '/bin:/usr/bin', + 'hour' => '1', + 'minute' => '10', + 'month' => 'Jan', + 'monthday' => '1', + 'provider' => 'crontab', + 'special' => 'absent', + 'target' => 'root', + 'user' => 'root', + 'weekday' => '6', + }, + ) + end end context 'cron with invalid ensure' do let(:title) { 'invalid' } let(:params) do - { :command => '/usr/local/bin/script', - :hour => '2', - :minute => '0', - :ensure => '!invalid', + { + command: '/usr/local/bin/script', + hour: '2', + minute: '0', + ensure: '!invalid', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::cron::invalid::ensure is invalid and does not match the regex\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::cron::invalid::ensure is invalid and does not match the regex\.}) end end end diff --git a/spec/defines/exec_spec.rb b/spec/defines/exec_spec.rb index 4644f2d..d9f749c 100644 --- a/spec/defines/exec_spec.rb +++ b/spec/defines/exec_spec.rb @@ -1,87 +1,91 @@ require 'spec_helper' describe 'types::exec' do let(:title) { 'testing' } - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } context 'exec with no parameter specified' do - it 'should fail' do - expect { should contain_class(subject) }.to raise_error(Puppet::Error, /(expects a value for parameter \'command\'|Must pass command to)/) + it 'fails' do + expect { is_expected.to contain_class(:subject) }.to raise_error(Puppet::Error, %r{(expects a value for parameter \'command\'|Must pass command to)}) end end context 'exec with bare minimum specified' do - let(:params) { { :command => '/spec/testing.sh' } } - it { should contain_exec('testing').only_with_command('/spec/testing.sh') } + let(:params) { { command: '/spec/testing.sh' } } + + it { is_expected.to contain_exec('testing').only_with_command('/spec/testing.sh') } end context 'exec with all options specified' do let(:title) { 'testing' } let(:params) do { - :command => '/spec/testing.sh', - :creates => '/creates', - :cwd => '/spec', - :environment => 'test=true', - :group => 'group', - :logoutput => true, - :onlyif => '/onlyif.sh', - :path => '/path', - :provider => 'shell', - :refresh => '/refresh.sh', - :refreshonly => true, - :returns => 242, - :timeout => 3, - :tries => 3, - :try_sleep => 3, - :unless => '/unless.sh', - :user => 'tester', + command: '/spec/testing.sh', + creates: '/creates', + cwd: '/spec', + environment: 'test=true', + group: 'group', + logoutput: true, + onlyif: '/onlyif.sh', + path: '/path', + provider: 'shell', + refresh: '/refresh.sh', + refreshonly: true, + returns: 242, + timeout: 3, + tries: 3, + try_sleep: 3, + unless: '/unless.sh', + user: 'tester', } end - it { - should contain_exec('testing').with({ - 'command' => '/spec/testing.sh', - 'creates' => '/creates', - 'cwd' => '/spec', - 'environment' => 'test=true', - 'group' => 'group', - 'logoutput' => true, - 'onlyif' => '/onlyif.sh', - 'path' => '/path', - 'provider' => 'shell', - 'refresh' => '/refresh.sh', - 'refreshonly' => true, - 'returns' => 242, - 'timeout' => 3, - 'tries' => 3, - 'try_sleep' => 3, - 'unless' => '/unless.sh', - 'user' => 'tester', - }) - } + it do + is_expected.to contain_exec('testing').with( + { + 'command' => '/spec/testing.sh', + 'creates' => '/creates', + 'cwd' => '/spec', + 'environment' => 'test=true', + 'group' => 'group', + 'logoutput' => true, + 'onlyif' => '/onlyif.sh', + 'path' => '/path', + 'provider' => 'shell', + 'refresh' => '/refresh.sh', + 'refreshonly' => true, + 'returns' => 242, + 'timeout' => 3, + 'tries' => 3, + 'try_sleep' => 3, + 'unless' => '/unless.sh', + 'user' => 'tester', + }, + ) + end end context 'exec with invalid provider' do - let(:params) { { :provider=> 'invalid', :command => '/spec/testing.sh' } } - it 'should fail' do - expect { should contain_class(subject) }.to raise_error(Puppet::Error, /types::exec::testing::provider is invalid and does not match the regex/) + let(:params) { { provider: 'invalid', command: '/spec/testing.sh' } } + + it 'fails' do + expect { is_expected.to contain_class(:subject) }.to raise_error(Puppet::Error, %r{types::exec::testing::provider is invalid and does not match the regex}) end end describe 'variable type and content validations' do - mandatory_params = { :command => '/spec/testing.sh' } + mandatory_params = { command: '/spec/testing.sh' } validations = { 'validate_absolute_path' => { - :name => %w[creates cwd], - :valid => ['/absolute/filepath', '/absolute/directory/'], - :invalid => ['./relative/path', %w[array], { 'ha' => 'sh' }, 3, 2.42, true, nil], - :message => 'is not an absolute path', + name: ['creates', 'cwd'], + valid: ['/absolute/filepath', '/absolute/directory/'], + invalid: ['./relative/path', ['array'], { 'ha' => 'sh' }, 3, 2.42, true, nil], + message: 'is not an absolute path', }, 'validate_re' => { - :name => %w[provider], - :valid => %w[posix shell windows], - :invalid => ['string', %w[array], { 'ha' => 'sh' }, 3, 2.42, true, nil], - :message => 'types::exec::testing::provider is invalid and does not match the regex', + name: ['provider'], + valid: ['posix', 'shell', 'windows'], + invalid: ['string', ['array'], { 'ha' => 'sh' }, 3, 2.42, true, nil], + message: 'types::exec::testing::provider is invalid and does not match the regex', }, } @@ -90,16 +94,18 @@ var[:params] = {} if var[:params].nil? var[:valid].each do |valid| context "when #{var_name} (#{type}) is set to valid #{valid} (as #{valid.class})" do - let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => valid, }].reduce(:merge) } - it { should compile } + let(:params) { [mandatory_params, var[:params], { "#{var_name}": valid, }].reduce(:merge) } + + it { is_expected.to compile } end end var[:invalid].each do |invalid| context "when #{var_name} (#{type}) is set to invalid #{invalid} (as #{invalid.class})" do - let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => invalid, }].reduce(:merge) } - it 'should fail' do - expect { should contain_class(subject) }.to raise_error(Puppet::Error, /#{var[:message]}/) + let(:params) { [mandatory_params, var[:params], { "#{var_name}": invalid, }].reduce(:merge) } + + it 'fails' do + expect { is_expected.to contain_class(:subject) }.to raise_error(Puppet::Error, %r{#{var[:message]}}) end end end diff --git a/spec/defines/file_line_spec.rb b/spec/defines/file_line_spec.rb index 1febdae..c8bdb44 100644 --- a/spec/defines/file_line_spec.rb +++ b/spec/defines/file_line_spec.rb @@ -5,68 +5,74 @@ context 'file_line with minimal parameters specified (path and line)' do let(:params) do { - :path => '/tmp/foo', - :line => 'option=asdf', + path: '/tmp/foo', + line: 'option=asdf', } end - it { should contain_file_line('some_file').with({ - 'path' => '/tmp/foo', - 'line' => 'option=asdf', - 'match' => nil, - }) - } + it do + is_expected.to contain_file_line('some_file').with( + { + 'path' => '/tmp/foo', + 'line' => 'option=asdf', + 'match' => nil, + }, + ) + end end context 'file_line with all parameters specified' do let(:params) do { - :ensure => 'present', - :path => '/tmp/foo', - :line => 'option=asdf', - :match => '^option', + ensure: 'present', + path: '/tmp/foo', + line: 'option=asdf', + match: '^option', } end - it { should contain_file_line('some_file').with({ - 'ensure' => 'present', - 'path' => '/tmp/foo', - 'line' => 'option=asdf', - 'match' => '^option', - }) - } + it do + is_expected.to contain_file_line('some_file').with( + { + 'ensure' => 'present', + 'path' => '/tmp/foo', + 'line' => 'option=asdf', + 'match' => '^option', + }, + ) + end end describe 'with an invalid path for the path parameter' do let(:params) do { - :path => 'invalid/path', - :line => 'option=asdf', - :match => '^option', + path: 'invalid/path', + line: 'option=asdf', + match: '^option', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/"invalid\/path" is not an absolute path/) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{"invalid/path" is not an absolute path}) end end describe 'with an invalid ensure parameter' do let(:params) do { - :ensure => '!invalid', - :path => '/tmp/foo', - :line => 'option=asdf', - :match => '^option', + ensure: '!invalid', + path: '/tmp/foo', + line: 'option=asdf', + match: '^option', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::file_line::some_file::ensure is invalid and does not match the regex\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::file_line::some_file::ensure is invalid and does not match the regex\.}) end end @@ -74,48 +80,48 @@ context 'for the path parameter' do let(:params) do { - :path => true, - :line => 'option=asdf', - :match => '^option', + path: true, + line: 'option=asdf', + match: '^option', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/true is not an absolute path/) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{true is not an absolute path}) end end context 'for the line parameter' do let(:params) do { - :path => '/tmp/foo', - :line => ['invalid','type'], - :match => '^option', + path: '/tmp/foo', + line: ['invalid', 'type'], + match: '^option', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a string/) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a string}) end end context 'for the match parameter' do let(:params) do { - :path => '/tmp/foo', - :line => 'option=asdf', - :match => ['invalid','type'], + path: '/tmp/foo', + line: 'option=asdf', + match: ['invalid', 'type'], } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a string/) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a string}) end end end diff --git a/spec/defines/file_spec.rb b/spec/defines/file_spec.rb index 3a8414b..db16fb7 100644 --- a/spec/defines/file_spec.rb +++ b/spec/defines/file_spec.rb @@ -3,119 +3,128 @@ let(:title) { '/tmp/foo' } context 'file with no options specified' do - it { should contain_file('/tmp/foo').with({ - 'ensure' => 'present', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + it do + is_expected.to contain_file('/tmp/foo').with( + { + 'ensure' => 'present', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }, + ) + end end context 'file with all options specified' do let(:params) do - { :ensure => 'present', - :mode => '0777', - :owner => 'root', - :group => 'root', - :content => 'This is the content', - :backup => 'foobucket', - :checksum => 'none', - :force => 'purge', - :ignore => ['.svn', '.foo'], - :links => 'follow', - :provider => 'posix', - :purge => true, - :recurse => true, - :recurselimit => 2, - :replace => false, - :selinux_ignore_defaults => false, - :selrange => 's0', - :selrole => 'object_r', - :seltype => 'var_t', - :seluser => 'system_u', - :show_diff => false, - :source => 'puppet://modules/types/mydir', - :sourceselect => 'first', + { + ensure: 'present', + mode: '0777', + owner: 'root', + group: 'root', + content: 'This is the content', + backup: 'foobucket', + checksum: 'none', + force: 'purge', + ignore: ['.svn', '.foo'], + links: 'follow', + provider: 'posix', + purge: true, + recurse: true, + recurselimit: 2, + replace: false, + selinux_ignore_defaults: false, + selrange: 's0', + selrole: 'object_r', + seltype: 'var_t', + seluser: 'system_u', + show_diff: false, + source: 'puppet://modules/types/mydir', + sourceselect: 'first', } end - it { - should contain_file('/tmp/foo').with({ - 'ensure' => 'present', - 'mode' => '0777', - 'owner' => 'root', - 'group' => 'root', - 'content' => 'This is the content', - 'backup' => 'foobucket', - 'checksum' => 'none', - 'force' => 'purge', - 'ignore' => ['.svn', '.foo'], - 'links' => 'follow', - 'provider' => 'posix', - 'purge' => true, - 'recurse' => true, - 'recurselimit' => 2, - 'replace' => false, - 'selinux_ignore_defaults' => false, - 'selrange' => 's0', - 'selrole' => 'object_r', - 'seltype' => 'var_t', - 'seluser' => 'system_u', - 'show_diff' => false, - 'source' => 'puppet://modules/types/mydir', - 'sourceselect' => 'first', - }) - } + it do + is_expected.to contain_file('/tmp/foo').with( + { + 'ensure' => 'present', + 'mode' => '0777', + 'owner' => 'root', + 'group' => 'root', + 'content' => 'This is the content', + 'backup' => 'foobucket', + 'checksum' => 'none', + 'force' => 'purge', + 'ignore' => ['.svn', '.foo'], + 'links' => 'follow', + 'provider' => 'posix', + 'purge' => true, + 'recurse' => true, + 'recurselimit' => 2, + 'replace' => false, + 'selinux_ignore_defaults' => false, + 'selrange' => 's0', + 'selrole' => 'object_r', + 'seltype' => 'var_t', + 'seluser' => 'system_u', + 'show_diff' => false, + 'source' => 'puppet://modules/types/mydir', + 'sourceselect' => 'first', + }, + ) + end end describe 'with ensure' do - ['present','absent','file','directory','link'].each do |value| + ['present', 'absent', 'file', 'directory', 'link'].each do |value| context "set to #{value}" do - let(:params) { { :ensure => value } } + let(:params) { { ensure: value } } - it { should contain_file('/tmp/foo').with({ - 'ensure' => value, - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) + it { + is_expected.to contain_file('/tmp/foo').with( + { + 'ensure' => value, + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }, + ) } end end end context 'file with invalid ensure' do - let(:params) { { :ensure => 'invalid' } } + let(:params) { { ensure: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::file::\/tmp\/foo::ensure is invalid and does not match the regex\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::file::/tmp/foo::ensure is invalid and does not match the regex\.}) end end describe 'file with mode set to invalid' do - ['666',665,'10666','foo',true].each do |value| + ['666', 665, '10666', 'foo', true].each do |value| context "value of #{value}" do - let(:params) { { :mode => 'invalid' } } + let(:params) { { mode: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::file::\/tmp\/foo::mode must be exactly 4 digits\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::file::/tmp/foo::mode must be exactly 4 digits\.}) end end end end context 'file with name that is not an absolute path' do - let(:params) { { :ensure => 'invalid/path' } } + let(:params) { { ensure: 'invalid/path' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::file::\/tmp\/foo::ensure is invalid and does not match the regex\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::file::/tmp/foo::ensure is invalid and does not match the regex\.}) end end end diff --git a/spec/defines/mount_spec.rb b/spec/defines/mount_spec.rb index 6acdc71..7bc4349 100644 --- a/spec/defines/mount_spec.rb +++ b/spec/defines/mount_spec.rb @@ -1,75 +1,81 @@ require 'spec_helper' describe 'types::mount' do - context 'mount with bare minimum specified' do let(:title) { '/mnt' } let(:params) do - { :device => '/dev/dvd', - :fstype => 'iso9660', + { + device: '/dev/dvd', + fstype: 'iso9660', } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it { - should contain_mount('/mnt').with({ - 'ensure' => 'mounted', - 'name' => '/mnt', - 'atboot' => true, - 'device' => '/dev/dvd', - 'fstype' => 'iso9660', - }) - } + it do + is_expected.to contain_mount('/mnt').with( + { + 'ensure' => 'mounted', + 'name' => '/mnt', + 'atboot' => true, + 'device' => '/dev/dvd', + 'fstype' => 'iso9660', + }, + ) + end end context 'mount with all options specified' do let(:title) { '/mnt' } let(:params) do - { :device => '/dev/fiction', - :fstype => 'iso9660', - :ensure => 'absent', - :atboot => false, - :blockdevice => '/dev/blockdevice', - :dump => '1', - :options => 'ro', - :pass => '1', - :provider => 'customprovider', - :remounts => true, + { + device: '/dev/fiction', + fstype: 'iso9660', + ensure: 'absent', + atboot: false, + blockdevice: '/dev/blockdevice', + dump: '1', + options: 'ro', + pass: '1', + provider: 'customprovider', + remounts: true, } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it { - should contain_mount('/mnt').with({ - 'ensure' => 'absent', - 'atboot' => false, - 'device' => '/dev/fiction', - 'fstype' => 'iso9660', - 'name' => '/mnt', - 'blockdevice' => '/dev/blockdevice', - 'dump' => '1', - 'options' => 'ro', - 'pass' => '1', - 'provider' => 'customprovider', - 'remounts' => true, - }) - } + it do + is_expected.to contain_mount('/mnt').with( + { + 'ensure' => 'absent', + 'atboot' => false, + 'device' => '/dev/fiction', + 'fstype' => 'iso9660', + 'name' => '/mnt', + 'blockdevice' => '/dev/blockdevice', + 'dump' => '1', + 'options' => 'ro', + 'pass' => '1', + 'provider' => 'customprovider', + 'remounts' => true, + }, + ) + end end context 'mount with invalid ensure' do let(:title) { 'invalid' } let(:params) do - { :device => '/dev/fiction', - :fstype => 'iso9660', - :target => '/mnt', - :ensure => '!invalid', + { + device: '/dev/fiction', + fstype: 'iso9660', + target: '/mnt', + ensure: '!invalid', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::mount::invalid::ensure is invalid and does not match the regex\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::mount::invalid::ensure is invalid and does not match the regex\.}) end end @@ -77,16 +83,17 @@ context 'on osfamily RedHat' do let(:title) { '/mnt/test' } let(:params) do - { :ensure => 'absent', - :device => '/dev/fiction', - :fstype => 'iso9660', + { + ensure: 'absent', + device: '/dev/fiction', + fstype: 'iso9660', } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it { - should_not contain_exec('mkdir_p-/mnt/test') - } + it do + is_expected.not_to contain_exec('mkdir_p-/mnt/test') + end end end @@ -94,41 +101,47 @@ context 'on osfamily Solaris' do let(:title) { '/mnt' } let(:params) do - { :device => '/dev/fiction', - :fstype => 'iso9660', - :options => 'defaults', + { + device: '/dev/fiction', + fstype: 'iso9660', + options: 'defaults', } end - let(:facts) { { :osfamily => 'Solaris' } } + let(:facts) { { osfamily: 'Solaris' } } - it { - should contain_mount('/mnt').with({ - 'ensure' => 'mounted', - 'device' => '/dev/fiction', - 'fstype' => 'iso9660', - 'options' => '-', - }) - } + it do + is_expected.to contain_mount('/mnt').with( + { + 'ensure' => 'mounted', + 'device' => '/dev/fiction', + 'fstype' => 'iso9660', + 'options' => '-', + }, + ) + end end context 'on osfamily that is not Solaris' do let(:title) { '/mnt' } let(:params) do - { :device => '/dev/fiction', - :fstype => 'iso9660', - :options => 'defaults', + { + device: '/dev/fiction', + fstype: 'iso9660', + options: 'defaults', } end - let(:facts) { { :osfamily => 'Debian' } } + let(:facts) { { osfamily: 'Debian' } } - it { - should contain_mount('/mnt').with({ - 'ensure' => 'mounted', - 'device' => '/dev/fiction', - 'fstype' => 'iso9660', - 'options' => 'defaults', - }) - } + it do + is_expected.to contain_mount('/mnt').with( + { + 'ensure' => 'mounted', + 'device' => '/dev/fiction', + 'fstype' => 'iso9660', + 'options' => 'defaults', + }, + ) + end end end end diff --git a/spec/defines/package_spec.rb b/spec/defines/package_spec.rb index 46026d3..cef1aab 100644 --- a/spec/defines/package_spec.rb +++ b/spec/defines/package_spec.rb @@ -1,58 +1,62 @@ require 'spec_helper' describe 'types::package' do - context 'package with bare minimum specified' do let(:title) { 'pkg1' } - it { - should contain_package('pkg1').with({ - 'ensure' => 'present', - }) - } + + it do + is_expected.to contain_package('pkg1').with( + { + 'ensure' => 'present', + }, + ) + end end context 'package with all options specified' do let(:title) { 'pkg1' } let(:params) do { - :ensure => 'installed', - :adminfile => '/path/to/adminfile', - :configfiles => 'keep', - :install_options => '--installoption', - :provider => 'yum', - :responsefile => '/path/to/responsefile', - :source => 'http://source/URL/', - :uninstall_options => '--uninstall_option', + ensure: 'installed', + adminfile: '/path/to/adminfile', + configfiles: 'keep', + install_options: '--installoption', + provider: 'yum', + responsefile: '/path/to/responsefile', + source: 'http://source/URL/', + uninstall_options: '--uninstall_option', } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it { - should contain_package('pkg1').with({ - 'ensure' => 'installed', - 'adminfile' => '/path/to/adminfile', - 'configfiles' => 'keep', - 'install_options' => '--installoption', - 'provider' => 'yum', - 'responsefile' => '/path/to/responsefile', - 'source' => 'http://source/URL/', - 'uninstall_options' => '--uninstall_option', - }) - } + it do + is_expected.to contain_package('pkg1').with( + { + 'ensure' => 'installed', + 'adminfile' => '/path/to/adminfile', + 'configfiles' => 'keep', + 'install_options' => '--installoption', + 'provider' => 'yum', + 'responsefile' => '/path/to/responsefile', + 'source' => 'http://source/URL/', + 'uninstall_options' => '--uninstall_option', + }, + ) + end end context 'package with invalid configfiles' do let(:title) { 'pkg1' } let(:params) do { - :configfiles => 'invalid', + configfiles: 'invalid', } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::package::pkg1::configfiles is invalid and does not match the regex\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::package::pkg1::configfiles is invalid and does not match the regex\.}) end end @@ -60,28 +64,30 @@ let(:title) { 'invalidtype' } let(:params) do { - :ensure => ['invalid','type'], + ensure: ['invalid', 'type'], } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a string\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a string\.}) end end context 'package with invalid responsefile' do let(:title) { 'pkg1' } let(:params) do - { :responsefile => 'invalid/path' } + { + responsefile: 'invalid/path' + } end - let(:facts) { { :osfamily => 'RedHat' } } + let(:facts) { { osfamily: 'RedHat' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/"invalid\/path" is not an absolute path\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{"invalid/path" is not an absolute path\.}) end end end diff --git a/spec/defines/selboolean_spec.rb b/spec/defines/selboolean_spec.rb index 3963b56..949c54f 100644 --- a/spec/defines/selboolean_spec.rb +++ b/spec/defines/selboolean_spec.rb @@ -4,79 +4,83 @@ context 'selboolean with all options specified' do let(:params) do - { :persistent => true, - :value => 'on', - :provider => 'getsebool', - } + { persistent: true, + value: 'on', + provider: 'getsebool', } end - it { - should contain_selboolean('nfs_export_all_ro').with({ - 'persistent' => true, - 'value' => 'on', - }) - } + it do + is_expected.to contain_selboolean('nfs_export_all_ro').with( + { + 'persistent' => true, + 'value' => 'on', + }, + ) + end end describe 'with value' do - ['on','off'].each do |value| + ['on', 'off'].each do |value| context "set to #{value}" do - let(:params) { { :value => value } } + let(:params) { { value: value } } - it { - should contain_selboolean('nfs_export_all_ro').with({ - 'persistent' => false, - 'value' => value, - }) - } + it do + is_expected.to contain_selboolean('nfs_export_all_ro').with( + { + 'persistent' => false, + 'value' => value, + }, + ) + end end end end context 'selboolean with invalid value for provider' do let(:params) do - { :provider => false, } + { provider: false, } end - it 'should fail' do + + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end context 'selboolean with invalid value for persistent' do let(:params) do - { :persistent => 'invalid setting', } + { persistent: 'invalid setting', } end - it 'should fail' do + + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end context 'selboolean with invalid value for value' do let(:params) do - { :value => 'invalid setting', } + { value: 'invalid setting', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end context 'selboolean with no value - value is mandatory' do let(:params) do - { :persistent => false } + { persistent: false } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') + is_expected.to contain_class('types') }.to raise_error(Puppet::Error) end end - end diff --git a/spec/defines/service_spec.rb b/spec/defines/service_spec.rb index 8ba7d7f..00117a9 100644 --- a/spec/defines/service_spec.rb +++ b/spec/defines/service_spec.rb @@ -1,105 +1,111 @@ require 'spec_helper' describe 'types::service' do - context 'service with bare minimum specified' do let(:title) { 'service_minimum' } - it { - should contain_service('service_minimum').with({ - 'ensure' => 'running', - 'enable' => true, - }) - } + + it do + is_expected.to contain_service('service_minimum').with( + { + 'ensure' => 'running', + 'enable' => true, + }, + ) + end end context 'service with all options specified' do let(:title) { 'service_maximum' } let(:params) do { - :ensure => 'stopped', - :binary => '/bin/true', - :control => 'SERVICE_MAXIMUM_START', - :enable => 'manual', - :hasrestart => 'true', - :hasstatus => 'false', - :manifest => '/bin/manifest', - :path => '/etc/init.d', - :pattern => 'service_maximum', - :provider => 'init', - :restart => '/bin/restart', - :start => '/bin/start', - :status => '/bin/status', - :stop => '/bin/stop', + ensure: 'stopped', + binary: '/bin/true', + control: 'SERVICE_MAXIMUM_START', + enable: 'manual', + hasrestart: 'true', + hasstatus: 'false', + manifest: '/bin/manifest', + path: '/etc/init.d', + pattern: 'service_maximum', + provider: 'init', + restart: '/bin/restart', + start: '/bin/start', + status: '/bin/status', + stop: '/bin/stop', } end - it { - should contain_service('service_maximum').with({ - 'ensure' => 'stopped', - 'binary' => '/bin/true', - 'control' => 'SERVICE_MAXIMUM_START', - 'enable' => 'manual', - 'hasrestart' => 'true', - 'hasstatus' => 'false', - 'manifest' => '/bin/manifest', - 'path' => '/etc/init.d', - 'pattern' => 'service_maximum', - 'provider' => 'init', - 'restart' => '/bin/restart', - 'start' => '/bin/start', - 'status' => '/bin/status', - 'stop' => '/bin/stop', - }) - } + it do + is_expected.to contain_service('service_maximum').with( + { + 'ensure' => 'stopped', + 'binary' => '/bin/true', + 'control' => 'SERVICE_MAXIMUM_START', + 'enable' => 'manual', + 'hasrestart' => 'true', + 'hasstatus' => 'false', + 'manifest' => '/bin/manifest', + 'path' => '/etc/init.d', + 'pattern' => 'service_maximum', + 'provider' => 'init', + 'restart' => '/bin/restart', + 'start' => '/bin/start', + 'status' => '/bin/status', + 'stop' => '/bin/stop', + }, + ) + end end context 'service with invalid ensure' do let(:title) { 'invalid' } let(:params) do { - :ensure => 'invalid', + ensure: 'invalid', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::service::invalid::ensure can only be , , or and is set to /) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::service::invalid::ensure can only be , , or and is set to }) end end describe 'with parameter enable' do - ['true',true,'false',false,'manual'].each do |value| + ['true', true, 'false', false, 'manual'].each do |value| context "set to #{value}" do let(:title) { 'my_service' } - let(:params) { { :enable => value } } + let(:params) { { enable: value } } - it { - should contain_service('my_service').with({ - 'enable' => value, - }) - } + it do + is_expected.to contain_service('my_service').with( + { + 'enable' => value, + }, + ) + end end end context 'set to an invalid string' do let(:title) { 'invalid' } - let(:params) { { :enable => 'invalid' } } + let(:params) { { enable: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/types::service::invalid::enable can only be , or and is set to /) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{types::service::invalid::enable can only be , or and is set to }) end end context 'set to an invalid type (non-string and non-boolean)' do let(:title) { 'invalid_type' } - let(:params) { { :enable => ['invalid','type'] } } + let(:params) { { enable: ['invalid', 'type'] } } - it 'should fail' do + it 'fails' do expect { - should contain_class('types') - }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a boolean\./) + is_expected.to contain_class('types') + }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a boolean\.}) end end end From ba724f101251cf262e8e5cf2df5cc9bf53587bb7 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Wed, 5 Apr 2023 10:59:25 +0000 Subject: [PATCH 03/17] Satisfy puppet lint --- manifests/cron.pp | 4 +--- manifests/exec.pp | 4 +--- manifests/file.pp | 4 +--- manifests/file_line.pp | 4 +--- manifests/init.pp | 1 - manifests/mount.pp | 8 +++----- manifests/package.pp | 4 +--- manifests/selboolean.pp | 4 +--- manifests/service.pp | 7 ++----- 9 files changed, 11 insertions(+), 29 deletions(-) diff --git a/manifests/cron.pp b/manifests/cron.pp index 67f1990..7120fa5 100644 --- a/manifests/cron.pp +++ b/manifests/cron.pp @@ -14,10 +14,8 @@ $user = undef, $weekday = undef, ) { - # validate params - validate_re($ensure, '^(present)|(absent)$', - "types::cron::${name}::ensure is invalid and does not match the regex.") + validate_re($ensure, '^(present)|(absent)$', "types::cron::${name}::ensure is invalid and does not match the regex.") cron { $name: ensure => $ensure, diff --git a/manifests/exec.pp b/manifests/exec.pp index 4bb98e1..dd3ee44 100644 --- a/manifests/exec.pp +++ b/manifests/exec.pp @@ -19,7 +19,6 @@ $unless = undef, $user = undef, ) { - # validate params if $creates != undef { validate_absolute_path($creates) @@ -28,8 +27,7 @@ validate_absolute_path($cwd) } if $provider != undef { - validate_re($provider, '^(posix|shell|windows)$', - "types::exec::${name}::provider is invalid and does not match the regex.") + validate_re($provider, '^(posix|shell|windows)$', "types::exec::${name}::provider is invalid and does not match the regex.") } exec { $name: diff --git a/manifests/file.pp b/manifests/file.pp index 990f46b..977808d 100644 --- a/manifests/file.pp +++ b/manifests/file.pp @@ -26,10 +26,8 @@ $sourceselect = undef, $target = undef, ) { - # validate params - validate_re($ensure, '^(present)|(absent)|(file)|(directory)|(link)$', - "types::file::${name}::ensure is invalid and does not match the regex.") + validate_re($ensure, '^(present)|(absent)|(file)|(directory)|(link)$', "types::file::${name}::ensure is invalid and does not match the regex.") validate_absolute_path($name) validate_re($mode, '^\d{4}$', "types::file::${name}::mode must be exactly 4 digits.") diff --git a/manifests/file_line.pp b/manifests/file_line.pp index c92b8e8..9c228c4 100644 --- a/manifests/file_line.pp +++ b/manifests/file_line.pp @@ -6,9 +6,7 @@ $match = undef, $ensure = 'present', ) { - - validate_re($ensure, '^(present)|(absent)$', - "types::file_line::${name}::ensure is invalid and does not match the regex.") + validate_re($ensure, '^(present)|(absent)$', "types::file_line::${name}::ensure is invalid and does not match the regex.") validate_absolute_path($path) validate_string($line) diff --git a/manifests/init.pp b/manifests/init.pp index 02de97f..c8df280 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -20,7 +20,6 @@ $selbooleans_hiera_merge = true, $services_hiera_merge = true, ) { - if is_string($crons_hiera_merge) { $crons_hiera_merge_real = str2bool($crons_hiera_merge) } else { diff --git a/manifests/mount.pp b/manifests/mount.pp index 90376b7..a495d76 100644 --- a/manifests/mount.pp +++ b/manifests/mount.pp @@ -13,22 +13,20 @@ $remounts = undef, $target = undef, ) { - # validate params - validate_re($ensure, '^(present)|(unmounted)|(absent)|(mounted)$', - "types::mount::${name}::ensure is invalid and does not match the regex.") + validate_re($ensure, '^(present)|(unmounted)|(absent)|(mounted)$', "types::mount::${name}::ensure is invalid and does not match the regex.") validate_absolute_path($name) if $ensure != 'absent' { # ensure target exists - include ::common + include common common::mkdir_p { $name: } } # Solaris cannot handle 'defaults' as a mount option. A common use case would # be to have NFS exports specified in Hiera for multiple systems and if the # system is Solaris, it would throw an error. - if $options == 'defaults' and $::osfamily == 'Solaris' { + if $options == 'defaults' and $facts['os']['family'] == 'Solaris' { $options_real = '-' } else { $options_real = $options diff --git a/manifests/package.pp b/manifests/package.pp index 52bfe52..e7151e7 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -11,7 +11,6 @@ $source = undef, $uninstall_options = undef, ) { - validate_string($ensure) if $adminfile != undef { @@ -19,8 +18,7 @@ } if $configfiles != undef { - validate_re($configfiles, '^(keep)|(replace)$', - "types::package::${name}::configfiles is invalid and does not match the regex.") + validate_re($configfiles, '^(keep)|(replace)$', "types::package::${name}::configfiles is invalid and does not match the regex.") } if $responsefile != undef { diff --git a/manifests/selboolean.pp b/manifests/selboolean.pp index f422328..dae832c 100644 --- a/manifests/selboolean.pp +++ b/manifests/selboolean.pp @@ -5,9 +5,7 @@ $persistent = false, $provider = undef, ) { - - validate_re($value, '^(on)|(off)$', - "types::selboolean::${name}::value is invalid should be 'on' or 'off'.") + validate_re($value, '^(on)|(off)$', "types::selboolean::${name}::value is invalid should be 'on' or 'off'.") validate_bool($persistent) if $provider != undef { validate_string($provider) diff --git a/manifests/service.pp b/manifests/service.pp index ce07a51..745b60a 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -16,17 +16,14 @@ $status = undef, $stop = undef, ) { - # validate params if $ensure != undef { - validate_re($ensure, '^(stopped|false|running|true)$', - "types::service::${name}::ensure can only be , , or and is set to <${ensure}>") + validate_re($ensure, '^(stopped|false|running|true)$', "types::service::${name}::ensure can only be , , or and is set to <${ensure}>") } if $enable != undef { if is_string($enable) { - validate_re($enable, '^(true|false|manual)$', - "types::service::${name}::enable can only be , or and is set to <${enable}>") + validate_re($enable, '^(true|false|manual)$', "types::service::${name}::enable can only be , or and is set to <${enable}>") } else { validate_bool($enable) } From 0f048891cdf7ccff4da45817ff97cf20c14aaf9f Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Wed, 5 Apr 2023 11:00:22 +0000 Subject: [PATCH 04/17] Use https for fixtures --- .fixtures.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index da1811f..5b5b3d1 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -7,13 +7,13 @@ fixtures: repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' ref: '4.6.0' cron: - repo: 'git://github.com/puppetlabs/puppetlabs-cron_core.git' + repo: 'https://github.com/puppetlabs/puppetlabs-cron_core.git' ref: '1.0.0' mount: - repo: 'git://github.com/puppetlabs/puppetlabs-mount_core.git' + repo: 'https://github.com/puppetlabs/puppetlabs-mount_core.git' ref: '1.0.2' selinux: - repo: 'git://github.com/puppetlabs/puppetlabs-selinux_core.git' + repo: 'https://github.com/puppetlabs/puppetlabs-selinux_core.git' ref: '1.0.1' symlinks: types: "#{source_dir}" From ab42f485e4dc268faef576ecb822b29b5e240e83 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Wed, 5 Apr 2023 12:53:26 +0000 Subject: [PATCH 05/17] Configure .sync.yml --- .gitlab-ci.yml | 53 --------------------------------------------- .puppet-lint.rc | 2 ++ .sync.yml | 33 +++++++++++++++++++++++++++- Gemfile | 4 ++++ Rakefile | 2 ++ appveyor.yml | 49 ----------------------------------------- spec/spec_helper.rb | 2 ++ 7 files changed, 42 insertions(+), 103 deletions(-) delete mode 100644 .gitlab-ci.yml delete mode 100644 appveyor.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 6d5e786..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -stages: - - syntax - - unit - -default: - cache: - paths: - - vendor/bundle - - 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) - -validate lint check rubocop-Ruby 2.5.7-Puppet ~> 6: - stage: syntax - image: ruby:2.5.7 - script: - - 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' - -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.7.2 - script: - - bundle exec rake parallel_spec - variables: - PUPPET_GEM_VERSION: '~> 7' - diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..4fa16f9 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,3 @@ --relative +--no-80chars-check +--no-140chars-check diff --git a/.sync.yml b/.sync.yml index 8c2c98e..90f2df6 100644 --- a/.sync.yml +++ b/.sync.yml @@ -5,4 +5,35 @@ # # See https://github.com/puppetlabs/pdk-templates/blob/main/config_defaults.yml # for the default values. ---- {} +--- +appveyor.yml: + delete: true + +.gitlab-ci.yml: + delete: true + +.travis.yml: + delete: true + +Gemfile: + unmanaged: false + optional: + ':development': + - gem: 'github_changelog_generator' + version: '~> 1.15' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" + ':test': + # provides metadata2gha, needed for unit tests + - gem: 'puppet_metadata' + version: '~> 1.9.0' + +spec/spec_helper.rb: + coverage_report: true + minimum_code_coverage_percentage: 100 + hiera_config: 'hiera' + mock_with: ':rspec' + +Rakefile: + default_disabled_lint_checks: + - '80chars' + - '140chars' diff --git a/Gemfile b/Gemfile index 4eaa0c3..9584486 100644 --- a/Gemfile +++ b/Gemfile @@ -34,11 +34,15 @@ group :development do gem "rubocop-performance", '= 1.9.1', require: false gem "rubocop-rspec", '= 2.0.1', require: false gem "rb-readline", '= 0.5.5', 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') end group :system_tests do gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] gem "serverspec", '~> 2.41', require: false end +group :test do + gem "puppet_metadata", '~> 1.9.0', require: false +end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 0f8754e..d68f852 100644 --- a/Rakefile +++ b/Rakefile @@ -42,6 +42,8 @@ def changelog_future_release end PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') if Bundler.rubygems.find_name('github_changelog_generator').any? diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index a70c01e..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,49 +0,0 @@ ---- -version: 1.1.x.{build} -skip_branch_with_pr: true -branches: - only: - - 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: 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/spec/spec_helper.rb b/spec/spec_helper.rb index 9b1fa6f..415ba7d 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,7 @@ RSpec.configure do |c| c.default_facts = default_facts + c.hiera_config = 'hiera' c.before :each do # set to strictest setting for testing # by default Puppet runs at warning level @@ -46,6 +47,7 @@ end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do + RSpec::Puppet::Coverage.report!(100) end # Filter backtrace noise From ca9cd2ffc505708b06bd6392bc3cb4c40fabada5 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Wed, 5 Apr 2023 12:56:58 +0000 Subject: [PATCH 06/17] Add Github CI workflow --- .github/workflows/ci.yml | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5c39551 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,92 @@ +--- +name: CI + +on: pull_request + +concurrency: + group: ${{ github.head_ref }} + cancel-in-progress: true + +jobs: + setup_matrix: + name: Setup Test Matrix + runs-on: ubuntu-20.04 + timeout-minutes: 40 + outputs: + puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} + github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} + steps: + - uses: actions/checkout@v3 + + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7.3' + bundler-cache: true + + - name: Run static validations + run: bundle exec rake validate lint + + - name: Run rake rubocop + run: bundle exec rake rubocop + + - name: Setup Test Matrix + id: get-outputs + run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false + + unit: + needs: setup_matrix + runs-on: ubuntu-20.04 + timeout-minutes: 40 + strategy: + fail-fast: false + matrix: + include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}} + name: Spec Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }}) + steps: + - uses: actions/checkout@v3 + + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: Run tests + run: bundle exec rake parallel_spec + +# TODO: active when acceptance tests have been added +# acceptance: +# name: Litmus Acceptance +# runs-on: ubuntu-20.04 +# env: +# BOLT_GEM: true +# CI: true +# steps: +# - uses: actions/checkout@v3 +# - name: Setup ruby +# uses: ruby/setup-ruby@v1 +# with: +# ruby-version: '2.7.3' +# bundler-cache: true +# +# - name: Provision Testing Environments +# run: | +# bundle exec rake 'litmus:provision_list[default]' +# bundle exec rake 'litmus:install_agent' +# bundle exec rake 'litmus:install_module' +# - name: Run Tests +# run: bundle exec rake 'litmus:acceptance:parallel' +# +# - name: Tear Down +# run: bundle exec rake 'litmus:tear_down' + + tests: + needs: + - unit +# TODO: active when acceptance tests have been added +# - acceptance + runs-on: ubuntu-20.04 + name: Test suite + steps: + - run: echo Test suite completed From 3e520bc3800058e4956d3bbb4a792e0a29732192 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Thu, 6 Apr 2023 09:45:26 +0000 Subject: [PATCH 07/17] Use stdlib 5.0.0 < 9.0.0 --- .fixtures.yml | 2 +- metadata.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 5b5b3d1..9391fb8 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,7 +5,7 @@ fixtures: ref: 'v1.7.0' stdlib: repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.6.0' + ref: '5.0.0' cron: repo: 'https://github.com/puppetlabs/puppetlabs-cron_core.git' ref: '1.0.0' diff --git a/metadata.json b/metadata.json index cc8ce79..0d4902e 100644 --- a/metadata.json +++ b/metadata.json @@ -10,7 +10,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.6.0 < 7.0.0" + "version_requirement": ">= 5.0.0 < 9.0.0" }, { "name": "ghoneycutt/common", From eafbfc5038635269ddf6505c88345a9ee76d6241 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Wed, 5 Apr 2023 14:19:25 +0000 Subject: [PATCH 08/17] Update code to PDK 2.7.1 --- manifests/cron.pp | 78 ++++++++++++---- manifests/exec.pp | 116 ++++++++++++++++++------ manifests/file.pp | 152 ++++++++++++++++++++++++++------ manifests/file_line.pp | 35 +++++--- manifests/init.pp | 110 +++++++++++++++++------ manifests/mount.pp | 73 +++++++++++---- manifests/package.pp | 71 ++++++++++----- manifests/selboolean.pp | 27 +++--- manifests/service.pp | 100 +++++++++++++++------ spec/classes/init_spec.rb | 86 ++++++++++++------ spec/defines/cron_spec.rb | 24 ++--- spec/defines/exec_spec.rb | 36 ++++---- spec/defines/file_line_spec.rb | 40 ++++----- spec/defines/file_spec.rb | 64 +++++++------- spec/defines/mount_spec.rb | 76 +++++++++++----- spec/defines/package_spec.rb | 20 ++--- spec/defines/selboolean_spec.rb | 8 +- spec/defines/service_spec.rb | 34 +++---- 18 files changed, 795 insertions(+), 355 deletions(-) diff --git a/manifests/cron.pp b/manifests/cron.pp index 7120fa5..4bf7f91 100644 --- a/manifests/cron.pp +++ b/manifests/cron.pp @@ -1,22 +1,68 @@ -# == Define: types::cron +# @summary Define for cron types +# For a full description of the cron type check: https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md +# +# @param command +# Value passed to command attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#command for more information. +# +# @param ensure +# Value passed to ensure attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#ensure for more information. +# +# @param environment +# Value passed to environment attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#environment for more information. +# +# @param hour +# Value passed to hour attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#hour for more information. +# +# @param minute +# Value passed to minute attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#minute for more information. +# +# @param month +# Value passed to month attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#month for more information. +# +# @param monthday +# Value passed to monthday attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#monthday for more information. +# +# @param provider +# Value passed to provider attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#provider for more information. +# +# @param special +# Value passed to special attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#special for more information. +# +# @param target +# Value passed to target attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#target for more information. +# +# @param user +# Value passed to user attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#user for more information. +# +# @param weekday +# Value passed to weekday attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-cron_core/blob/main/REFERENCE.md#weekday for more information. # define types::cron ( - $command, - $ensure = 'present', - $environment = undef, - $hour = undef, - $minute = undef, - $month = undef, - $monthday = undef, - $provider = undef, - $special = undef, - $target = undef, - $user = undef, - $weekday = undef, + String[1] $command, + Enum['present', 'absent'] $ensure = 'present', + Optional[String[1]] $environment = undef, + Optional[String[1]] $hour = undef, + Optional[String[1]] $minute = undef, + Optional[String[1]] $month = undef, + Optional[String[1]] $monthday = undef, + Optional[String[1]] $provider = undef, + Optional[String[1]] $special = undef, + Optional[String[1]] $target = undef, + Optional[String[1]] $user = undef, + Optional[String[1]] $weekday = undef, ) { - # validate params - validate_re($ensure, '^(present)|(absent)$', "types::cron::${name}::ensure is invalid and does not match the regex.") - cron { $name: ensure => $ensure, command => $command, diff --git a/manifests/exec.pp b/manifests/exec.pp index dd3ee44..534408b 100644 --- a/manifests/exec.pp +++ b/manifests/exec.pp @@ -1,35 +1,93 @@ -# == Define: types::exec +# @summary Define for exec types +# For a full description of the exec type check: https://www.puppet.com/docs/puppet/7/types/exec.html +# +# @param command +# Value passed to command attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-command for more information. +# +# @param creates +# Value passed to creates attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-creates for more information. +# +# @param cwd +# Value passed to cwd attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-cwd for more information. +# +# @param environment +# Value passed to environment attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-environment for more information. +# +# @param group +# Value passed to group attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-group for more information. +# +# @param logoutput +# Value passed to logoutput attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-logoutput for more information. +# +# @param onlyif +# Value passed to onlyif attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-onlyif for more information. +# +# @param path +# Value passed to path attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-path for more information. +# +# @param provider +# Value passed to provider attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-provider for more information. +# +# @param refresh +# Value passed to refresh attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-refresh for more information. +# +# @param refreshonly +# Value passed to refreshonly attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-refreshonly for more information. +# +# @param returns +# Value passed to returns attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-returns for more information. +# +# @param timeout +# Value passed to timeout attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-timeout for more information. +# +# @param tries +# Value passed to tries attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-tries for more information. +# +# @param try_sleep +# Value passed to try_sleep attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-try_sleep for more information. +# +# @param unless +# Value passed to unless attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-unless for more information. +# +# @param user +# Value passed to user attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/exec.html#exec-attribute-user for more information. # define types::exec ( - $command, - $creates = undef, - $cwd = undef, - $environment = undef, - $group = undef, - $logoutput = undef, - $onlyif = undef, - $path = undef, - $provider = undef, - $refresh = undef, - $refreshonly = undef, - $returns = undef, - $timeout = undef, - $tries = undef, - $try_sleep = undef, - $unless = undef, - $user = undef, + String[1] $command, + Optional[Stdlib::Absolutepath] $creates = undef, + Optional[Stdlib::Absolutepath] $cwd = undef, + Optional[String[1]] $environment = undef, + Optional[String[1]] $group = undef, + Optional[Variant[Boolean, Enum['on_failure']]] $logoutput = undef, + Optional[String[1]] $onlyif = undef, + Optional[String[1]] $path = undef, + Optional[Enum['posix', 'shell', 'windows']] $provider = undef, + Optional[String[1]] $refresh = undef, + Optional[Boolean] $refreshonly = undef, + Optional[Integer] $returns = undef, + Optional[Integer] $timeout = undef, + Optional[Integer] $tries = undef, + Optional[Integer] $try_sleep = undef, + Optional[String[1]] $unless = undef, + Optional[String[1]] $user = undef, ) { - # validate params - if $creates != undef { - validate_absolute_path($creates) - } - if $cwd != undef { - validate_absolute_path($cwd) - } - if $provider != undef { - validate_re($provider, '^(posix|shell|windows)$', "types::exec::${name}::provider is invalid and does not match the regex.") - } - exec { $name: command => $command, creates => $creates, diff --git a/manifests/file.pp b/manifests/file.pp index 977808d..246225f 100644 --- a/manifests/file.pp +++ b/manifests/file.pp @@ -1,35 +1,129 @@ -# == Define: types::file +# @summary Define for file types +# For a full description of the exec type check: https://www.puppet.com/docs/puppet/7/types/file.html +# +# @param ensure +# Value passed to ensure attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-ensure for more information. +# +# @param owner +# Value passed to owner attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-owner for more information. +# +# @param group +# Value passed to group attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-group for more information. +# +# @param mode +# Value passed to mode attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-mode for more information. +# +# @param backup +# Value passed to backup attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-backup for more information. +# +# @param checksum +# Value passed to checksum attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-checksum for more information. +# +# @param content +# Value passed to content attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-content for more information. +# +# @param force +# Value passed to force attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-force for more information. +# +# @param ignore +# Value passed to ignore attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-ignore for more information. +# +# @param links +# Value passed to links attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-links for more information. +# +# @param provider +# Value passed to provider attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-provider for more information. +# +# @param purge +# Value passed to purge attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-purge for more information. +# +# @param recurse +# Value passed to recurse attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-recurse for more information. +# +# @param recurselimit +# Value passed to recurselimit attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-recurselimit for more information. +# +# @param replace +# Value passed to replace attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-replace for more information. +# +# @param selinux_ignore_defaults +# Value passed to selinux_ignore_defaults attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-selinux_ignore_defaults for more information. +# +# @param selrange +# Value passed to selrange attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-selrange for more information. +# +# @param selrole +# Value passed to selrole attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-selrole for more information. +# +# @param seltype +# Value passed to seltype attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-seltype for more information. +# +# @param seluser +# Value passed to seluser attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-seluser for more information. +# +# @param show_diff +# Value passed to show_diff attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-show_diff for more information. +# +# @param source +# Value passed to source attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-source for more information. +# +# @param sourceselect +# Value passed to sourceselect attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-sourceselect for more information. +# +# @param target +# Value passed to target attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/file.html#file-attribute-target for more information. # define types::file ( - $ensure = present, - $owner = root, - $group = root, - $mode = '0644', - $backup = undef, - $checksum = undef, - $content = undef, - $force = undef, - $ignore = undef, - $links = undef, - $provider = undef, - $purge = undef, - $recurse = undef, - $recurselimit = undef, - $replace = undef, - $selinux_ignore_defaults = undef, - $selrange = undef, - $selrole = undef, - $seltype = undef, - $seluser = undef, - $show_diff = undef, - $source = undef, - $sourceselect = undef, - $target = undef, + Enum['present', 'absent', 'file', 'directory', 'link'] $ensure = 'present', + String[1] $owner = 'root', + String[1] $group = 'root', + Stdlib::Filemode $mode = '0644', + Optional[String[1]] $backup = undef, + Optional[String[1]] $checksum = undef, + Optional[String[1]] $content = undef, + Optional[String[1]] $force = undef, + Optional[Variant[String[1], Array[String[1]]]] $ignore = undef, + Optional[String[1]] $links = undef, + Optional[String[1]] $provider = undef, + Optional[Variant[Boolean, Enum['yes', 'no']]] $purge = undef, + Optional[Variant[Boolean, Enum['remote']]] $recurse = undef, + Optional[Integer] $recurselimit = undef, + Optional[Variant[Boolean, Enum['yes', 'no']]] $replace = undef, + Optional[Boolean] $selinux_ignore_defaults = undef, + Optional[String[1]] $selrange = undef, + Optional[String[1]] $selrole = undef, + Optional[String[1]] $seltype = undef, + Optional[String[1]] $seluser = undef, + Optional[Variant[Boolean, Enum['yes', 'no']]] $show_diff = undef, + Optional[String[1]] $source = undef, + Optional[String[1]] $sourceselect = undef, + Optional[String[1]] $target = undef, ) { - # validate params - validate_re($ensure, '^(present)|(absent)|(file)|(directory)|(link)$', "types::file::${name}::ensure is invalid and does not match the regex.") - validate_absolute_path($name) - validate_re($mode, '^\d{4}$', "types::file::${name}::mode must be exactly 4 digits.") + assert_type(Stdlib::Absolutepath, $name) file { $name: ensure => $ensure, diff --git a/manifests/file_line.pp b/manifests/file_line.pp index 9c228c4..ea8941b 100644 --- a/manifests/file_line.pp +++ b/manifests/file_line.pp @@ -1,19 +1,28 @@ -# == Define: types::file_line +# @summary Define for file_line types +# For a full description of the exec type check: https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/REFERENCE.md#file_line +# +# @param path +# Value passed to path attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/REFERENCE.md#-file_line--path for more information. +# +# @param line +# Value passed to line attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/REFERENCE.md#line for more information. +# +# @param match +# Value passed to match attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/REFERENCE.md#-file_line--match for more information. +# +# @param ensure +# Value passed to ensure attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/REFERENCE.md#ensure for more information. # define types::file_line ( - $path, - $line, - $match = undef, - $ensure = 'present', + Stdlib::Absolutepath $path, + String[1] $line, + Optional[String[1]] $match = undef, + Enum['present', 'absent'] $ensure = 'present', ) { - validate_re($ensure, '^(present)|(absent)$', "types::file_line::${name}::ensure is invalid and does not match the regex.") - validate_absolute_path($path) - validate_string($line) - - if $match { - validate_string($match) - } - file_line { $name: ensure => $ensure, path => $path, diff --git a/manifests/init.pp b/manifests/init.pp index c8df280..52e4006 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,24 +1,82 @@ -# == Class: types +# @summary Module to manage types +# Puppet module to manage default types through hashes in Hiera with the +# create_resources() function. This module adds validation and helper functions, +# such as ensuring directories. Without specifying any hashes, this module will +# take no action. # -# Module to manage types +# @param crons +# Hash of resource type `cron`. +# +# @param execs +# Hash of resource type `exec`. +# +# @param file_lines +# Hash of resource type `file_line`. +# +# @param files +# Hash of resource type `file`. +# +# @param mounts +# Hash of resource type `mount`. +# +# @param packages +# Hash of resource type `package`. +# +# @param selbooleans +# Hash of resource type `selboolean`. +# +# @param services +# Hash of resource type `service`. +# +# @param crons_hiera_merge +# Boolean to control merges of all found instances of types::crons in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. +# +# @param execs_hiera_merge +# Boolean to control merges of all found instances of types::execs in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. +# +# @param file_lines_hiera_merge +# Boolean to control merges of all found instances of types::file_lines in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. +# +# @param files_hiera_merge +# Boolean to control merges of all found instances of types::files in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. +# +# @param mounts_hiera_merge +# Boolean to control merges of all found instances of types::mounts in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. +# +# @param packages_hiera_merge +# Boolean to control merges of all found instances of types::packages in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. +# +# @param selbooleans_hiera_merge +# Boolean to control merges of all found instances of types::selbooleans in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. +# +# @param services_hiera_merge +# Boolean to control merges of all found instances of types::services in Hiera. +# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. # class types ( - $crons = undef, - $execs = undef, - $file_lines = undef, - $files = undef, - $mounts = undef, - $packages = undef, - $selbooleans = undef, - $services = undef, - $crons_hiera_merge = false, - $execs_hiera_merge = false, - $file_lines_hiera_merge = true, - $files_hiera_merge = false, - $mounts_hiera_merge = false, - $packages_hiera_merge = true, - $selbooleans_hiera_merge = true, - $services_hiera_merge = true, + Hash $crons = {}, + Hash $execs = {}, + Hash $file_lines = {}, + Hash $files = {}, + Hash $mounts = {}, + Hash $packages = {}, + Hash $selbooleans = {}, + Hash $services = {}, + Boolean $crons_hiera_merge = false, + Boolean $execs_hiera_merge = false, + Boolean $file_lines_hiera_merge = true, + Boolean $files_hiera_merge = false, + Boolean $mounts_hiera_merge = false, + Boolean $packages_hiera_merge = true, + Boolean $selbooleans_hiera_merge = true, + Boolean $services_hiera_merge = true, ) { if is_string($crons_hiera_merge) { $crons_hiera_merge_real = str2bool($crons_hiera_merge) @@ -71,7 +129,7 @@ } validate_bool($services_hiera_merge_real) - if $crons != undef { + if $crons != {} { if $crons_hiera_merge_real == true { $crons_real = hiera_hash('types::crons') } else { @@ -81,7 +139,7 @@ create_resources('types::cron',$crons_real) } - if $execs != undef { + if $execs != {} { if $execs_hiera_merge_bool == true { $execs_real = hiera_hash('types::execs') } else { @@ -91,7 +149,7 @@ create_resources('types::exec',$execs_real) } - if $file_lines != undef { + if $file_lines != {} { if $file_lines_hiera_merge_real == true { $file_lines_real = hiera_hash('types::file_lines') } else { @@ -101,7 +159,7 @@ create_resources('types::file_line',$file_lines_real) } - if $files != undef { + if $files != {} { if $files_hiera_merge_real == true { $files_real = hiera_hash('types::files') } else { @@ -111,7 +169,7 @@ create_resources('types::file',$files_real) } - if $mounts != undef { + if $mounts != {} { if $mounts_hiera_merge_real == true { $mounts_real = hiera_hash('types::mounts') } else { @@ -121,7 +179,7 @@ create_resources('types::mount',$mounts_real) } - if $packages != undef { + if $packages != {} { if $packages_hiera_merge_real == true { $packages_real = hiera_hash('types::packages') } else { @@ -131,7 +189,7 @@ create_resources('types::package',$packages_real) } - if $selbooleans != undef { + if $selbooleans != {} { if $selbooleans_hiera_merge_real == true { $selbooleans_real = hiera_hash('types::selboolean') } else { @@ -141,7 +199,7 @@ create_resources('types::selboolean',$selbooleans_real) } - if $services != undef { + if $services != {} { if $services_hiera_merge_real == true { $services_real = hiera_hash('types::services') } else { diff --git a/manifests/mount.pp b/manifests/mount.pp index a495d76..ba4d7ef 100644 --- a/manifests/mount.pp +++ b/manifests/mount.pp @@ -1,22 +1,63 @@ -# == Define: types::mount +# @summary Define for mount types +# For a full description of the mount type check: https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md +# +# @param device +# Value passed to device attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#device for more information. +# +# @param fstype +# Value passed to fstype attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#fstype for more information. +# +# @param ensure +# Value passed to ensure attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#ensure for more information. +# +# @param atboot +# Value passed to atboot attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#atboot for more information. +# +# @param blockdevice +# Value passed to blockdevice attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#blockdevice for more information. +# +# @param dump +# Value passed to dump attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#dump for more information. +# +# @param options +# Value passed to options attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#options for more information. +# +# @param pass +# Value passed to pass attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#pass for more information. +# +# @param provider +# Value passed to provider attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#provider for more information. +# +# @param remounts +# Value passed to remounts attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#remounts for more information. +# +# @param target +# Value passed to target attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-mount_core/blob/main/REFERENCE.md#target for more information. # define types::mount ( - $device, - $fstype, - $ensure = mounted, - $atboot = true, - $blockdevice = undef, - $dump = undef, - $options = undef, - $pass = undef, - $provider = undef, - $remounts = undef, - $target = undef, + String[1] $device, + String[1] $fstype, + Enum['defined', 'present', 'unmounted', 'absent', 'mounted'] $ensure = 'mounted', + Boolean $atboot = true, + Optional[String[1]] $blockdevice = undef, + Optional[String[1]] $dump = undef, + Optional[String[1]] $options = undef, + Optional[String[1]] $pass = undef, + Optional[String[1]] $provider = undef, + Optional[Boolean] $remounts = undef, + Optional[String[1]] $target = undef, ) { - # validate params - validate_re($ensure, '^(present)|(unmounted)|(absent)|(mounted)$', "types::mount::${name}::ensure is invalid and does not match the regex.") - validate_absolute_path($name) - if $ensure != 'absent' { # ensure target exists include common diff --git a/manifests/package.pp b/manifests/package.pp index e7151e7..6b13238 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -1,30 +1,53 @@ -# == Define: types::package +# @summary Define for package types +# For a full description of the exec type check: https://www.puppet.com/docs/puppet/7/types/package.html +# +# @param ensure +# Value passed to ensure attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-ensure for more information. +# +# @param adminfile +# Value passed to adminfile attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-adminfile for more information. +# +# @param allowcdrom +# Value passed to allowcdrom attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-allowcdrom for more information. +# +# @param configfiles +# Value passed to configfiles attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-configfiles for more information. +# +# @param install_options +# Value passed to install_options attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-install_options for more information. +# +# @param provider +# Value passed to provider attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-provider for more information. +# +# @param responsefile +# Value passed to responsefile attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-responsefile for more information. +# +# @param source +# Value passed to source attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-source for more information. +# +# @param uninstall_options +# Value passed to uninstall_options attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/package.html#package-attribute-uninstall_options for more information. # define types::package ( - $ensure = 'present', - $adminfile = undef, - $allowcdrom = undef, - $configfiles = undef, - $install_options = undef, - $provider = undef, - $responsefile = undef, - $source = undef, - $uninstall_options = undef, + Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'] $ensure = 'present', + Optional[Stdlib::Absolutepath] $adminfile = undef, + Optional[String[1]] $allowcdrom = undef, + Optional[Enum['keep', 'replace']] $configfiles = undef, + Optional[String[1]] $install_options = undef, + Optional[String[1]] $provider = undef, + Optional[Stdlib::Absolutepath] $responsefile = undef, + Optional[String[1]] $source = undef, + Optional[String[1]] $uninstall_options = undef, ) { - validate_string($ensure) - - if $adminfile != undef { - validate_absolute_path($adminfile) - } - - if $configfiles != undef { - validate_re($configfiles, '^(keep)|(replace)$', "types::package::${name}::configfiles is invalid and does not match the regex.") - } - - if $responsefile != undef { - validate_absolute_path($responsefile) - } - package { $name: ensure => $ensure, adminfile => $adminfile, diff --git a/manifests/selboolean.pp b/manifests/selboolean.pp index dae832c..ff98493 100644 --- a/manifests/selboolean.pp +++ b/manifests/selboolean.pp @@ -1,16 +1,23 @@ -# == Define: types::selboolean +# @summary Define for selboolean types +# For a full description of the cron type check: https://github.com/puppetlabs/puppetlabs-selinux_core/blob/main/REFERENCE.md +# +# @param value +# Value passed to value attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-selinux_core/blob/main/REFERENCE.md#value for more information. +# +# @param persistent +# Value passed to persistent attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-selinux_core/blob/main/REFERENCE.md#persistent for more information. +# +# @param provider +# Value passed to provider attribute. Unused if empty. +# Check https://github.com/puppetlabs/puppetlabs-selinux_core/blob/main/REFERENCE.md#provider for more information. # define types::selboolean ( - $value, - $persistent = false, - $provider = undef, + Enum['on', 'off'] $value, + Boolean $persistent = false, + Optional[String[1]] $provider = undef, ) { - validate_re($value, '^(on)|(off)$', "types::selboolean::${name}::value is invalid should be 'on' or 'off'.") - validate_bool($persistent) - if $provider != undef { - validate_string($provider) - } - selboolean { $name: value => $value, persistent => $persistent, diff --git a/manifests/service.pp b/manifests/service.pp index 745b60a..379f4de 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,34 +1,78 @@ -# == Define: types::service +# @summary Define for service types +# For a full description of the exec type check: https://www.puppet.com/docs/puppet/7/types/service.html +# +# @param ensure +# Value passed to ensure attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-ensure for more information. +# +# @param binary +# Value passed to binary attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-binary for more information. +# +# @param control +# Value passed to control attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-control for more information. +# +# @param enable +# Value passed to enable attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-enable for more information. +# +# @param hasrestart +# Value passed to hasrestart attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-hasrestart for more information. +# +# @param hasstatus +# Value passed to hasstatus attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-hasstatus for more information. +# +# @param manifest +# Value passed to manifest attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-manifest for more information. +# +# @param path +# Value passed to path attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-path for more information. +# +# @param pattern +# Value passed to pattern attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-pattern for more information. +# +# @param provider +# Value passed to provider attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-provider for more information. +# +# @param restart +# Value passed to restart attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-restart for more information. +# +# @param start +# Value passed to start attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-start for more information. +# +# @param status +# Value passed to status attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-status for more information. +# +# @param stop +# Value passed to stop attribute. Unused if empty. +# Check https://www.puppet.com/docs/puppet/7/types/service.html#service-attribute-stop for more information. # define types::service ( - $ensure = 'running', - $binary = undef, - $control = undef, - $enable = true, - $hasrestart = undef, - $hasstatus = undef, - $manifest = undef, - $path = undef, - $pattern = undef, - $provider = undef, - $restart = undef, - $start = undef, - $status = undef, - $stop = undef, + Variant[Boolean, Enum['stopped', 'running', 'false', 'true']] $ensure = 'running', + Optional[String[1]] $binary = undef, + Optional[String[1]] $control = undef, + Variant[Boolean, Enum['true', 'false', 'manual']] $enable = true, + Optional[Variant[Boolean, Enum['true', 'false']]] $hasrestart = undef, + Optional[Variant[Boolean, Enum['true', 'false']]] $hasstatus = undef, + Optional[String[1]] $manifest = undef, + Optional[String[1]] $path = undef, + Optional[String[1]] $pattern = undef, + Optional[String[1]] $provider = undef, + Optional[String[1]] $restart = undef, + Optional[String[1]] $start = undef, + Optional[String[1]] $status = undef, + Optional[String[1]] $stop = undef, ) { - # validate params - if $ensure != undef { - validate_re($ensure, '^(stopped|false|running|true)$', "types::service::${name}::ensure can only be , , or and is set to <${ensure}>") - } - - if $enable != undef { - if is_string($enable) { - validate_re($enable, '^(true|false|manual)$', "types::service::${name}::enable can only be , or and is set to <${enable}>") - } else { - validate_bool($enable) - } - } - service { $name: ensure => $ensure, binary => $binary, diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 26923fc..df1e1d5 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -14,14 +14,14 @@ '/mnt' => { 'device' => '/dev/dvd', 'fstype' => 'iso9660', - 'atboot' => 'no', - 'remounts' => 'true', + 'atboot' => false, + 'remounts' => true, }, '/srv/nfs/home' => { 'device' => 'nfsserver:/export/home', 'fstype' => 'nfs', 'options' => 'rw,rsize=8192,wsize=8192', - 'remounts' => 'true', + 'remounts' => true, 'blockdevice' => '-', } } @@ -36,8 +36,8 @@ 'ensure' => 'mounted', 'device' => '/dev/dvd', 'fstype' => 'iso9660', - 'atboot' => 'no', - 'remounts' => 'true', + 'atboot' => false, + 'remounts' => true, }, ) end @@ -57,7 +57,7 @@ 'device' => 'nfsserver:/export/home', 'fstype' => 'nfs', 'options' => 'rw,rsize=8192,wsize=8192', - 'remounts' => 'true', + 'remounts' => true, 'blockdevice' => '-', }, ) @@ -71,13 +71,18 @@ }, ) end + + it { is_expected.to contain_types__mount('/mnt') } # only needed for 100% resource coverage + it { is_expected.to contain_types__mount('/srv/nfs/home') } # only needed for 100% resource coverage + it { is_expected.to contain_common__mkdir_p('/mnt') } # only needed for 100% resource coverage + it { is_expected.to contain_common__mkdir_p('/srv/nfs/home') } # only needed for 100% resource coverage end context 'with file_lines specified as a hash' do let(:facts) { { osfamily: 'RedHat' } } let :params do { - file_lines_hiera_merge: 'false', + file_lines_hiera_merge: false, file_lines: { 'some_file' => { 'path' => '/tmp/foo', @@ -112,7 +117,7 @@ it do is_expected.to contain_file_line('some_other_file').with( { - 'path' => '/tmp/bar', + 'path' => '/tmp/bar', 'line' => 'option=asdf', 'match' => '^option', }, @@ -128,6 +133,10 @@ }, ) end + + it { is_expected.to contain_types__file_line('some_file') } # only needed for 100% resource coverage + it { is_expected.to contain_types__file_line('some_other_file') } # only needed for 100% resource coverage + it { is_expected.to contain_types__file_line('another_line') } # only needed for 100% resource coverage end context 'with files specified as a hash' do @@ -187,10 +196,10 @@ it do is_expected.to contain_file('/localdisk').with( { - 'ensure' => 'directory', - 'mode' => '0755', - 'owner' => 'root', - 'group' => 'root', + 'ensure' => 'directory', + 'mode' => '0755', + 'owner' => 'root', + 'group' => 'root', }, ) end @@ -198,7 +207,7 @@ it do is_expected.to contain_file('/tmp/file1').with( { - 'ensure' => 'present', + 'ensure' => 'present', 'mode' => '0777', 'owner' => 'root', 'group' => 'root', @@ -228,10 +237,10 @@ it do is_expected.to contain_file('/tmp/file2').with( { - 'ensure' => 'present', - 'mode' => '0644', - 'owner' => 'root', - 'group' => 'root', + 'ensure' => 'present', + 'mode' => '0644', + 'owner' => 'root', + 'group' => 'root', }, ) end @@ -239,20 +248,27 @@ it do is_expected.to contain_file('/tmp/dir').with( { - 'ensure' => 'directory', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0777', + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0777', }, ) end + + it { is_expected.to contain_file('/softlink') } # only needed for 100% resource coverage + it { is_expected.to contain_types__file('/localdisk') } # only needed for 100% resource coverage + it { is_expected.to contain_types__file('/softlink') } # only needed for 100% resource coverage + it { is_expected.to contain_types__file('/tmp/dir') } # only needed for 100% resource coverage + it { is_expected.to contain_types__file('/tmp/file1') } # only needed for 100% resource coverage + it { is_expected.to contain_types__file('/tmp/file2') } # only needed for 100% resource coverage end context 'with packages specified as a hash' do let(:facts) { { osfamily: 'RedHat' } } let :params do { - packages_hiera_merge: 'false', + packages_hiera_merge: false, packages: { 'pkg1' => { 'ensure' => 'present', @@ -292,13 +308,17 @@ }, ) end + + it { is_expected.to contain_types__package('pkg1') } + it { is_expected.to contain_types__package('pkg2') } # only needed for 100% resource coverage + it { is_expected.to contain_types__package('pkg3') } # only needed for 100% resource coverage end context 'with selboolean specified as a hash' do let(:facts) { { osfamily: 'RedHat' } } let :params do { - selbooleans_hiera_merge: 'false', + selbooleans_hiera_merge: false, selbooleans: { 'nfs_export_all_ro' => { 'value' => 'on', @@ -328,6 +348,9 @@ }, ) end + + it { is_expected.to contain_types__selboolean('nfs_export_all_ro') } # only needed for 100% resource coverage + it { is_expected.to contain_types__selboolean('nfs_export_all_rw') } # only needed for 100% resource coverage end context 'with selboolean specified as an invalid type' do @@ -347,7 +370,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{\["not", "a", "hash"\] is not a Hash\.}) + }.to raise_error(Puppet::Error, %r{expects a Hash value}) end end @@ -377,7 +400,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{\["not", "a", "hash"\] is not a Hash\.}) + }.to raise_error(Puppet::Error, %r{expects a Hash value}) end end @@ -427,6 +450,9 @@ }, ) end + + it { is_expected.to contain_types__cron('cronjob-1') } # only needed for 100% resource coverage + it { is_expected.to contain_types__cron('cronjob-2') } # only needed for 100% resource coverage end context 'with cron specified as an invalid type' do @@ -435,7 +461,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{\["not", "a", "hash"\] is not a Hash\.}) + }.to raise_error(Puppet::Error, %r{expects a Hash value}) end end @@ -503,12 +529,15 @@ }, ) end + + it { is_expected.to contain_exec('exec-1') } # only needed for 100% resource coverage + it { is_expected.to contain_exec('exec-2') } # only needed for 100% resource coverage end context 'with services specified as a hash' do let :params do { - services_hiera_merge: 'false', + services_hiera_merge: false, services: { 'service-stopped' => { 'ensure' => 'stopped', @@ -541,6 +570,9 @@ }, ) end + + it { is_expected.to contain_types__service('service-stopped') } # only needed for 100% resource coverage + it { is_expected.to contain_types__service('service-running') } # only needed for 100% resource coverage end context 'with service specified as an invalid type' do diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index c6bd3c2..455b7bd 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -21,18 +21,18 @@ let(:title) { 'cronjob-1' } let(:params) do { - command: '/usr/local/bin/script.sh', - ensure: 'absent', + command: '/usr/local/bin/script.sh', + ensure: 'absent', environment: '/bin:/usr/bin', - hour: '1', - minute: '10', - month: 'Jan', - monthday: '1', - provider: 'crontab', - special: 'absent', - target: 'root', - user: 'root', - weekday: '6', + hour: '1', + minute: '10', + month: 'Jan', + monthday: '1', + provider: 'crontab', + special: 'absent', + target: 'root', + user: 'root', + weekday: '6', } end let(:facts) { { osfamily: 'RedHat' } } @@ -71,7 +71,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::cron::invalid::ensure is invalid and does not match the regex\.}) + }.to raise_error(Puppet::Error, %r{expects a match for Enum}) end end end diff --git a/spec/defines/exec_spec.rb b/spec/defines/exec_spec.rb index d9f749c..fa3b02e 100644 --- a/spec/defines/exec_spec.rb +++ b/spec/defines/exec_spec.rb @@ -19,23 +19,23 @@ let(:title) { 'testing' } let(:params) do { - command: '/spec/testing.sh', - creates: '/creates', - cwd: '/spec', + command: '/spec/testing.sh', + creates: '/creates', + cwd: '/spec', environment: 'test=true', - group: 'group', - logoutput: true, - onlyif: '/onlyif.sh', - path: '/path', - provider: 'shell', - refresh: '/refresh.sh', + group: 'group', + logoutput: true, + onlyif: '/onlyif.sh', + path: '/path', + provider: 'shell', + refresh: '/refresh.sh', refreshonly: true, - returns: 242, - timeout: 3, - tries: 3, - try_sleep: 3, - unless: '/unless.sh', - user: 'tester', + returns: 242, + timeout: 3, + tries: 3, + try_sleep: 3, + unless: '/unless.sh', + user: 'tester', } end @@ -68,7 +68,7 @@ let(:params) { { provider: 'invalid', command: '/spec/testing.sh' } } it 'fails' do - expect { is_expected.to contain_class(:subject) }.to raise_error(Puppet::Error, %r{types::exec::testing::provider is invalid and does not match the regex}) + expect { is_expected.to contain_class(:subject) }.to raise_error(Puppet::Error, %r{expects an undef value or a match for Enum}) end end @@ -79,13 +79,13 @@ name: ['creates', 'cwd'], valid: ['/absolute/filepath', '/absolute/directory/'], invalid: ['./relative/path', ['array'], { 'ha' => 'sh' }, 3, 2.42, true, nil], - message: 'is not an absolute path', + message: 'expects a Stdlib::Absolutepath', }, 'validate_re' => { name: ['provider'], valid: ['posix', 'shell', 'windows'], invalid: ['string', ['array'], { 'ha' => 'sh' }, 3, 2.42, true, nil], - message: 'types::exec::testing::provider is invalid and does not match the regex', + message: 'expects an undef value or a match for Enum', }, } diff --git a/spec/defines/file_line_spec.rb b/spec/defines/file_line_spec.rb index c8bdb44..cce5510 100644 --- a/spec/defines/file_line_spec.rb +++ b/spec/defines/file_line_spec.rb @@ -13,7 +13,7 @@ it do is_expected.to contain_file_line('some_file').with( { - 'path' => '/tmp/foo', + 'path' => '/tmp/foo', 'line' => 'option=asdf', 'match' => nil, }, @@ -25,9 +25,9 @@ let(:params) do { ensure: 'present', - path: '/tmp/foo', - line: 'option=asdf', - match: '^option', + path: '/tmp/foo', + line: 'option=asdf', + match: '^option', } end @@ -46,8 +46,8 @@ describe 'with an invalid path for the path parameter' do let(:params) do { - path: 'invalid/path', - line: 'option=asdf', + path: 'invalid/path', + line: 'option=asdf', match: '^option', } end @@ -55,7 +55,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{"invalid/path" is not an absolute path}) + }.to raise_error(Puppet::Error, %r{expects a Stdlib::Absolutepath}) end end @@ -63,16 +63,16 @@ let(:params) do { ensure: '!invalid', - path: '/tmp/foo', - line: 'option=asdf', - match: '^option', + path: '/tmp/foo', + line: 'option=asdf', + match: '^option', } end it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::file_line::some_file::ensure is invalid and does not match the regex\.}) + }.to raise_error(Puppet::Error, %r{expects a match for Enum}) end end @@ -80,8 +80,8 @@ context 'for the path parameter' do let(:params) do { - path: true, - line: 'option=asdf', + path: true, + line: 'option=asdf', match: '^option', } end @@ -89,15 +89,15 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{true is not an absolute path}) + }.to raise_error(Puppet::Error, %r{expects a Stdlib::Absolutepath}) end end context 'for the line parameter' do let(:params) do { - path: '/tmp/foo', - line: ['invalid', 'type'], + path: '/tmp/foo', + line: ['invalid', 'type'], match: '^option', } end @@ -105,15 +105,15 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a string}) + }.to raise_error(Puppet::Error, %r{expects a String value}) end end context 'for the match parameter' do let(:params) do { - path: '/tmp/foo', - line: 'option=asdf', + path: '/tmp/foo', + line: 'option=asdf', match: ['invalid', 'type'], } end @@ -121,7 +121,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a string}) + }.to raise_error(Puppet::Error, %r{expects a value of type Undef or String}) end end end diff --git a/spec/defines/file_spec.rb b/spec/defines/file_spec.rb index db16fb7..7a333ef 100644 --- a/spec/defines/file_spec.rb +++ b/spec/defines/file_spec.rb @@ -7,9 +7,9 @@ is_expected.to contain_file('/tmp/foo').with( { 'ensure' => 'present', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', }, ) end @@ -18,29 +18,29 @@ context 'file with all options specified' do let(:params) do { - ensure: 'present', - mode: '0777', - owner: 'root', - group: 'root', - content: 'This is the content', - backup: 'foobucket', - checksum: 'none', - force: 'purge', - ignore: ['.svn', '.foo'], - links: 'follow', - provider: 'posix', - purge: true, - recurse: true, - recurselimit: 2, - replace: false, + ensure: 'present', + mode: '0777', + owner: 'root', + group: 'root', + content: 'This is the content', + backup: 'foobucket', + checksum: 'none', + force: 'purge', + ignore: ['.svn', '.foo'], + links: 'follow', + provider: 'posix', + purge: true, + recurse: true, + recurselimit: 2, + replace: false, selinux_ignore_defaults: false, - selrange: 's0', - selrole: 'object_r', - seltype: 'var_t', - seluser: 'system_u', - show_diff: false, - source: 'puppet://modules/types/mydir', - sourceselect: 'first', + selrange: 's0', + selrole: 'object_r', + seltype: 'var_t', + seluser: 'system_u', + show_diff: false, + source: 'puppet://modules/types/mydir', + sourceselect: 'first', } end @@ -84,9 +84,9 @@ is_expected.to contain_file('/tmp/foo').with( { 'ensure' => value, - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', }, ) } @@ -100,7 +100,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::file::/tmp/foo::ensure is invalid and does not match the regex\.}) + }.to raise_error(Puppet::Error, %r{expects a match for Enum}) end end @@ -112,19 +112,19 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::file::/tmp/foo::mode must be exactly 4 digits\.}) + }.to raise_error(Puppet::Error, %r{expects a match for Stdlib::Filemode}) end end end end context 'file with name that is not an absolute path' do - let(:params) { { ensure: 'invalid/path' } } + let(:title) { 'invalid/path' } it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::file::/tmp/foo::ensure is invalid and does not match the regex\.}) + }.to raise_error(Puppet::Error, %r{expects a Stdlib::Absolutepath}) end end end diff --git a/spec/defines/mount_spec.rb b/spec/defines/mount_spec.rb index 7bc4349..9e022ad 100644 --- a/spec/defines/mount_spec.rb +++ b/spec/defines/mount_spec.rb @@ -9,7 +9,15 @@ fstype: 'iso9660', } end - let(:facts) { { osfamily: 'RedHat' } } + let(:facts) do + { + os: + { + family: 'Redhat', + }, + osfamily: 'RedHat', # needed for common module :( + } + end it do is_expected.to contain_mount('/mnt').with( @@ -28,24 +36,24 @@ let(:title) { '/mnt' } let(:params) do { - device: '/dev/fiction', - fstype: 'iso9660', - ensure: 'absent', - atboot: false, + device: '/dev/fiction', + fstype: 'iso9660', + ensure: 'absent', + atboot: false, blockdevice: '/dev/blockdevice', - dump: '1', - options: 'ro', - pass: '1', - provider: 'customprovider', - remounts: true, + dump: '1', + options: 'ro', + pass: '1', + provider: 'customprovider', + remounts: true, } end - let(:facts) { { osfamily: 'RedHat' } } + let(:facts) { { os: { family: 'Redhat' } } } it do is_expected.to contain_mount('/mnt').with( { - 'ensure' => 'absent', + 'ensure' => 'absent', 'atboot' => false, 'device' => '/dev/fiction', 'fstype' => 'iso9660', @@ -75,7 +83,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::mount::invalid::ensure is invalid and does not match the regex\.}) + }.to raise_error(Puppet::Error, %r{expects a match for Enum}) end end @@ -94,6 +102,8 @@ it do is_expected.not_to contain_exec('mkdir_p-/mnt/test') end + + it { is_expected.to contain_mount('/mnt/test') } end end @@ -102,43 +112,61 @@ let(:title) { '/mnt' } let(:params) do { - device: '/dev/fiction', - fstype: 'iso9660', + device: '/dev/fiction', + fstype: 'iso9660', options: 'defaults', } end - let(:facts) { { osfamily: 'Solaris' } } + let(:facts) do + { + os: + { + family: 'Solaris', + }, + osfamily: 'Solaris', # needed for common module :( + } + end it do is_expected.to contain_mount('/mnt').with( { - 'ensure' => 'mounted', + 'ensure' => 'mounted', 'device' => '/dev/fiction', 'fstype' => 'iso9660', 'options' => '-', }, ) end + + it { is_expected.to contain_common__mkdir_p('/mnt') } end context 'on osfamily that is not Solaris' do let(:title) { '/mnt' } let(:params) do { - device: '/dev/fiction', - fstype: 'iso9660', + device: '/dev/fiction', + fstype: 'iso9660', options: 'defaults', } end - let(:facts) { { osfamily: 'Debian' } } + let(:facts) do + { + os: + { + family: 'Debian', + }, + osfamily: 'Debian', # needed for common module :( + } + end it do is_expected.to contain_mount('/mnt').with( { - 'ensure' => 'mounted', - 'device' => '/dev/fiction', - 'fstype' => 'iso9660', - 'options' => 'defaults', + 'ensure' => 'mounted', + 'device' => '/dev/fiction', + 'fstype' => 'iso9660', + 'options' => 'defaults', }, ) end diff --git a/spec/defines/package_spec.rb b/spec/defines/package_spec.rb index cef1aab..d144171 100644 --- a/spec/defines/package_spec.rb +++ b/spec/defines/package_spec.rb @@ -16,13 +16,13 @@ let(:title) { 'pkg1' } let(:params) do { - ensure: 'installed', - adminfile: '/path/to/adminfile', - configfiles: 'keep', - install_options: '--installoption', - provider: 'yum', - responsefile: '/path/to/responsefile', - source: 'http://source/URL/', + ensure: 'installed', + adminfile: '/path/to/adminfile', + configfiles: 'keep', + install_options: '--installoption', + provider: 'yum', + responsefile: '/path/to/responsefile', + source: 'http://source/URL/', uninstall_options: '--uninstall_option', } end @@ -56,7 +56,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::package::pkg1::configfiles is invalid and does not match the regex\.}) + }.to raise_error(Puppet::Error, %r{expects an undef value or a match for Enum}) end end @@ -71,7 +71,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a string\.}) + }.to raise_error(Puppet::Error, %r{expects a match for Enum}) end end @@ -87,7 +87,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{"invalid/path" is not an absolute path\.}) + }.to raise_error(Puppet::Error, %r{expects a Stdlib::Absolutepath}) end end end diff --git a/spec/defines/selboolean_spec.rb b/spec/defines/selboolean_spec.rb index 949c54f..f7359c7 100644 --- a/spec/defines/selboolean_spec.rb +++ b/spec/defines/selboolean_spec.rb @@ -5,15 +5,15 @@ context 'selboolean with all options specified' do let(:params) do { persistent: true, - value: 'on', - provider: 'getsebool', } + value: 'on', + provider: 'getsebool', } end it do is_expected.to contain_selboolean('nfs_export_all_ro').with( { 'persistent' => true, - 'value' => 'on', + 'value' => 'on', }, ) end @@ -28,7 +28,7 @@ is_expected.to contain_selboolean('nfs_export_all_ro').with( { 'persistent' => false, - 'value' => value, + 'value' => value, }, ) end diff --git a/spec/defines/service_spec.rb b/spec/defines/service_spec.rb index 00117a9..7b9fa3f 100644 --- a/spec/defines/service_spec.rb +++ b/spec/defines/service_spec.rb @@ -17,27 +17,27 @@ let(:title) { 'service_maximum' } let(:params) do { - ensure: 'stopped', - binary: '/bin/true', - control: 'SERVICE_MAXIMUM_START', - enable: 'manual', + ensure: 'stopped', + binary: '/bin/true', + control: 'SERVICE_MAXIMUM_START', + enable: 'manual', hasrestart: 'true', - hasstatus: 'false', - manifest: '/bin/manifest', - path: '/etc/init.d', - pattern: 'service_maximum', - provider: 'init', - restart: '/bin/restart', - start: '/bin/start', - status: '/bin/status', - stop: '/bin/stop', + hasstatus: 'false', + manifest: '/bin/manifest', + path: '/etc/init.d', + pattern: 'service_maximum', + provider: 'init', + restart: '/bin/restart', + start: '/bin/start', + status: '/bin/status', + stop: '/bin/stop', } end it do is_expected.to contain_service('service_maximum').with( { - 'ensure' => 'stopped', + 'ensure' => 'stopped', 'binary' => '/bin/true', 'control' => 'SERVICE_MAXIMUM_START', 'enable' => 'manual', @@ -67,7 +67,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::service::invalid::ensure can only be , , or and is set to }) + }.to raise_error(Puppet::Error, %r{expects a value of type Boolean or Enum}) end end @@ -94,7 +94,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{types::service::invalid::enable can only be , or and is set to }) + }.to raise_error(Puppet::Error, %r{expects a value of type Boolean or Enum}) end end @@ -105,7 +105,7 @@ it 'fails' do expect { is_expected.to contain_class('types') - }.to raise_error(Puppet::Error, %r{\["invalid", "type"\] is not a boolean\.}) + }.to raise_error(Puppet::Error, %r{expects a value of type Boolean or Enum}) end end end From ab6192c4915954010d43807354c2953f623f9977 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Thu, 6 Apr 2023 10:48:15 +0000 Subject: [PATCH 09/17] Small Refactoring --- spec/classes/init_spec.rb | 8 ++++---- spec/defines/cron_spec.rb | 6 ++---- spec/defines/exec_spec.rb | 2 +- spec/defines/file_line_spec.rb | 2 +- spec/defines/file_spec.rb | 2 +- spec/defines/mount_spec.rb | 30 ++++++++++++++---------------- spec/defines/package_spec.rb | 32 ++++++-------------------------- spec/defines/selboolean_spec.rb | 25 ++++++++++--------------- spec/defines/service_spec.rb | 8 ++------ 9 files changed, 41 insertions(+), 74 deletions(-) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index df1e1d5..4b269d9 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -80,7 +80,7 @@ context 'with file_lines specified as a hash' do let(:facts) { { osfamily: 'RedHat' } } - let :params do + let(:params) do { file_lines_hiera_merge: false, file_lines: { @@ -266,7 +266,7 @@ context 'with packages specified as a hash' do let(:facts) { { osfamily: 'RedHat' } } - let :params do + let(:params) do { packages_hiera_merge: false, packages: { @@ -316,7 +316,7 @@ context 'with selboolean specified as a hash' do let(:facts) { { osfamily: 'RedHat' } } - let :params do + let(:params) do { selbooleans_hiera_merge: false, selbooleans: { @@ -535,7 +535,7 @@ end context 'with services specified as a hash' do - let :params do + let(:params) do { services_hiera_merge: false, services: { diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 455b7bd..82f9fd6 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -2,9 +2,7 @@ describe 'types::cron' do context 'cron with bare minimum specified' do let(:title) { 'cronjob-1' } - let(:params) do - { command: '/usr/local/bin/script.sh' } - end + let(:params) { { command: '/usr/local/bin/script.sh' } } let(:facts) { { osfamily: 'RedHat' } } it do @@ -38,7 +36,7 @@ let(:facts) { { osfamily: 'RedHat' } } it do - is_expected.to contain_cron('cronjob-1').with( + is_expected.to contain_cron('cronjob-1').only_with( { 'ensure' => 'absent', 'command' => '/usr/local/bin/script.sh', diff --git a/spec/defines/exec_spec.rb b/spec/defines/exec_spec.rb index fa3b02e..59d2363 100644 --- a/spec/defines/exec_spec.rb +++ b/spec/defines/exec_spec.rb @@ -40,7 +40,7 @@ end it do - is_expected.to contain_exec('testing').with( + is_expected.to contain_exec('testing').only_with( { 'command' => '/spec/testing.sh', 'creates' => '/creates', diff --git a/spec/defines/file_line_spec.rb b/spec/defines/file_line_spec.rb index cce5510..10719d0 100644 --- a/spec/defines/file_line_spec.rb +++ b/spec/defines/file_line_spec.rb @@ -32,7 +32,7 @@ end it do - is_expected.to contain_file_line('some_file').with( + is_expected.to contain_file_line('some_file').only_with( { 'ensure' => 'present', 'path' => '/tmp/foo', diff --git a/spec/defines/file_spec.rb b/spec/defines/file_spec.rb index 7a333ef..1342776 100644 --- a/spec/defines/file_spec.rb +++ b/spec/defines/file_spec.rb @@ -45,7 +45,7 @@ end it do - is_expected.to contain_file('/tmp/foo').with( + is_expected.to contain_file('/tmp/foo').only_with( { 'ensure' => 'present', 'mode' => '0777', diff --git a/spec/defines/mount_spec.rb b/spec/defines/mount_spec.rb index 9e022ad..bf253fb 100644 --- a/spec/defines/mount_spec.rb +++ b/spec/defines/mount_spec.rb @@ -11,10 +11,7 @@ end let(:facts) do { - os: - { - family: 'Redhat', - }, + os: { family: 'Redhat' }, osfamily: 'RedHat', # needed for common module :( } end @@ -30,6 +27,8 @@ }, ) end + + it { is_expected.to contain_common__mkdir_p('/mnt') } end context 'mount with all options specified' do @@ -48,10 +47,9 @@ remounts: true, } end - let(:facts) { { os: { family: 'Redhat' } } } it do - is_expected.to contain_mount('/mnt').with( + is_expected.to contain_mount('/mnt').only_with( { 'ensure' => 'absent', 'atboot' => false, @@ -100,10 +98,16 @@ let(:facts) { { osfamily: 'RedHat' } } it do - is_expected.not_to contain_exec('mkdir_p-/mnt/test') + is_expected.to contain_mount('/mnt/test').with( + { + 'ensure' => 'absent', + 'device' => '/dev/fiction', + 'fstype' => 'iso9660', + }, + ) end - it { is_expected.to contain_mount('/mnt/test') } + it { is_expected.not_to contain_exec('mkdir_p-/mnt/test') } end end @@ -119,10 +123,7 @@ end let(:facts) do { - os: - { - family: 'Solaris', - }, + os: { family: 'Solaris' }, osfamily: 'Solaris', # needed for common module :( } end @@ -152,10 +153,7 @@ end let(:facts) do { - os: - { - family: 'Debian', - }, + os: { family: 'Debian' }, osfamily: 'Debian', # needed for common module :( } end diff --git a/spec/defines/package_spec.rb b/spec/defines/package_spec.rb index d144171..863e231 100644 --- a/spec/defines/package_spec.rb +++ b/spec/defines/package_spec.rb @@ -2,14 +2,9 @@ describe 'types::package' do context 'package with bare minimum specified' do let(:title) { 'pkg1' } + let(:facts) { { osfamily: 'RedHat' } } - it do - is_expected.to contain_package('pkg1').with( - { - 'ensure' => 'present', - }, - ) - end + it { is_expected.to contain_package('pkg1').with_ensure('present') } end context 'package with all options specified' do @@ -26,10 +21,9 @@ uninstall_options: '--uninstall_option', } end - let(:facts) { { osfamily: 'RedHat' } } it do - is_expected.to contain_package('pkg1').with( + is_expected.to contain_package('pkg1').only_with( { 'ensure' => 'installed', 'adminfile' => '/path/to/adminfile', @@ -46,12 +40,7 @@ context 'package with invalid configfiles' do let(:title) { 'pkg1' } - let(:params) do - { - configfiles: 'invalid', - } - end - let(:facts) { { osfamily: 'RedHat' } } + let(:params) { { configfiles: 'invalid' } } it 'fails' do expect { @@ -62,11 +51,7 @@ context 'package with invalid type for ensure' do let(:title) { 'invalidtype' } - let(:params) do - { - ensure: ['invalid', 'type'], - } - end + let(:params) { { ensure: ['invalid', 'type'] } } it 'fails' do expect { @@ -77,12 +62,7 @@ context 'package with invalid responsefile' do let(:title) { 'pkg1' } - let(:params) do - { - responsefile: 'invalid/path' - } - end - let(:facts) { { osfamily: 'RedHat' } } + let(:params) { { responsefile: 'invalid/path' } } it 'fails' do expect { diff --git a/spec/defines/selboolean_spec.rb b/spec/defines/selboolean_spec.rb index f7359c7..ad43ae8 100644 --- a/spec/defines/selboolean_spec.rb +++ b/spec/defines/selboolean_spec.rb @@ -4,16 +4,19 @@ context 'selboolean with all options specified' do let(:params) do - { persistent: true, + { + persistent: true, value: 'on', - provider: 'getsebool', } + provider: 'getsebool', + } end it do - is_expected.to contain_selboolean('nfs_export_all_ro').with( + is_expected.to contain_selboolean('nfs_export_all_ro').only_with( { 'persistent' => true, 'value' => 'on', + 'provider' => 'getsebool', }, ) end @@ -37,9 +40,7 @@ end context 'selboolean with invalid value for provider' do - let(:params) do - { provider: false, } - end + let(:params) { { provider: false } } it 'fails' do expect { @@ -49,9 +50,7 @@ end context 'selboolean with invalid value for persistent' do - let(:params) do - { persistent: 'invalid setting', } - end + let(:params) { { persistent: 'invalid setting' } } it 'fails' do expect { @@ -61,9 +60,7 @@ end context 'selboolean with invalid value for value' do - let(:params) do - { value: 'invalid setting', } - end + let(:params) { { value: 'invalid setting' } } it 'fails' do expect { @@ -73,9 +70,7 @@ end context 'selboolean with no value - value is mandatory' do - let(:params) do - { persistent: false } - end + let(:params) { { persistent: false } } it 'fails' do expect { diff --git a/spec/defines/service_spec.rb b/spec/defines/service_spec.rb index 7b9fa3f..6c0077a 100644 --- a/spec/defines/service_spec.rb +++ b/spec/defines/service_spec.rb @@ -35,7 +35,7 @@ end it do - is_expected.to contain_service('service_maximum').with( + is_expected.to contain_service('service_maximum').only_with( { 'ensure' => 'stopped', 'binary' => '/bin/true', @@ -58,11 +58,7 @@ context 'service with invalid ensure' do let(:title) { 'invalid' } - let(:params) do - { - ensure: 'invalid', - } - end + let(:params) { { ensure: 'invalid' } } it 'fails' do expect { From 1c4bbfecb56c35879666ba8d26cff484058ee602 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Thu, 6 Apr 2023 10:50:11 +0000 Subject: [PATCH 10/17] Remove TravisCI configuration snippets --- .fixtures-puppetv3.yml | 10 -------- .travis.yml | 57 ------------------------------------------ 2 files changed, 67 deletions(-) delete mode 100644 .fixtures-puppetv3.yml delete mode 100644 .travis.yml diff --git a/.fixtures-puppetv3.yml b/.fixtures-puppetv3.yml deleted file mode 100644 index 46e0628..0000000 --- a/.fixtures-puppetv3.yml +++ /dev/null @@ -1,10 +0,0 @@ -fixtures: - repositories: - common: - repo: 'https://github.com/ghoneycutt/puppet-module-common.git' - ref: 'v1.7.0' - stdlib: - repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.6.0' - symlinks: - types: "#{source_dir}" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7385f2a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,57 +0,0 @@ ---- -language: ruby - -cache: bundler - -before_install: - - bundle -v - - rm Gemfile.lock || true - - gem update --system - - gem update bundler - - gem --version - - bundle -v - -sudo: false - -script: 'SPEC_OPTS="--format documentation" bundle exec rake validate lint spec' - -matrix: - fast_finish: true - include: - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" FUTURE_PARSER="yes" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" FUTURE_PARSER="yes" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" FUTURE_PARSER="yes" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 3" FIXTURES_YML=".fixtures-puppetv3.yml" FUTURE_PARSER="yes" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.5.0" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.6.0" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.7.0" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.8.0" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.9.0" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4.10.0" - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4" - - rvm: 2.4.1 - env: PUPPET_GEM_VERSION="~> 5" - - rvm: 2.5.1 - env: PUPPET_GEM_VERSION="~> 6" - -notifications: - email: false From 2ccdb7f504f0842b500d19417e0660bd014baed0 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Tue, 11 Apr 2023 08:53:59 +0000 Subject: [PATCH 11/17] Remove outdated validations for booleans --- manifests/init.pp | 67 ++++++----------------------------------------- 1 file changed, 8 insertions(+), 59 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 52e4006..e777f05 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -78,59 +78,8 @@ Boolean $selbooleans_hiera_merge = true, Boolean $services_hiera_merge = true, ) { - if is_string($crons_hiera_merge) { - $crons_hiera_merge_real = str2bool($crons_hiera_merge) - } else { - $crons_hiera_merge_real = $crons_hiera_merge - } - validate_bool($crons_hiera_merge_real) - - $execs_hiera_merge_bool = str2bool($execs_hiera_merge) - - if is_string($file_lines_hiera_merge) { - $file_lines_hiera_merge_real = str2bool($file_lines_hiera_merge) - } else { - $file_lines_hiera_merge_real = $file_lines_hiera_merge - } - validate_bool($file_lines_hiera_merge_real) - - if is_string($files_hiera_merge) { - $files_hiera_merge_real = str2bool($files_hiera_merge) - } else { - $files_hiera_merge_real = $files_hiera_merge - } - validate_bool($files_hiera_merge_real) - - if is_string($mounts_hiera_merge) { - $mounts_hiera_merge_real = str2bool($mounts_hiera_merge) - } else { - $mounts_hiera_merge_real = $mounts_hiera_merge - } - validate_bool($mounts_hiera_merge_real) - - if is_string($packages_hiera_merge) { - $packages_hiera_merge_real = str2bool($packages_hiera_merge) - } else { - $packages_hiera_merge_real = $packages_hiera_merge - } - validate_bool($packages_hiera_merge_real) - - if is_string($selbooleans_hiera_merge) { - $selbooleans_hiera_merge_real = str2bool($selbooleans_hiera_merge) - } else { - $selbooleans_hiera_merge_real = $selbooleans_hiera_merge - } - validate_bool($selbooleans_hiera_merge_real) - - if is_string($services_hiera_merge) { - $services_hiera_merge_real = str2bool($services_hiera_merge) - } else { - $services_hiera_merge_real = $services_hiera_merge - } - validate_bool($services_hiera_merge_real) - if $crons != {} { - if $crons_hiera_merge_real == true { + if $crons_hiera_merge == true { $crons_real = hiera_hash('types::crons') } else { $crons_real = $crons @@ -140,7 +89,7 @@ } if $execs != {} { - if $execs_hiera_merge_bool == true { + if $execs_hiera_merge == true { $execs_real = hiera_hash('types::execs') } else { $execs_real = $execs @@ -150,7 +99,7 @@ } if $file_lines != {} { - if $file_lines_hiera_merge_real == true { + if $file_lines_hiera_merge == true { $file_lines_real = hiera_hash('types::file_lines') } else { $file_lines_real = $file_lines @@ -160,7 +109,7 @@ } if $files != {} { - if $files_hiera_merge_real == true { + if $files_hiera_merge == true { $files_real = hiera_hash('types::files') } else { $files_real = $files @@ -170,7 +119,7 @@ } if $mounts != {} { - if $mounts_hiera_merge_real == true { + if $mounts_hiera_merge == true { $mounts_real = hiera_hash('types::mounts') } else { $mounts_real = $mounts @@ -180,7 +129,7 @@ } if $packages != {} { - if $packages_hiera_merge_real == true { + if $packages_hiera_merge == true { $packages_real = hiera_hash('types::packages') } else { $packages_real = $packages @@ -190,7 +139,7 @@ } if $selbooleans != {} { - if $selbooleans_hiera_merge_real == true { + if $selbooleans_hiera_merge == true { $selbooleans_real = hiera_hash('types::selboolean') } else { $selbooleans_real = $selbooleans @@ -200,7 +149,7 @@ } if $services != {} { - if $services_hiera_merge_real == true { + if $services_hiera_merge == true { $services_real = hiera_hash('types::services') } else { $services_real = $services From a4ac00c830c0ad91277e839a6ede92bf4f5b704b Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Tue, 11 Apr 2023 09:03:46 +0000 Subject: [PATCH 12/17] Remove outdated hiera_merge functionality --- README.md | 60 ------------------ manifests/init.pp | 127 +++----------------------------------- spec/classes/init_spec.rb | 4 -- 3 files changed, 8 insertions(+), 183 deletions(-) diff --git a/README.md b/README.md index f0d19f0..26680fb 100644 --- a/README.md +++ b/README.md @@ -40,108 +40,48 @@ Hash of resource type `cron`. - *Default*: undef -crons_hiera_merge ------------------ -Boolean to control merges of all found instances of types::crons in Hiera. This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. - -This will default to 'true' in future versions. - -- *Default*: false - execs ----- Hash of resource type `exec`. - *Default*: undef -execs_hiera_merge ------------------ -Boolean to control merges of all found instances of types::execs in Hiera. This is useful for specifying exec resources at different levels of the hierarchy and having them all included in the catalog. - -This will default to 'true' in future versions. - -- *Default*: false - file_lines ---------- Hash of resource type `file_line`. - *Default*: undef -file_lines_hiera_merge ----------------------- -Boolean to control merges of all found instances of types::file_lines in Hiera. -This is useful for specifying file_line resources at different levels of the -hierarchy and having them all included in the catalog. - -This will default to 'true' in future versions. - -- *Default*: true - files ----- Hash of resource type `file`. - *Default*: undef -files_hiera_merge ------------------ -Boolean to control merges of all found instances of types::files in Hiera. This is useful for specifying file resources at different levels of the hierarchy and having them all included in the catalog. - -This will default to 'true' in future versions. - -- *Default*: false - mounts ------ Hash of resource type `mount`. - *Default*: undef -mounts_hiera_merge ------------------- -Boolean to control merges of all found instances of types::mounts in Hiera. This is useful for specifying mount resources at different levels of the hierarchy and having them all included in the catalog. - -This will default to 'true' in future versions. - -- *Default*: false - packages -------- Hash of resource type `package`. - *Default*: undef -packages_hiera_merge --------------------- -Boolean to control merges of all found instances of types::packages in Hiera. This is useful for specifying package resources at different levels of the hierarchy and having them all included in the catalog. - -- *Default*: true - selbooleans ----------- Hash of resource type `selboolean`. - *Default*: undef -selbooleans_hiera_merge ------------------------ -Boolean to control merges of all found instances of types::selboolean in Hiera. This is useful for specifying selboolean resources at different levels of the hierarchy and having them all included in the catalog. - -- *Default*: true - services -------- Hash of resource type `service`. - *Default*: undef -services_hiera_merge --------------------- -Boolean to control merges of all found instances of types::services in Hiera. This is useful for specifying file resources at different levels of the hierarchy and having them all included in the catalog. - -- *Default*: true - === # Defines diff --git a/manifests/init.pp b/manifests/init.pp index e777f05..6092ef7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -28,38 +28,6 @@ # @param services # Hash of resource type `service`. # -# @param crons_hiera_merge -# Boolean to control merges of all found instances of types::crons in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# -# @param execs_hiera_merge -# Boolean to control merges of all found instances of types::execs in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# -# @param file_lines_hiera_merge -# Boolean to control merges of all found instances of types::file_lines in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# -# @param files_hiera_merge -# Boolean to control merges of all found instances of types::files in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# -# @param mounts_hiera_merge -# Boolean to control merges of all found instances of types::mounts in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# -# @param packages_hiera_merge -# Boolean to control merges of all found instances of types::packages in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# -# @param selbooleans_hiera_merge -# Boolean to control merges of all found instances of types::selbooleans in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# -# @param services_hiera_merge -# Boolean to control merges of all found instances of types::services in Hiera. -# This is useful for specifying cron resources at different levels of the hierarchy and having them all included in the catalog. -# class types ( Hash $crons = {}, Hash $execs = {}, @@ -69,92 +37,13 @@ Hash $packages = {}, Hash $selbooleans = {}, Hash $services = {}, - Boolean $crons_hiera_merge = false, - Boolean $execs_hiera_merge = false, - Boolean $file_lines_hiera_merge = true, - Boolean $files_hiera_merge = false, - Boolean $mounts_hiera_merge = false, - Boolean $packages_hiera_merge = true, - Boolean $selbooleans_hiera_merge = true, - Boolean $services_hiera_merge = true, ) { - if $crons != {} { - if $crons_hiera_merge == true { - $crons_real = hiera_hash('types::crons') - } else { - $crons_real = $crons - } - validate_hash($crons_real) - create_resources('types::cron',$crons_real) - } - - if $execs != {} { - if $execs_hiera_merge == true { - $execs_real = hiera_hash('types::execs') - } else { - $execs_real = $execs - } - validate_hash($execs_real) - create_resources('types::exec',$execs_real) - } - - if $file_lines != {} { - if $file_lines_hiera_merge == true { - $file_lines_real = hiera_hash('types::file_lines') - } else { - $file_lines_real = $file_lines - } - validate_hash($file_lines_real) - create_resources('types::file_line',$file_lines_real) - } - - if $files != {} { - if $files_hiera_merge == true { - $files_real = hiera_hash('types::files') - } else { - $files_real = $files - } - validate_hash($files_real) - create_resources('types::file',$files_real) - } - - if $mounts != {} { - if $mounts_hiera_merge == true { - $mounts_real = hiera_hash('types::mounts') - } else { - $mounts_real = $mounts - } - validate_hash($mounts_real) - create_resources('types::mount',$mounts_real) - } - - if $packages != {} { - if $packages_hiera_merge == true { - $packages_real = hiera_hash('types::packages') - } else { - $packages_real = $packages - } - validate_hash($packages_real) - create_resources('types::package',$packages_real) - } - - if $selbooleans != {} { - if $selbooleans_hiera_merge == true { - $selbooleans_real = hiera_hash('types::selboolean') - } else { - $selbooleans_real = $selbooleans - } - validate_hash($selbooleans_real) - create_resources('types::selboolean',$selbooleans_real) - } - - if $services != {} { - if $services_hiera_merge == true { - $services_real = hiera_hash('types::services') - } else { - $services_real = $services - } - validate_hash($services_real) - create_resources('types::service',$services_real) - } + create_resources('types::cron',$crons) + create_resources('types::exec',$execs) + create_resources('types::file_line',$file_lines) + create_resources('types::file',$files) + create_resources('types::mount',$mounts) + create_resources('types::package',$packages) + create_resources('types::selboolean',$selbooleans) + create_resources('types::service',$services) } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 4b269d9..c0cce80 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -82,7 +82,6 @@ let(:facts) { { osfamily: 'RedHat' } } let(:params) do { - file_lines_hiera_merge: false, file_lines: { 'some_file' => { 'path' => '/tmp/foo', @@ -268,7 +267,6 @@ let(:facts) { { osfamily: 'RedHat' } } let(:params) do { - packages_hiera_merge: false, packages: { 'pkg1' => { 'ensure' => 'present', @@ -318,7 +316,6 @@ let(:facts) { { osfamily: 'RedHat' } } let(:params) do { - selbooleans_hiera_merge: false, selbooleans: { 'nfs_export_all_ro' => { 'value' => 'on', @@ -537,7 +534,6 @@ context 'with services specified as a hash' do let(:params) do { - services_hiera_merge: false, services: { 'service-stopped' => { 'ensure' => 'stopped', From 2c93e1d97acf08462ee5f763741108c3966ed603 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Mon, 17 Jul 2023 10:40:24 +0000 Subject: [PATCH 13/17] Use PDK v3.0.0 --- .gitignore | 2 +- .pdkignore | 7 +- .rubocop.yml | 216 ++++++++++++++++++++++++++++++++++++++++++-- Gemfile | 47 +++++----- Rakefile | 9 +- metadata.json | 6 +- spec/spec_helper.rb | 4 +- 7 files changed, 246 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index 988dcbb..3f15512 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ /log/ /pkg/ /spec/fixtures/manifests/ -/spec/fixtures/modules/ +/spec/fixtures/modules/* /tmp/ /vendor/ /convert_report.txt diff --git a/.pdkignore b/.pdkignore index a956c8f..584438f 100644 --- a/.pdkignore +++ b/.pdkignore @@ -16,7 +16,7 @@ /log/ /pkg/ /spec/fixtures/manifests/ -/spec/fixtures/modules/ +/spec/fixtures/modules/* /tmp/ /vendor/ /convert_report.txt @@ -26,19 +26,16 @@ .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 +/..yml /.yardopts /spec/ /.vscode/ diff --git a/.rubocop.yml b/.rubocop.yml index 31e8248..5be1f9f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ require: - rubocop-rspec AllCops: DisplayCopNames: true - TargetRubyVersion: '2.5' + TargetRubyVersion: '2.6' Include: - "**/*.rb" Exclude: @@ -111,8 +111,14 @@ 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: @@ -287,11 +293,9 @@ Performance/UriDefaultParser: Enabled: false RSpec/Be: Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false RSpec/Capybara/FeatureMethods: Enabled: false -RSpec/Capybara/VisibilityMatcher: +RSpec/ContainExactly: Enabled: false RSpec/ContextMethod: Enabled: false @@ -331,6 +335,8 @@ RSpec/LeakyConstantDeclaration: Enabled: false RSpec/LetBeforeExamples: Enabled: false +RSpec/MatchArray: + Enabled: false RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: @@ -373,8 +379,6 @@ Style/AccessModifierDeclarations: Enabled: false Style/AccessorGrouping: Enabled: false -Style/AsciiComments: - Enabled: false Style/BisectedAttrAccessor: Enabled: false Style/CaseLikeIf: @@ -485,35 +489,235 @@ Style/TrailingMethodEndStatement: Enabled: false Style/UnpackFirst: Enabled: false +Capybara/MatchStyle: + Enabled: false +Capybara/NegationMatcher: + Enabled: false +Capybara/SpecificActions: + Enabled: false +Capybara/SpecificFinders: + Enabled: false +Capybara/SpecificMatcher: + Enabled: false +Gemspec/DeprecatedAttributeAssignment: + Enabled: false +Gemspec/DevelopmentDependencies: + Enabled: false +Gemspec/RequireMFA: + Enabled: false +Layout/LineContinuationLeadingSpace: + Enabled: false +Layout/LineContinuationSpacing: + Enabled: false +Layout/LineEndStringConcatenationIndentation: + Enabled: false +Layout/SpaceBeforeBrackets: + Enabled: false +Lint/AmbiguousAssignment: + Enabled: false +Lint/AmbiguousOperatorPrecedence: + Enabled: false +Lint/AmbiguousRange: + Enabled: false +Lint/ConstantOverwrittenInRescue: + Enabled: false +Lint/DeprecatedConstants: + Enabled: false Lint/DuplicateBranch: Enabled: false +Lint/DuplicateMagicComment: + Enabled: false Lint/DuplicateRegexpCharacterClassElement: Enabled: false Lint/EmptyBlock: Enabled: false Lint/EmptyClass: Enabled: false +Lint/EmptyInPattern: + Enabled: false +Lint/IncompatibleIoSelectWithFiberScheduler: + Enabled: false +Lint/LambdaWithoutLiteralBlock: + Enabled: false Lint/NoReturnInBeginEndBlocks: Enabled: false +Lint/NonAtomicFileOperation: + Enabled: false +Lint/NumberedParameterAssignment: + Enabled: false +Lint/OrAssignmentToConstant: + Enabled: false +Lint/RedundantDirGlobSort: + Enabled: false +Lint/RefinementImportMethods: + Enabled: false +Lint/RequireRangeParentheses: + Enabled: false +Lint/RequireRelativeSelfPath: + Enabled: false +Lint/SymbolConversion: + Enabled: false Lint/ToEnumArguments: Enabled: false +Lint/TripleQuotes: + Enabled: false Lint/UnexpectedBlockArity: Enabled: false Lint/UnmodifiedReduceAccumulator: Enabled: false +Lint/UselessRescue: + Enabled: false +Lint/UselessRuby2Keywords: + Enabled: false +Metrics/CollectionLiteralLength: + Enabled: false +Naming/BlockForwarding: + Enabled: false Performance/CollectionLiteralInLoop: Enabled: false +Performance/ConcurrentMonotonicTime: + Enabled: false +Performance/MapCompact: + Enabled: false +Performance/RedundantEqualityComparisonBlock: + Enabled: false +Performance/RedundantSplitRegexpArgument: + Enabled: false +Performance/StringIdentifierArgument: + Enabled: false +RSpec/BeEq: + Enabled: false +RSpec/BeNil: + Enabled: false +RSpec/ChangeByZero: + Enabled: false +RSpec/ClassCheck: + Enabled: false +RSpec/DuplicatedMetadata: + Enabled: false +RSpec/ExcessiveDocstringSpacing: + Enabled: false +RSpec/FactoryBot/ConsistentParenthesesStyle: + Enabled: false +RSpec/FactoryBot/FactoryNameStyle: + Enabled: false +RSpec/FactoryBot/SyntaxMethods: + Enabled: false +RSpec/IdenticalEqualityAssertion: + Enabled: false +RSpec/NoExpectationExample: + Enabled: false +RSpec/PendingWithoutReason: + Enabled: false +RSpec/Rails/AvoidSetupHook: + Enabled: false +RSpec/Rails/HaveHttpStatus: + Enabled: false +RSpec/Rails/InferredSpecType: + Enabled: false +RSpec/Rails/MinitestAssertions: + Enabled: false +RSpec/Rails/TravelAround: + Enabled: false +RSpec/RedundantAround: + Enabled: false +RSpec/SkipBlockInsideExample: + Enabled: false +RSpec/SortMetadata: + Enabled: false +RSpec/SubjectDeclaration: + Enabled: false +RSpec/VerifiedDoubleReference: + Enabled: false +Security/CompoundHash: + Enabled: false +Security/IoMethods: + Enabled: false Style/ArgumentsForwarding: Enabled: false +Style/ArrayIntersect: + Enabled: false Style/CollectionCompact: Enabled: false +Style/ComparableClamp: + Enabled: false +Style/ConcatArrayLiterals: + Enabled: false +Style/DirEmpty: + Enabled: false Style/DocumentDynamicEvalDefinition: Enabled: false +Style/EmptyHeredoc: + Enabled: false +Style/EndlessMethod: + Enabled: false +Style/EnvHome: + Enabled: false +Style/FetchEnvVar: + Enabled: false +Style/FileEmpty: + Enabled: false +Style/FileRead: + Enabled: false +Style/FileWrite: + Enabled: false +Style/HashConversion: + Enabled: false +Style/HashExcept: + Enabled: false +Style/IfWithBooleanLiteralBranches: + Enabled: false +Style/InPatternThen: + Enabled: false +Style/MagicCommentFormat: + Enabled: false +Style/MapCompactWithConditionalBlock: + Enabled: false +Style/MapToHash: + Enabled: false +Style/MapToSet: + Enabled: false +Style/MinMaxComparison: + Enabled: false +Style/MultilineInPatternThen: + Enabled: false Style/NegatedIfElseCondition: Enabled: false +Style/NestedFileDirname: + Enabled: false Style/NilLambda: Enabled: false +Style/NumberedParameters: + Enabled: false +Style/NumberedParametersLimit: + Enabled: false +Style/ObjectThen: + Enabled: false +Style/OpenStructUse: + Enabled: false +Style/OperatorMethodCall: + Enabled: false +Style/QuotedSymbols: + Enabled: false Style/RedundantArgument: Enabled: false +Style/RedundantConstantBase: + Enabled: false +Style/RedundantDoubleSplatHashBraces: + Enabled: false +Style/RedundantEach: + Enabled: false +Style/RedundantHeredocDelimiterQuotes: + Enabled: false +Style/RedundantInitialize: + Enabled: false +Style/RedundantSelfAssignmentBranch: + Enabled: false +Style/RedundantStringEscape: + Enabled: false +Style/SelectByRegexp: + Enabled: false +Style/StringChars: + Enabled: false Style/SwapValues: Enabled: false diff --git a/Gemfile b/Gemfile index 9584486..5830a25 100644 --- a/Gemfile +++ b/Gemfile @@ -14,31 +14,32 @@ def location_for(place_or_version, fake_version = nil) 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 "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false - gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false - gem "puppetlabs_spec_helper", '~> 5.0', require: false - gem "rspec-puppet-facts", '~> 2.0', require: false - gem "codecov", '~> 0.2', require: false - gem "dependency_checker", '~> 0.2', require: false - gem "parallel_tests", '= 3.12.1', require: false - gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.5', require: false - gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false - gem "rb-readline", '= 0.5.5', 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.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '~> 3.0', require: false + gem "puppetlabs_spec_helper", '~> 6.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 1.0.0', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "rb-readline", '= 0.5.5', 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') end group :system_tests do - gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] - gem "serverspec", '~> 2.41', require: false + gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end group :test do gem "puppet_metadata", '~> 1.9.0', require: false diff --git a/Rakefile b/Rakefile index d68f852..d34d683 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,11 @@ # frozen_string_literal: true require 'bundler' -require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? +require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? -require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? -require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? +require 'github_changelog_generator/task' if Gem.loaded_specs.key? 'github_changelog_generator' +require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' def changelog_user return unless Rake.application.top_level_tasks.include? "changelog" @@ -46,7 +45,7 @@ PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.send('disable_140chars') -if Bundler.rubygems.find_name('github_changelog_generator').any? +if Gem.loaded_specs.key? 'github_changelog_generator' GitHubChangelogGenerator::RakeTask.new :changelog do |config| raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? config.user = "#{changelog_user}" diff --git a/metadata.json b/metadata.json index 0d4902e..2fe2d4e 100644 --- a/metadata.json +++ b/metadata.json @@ -68,7 +68,7 @@ } ], "description": "Puppet module to manage default types through hashes in Hiera with the\ncreate_resources() function. This module adds validation and helper functions,\nsuch as ensuring directories. Without specifying any hashes, this module will take no action.", - "pdk-version": "2.7.1", - "template-url": "pdk-default#2.7.4", - "template-ref": "tags/2.7.4-0-g58edf57" + "pdk-version": "3.0.0", + "template-url": "pdk-default#3.0.0", + "template-ref": "tags/3.0.0-0-g056e50d" } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 415ba7d..12c4cb8 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,8 +25,8 @@ next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin - default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + default_facts.merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end From 38266ccdd264869c0d8cc63440b48c780a1d5d89 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Mon, 17 Jul 2023 10:41:40 +0000 Subject: [PATCH 14/17] Remove non-working github_changelog_generator traces --- .sync.yml | 15 --------------- Gemfile | 4 ---- 2 files changed, 19 deletions(-) diff --git a/.sync.yml b/.sync.yml index 90f2df6..91fbbfc 100644 --- a/.sync.yml +++ b/.sync.yml @@ -12,21 +12,6 @@ appveyor.yml: .gitlab-ci.yml: delete: true -.travis.yml: - delete: true - -Gemfile: - unmanaged: false - optional: - ':development': - - gem: 'github_changelog_generator' - version: '~> 1.15' - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" - ':test': - # provides metadata2gha, needed for unit tests - - gem: 'puppet_metadata' - version: '~> 1.9.0' - spec/spec_helper.rb: coverage_report: true minimum_code_coverage_percentage: 100 diff --git a/Gemfile b/Gemfile index 5830a25..add1873 100644 --- a/Gemfile +++ b/Gemfile @@ -35,15 +35,11 @@ group :development do 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 "github_changelog_generator", '~> 1.15', require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') end group :system_tests do gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] gem "serverspec", '~> 2.41', require: false end -group :test do - gem "puppet_metadata", '~> 1.9.0', require: false -end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] From cc0467a4516c679c2a21df4f59dbc5b6dd107d1c Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Mon, 17 Jul 2023 10:42:28 +0000 Subject: [PATCH 15/17] Update Github CI actions to test Puppet 8 --- .github/workflows/ci.yml | 92 ------------------- .../workflows/run-pdk-tests-on-puppet-7.yml | 34 +++++++ .../workflows/run-pdk-tests-on-puppet-8.yml | 34 +++++++ 3 files changed, 68 insertions(+), 92 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/run-pdk-tests-on-puppet-7.yml create mode 100644 .github/workflows/run-pdk-tests-on-puppet-8.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 5c39551..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,92 +0,0 @@ ---- -name: CI - -on: pull_request - -concurrency: - group: ${{ github.head_ref }} - cancel-in-progress: true - -jobs: - setup_matrix: - name: Setup Test Matrix - runs-on: ubuntu-20.04 - timeout-minutes: 40 - outputs: - puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} - github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} - steps: - - uses: actions/checkout@v3 - - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '2.7.3' - bundler-cache: true - - - name: Run static validations - run: bundle exec rake validate lint - - - name: Run rake rubocop - run: bundle exec rake rubocop - - - name: Setup Test Matrix - id: get-outputs - run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false - - unit: - needs: setup_matrix - runs-on: ubuntu-20.04 - timeout-minutes: 40 - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}} - name: Spec Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }}) - steps: - - uses: actions/checkout@v3 - - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - - name: Run tests - run: bundle exec rake parallel_spec - -# TODO: active when acceptance tests have been added -# acceptance: -# name: Litmus Acceptance -# runs-on: ubuntu-20.04 -# env: -# BOLT_GEM: true -# CI: true -# steps: -# - uses: actions/checkout@v3 -# - name: Setup ruby -# uses: ruby/setup-ruby@v1 -# with: -# ruby-version: '2.7.3' -# bundler-cache: true -# -# - name: Provision Testing Environments -# run: | -# bundle exec rake 'litmus:provision_list[default]' -# bundle exec rake 'litmus:install_agent' -# bundle exec rake 'litmus:install_module' -# - name: Run Tests -# run: bundle exec rake 'litmus:acceptance:parallel' -# -# - name: Tear Down -# run: bundle exec rake 'litmus:tear_down' - - tests: - needs: - - unit -# TODO: active when acceptance tests have been added -# - acceptance - runs-on: ubuntu-20.04 - name: Test suite - steps: - - run: echo Test suite completed diff --git a/.github/workflows/run-pdk-tests-on-puppet-7.yml b/.github/workflows/run-pdk-tests-on-puppet-7.yml new file mode 100644 index 0000000..1b13f18 --- /dev/null +++ b/.github/workflows/run-pdk-tests-on-puppet-7.yml @@ -0,0 +1,34 @@ +name: Run PDK tests on Puppet 7.x + +on: + - push + - pull_request + +jobs: + validate-7: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Run pdk validate + uses: puppets-epic-show-theatre/action-pdk-validate@v1 + with: + puppet-version: "7" + # [optional] A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5". + # pe-version: "" + # [optional] A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1". + + test-7: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Run unit tests + uses: puppets-epic-show-theatre/action-pdk-test-unit@v1 + with: + puppet-version: "7" + # [optional] A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5". + # pe-version: "" + # [optional] A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1". diff --git a/.github/workflows/run-pdk-tests-on-puppet-8.yml b/.github/workflows/run-pdk-tests-on-puppet-8.yml new file mode 100644 index 0000000..12460e0 --- /dev/null +++ b/.github/workflows/run-pdk-tests-on-puppet-8.yml @@ -0,0 +1,34 @@ +name: Run PDK tests on Puppet 8.x + +on: + - push + - pull_request + +jobs: + validate-8: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Run pdk validate + uses: puppets-epic-show-theatre/action-pdk-validate@v1 + with: + puppet-version: "8" + # [optional] A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5". + # pe-version: "" + # [optional] A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1". + + test-8: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Run unit tests + uses: puppets-epic-show-theatre/action-pdk-test-unit@v1 + with: + puppet-version: "8" + # [optional] A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5". + # pe-version: "" + # [optional] A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1". From 4dd5526249702316b28edf6a46302ab55dfc7d27 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Mon, 17 Jul 2023 10:42:54 +0000 Subject: [PATCH 16/17] Add support for Puppet 8, remove Puppet 6 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 2fe2d4e..ca783d8 100644 --- a/metadata.json +++ b/metadata.json @@ -64,7 +64,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.0.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "description": "Puppet module to manage default types through hashes in Hiera with the\ncreate_resources() function. This module adds validation and helper functions,\nsuch as ensuring directories. Without specifying any hashes, this module will take no action.", From d5171a2670b75280f3c8a52ab75c78725934adec Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Mon, 17 Jul 2023 10:46:00 +0000 Subject: [PATCH 17/17] Satisfy rubocop --- spec/classes/init_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index c0cce80..4c8ea71 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -174,8 +174,7 @@ 'source' => 'puppet://modules/types/mydir', 'sourceselect' => 'first', }, - '/tmp/file2' => { - }, + '/tmp/file2' => {}, '/softlink' => { 'ensure' => 'link', 'target' => '/etc/motd',