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/.fixtures.yml b/.fixtures.yml index b6fb661..6ca8d5c 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,6 +5,6 @@ fixtures: ref: 'v1.4.1' stdlib: repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.6.0' + ref: 'v8.0.0' symlinks: ntp: "#{source_dir}" 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/.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 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/.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..a3457cc --- /dev/null +++ b/.sync.yml @@ -0,0 +1,30 @@ +# 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. +--- +appveyor.yml: + delete: true + +.gitlab-ci.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: 'spec/fixtures/hiera/hiera.yaml' 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/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..16e6238 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## Release 4.3.0 + +**Features** + +**Bugfixes** + +**Known Issues** diff --git a/Gemfile b/Gemfile index 8c48d01..9584486 100644 --- a/Gemfile +++ b/Gemfile @@ -1,41 +1,76 @@ 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] + 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'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables + +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version + +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params +end + +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] -gem 'facter', '>= 2.2.0' -gem 'rspec-puppet', '~> 2.0' -gem 'puppet-lint' -gem 'puppet-lint-absolute_classname-check' -gem 'puppet-lint-alias-check' -gem 'puppet-lint-empty_string-check' -gem 'puppet-lint-file_ensure-check' -gem 'puppet-lint-file_source_rights-check' -gem 'puppet-lint-leading_zero-check' -gem 'puppet-lint-spaceship_operator_without_tag-check' -gem 'puppet-lint-trailing_comma-check' -gem 'puppet-lint-undef_in_function-check' -gem 'puppet-lint-unquoted_string-check' -gem 'puppet-lint-variable_contains_upcase' - -gem 'rspec', '~> 2.0' if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' -gem 'rake', '~> 10.0' if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' -gem 'json', '<= 1.8' if RUBY_VERSION < '2.0.0' -gem 'json_pure', '<= 2.0.1' if RUBY_VERSION < '2.0.0' -gem 'metadata-json-lint', '0.0.11' if RUBY_VERSION <= '1.9.3' -gem 'metadata-json-lint' if RUBY_VERSION > '1.9.3' -gem 'public_suffix', '~> 1.1.0' if RUBY_VERSION < '2.1.1' && RUBY_VERSION >= '1.9' -gem 'public_suffix', '1.3.0' if RUBY_VERSION < '1.9' - -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' && RUBY_VERSION >= '1.9' -gem 'parallel_tests', '1.0.9', :require => false if RUBY_VERSION < '1.9' -gem 'parallel', '1.3.3.1', :require => false if RUBY_VERSION < '1.9' - -if puppetversion && puppetversion < '5.0' && RUBY_VERSION >= '2.1.9' - gem 'semantic_puppet', :require => false +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 2e8251e..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, and ruby files' -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/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/manifests/init.pp b/manifests/init.pp index 6e225a1..c8feb56 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,77 +2,158 @@ # # This module manages the ntp service. # +# @param config_file +# ntp.conf's owner. +# +# @param config_file_group +# ntp.conf's group. +# +# @param config_file_mode +# ntp.conf's mode. +# +# @param config_file_owner +# ntp.conf's owner. +# +# @param disable_monitor +# Adds 'disable monitor' line - disables NTP Monlist command, useful to prevent +# NTP reflection attack. https://isc.sans.edu/forums/diary/NTP+reflection+attack/17300 +# +# @param driftfile +# Path of the drift file. String with absolute path. Set to '' to disable drift file +# usage. 'USE_DEFAULTS' will choose the appropriate default for the system. +# +# @param enable_stats +# If statistics should be enabled. +# +# @param enable_tinker +# If tinker should be enabled (boolean). +# +# @param fudge_stratum +# Stratum value. +# +# @param ignore_local_clock +# Boolean to ignore the local clock. By setting this to true it ensures local clock +# is not referenced, useful if local clock drifts. +# +# @param keys +# Path of the symmetric key file. See ntpd(1). Set to '' to disable drift file usage. +# 'USE_DEFAULTS' will choose the appropriate default for the system. +# +# @param logfile +# Log file name. +# +# @param orphan_mode_stratum +# Orphan stratum configuration. +# +# @param package_adminfile +# Path to the admin file used for installation on Solaris 5.10 and earlier. +# +# @param package_latest +# Use the latest version of the package. +# +# @param package_name +# String or Array of the related ntp packages. +# 'USE_DEFAULTS' will choose the appropriate default for the system. +# +# @param package_noop +# The noop parameter of the package resource. +# +# @param package_source +# The source for packages on Solaris 5.10 and earlier. +# +# @param peers +# String or Array or Hash of peer servers. +# +# @param restrict_localhost +# Array with options to provide to access control configuration (restrict) in ntp.conf. +# 'USE_DEFAULTS' will choose the appropriate default for the system to allow localhost +# access only. +# +# @param restrict_options +# Array with options to provide to access control configuration (restrict) in ntp.conf. +# 'USE_DEFAULTS' will choose the appropriate default for the system. +# For backward compatibility a string can still be used here. It will be used for IPv4 +# and IPv6 configuration. +# +# @param server_options +# Extra options to provide to ntp servers. +# +# @param servers +# Array of pools to check time against. +# +# @param service_hasrestart +# Service has a restart option. +# +# @param service_hasstatus +# Service has a status option. +# +# @param service_name +# Name of the service. +# +# @param service_running +# If service should be running. +# +# @param statsdir +# Path for the statsdir to be used when $enable_stats is enabled. +# +# @param step_tickers_ensure +# Ensure step tickers file. Valid values are 'present' and 'absent'. +# +# @param step_tickers_group +# step-tickers's group. +# +# @param step_tickers_mode +# step-tickers's mode. +# +# @param step_tickers_owner +# step-tickers's owner. +# +# @param step_tickers_path +# step-tickers's path. +# +# @param sysconfig_options +# String with startup options to pass to ntp. +# +# @param sysconfig_path +# Path to the ntp sysconfig config file. +# class ntp ( - $config_file_owner = 'root', - $config_file_group = 'root', - $config_file_mode = '0644', - $package_latest = false, - $package_name = 'USE_DEFAULTS', - $package_noop = 'USE_DEFAULTS', - $package_source = 'USE_DEFAULTS', - $package_adminfile = 'USE_DEFAULTS', - $service_name = 'USE_DEFAULTS', - $config_file = 'USE_DEFAULTS', - $driftfile = 'USE_DEFAULTS', - $service_running = true, - $service_hasstatus = true, - $service_hasrestart = true, - $keys = 'USE_DEFAULTS', - $servers = ['0.us.pool.ntp.org', - '1.us.pool.ntp.org', - '2.us.pool.ntp.org'], - $server_options = 'UNSET', - $peers = 'UNSET', - $restrict_options = 'USE_DEFAULTS', - $restrict_localhost = 'USE_DEFAULTS', - $step_tickers_ensure = 'USE_DEFAULTS', - $step_tickers_path = '/etc/ntp/step-tickers', - $step_tickers_owner = 'root', - $step_tickers_group = 'root', - $step_tickers_mode = '0644', - $orphan_mode_stratum = 'UNSET', - $fudge_stratum = '10', - $enable_stats = false, - $enable_tinker = 'USE_DEFAULTS', - $statsdir = '/var/log/ntpstats/', - $logfile = 'UNSET', - $ignore_local_clock = false, - $disable_monitor = true, - $sysconfig_path = 'USE_DEFAULTS', - $sysconfig_options = 'USE_DEFAULTS', + String[1] $config_file_owner = 'root', + String[1] $config_file_group = 'root', + Stdlib::Filemode $config_file_mode = '0644', + Boolean $package_latest = false, + Variant[Array, String] $package_name = 'USE_DEFAULTS', + String[1] $package_noop = 'USE_DEFAULTS', + String[1] $package_source = 'USE_DEFAULTS', + String $package_adminfile = 'USE_DEFAULTS', + String[1] $service_name = 'USE_DEFAULTS', + String[1] $config_file = 'USE_DEFAULTS', + Variant[Stdlib::Absolutepath, String] $driftfile = 'USE_DEFAULTS', + Boolean $service_running = true, + Boolean $service_hasstatus = true, + Boolean $service_hasrestart = true, + Variant[Stdlib::Absolutepath, String] $keys = 'USE_DEFAULTS', + Array $servers = ['0.us.pool.ntp.org', '1.us.pool.ntp.org', '2.us.pool.ntp.org'], + String[1] $server_options = 'UNSET', + Variant[Hash, Array, String] $peers = 'UNSET', + Variant[Array, String] $restrict_options = 'USE_DEFAULTS', + Variant[Array, Enum['USE_DEFAULTS']] $restrict_localhost = 'USE_DEFAULTS', + String[1] $step_tickers_ensure = 'USE_DEFAULTS', + Stdlib::Absolutepath $step_tickers_path = '/etc/ntp/step-tickers', + String[1] $step_tickers_owner = 'root', + String[1] $step_tickers_group = 'root', + Stdlib::Filemode $step_tickers_mode = '0644', + String[1] $orphan_mode_stratum = 'UNSET', + String[1] $fudge_stratum = '10', + Boolean $enable_stats = false, + Variant[Boolean, Enum['USE_DEFAULTS']] $enable_tinker = 'USE_DEFAULTS', + Stdlib::Absolutepath $statsdir = '/var/log/ntpstats/', + String[1] $logfile = 'UNSET', + Boolean $ignore_local_clock = false, + Boolean $disable_monitor = true, + String[1] $sysconfig_path = 'USE_DEFAULTS', + String $sysconfig_options = 'USE_DEFAULTS', ) { - - # validate type as array or fail - validate_array($servers) - - # validate type and convert string to boolean if necessary - if is_string($package_latest) == true { - $my_package_latest = str2bool($package_latest) - } else { - $my_package_latest = $package_latest - } - - # validate type and convert string to boolean if necessary - if is_string($service_running) == true { - $my_service_running = str2bool($service_running) - } else { - $my_service_running = $service_running - } - - # validate type and convert string to boolean if necessary - if is_string($service_hasstatus) == true { - $my_service_hasstatus = str2bool($service_hasstatus) - } else { - $my_service_hasstatus = $service_hasstatus - } - - # validate type and convert string to boolean if necessary - if is_string($service_hasrestart) == true { - $my_service_hasrestart = str2bool($service_hasrestart) - } else { - $my_service_hasrestart = $service_hasrestart - } - if $peers != 'UNSET' { if is_array($peers) == true { $my_peers = $peers @@ -91,21 +172,13 @@ } } - # validate type and convert string to boolean if necessary - if is_string($enable_stats) == true { - $my_enable_stats = str2bool($enable_stats) - } else { - $my_enable_stats = $enable_stats - } - validate_bool($my_enable_stats) - - if $my_package_latest == true { + if $package_latest == true { $package_ensure = latest } else { $package_ensure = present } - if $my_service_running == true { + if $service_running == true { $service_ensure = running $service_enable = true } else { @@ -113,28 +186,14 @@ $service_enable = false } - if is_string($ignore_local_clock) == true { - $ignore_local_clock_real = str2bool($ignore_local_clock) - } else { - $ignore_local_clock_real = $ignore_local_clock - } - validate_bool($ignore_local_clock_real) - - if is_bool($disable_monitor) == true { - $disable_monitor_real = $disable_monitor - } else { - $disable_monitor_real = str2bool($disable_monitor) - } - validate_bool($disable_monitor_real) - - case $::osfamily { + case $facts['os']['family'] { 'Debian': { - $default_package_name = [ 'ntp' ] + $default_package_name = ['ntp'] $default_package_noop = false $default_package_source = undef $default_package_adminfile = undef - $default_restrict_options = [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ] - $default_restrict_localhost = [ '127.0.0.1', '::1', ] + $default_restrict_options = ['-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery'] + $default_restrict_localhost = ['127.0.0.1', '::1'] $default_step_tickers_ensure = 'absent' $default_service_name = 'ntp' $default_config_file = '/etc/ntp.conf' @@ -146,19 +205,19 @@ $default_sysconfig_options = '-g' } 'RedHat': { - $default_package_name = [ 'ntp' ] + $default_package_name = ['ntp'] $default_package_noop = false $default_package_source = undef $default_package_adminfile = undef - $default_restrict_options = [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ] - $default_restrict_localhost = [ '127.0.0.1', '::1', ] + $default_restrict_options = ['-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery'] + $default_restrict_localhost = ['127.0.0.1', '::1'] $default_step_tickers_ensure = 'present' $default_service_name = 'ntpd' $default_config_file = '/etc/ntp.conf' $default_keys = '/etc/ntp/keys' $default_enable_tinker = true $default_sysconfig_path = '/etc/sysconfig/ntpd' - case $::operatingsystemrelease { + case $facts['os']['release']['full'] { /^5/: { $default_driftfile = '/var/lib/ntp/ntp.drift' $sysconfig_erb = 'sysconfig.rhel5.erb' @@ -175,17 +234,16 @@ $default_sysconfig_options = '-g' } default: { - fail("The ntp module supports RedHat like systems with major releases 5, 6, and 7 and you have ${::operatingsystemrelease}") + fail("The ntp module supports RedHat like systems with major releases 5, 6, and 7 and you have ${facts['os']['release']['full']}") } } - } 'Suse': { $default_package_noop = false $default_package_source = undef $default_package_adminfile = undef - $default_restrict_options = [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ] - $default_restrict_localhost = [ '127.0.0.1', '::1', ] + $default_restrict_options = ['-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery'] + $default_restrict_localhost = ['127.0.0.1', '::1'] $default_step_tickers_ensure = 'absent' $default_config_file = '/etc/ntp.conf' $default_driftfile = '/var/lib/ntp/drift/ntp.drift' @@ -193,54 +251,54 @@ $default_enable_tinker = true $default_sysconfig_path = '/etc/sysconfig/ntp' - case $::operatingsystemrelease { + case $facts['os']['release']['full'] { /^9/: { - $default_package_name = [ 'xntp' ] + $default_package_name = ['xntp'] $default_service_name = 'ntp' $default_sysconfig_options = '-u ntp' $sysconfig_erb = 'sysconfig.suse9.erb' } /^10/: { - $default_package_name = [ 'xntp' ] + $default_package_name = ['xntp'] $default_service_name = 'ntp' $default_sysconfig_options = '-u ntp' $sysconfig_erb = 'sysconfig.suse10.erb' } /^11/: { - $default_package_name = [ 'ntp' ] + $default_package_name = ['ntp'] $default_service_name = 'ntp' $default_sysconfig_options = '-g -u ntp:ntp' $sysconfig_erb = 'sysconfig.suse11.erb' } /^12/: { - $default_package_name = [ 'ntp' ] + $default_package_name = ['ntp'] $default_sysconfig_options = '-g -u ntp:ntp' $sysconfig_erb = 'sysconfig.suse12.erb' - if $::operatingsystem == 'OpenSuSE' { + if $facts['os']['name'] == 'OpenSuSE' { $default_service_name = 'ntp' } else { $default_service_name = 'ntpd' } } default: { - fail("The ntp module supports Suse like systems with major releases 9, 10, 11, and 12 and you have ${::operatingsystemrelease}") + fail("The ntp module supports Suse like systems with major releases 9 to 12 and you have ${facts['os']['release']['full']}") } } } 'Solaris': { - case $::kernelrelease { + case $facts['kernelrelease'] { '5.9','5.10': { - $default_package_name = [ 'SUNWntp4r', 'SUNWntp4u' ] - $default_restrict_options = [ 'default noserve noquery', ] - $default_restrict_localhost = [ '127.0.0.1', ] + $default_package_name = ['SUNWntp4r', 'SUNWntp4u'] + $default_restrict_options = ['default noserve noquery'] + $default_restrict_localhost = ['127.0.0.1'] } '5.11': { - $default_package_name = [ 'network/ntp' ] - $default_restrict_options = [ 'default kod notrap nomodify nopeer noquery', ] - $default_restrict_localhost = [ '127.0.0.1', '::1', ] + $default_package_name = ['network/ntp'] + $default_restrict_options = ['default kod notrap nomodify nopeer noquery'] + $default_restrict_localhost = ['127.0.0.1', '::1'] } default: { - fail("The ntp module supports Solaris kernel release 5.9, 5.10 and 5.11. You are running ${::kernelrelease}.") + fail("The ntp module supports Solaris kernel release 5.9, 5.10 and 5.11. You are running ${facts['kernelrelease']}.") } } $default_package_noop = true @@ -256,7 +314,7 @@ $default_sysconfig_options = undef } default: { - fail("The ntp module is supported by OS Families Debian, RedHat, Suse, and Solaris. Your operatingsystem, ${::operatingsystem}, is part of the osfamily, ${::osfamily}") + fail("The ntp module is supported by OS Families Debian, RedHat, Suse, and Solaris. Detected,the osfamily, ${facts['os']['family']}") } } @@ -316,7 +374,7 @@ $step_tickers_ensure_real = $step_tickers_ensure } validate_re($step_tickers_ensure_real, '^(present)|(absent)$', - "ntp::step_tickers_ensure must be 'present' or 'absent'. Detected value is <${step_tickers_ensure_real}>.") + "ntp::step_tickers_ensure must be 'present' or 'absent'. Detected value is <${step_tickers_ensure_real}>.") validate_absolute_path($step_tickers_path) @@ -348,7 +406,7 @@ elsif is_string($restrict_options) == true { $restrict_options_real = $restrict_options ? { 'USE_DEFAULTS' => $default_restrict_options, - default => [ "-4 ${restrict_options}", "-6 ${restrict_options}", ] + default => ["-4 ${restrict_options}", "-6 ${restrict_options}"] } } else { @@ -382,7 +440,6 @@ } if ($package_adminfile_real != '') and ($package_adminfile_real != undef) { - file { 'admin_file': ensure => 'present', # lint:ignore:file_ensure - this could be a symlink or a file path => $package_adminfile_real, @@ -401,8 +458,7 @@ before => File['ntp_conf'], } - if $::kernel == 'Linux' { - + if $facts['kernel'] == 'Linux' { validate_absolute_path($sysconfig_path_real) file { 'ntp_sysconfig': @@ -427,7 +483,6 @@ } if $step_tickers_ensure_real == 'present' { - $step_tickers_dir = dirname($step_tickers_path) validate_absolute_path($step_tickers_dir) @@ -449,9 +504,7 @@ group => $step_tickers_group, mode => $step_tickers_mode, content => template('ntp/step-tickers.erb'), - require => [ Package[$package_name_real], - File['step_tickers_dir'], - ], + require => [Package[$package_name_real], File['step_tickers_dir']], } } @@ -459,14 +512,12 @@ ensure => $service_ensure, name => $service_name_real, enable => $service_enable, - hasstatus => $my_service_hasstatus, - hasrestart => $my_service_hasrestart, - subscribe => [ Package[$package_name_real], - File['ntp_conf'], - ], + hasstatus => $service_hasstatus, + hasrestart => $service_hasrestart, + subscribe => [Package[$package_name_real], File['ntp_conf']], } - if $::virtual == 'xenu' and $::kernel == 'Linux' { + if $facts['virtual'] == 'xenu' and $facts['kernel'] == 'Linux' { exec { 'xen_independent_wallclock': path => '/bin:/usr/bin', command => 'echo 1 > /proc/sys/xen/independent_wallclock', diff --git a/metadata.json b/metadata.json index ebcbfcf..aeee628 100644 --- a/metadata.json +++ b/metadata.json @@ -7,11 +7,14 @@ "source": "git://github.com/ghoneycutt/puppet-module-ntp.git", "project_page": "https://github.com/ghoneycutt/puppet-module-ntp", "issues_url": "https://github.com/ghoneycutt/puppet-module-ntp/issues", - "description": "Manages NTP server", - "requirements": [ + "dependencies": [ { - "name": "puppet", - "version_requirement": ">= 3.0.0 < 7.0.0" + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.6.0 < 5.0.0" + }, + { + "name": "ghoneycutt/common", + "version_requirement": ">= 1.4.1 < 2.0.0" } ], "operatingsystem_support": [ @@ -86,8 +89,14 @@ ] } ], - "dependencies": [ - {"name":"puppetlabs/stdlib","version_requirement":">= 4.6.0 < 5.0.0"}, - {"name":"ghoneycutt/common","version_requirement":">= 1.4.1 < 2.0.0"} - ] + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 6.0.0 < 9.0.0" + } + ], + "description": "Manages NTP server", + "pdk-version": "2.7.1", + "template-url": "pdk-default#2.7.4", + "template-ref": "tags/2.7.4-0-g58edf57" } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 9d73b2f..86230a0 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,438 +1,476 @@ require 'spec_helper' describe 'ntp' do - platforms = { 'debian6' => - { :osfamily => 'Debian', - :operatingsystem => 'Debian', - :release => '6', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/ntp.drift', - :keys => '/etc/ntp/keys', - :enable_tinker => true, + { + osfamily: 'Debian', + operatingsystem: 'Debian', + release: '6', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/ntp.drift', + keys: '/etc/ntp/keys', + enable_tinker: true, }, 'el5' => - { :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :release => '5', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'present', - :service_name => 'ntpd', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/ntp.drift', - :keys => '/etc/ntp/keys', - :enable_tinker => true, + { + osfamily: 'RedHat', + operatingsystem: 'RedHat', + release: '5', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'present', + service_name: 'ntpd', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/ntp.drift', + keys: '/etc/ntp/keys', + enable_tinker: true, }, 'el6' => - { :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :release => '6', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'present', - :service_name => 'ntpd', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/ntp.drift', - :keys => '/etc/ntp/keys', - :enable_tinker => true, + { + osfamily: 'RedHat', + operatingsystem: 'RedHat', + release: '6', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'present', + service_name: 'ntpd', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/ntp.drift', + keys: '/etc/ntp/keys', + enable_tinker: true, }, 'el7' => - { :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :release => '7', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'present', - :service_name => 'ntpd', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/drift', - :keys => '/etc/ntp/keys', - :enable_tinker => true, + { + osfamily: 'RedHat', + operatingsystem: 'RedHat', + release: '7', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'present', + service_name: 'ntpd', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/drift', + keys: '/etc/ntp/keys', + enable_tinker: true, }, 'suse9' => - { :osfamily => 'Suse', - :operatingsystem => 'SLES', - :release => '9', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['xntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/drift/ntp.drift', - :keys => '', - :enable_tinker => true, + { + osfamily: 'Suse', + operatingsystem: 'SLES', + release: '9', + kernel: 'Linux', + virtual: 'physical', + package_name: ['xntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/drift/ntp.drift', + keys: '', + enable_tinker: true, }, 'suse10' => - { :osfamily => 'Suse', - :operatingsystem => 'SLES', - :release => '10', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['xntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/drift/ntp.drift', - :keys => '', - :enable_tinker => true, + { + osfamily: 'Suse', + operatingsystem: 'SLES', + release: '10', + kernel: 'Linux', + virtual: 'physical', + package_name: ['xntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/drift/ntp.drift', + keys: '', + enable_tinker: true, }, 'suse11' => - { :osfamily => 'Suse', - :operatingsystem => 'SLES', - :release => '11', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/drift/ntp.drift', - :keys => '', - :enable_tinker => true, + { + osfamily: 'Suse', + operatingsystem: 'SLES', + release: '11', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/drift/ntp.drift', + keys: '', + enable_tinker: true, }, 'suse12' => - { :osfamily => 'Suse', - :operatingsystem => 'SLES', - :release => '12', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntpd', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/drift/ntp.drift', - :keys => '', - :enable_tinker => true, + { + osfamily: 'Suse', + operatingsystem: 'SLES', + release: '12', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntpd', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/drift/ntp.drift', + keys: '', + enable_tinker: true, }, 'opensuse12' => - { :osfamily => 'Suse', - :operatingsystem => 'OpenSuSE', - :release => '12', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/drift/ntp.drift', - :keys => '', - :enable_tinker => true, + { + osfamily: 'Suse', + operatingsystem: 'OpenSuSE', + release: '12', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/drift/ntp.drift', + keys: '', + enable_tinker: true, }, 'solaris9' => - { :osfamily => 'Solaris', - :operatingsystem => 'Solaris', - :release => '5.9', - :kernel => 'SunOS', - :virtual => 'physical', - :package_name => ['SUNWntp4r','SUNWntp4u'], - :package_noop => true, - :package_source => '/var/spool/pkg', - :package_adminfile => '/var/sadm/install/admin/puppet-ntp', - :restrict_options => [ 'default noserve noquery', ], - :restrict_localhost => [ '127.0.0.1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp4', - :config_file => '/etc/inet/ntp.conf', - :driftfile => '/var/ntp/ntp.drift', - :keys => '/etc/inet/ntp.keys', - :enable_tinker => false, + { + osfamily: 'Solaris', + operatingsystem: 'Solaris', + release: '5.9', + kernel: 'SunOS', + virtual: 'physical', + package_name: ['SUNWntp4r', 'SUNWntp4u'], + package_noop: true, + package_source: '/var/spool/pkg', + package_adminfile: '/var/sadm/install/admin/puppet-ntp', + restrict_options: [ 'default noserve noquery' ], + restrict_localhost: [ '127.0.0.1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp4', + config_file: '/etc/inet/ntp.conf', + driftfile: '/var/ntp/ntp.drift', + keys: '/etc/inet/ntp.keys', + enable_tinker: false, }, 'solaris10' => - { :osfamily => 'Solaris', - :operatingsystem => 'Solaris', - :release => '5.10', - :kernel => 'SunOS', - :virtual => 'physical', - :package_name => ['SUNWntp4r','SUNWntp4u'], - :package_noop => true, - :package_source => '/var/spool/pkg', - :package_adminfile => '/var/sadm/install/admin/puppet-ntp', - :restrict_options => [ 'default noserve noquery', ], - :restrict_localhost => [ '127.0.0.1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp4', - :config_file => '/etc/inet/ntp.conf', - :driftfile => '/var/ntp/ntp.drift', - :keys => '/etc/inet/ntp.keys', - :enable_tinker => false, + { + osfamily: 'Solaris', + operatingsystem: 'Solaris', + release: '5.10', + kernel: 'SunOS', + virtual: 'physical', + package_name: ['SUNWntp4r', 'SUNWntp4u'], + package_noop: true, + package_source: '/var/spool/pkg', + package_adminfile: '/var/sadm/install/admin/puppet-ntp', + restrict_options: [ 'default noserve noquery' ], + restrict_localhost: [ '127.0.0.1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp4', + config_file: '/etc/inet/ntp.conf', + driftfile: '/var/ntp/ntp.drift', + keys: '/etc/inet/ntp.keys', + enable_tinker: false, }, 'solaris11' => - { :osfamily => 'Solaris', - :operatingsystem => 'Solaris', - :release => '5.11', - :kernel => 'SunOS', - :virtual => 'physical', - :package_name => ['network/ntp'], - :package_noop => true, - :package_source => '/var/spool/pkg', - :package_adminfile => '/var/sadm/install/admin/puppet-ntp', - :restrict_options => [ 'default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp4', - :config_file => '/etc/inet/ntp.conf', - :driftfile => '/var/ntp/ntp.drift', - :keys => '/etc/inet/ntp.keys', - :enable_tinker => false, + { + osfamily: 'Solaris', + operatingsystem: 'Solaris', + release: '5.11', + kernel: 'SunOS', + virtual: 'physical', + package_name: ['network/ntp'], + package_noop: true, + package_source: '/var/spool/pkg', + package_adminfile: '/var/sadm/install/admin/puppet-ntp', + restrict_options: [ 'default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp4', + config_file: '/etc/inet/ntp.conf', + driftfile: '/var/ntp/ntp.drift', + keys: '/etc/inet/ntp.keys', + enable_tinker: false, }, 'ubuntu1204' => - { :osfamily => 'Debian', - :operatingsystem => 'Ubuntu', - :release => '12.04', - :kernel => 'Linux', - :virtual => 'physical', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'absent', - :service_name => 'ntp', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/ntp.drift', - :keys => '/etc/ntp/keys', - :enable_tinker => true, + { + osfamily: 'Debian', + operatingsystem: 'Ubuntu', + release: '12.04', + kernel: 'Linux', + virtual: 'physical', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'absent', + service_name: 'ntp', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/ntp.drift', + keys: '/etc/ntp/keys', + enable_tinker: true, }, 'xenu' => - { :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :release => '5', - :kernel => 'Linux', - :virtual => 'xenu', - :package_name => ['ntp'], - :package_noop => false, - :package_source => nil, - :package_adminfile => nil, - :restrict_options => [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery', ], - :restrict_localhost => [ '127.0.0.1', '::1', ], - :step_tickers_ensure => 'present', - :service_name => 'ntpd', - :config_file => '/etc/ntp.conf', - :driftfile => '/var/lib/ntp/ntp.drift', - :keys => '/etc/ntp/keys', - :enable_tinker => true, + { + osfamily: 'RedHat', + operatingsystem: 'RedHat', + release: '5', + kernel: 'Linux', + virtual: 'xenu', + package_name: ['ntp'], + package_noop: false, + package_source: nil, + package_adminfile: nil, + restrict_options: [ '-4 default kod notrap nomodify nopeer noquery', '-6 default kod notrap nomodify nopeer noquery' ], + restrict_localhost: [ '127.0.0.1', '::1' ], + step_tickers_ensure: 'present', + service_name: 'ntpd', + config_file: '/etc/ntp.conf', + driftfile: '/var/lib/ntp/ntp.drift', + keys: '/etc/ntp/keys', + enable_tinker: true, }, } peers = { - 'ntp1' => { 'host' => 'ntp1.example.com', - 'options' => 'true', - 'comment' => 'ntp1' }, - 'ntp2' => { 'host' => 'ntp2.example.com', - 'options' => 'true', - 'comment' => 'ntp2' }, + 'ntp1' => + { + 'host' => 'ntp1.example.com', + 'options' => 'true', + 'comment' => 'ntp1' + }, + 'ntp2' => + { + 'host' => 'ntp2.example.com', + 'options' => 'true', + 'comment' => 'ntp2', + }, } describe 'with default values for parameters on' do - platforms.sort.each do |k,v| - context "#{k}" do + platforms.sort.each do |k, v| + context k.to_s do if v[:osfamily] == 'Solaris' let :facts do { - :osfamily => v[:osfamily], - :operatingsystem => v[:operatingsystem], - :kernelrelease => v[:release], - :kernel => v[:kernel], - :virtual => v[:virtual], + + os: { + family: v[:osfamily], + name: v[:operatingsystem], + release: { + full: v[:release], + }, + }, + kernelrelease: v[:release], + kernel: v[:kernel], + virtual: v[:virtual], } end else let :facts do { - :osfamily => v[:osfamily], - :operatingsystem => v[:operatingsystem], - :operatingsystemrelease => v[:release], - :kernel => v[:kernel], - :virtual => v[:virtual], + os: { + family: v[:osfamily], + name: v[:operatingsystem], + release: { + full: v[:release], + }, + }, + kernel: v[:kernel], + virtual: v[:virtual], } end end - it { should compile.with_all_deps } + it { is_expected.to compile.with_all_deps } - it { should contain_class('ntp')} + it { is_expected.to contain_class('ntp') } v[:package_name].each do |pkg| it { - should contain_package(pkg).with({ - 'ensure' => 'present', - 'noop' => v[:package_noop], - 'source' => v[:package_source], - 'adminfile' => v[:package_adminfile], - 'before' => 'File[ntp_conf]', - }) + is_expected.to contain_package(pkg).with( + { + 'ensure' => 'present', + 'noop' => v[:package_noop], + 'source' => v[:package_source], + 'adminfile' => v[:package_adminfile], + 'before' => 'File[ntp_conf]', + }, + ) } end it { - should contain_file('ntp_conf').with({ - 'ensure' => 'file', - 'path' => v[:config_file], - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) + is_expected.to contain_file('ntp_conf').with( + { + 'ensure' => 'file', + 'path' => v[:config_file], + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }, + ) } if v[:driftfile] != '' - it { should contain_file('ntp_conf').with_content(/driftfile #{Regexp.escape(v[:driftfile])}/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{driftfile #{Regexp.escape(v[:driftfile])}}) } else - it { should contain_file('ntp_conf').without_content(/driftfile/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{driftfile}) } end if v[:enable_tinker] - it { should contain_file('ntp_conf').with_content(/^tinker panic 0$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^tinker panic 0$}) } else - it { should contain_file('ntp_conf').without_content(/^tinker panic 0$/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^tinker panic 0$}) } end - it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged$/) } - it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } - it { should contain_file('ntp_conf').with_content(/^disable monitor$/) } - it { should contain_file('ntp_conf').without_content(/^\s*peer/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{# Statistics are not being logged$}) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org}) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^disable monitor$}) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^\s*peer}) } if v[:keys] != '' - it { should contain_file('ntp_conf').with_content(/^keys #{Regexp.escape(v[:keys])}$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^keys #{Regexp.escape(v[:keys])}$}) } else - it { should contain_file('ntp_conf').without_content(/^\s*keys /) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^\s*keys }) } end - it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{fudge 127.127.1.0 stratum 10$}) } v[:restrict_options].each do |restrict_options| - it { should contain_file('ntp_conf').with_content(/^restrict #{restrict_options}$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^restrict #{restrict_options}$}) } end v[:restrict_localhost].each do |restrict_localhost| - it { should contain_file('ntp_conf').with_content(/^restrict #{restrict_localhost}$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^restrict #{restrict_localhost}$}) } end if v[:step_tickers_ensure] == 'present' - it { - should contain_exec('mkdir_p-/etc/ntp').with({ - 'command' => 'mkdir -p /etc/ntp', - 'unless' => 'test -d /etc/ntp', - }) - } + it { is_expected.to contain_common__mkdir_p('/etc/ntp') } it { - should contain_file('step_tickers_dir').with({ - 'ensure' => 'directory', - 'path' => '/etc/ntp', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'require' => 'Common::Mkdir_p[/etc/ntp]', - }) + is_expected.to contain_file('step_tickers_dir').with( + { + 'ensure' => 'directory', + 'path' => '/etc/ntp', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Common::Mkdir_p[/etc/ntp]', + }, + ) } it { - should contain_file('step-tickers').with({ - 'ensure' => 'present', - 'path' => '/etc/ntp/step-tickers', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'require' => ['Package[ntp]', 'File[step_tickers_dir]'], - }) + is_expected.to contain_file('step-tickers').with( + { + 'ensure' => 'present', + 'path' => '/etc/ntp/step-tickers', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => ['Package[ntp]', 'File[step_tickers_dir]'], + }, + ) } - it { should contain_file('step-tickers').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } + it { is_expected.to contain_file('step-tickers').with_content(%r{server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org}) } elsif v[:step_tickers_ensure] == 'absent' - it { should_not contain_exec('mkdir_p-/etc/ntp') } + it { is_expected.not_to contain_exec('mkdir_p-/etc/ntp') } - it { should_not contain_file('step_tickers_dir') } + it { is_expected.not_to contain_file('step_tickers_dir') } - it { should_not contain_file('step-tickers') } + it { is_expected.not_to contain_file('step-tickers') } end if v[:package_adminfile] it { - should contain_file('admin_file').with({ - 'ensure' => 'present', - 'path' => v[:package_adminfile], - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) + is_expected.to contain_file('admin_file').with( + { + 'ensure' => 'present', + 'path' => v[:package_adminfile], + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }, + ) } else - it { should_not contain_file('admin_file') } + it { is_expected.not_to contain_file('admin_file') } end it { - should contain_service('ntp_service').with({ - 'ensure' => 'running', - 'name' => v[:service_name], - 'enable' => 'true', - }) + is_expected.to contain_service('ntp_service').with( + { + 'ensure' => 'running', + 'name' => v[:service_name], + 'enable' => 'true', + }, + ) } - if v[:virtual] == 'xenu' and v[:kernel] == 'Linux' + if v[:virtual] == 'xenu' && v[:kernel] == 'Linux' it { - should contain_exec('xen_independent_wallclock').with({ - 'path' => '/bin:/usr/bin', - 'command' => 'echo 1 > /proc/sys/xen/independent_wallclock', - 'unless' => 'grep ^1 /proc/sys/xen/independent_wallclock', - 'onlyif' => 'test -f /proc/sys/xen/independent_wallclock', - }) + is_expected.to contain_exec('xen_independent_wallclock').with( + { + 'path' => '/bin:/usr/bin', + 'command' => 'echo 1 > /proc/sys/xen/independent_wallclock', + 'unless' => 'grep ^1 /proc/sys/xen/independent_wallclock', + 'onlyif' => 'test -f /proc/sys/xen/independent_wallclock', + }, + ) } else - it { should_not contain_exec('xen_independent_wallclock') } + it { is_expected.not_to contain_exec('xen_independent_wallclock') } end end end @@ -441,34 +479,38 @@ describe 'with driftfile set to' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + virtual: 'physical', + kernel: 'Linux', } end - [ '', '/var/lib/ntp/ntp.drift','/etc/ntp/drift'].each do |value| + [ '', '/var/lib/ntp/ntp.drift', '/etc/ntp/drift'].each do |value| context "valid #{value} as #{value.class}" do - let(:params) { { :driftfile => value } } + let(:params) { { driftfile: value } } if value != '' - it { should contain_file('ntp_conf').with_content(/driftfile #{Regexp.escape(value)}/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{driftfile #{Regexp.escape(value)}}) } else - it { should contain_file('ntp_conf').without_content(/driftfile/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{driftfile}) } end end end - ['../invalid/path',3,2.42,['array'],a = { 'ha' => 'sh' }].each do |value| + ['../invalid/path', 3, 2.42, ['array'], { 'ha' => 'sh' }].each do |value| context "invalid #{value} as #{value.class}" do - let(:params) { { :driftfile => value } } + let(:params) { { driftfile: value } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/is not an absolute path/) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error) end end end @@ -477,46 +519,60 @@ describe 'with enable_stats' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end - ['true',true].each do |value| - context "specified as #{value}" do - let(:params) { { :enable_stats => value } } + content = <<-END.gsub(%r{^\s+\|}, '') + |statsdir /var/log/ntpstats/ + |statistics loopstats peerstats clockstats + |filegen loopstats file loopstats type day enable + |filegen peerstats file peerstats type day enable + |filegen clockstats file clockstats type day enable + END - it { should contain_file('ntp_conf').with_content(/^statsdir \/var\/log\/ntpstats\/\nstatistics loopstats peerstats clockstats\nfilegen loopstats file loopstats type day enable\nfilegen peerstats file peerstats type day enable\nfilegen clockstats file clockstats type day enable$/) } - end + context 'specified as true' do + let(:params) { { enable_stats: true } } + + regex_content = Regexp.new(Regexp.escape(content.strip), Regexp::MULTILINE) + it { is_expected.to contain_file('ntp_conf').with_content(regex_content) } end - ['false',false].each do |value| - context "specified as #{value}" do - let(:params) { { :enable_stats => value } } + context 'specified as false' do + let(:params) { { enable_stats: false } } - it { should contain_file('ntp_conf').without_content(/^statsdir \/var\/log\/ntpstats\/\nstatistics loopstats peerstats clockstats\nfilegen loopstats file loopstats type day enable\nfilegen peerstats file peerstats type day enable\nfilegen clockstats file clockstats type day enable$/) } - end + regex_content = Regexp.new(Regexp.escape(content.strip), Regexp::MULTILINE) + it { is_expected.to contain_file('ntp_conf').without_content(regex_content) } end context 'as an invalid type (non-boolean)' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end - let(:params) { { :enable_stats => ['not','a','boolean'] } } + let(:params) { { enable_stats: ['not', 'a', 'boolean'] } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/\["not", "a", "boolean"\] is not a boolean/) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{expects a Boolean}) end end end @@ -524,46 +580,49 @@ describe 'with statsdir' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end context 'specified as a valid path' do context 'with enable_stats as true' do - let(:params) do { - :enable_stats => true, - :statsdir => '/path/to/statsdir', + enable_stats: true, + statsdir: '/path/to/statsdir', } end - it { should contain_file('ntp_conf').with_content(/^statsdir \/path\/to\/statsdir\nstatistics loopstats peerstats clockstats\nfilegen loopstats file loopstats type day enable\nfilegen peerstats file peerstats type day enable\nfilegen clockstats file clockstats type day enable$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{statsdir /path/to/statsdir}) } end context 'with enable_stats as false' do let(:params) do { - :enable_stats => false, - :statsdir => '/path/to/statsdir', + enable_stats: false, + statsdir: '/path/to/statsdir', } end - it { should contain_file('ntp_conf').without_content(/^statsdir \/path\/to\/statsdir\/\nstatistics loopstats peerstats clockstats\nfilegen loopstats file loopstats type day enable\nfilegen peerstats file peerstats type day enable\nfilegen clockstats file clockstats type day enable$/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{statsdir}) } end end context 'specified as an invalid path' do - let(:params) { { :statsdir => 'invalid/path' } } + let(:params) { { statsdir: 'invalid/path' } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/"invalid\/path" is not an absolute path/) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{expects a Stdlib::Absolutepath}) end end end @@ -571,34 +630,38 @@ describe 'with keys set to' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end - [ '', '/var/lib/ntp/keys','/etc/ntp/keysfile'].each do |value| + [ '', '/var/lib/ntp/keys', '/etc/ntp/keysfile'].each do |value| context "valid #{value} as #{value.class}" do - let(:params) { { :keys => value } } + let(:params) { { keys: value } } if value != '' - it { should contain_file('ntp_conf').with_content(/keys #{Regexp.escape(value)}/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{keys #{Regexp.escape(value)}}) } else - it { should contain_file('ntp_conf').without_content(/keys/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{keys}) } end end end - ['../invalid/path',3,2.42,['array'],a = { 'ha' => 'sh' }].each do |value| + ['../invalid/path', 3, 2.42, ['array'], { 'ha' => 'sh' }].each do |value| context "invalid #{value} as #{value.class}" do - let(:params) { { :keys => value } } + let(:params) { { keys: value } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/is not an absolute path/) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error) end end end @@ -607,47 +670,51 @@ describe 'with peers param set' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end context 'to a hash' do - let(:params) { { :peers => peers } } + let(:params) { { peers: peers } } - it { should contain_class('ntp')} + it { is_expected.to contain_class('ntp') } - it { should contain_file('ntp_conf').with_content(/^peer ntp1.example.com true # ntp1$/) } - it { should contain_file('ntp_conf').with_content(/^peer ntp2.example.com true # ntp2$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^peer ntp1.example.com true # ntp1$}) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^peer ntp2.example.com true # ntp2$}) } end context 'to an array' do - let(:params) { { :peers => [ 'ntp1.example.com', 'ntp2.example.com' ] } } + let(:params) { { peers: [ 'ntp1.example.com', 'ntp2.example.com' ] } } - it { should contain_class('ntp')} + it { is_expected.to contain_class('ntp') } - it { should contain_file('ntp_conf').with_content(/^peer ntp1.example.com$/) } - it { should contain_file('ntp_conf').with_content(/^peer ntp2.example.com$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^peer ntp1.example.com$}) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^peer ntp2.example.com$}) } end context 'to a string' do - let(:params) { { :peers => 'ntp1.example.com' } } + let(:params) { { peers: 'ntp1.example.com' } } - it { should contain_class('ntp')} + it { is_expected.to contain_class('ntp') } - it { should contain_file('ntp_conf').with_content(/^peer ntp1.example.com$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^peer ntp1.example.com$}) } end context 'to an invalid type (boolean)' do - let(:params) { { :peers => true } } + let(:params) { { peers: true } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error, /ntp::peers must be a string or an array or an hash./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error) end end end @@ -656,294 +723,355 @@ context 'with no package_adminfile' do let :facts do { - :osfamily => 'Solaris', - :kernel => 'SunOS', - :kernelrelease => '5.11', - :virtual => 'physical', + os: { + family: 'Solaris', + }, + kernel: 'SunOS', + kernelrelease: '5.11', + virtual: 'physical', } end - let(:params) { { :package_adminfile => '' } } + let(:params) { { package_adminfile: '' } } - it { should contain_class('ntp')} + it { is_expected.to contain_class('ntp') } it { - should contain_package('network/ntp').with({ - 'ensure' => 'present', - 'adminfile' => '', - }) + is_expected.to contain_package('network/ntp').with( + { + 'ensure' => 'present', + 'adminfile' => '', + }, + ) } - it { should_not contain_file('admin_file') } + it { is_expected.not_to contain_file('admin_file') } end context 'with package_adminfile specified' do let :facts do { - :osfamily => 'Solaris', - :kernel => 'SunOS', - :kernelrelease => '5.11', - :virtual => 'physical', + os: { + family: 'Solaris', + }, + kernel: 'SunOS', + kernelrelease: '5.11', + virtual: 'physical', } end - let(:params) { { :package_adminfile => '/tmp/admin' } } + let(:params) { { package_adminfile: '/tmp/admin' } } it { - should contain_package('network/ntp').with({ - 'ensure' => 'present', - 'adminfile' => '/tmp/admin', - }) + is_expected.to contain_package('network/ntp').with( + { + 'ensure' => 'present', + 'adminfile' => '/tmp/admin', + }, + ) } it { - should contain_file('admin_file').with({ - 'ensure' => 'present', - 'path' => '/tmp/admin', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) + is_expected.to contain_file('admin_file').with( + { + 'ensure' => 'present', + 'path' => '/tmp/admin', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }, + ) } end end - context 'on unsupported SuSE platform should fail' do + context 'on unsupported SuSE platform is_expected.to fail' do let :facts do { - :osfamily => 'Suse', - :kernel => 'Linux', - :operatingsystem => 'Suse', - :operatingsystemrelease => '1.0', - :virtual => 'physical', + os: { + family: 'Suse', + name: 'Suse', + release: { + full: '1.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/The ntp module supports Suse like systems with major releases 9, 10, 11, and 12 and you have./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{The ntp module supports Suse like systems with major releases 9 to 12 and you have.}) end end - context 'on unsupported Solaris platform should fail' do + context 'on unsupported Solaris platform is_expected.to fail' do let :facts do { - :osfamily => 'Solaris', - :operatingsystem => 'Solaris', - :kernelrelease => '5.8', - :kernel => 'SunOS', - :virtual => 'physical', + os: { + family: 'Solaris', + }, + operatingsystem: 'Solaris', + kernelrelease: '5.8', + kernel: 'SunOS', + virtual: 'physical', } end it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/The ntp module supports Solaris kernel release 5.9, 5.10 and 5.11./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{The ntp module supports Solaris kernel release 5.9, 5.10 and 5.11.}) end end - context 'on unsupported platform should fail' do + context 'on unsupported platform is_expected.to fail' do let :facts do { - :osfamily => 'Slackware', - :kernel => 'Linux', - :operatingsystem => 'Slackware', - :operatingsystemrelease => '1.0', - :virtual => 'physical', + os: { + family: 'Slackware', + name: 'Slackware', + release: { + full: '1.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/The ntp module is supported by OS Families Debian, RedHat, Suse, and Solaris./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{The ntp module is supported by OS Families Debian, RedHat, Suse, and Solaris.}) end end context 'with invalid value for step_tickers_ensure param' do - let(:params) { { :step_tickers_ensure => 'invalid' } } + let(:params) { { step_tickers_ensure: 'invalid' } } let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/ntp::step_tickers_ensure must be 'present' or 'absent'. Detected value is ./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{ntp::step_tickers_ensure must be 'present' or 'absent'. Detected value is .}) end end context 'with invalid path for step_tickers_path param' do - let(:params) { { :step_tickers_path => 'invalid/path' } } + let(:params) { { step_tickers_path: 'invalid/path' } } let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end it do expect { - should contain_class('ntp') + is_expected.to contain_class('ntp') }.to raise_error(Puppet::Error) end end - [true,'true'].each do |value| - context "with ignore_local_clock set to #{value}" do - let(:params) { { :ignore_local_clock => value } } - let :facts do - { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', - } - end - - it { should contain_file('ntp_conf').without_content(/^server\s+127.127.1.0/) } - it { should contain_file('ntp_conf').without_content(/^fudge\s+127.127.1.0 stratum 10/) } + context 'with ignore_local_clock set to valid true' do + let(:params) { { ignore_local_clock: true } } + let :facts do + { + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', + } end + + it { is_expected.to contain_file('ntp_conf').without_content(%r{^server\s+127.127.1.0}) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^fudge\s+127.127.1.0 stratum 10}) } end context 'with invalid ignore_local_clock 1' do - let(:params) { { :ignore_local_clock => ['bad','input'] } } + let(:params) { { ignore_local_clock: ['bad', 'input'] } } let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end it do expect { - should contain_class('ntp') + is_expected.to contain_class('ntp') }.to raise_error(Puppet::Error) end end context 'with invalid ignore_local_clock 2' do - let(:params) { { :ignore_local_clock => 'nottrue' } } + let(:params) { { ignore_local_clock: 'nottrue' } } let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end it do expect { - should contain_class('ntp') + is_expected.to contain_class('ntp') }.to raise_error(Puppet::Error) end end context 'on Linux physical machine' do let :facts do - { :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', - :kernel => 'Linux' + { + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end - it { should_not contain_exec('xen_independent_wallclock') } + it { is_expected.not_to contain_exec('xen_independent_wallclock') } end context 'on Linux Xen guest' do let :facts do - { :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6', - :virtual => 'xenu', - :kernel => 'Linux' + { + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'xenu', } end - it { should contain_exec('xen_independent_wallclock') } + it { is_expected.to contain_exec('xen_independent_wallclock') } end context 'on non-Linux Xen guest' do let :facts do - { :osfamily => 'Solaris', - :kernelrelease => '5.11', - :virtual => 'xenu', - :kernel => 'Solaris' + { + os: { + family: 'Solaris', + }, + kernelrelease: '5.11', + virtual: 'xenu', + kernel: 'Solaris', } end - it { should_not contain_exec('xen_independent_wallclock') } + it { is_expected.not_to contain_exec('xen_independent_wallclock') } end describe 'with package_name set' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end context 'to an array' do - let(:params) { { :package_name => ['ntp','ntphelper'] } } + let(:params) { { package_name: ['ntp', 'ntphelper'] } } - it { should compile.with_all_deps } - it { should contain_class('ntp') } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('ntp') } it { - should contain_package('ntp').with({ - 'ensure' => 'present', - }) + is_expected.to contain_package('ntp').with( + { + 'ensure' => 'present', + }, + ) } it { - should contain_package('ntphelper').with({ - 'ensure' => 'present', - }) + is_expected.to contain_package('ntphelper').with( + { + 'ensure' => 'present', + }, + ) } end context 'to a string' do - let(:params) { { :package_name => 'myntp' } } + let(:params) { { package_name: 'myntp' } } - it { should compile.with_all_deps } - it { should contain_class('ntp') } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('ntp') } it { - should contain_package('myntp').with({ - 'ensure' => 'present', - }) + is_expected.to contain_package('myntp').with( + { + 'ensure' => 'present', + }, + ) } end context 'to an invalid type (boolean)' do - let(:params) { { :package_name => true } } + let(:params) { { package_name: true } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/ntp::package_name must be a string or an array./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error) end end end @@ -951,35 +1079,39 @@ describe 'with restrict_options set' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end context 'to valid \'default kod notrap\'' do - let(:params) { { :restrict_options => 'default kod notrap' } } + let(:params) { { restrict_options: 'default kod notrap' } } - it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap$/) } - it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^restrict -4 default kod notrap$}) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^restrict -6 default kod notrap$}) } end context 'to valid [ \'\', ]' do - let(:params) { { :restrict_options => [ '', ] } } + let(:params) { { restrict_options: [ '' ] } } - it { should contain_file('ntp_conf').without_content(/^restrict$/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^restrict$}) } end - [true,false,3,2.42,a = { 'ha' => 'sh' }].each do |value| + [true, false, 3, 2.42, { 'ha' => 'sh' }].each do |value| context "to invalid #{value} as #{value.class}" do - let(:params) { { :restrict_options => value } } + let(:params) { { restrict_options: value } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/restrict_options must be an array \(prefered\) or a string \(will be deprecated\)/) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error) end end end @@ -988,35 +1120,39 @@ describe 'with restrict_localhost set' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end - context 'to valid [ \'10.0.0.0\', \'127.0.0.2\', ]' do - let(:params) { { :restrict_localhost => [ '10.0.0.0', '127.0.0.2', ] } } + context 'to valid [ \'10.0.0.0\', \'127.0.0.2\' ]' do + let(:params) { { restrict_localhost: [ '10.0.0.0', '127.0.0.2' ] } } - it { should contain_file('ntp_conf').with_content(/^restrict 10.0.0.0$/) } - it { should contain_file('ntp_conf').with_content(/^restrict 127.0.0.2$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^restrict 10.0.0.0$}) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^restrict 127.0.0.2$}) } end - context 'to valid [ \'\', ]' do - let(:params) { { :restrict_localhost => [ '', ] } } + context 'to valid [ \'\' ]' do + let(:params) { { restrict_localhost: [ '' ] } } - it { should contain_file('ntp_conf').without_content(/^restrict$/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^restrict$}) } end - ['true',true,false,1,2.42,h = { 'a' => 'sh' }].each do |value| + ['true', true, false, 1, 2.42, { 'ha' => 'sh' }].each do |value| context "to invalid #{value} as #{value.class}" do - let(:params) { { :restrict_localhost => value } } + let(:params) { { restrict_localhost: value } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/restrict_localhost must be an array or the string \'USE_DEFAULTS\'./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error) end end end @@ -1025,35 +1161,39 @@ describe 'with servers set' do let(:facts) do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end context 'to valid [ \'ntp1.example.com\', \'ntp2.example.com\', ]' do - let(:params) { { :servers => [ 'ntp1.example.com', 'ntp2.example.com', ] } } + let(:params) { { servers: [ 'ntp1.example.com', 'ntp2.example.com' ] } } - it { should contain_file('ntp_conf').with_content(/^server ntp1.example.com$/) } - it { should contain_file('ntp_conf').with_content(/^server ntp2.example.com$/) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^server ntp1.example.com$}) } + it { is_expected.to contain_file('ntp_conf').with_content(%r{^server ntp2.example.com$}) } end context 'to valid [ \'\', ]' do - let(:params) { { :servers => [ '', ] } } + let(:params) { { servers: [ '' ] } } - it { should contain_file('ntp_conf').without_content(/^server$/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^server$}) } end - ['true',true,false,1,2.42,h = { 'a' => 'sh' }].each do |value| + ['true', true, false, 1, 2.42, { 'a' => 'sh' }].each do |value| context "to invalid #{value} as #{value.class}" do - let(:params) { { :servers => value } } + let(:params) { { servers: value } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/is not an Array./) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{expects an Array}) end end end @@ -1062,36 +1202,40 @@ describe 'with disable_monitor set' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end - [true,'true',false,'false'].each do |value| + [true, false].each do |value| context "to #{value} as #{value.class}" do - let(:params) { { :disable_monitor => value } } + let(:params) { { disable_monitor: value } } - it { should compile.with_all_deps } - it { should contain_class('ntp') } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('ntp') } - if value == true or value == 'true' - it { should contain_file('ntp_conf').with_content(/^disable monitor$/) } + if value == true + it { is_expected.to contain_file('ntp_conf').with_content(%r{^disable monitor$}) } else - it { should contain_file('ntp_conf').without_content(/^disable monitor$/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^disable monitor$}) } end end end context 'to invalid type' do - let(:params) { { :disable_monitor => [ 'invalid', 'type' ] } } + let(:params) { { disable_monitor: [ 'invalid', 'type' ] } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/str2bool/) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error, %r{expects a Boolean}) end end end @@ -1099,35 +1243,38 @@ describe 'with enable_tinker set to' do let :facts do { - :osfamily => 'RedHat', - :kernel => 'Linux', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :virtual => 'physical', + os: { + family: 'RedHat', + name: 'RedHat', + release: { + full: '6.0', + }, + }, + kernel: 'Linux', + virtual: 'physical', } end - [true,'true',false,'false'].each do |value| + [true, false].each do |value| context "valid #{value} as #{value.class}" do - let(:params) { { :enable_tinker => value } } + let(:params) { { enable_tinker: value } } - if value == true or value == 'true' - it { should contain_file('ntp_conf').with_content(/^tinker panic 0$/) } + if [true, 'true'].include?(value) + it { is_expected.to contain_file('ntp_conf').with_content(%r{^tinker panic 0$}) } else - it { should contain_file('ntp_conf').without_content(/^tinker panic 0$/) } + it { is_expected.to contain_file('ntp_conf').without_content(%r{^tinker panic 0$}) } end - end end - ['invalid',3,2.42,['array'],a = { 'ha' => 'sh' }].each do |value| + ['invalid', 3, 2.42, ['array'], { 'ha' => 'sh' }].each do |value| context "invalid #{value} as #{value.class}" do - let(:params) { { :enable_tinker => value } } + let(:params) { { enable_tinker: value } } it do expect { - should contain_class('ntp') - }.to raise_error(Puppet::Error,/str2bool/) + is_expected.to contain_class('ntp') + }.to raise_error(Puppet::Error) end end end @@ -1135,151 +1282,169 @@ platforms = { 'debian6' => - { :kernel => 'Linux', - :osfamily => 'Debian', - :operatingsystem => 'Debian', - :operatingsystemrelease => '6', - :sysconffixture => 'sysconfig.debian', - :sysconfig_options => '-g -x' + { + kernel: 'Linux', + osfamily: 'Debian', + operatingsystem: 'Debian', + operatingsystemrelease: '6', + sysconffixture: 'sysconfig.debian', + sysconfig_options: '-g -x', }, 'ubuntu1204' => - { :kernel => 'Linux', - :osfamily => 'Debian', - :operatingsystem => 'Debian', - :operatingsystemrelease => '12.04', - :sysconffixture => 'sysconfig.debian', - :sysconfig_options => '-g -x' + { + kernel: 'Linux', + osfamily: 'Debian', + operatingsystem: 'Debian', + operatingsystemrelease: '12.04', + sysconffixture: 'sysconfig.debian', + sysconfig_options: '-g -x', }, 'rhel5' => - { :kernel => 'Linux', - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '5.0', - :sysconffixture => 'sysconfig.rhel5', - :sysconfig_options => '-u ntp:ntp -p /var/run/ntpd.pid -x' + { + kernel: 'Linux', + osfamily: 'RedHat', + operatingsystem: 'RedHat', + operatingsystemrelease: '5.0', + sysconffixture: 'sysconfig.rhel5', + sysconfig_options: '-u ntp:ntp -p /var/run/ntpd.pid -x', }, 'rhel6' => - { :kernel => 'Linux', - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '6.0', - :sysconffixture => 'sysconfig.rhel6', - :sysconfig_options => '-u ntp:ntp -p /var/run/ntpd.pid -g -x' + { + kernel: 'Linux', + osfamily: 'RedHat', + operatingsystem: 'RedHat', + operatingsystemrelease: '6.0', + sysconffixture: 'sysconfig.rhel6', + sysconfig_options: '-u ntp:ntp -p /var/run/ntpd.pid -g -x', }, 'rhel7' => - { :kernel => 'Linux', - :osfamily => 'RedHat', - :operatingsystem => 'RedHat', - :operatingsystemrelease => '7.0', - :sysconffixture => 'sysconfig.rhel7', - :sysconfig_options => '-g -x' + { + kernel: 'Linux', + osfamily: 'RedHat', + operatingsystem: 'RedHat', + operatingsystemrelease: '7.0', + sysconffixture: 'sysconfig.rhel7', + sysconfig_options: '-g -x', }, 'suse9' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '9.0', - :sysconffixture => 'sysconfig.suse9', - :sysconfig_options => '' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '9.0', + sysconffixture: 'sysconfig.suse9', + sysconfig_options: '', }, 'suse10' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '10.0', - :sysconffixture => 'sysconfig.suse10', - :sysconfig_options => '-u ntp -x' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '10.0', + sysconffixture: 'sysconfig.suse10', + sysconfig_options: '-u ntp -x', }, 'suse11.0' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '11.0', - :sysconffixture => 'sysconfig.suse11.0', - :sysconfig_options => '-g -u ntp:ntp -x' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '11.0', + sysconffixture: 'sysconfig.suse11.0', + sysconfig_options: '-g -u ntp:ntp -x', }, 'suse11.1' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '11.1', - :sysconffixture => 'sysconfig.suse11.1', - :sysconfig_options => '-g -u ntp:ntp -x' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '11.1', + sysconffixture: 'sysconfig.suse11.1', + sysconfig_options: '-g -u ntp:ntp -x', }, 'suse11.2' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '11.2', - :sysconffixture => 'sysconfig.suse11.2', - :sysconfig_options => '-g -u ntp:ntp -x' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '11.2', + sysconffixture: 'sysconfig.suse11.2', + sysconfig_options: '-g -u ntp:ntp -x', }, 'suse11.3' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '11.3', - :sysconffixture => 'sysconfig.suse11.3', - :sysconfig_options => '-g -u ntp:ntp -x' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '11.3', + sysconffixture: 'sysconfig.suse11.3', + sysconfig_options: '-g -u ntp:ntp -x', }, 'suse11.4' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '11.4', - :sysconffixture => 'sysconfig.suse11.4', - :sysconfig_options => '-g -u ntp:ntp -x' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '11.4', + sysconffixture: 'sysconfig.suse11.4', + sysconfig_options: '-g -u ntp:ntp -x', }, 'suse12' => - { :kernel => 'Linux', - :osfamily => 'Suse', - :operatingsystem => 'Suse', - :operatingsystemrelease => '12.0', - :sysconffixture => 'sysconfig.suse12', - :sysconfig_options => '-g -u ntp:ntp -x' + { + kernel: 'Linux', + osfamily: 'Suse', + operatingsystem: 'Suse', + operatingsystemrelease: '12.0', + sysconffixture: 'sysconfig.suse12', + sysconfig_options: '-g -u ntp:ntp -x', }, } describe 'sysconfig file with default values for parameters on' do - platforms.sort.each do |k,v| - context "#{k}" do - let :facts do + platforms.sort.each do |k, v| + context k.to_s do + let(:facts) do { - :kernel => v[:kernel], - :osfamily => v[:osfamily], - :operatingsystem => v[:operatingsystem], - :operatingsystemrelease => v[:operatingsystemrelease], - :virtual => 'physical', + os: { + family: v[:osfamily], + name: v[:operatingsystem], + release: { + full: v[:operatingsystemrelease], + }, + }, + kernel: v[:kernel], + virtual: 'physical', } end - sysconfig_fixture = File.read(fixtures("#{v[:sysconffixture]}")) + sysconfig_fixture = File.read(fixtures(v[:sysconffixture].to_s)) it { - should contain_file('ntp_sysconfig').with_content(sysconfig_fixture) + is_expected.to contain_file('ntp_sysconfig').with_content(sysconfig_fixture) } end end end + describe 'sysconfig file with non-default values for parameters on' do - platforms.sort.each do |k,v| - context "#{k}" do - let :facts do + platforms.sort.each do |k, v| + context k.to_s do + let(:facts) do { - :kernel => v[:kernel], - :osfamily => v[:osfamily], - :operatingsystem => v[:operatingsystem], - :operatingsystemrelease => v[:operatingsystemrelease], - :virtual => 'physical', - } - end - let :params do - { :sysconfig_options => v[:sysconfig_options], + os: { + family: v[:osfamily], + name: v[:operatingsystem], + release: { + full: v[:operatingsystemrelease], + }, + }, + kernel: v[:kernel], + virtual: 'physical', } end + let(:params) { { sysconfig_options: v[:sysconfig_options] } } - sysconfig_fixture = File.read(fixtures("#{v[:sysconffixture]}")) it { - should contain_file('ntp_sysconfig').with_content(/#{v[:sysconfig_options]}/) + is_expected.to contain_file('ntp_sysconfig').with_content(%r{#{v[:sysconfig_options]}}) } end end 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 cd91de5..8c48ec5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,20 +1,75 @@ +# frozen_string_literal: true + RSpec.configure do |c| c.mock_with :rspec end require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' + +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + +include RspecPuppetFacts + +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) + + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end + +# read default_facts and merge them over what is provided by facterdb +default_facts.each do |fact, value| + add_custom_fact fact, value +end + +RSpec.configure do |c| + c.default_facts = default_facts + c.hiera_config = 'spec/fixtures/hiera/hiera.yaml' + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + RSpec::Puppet::Coverage.report!(100) + end -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 + # 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 - config.default_facts = { - :environment => 'rp_env', - } end + +# Ensures that a module is defined +# @param module_name Name of the module +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end +end + +# 'spec_overrides' from sync.yml will appear below this line diff --git a/templates/ntp.conf.erb b/templates/ntp.conf.erb index d1d3871..4d92d8e 100644 --- a/templates/ntp.conf.erb +++ b/templates/ntp.conf.erb @@ -11,7 +11,7 @@ driftfile <%= @driftfile_real %> <% end -%> -<% if @my_enable_stats == true %> +<% if @enable_stats == true %> # Statistics are being logged statsdir <%= @statsdir %> statistics loopstats peerstats clockstats @@ -80,12 +80,12 @@ restrict <%= value %> # next lines. Please do this only if you trust everybody on the network! #disable auth #broadcastclient -<% if @ignore_local_clock_real == false -%> +<% if @ignore_local_clock == false -%> # Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. server 127.127.1.0 # local clock -fudge 127.127.1.0 stratum <%= @fudge_stratum %> +fudge 127.127.1.0 stratum <%= @fudge_stratum.to_s %> <% end -%> <% if @keys_real != '' and @keys_real != nil -%> @@ -111,7 +111,7 @@ keys <%= @keys_real %> # Accept any offset - useful for VM's or suspended systems tinker panic 0 <% end -%> -<% if @disable_monitor_real == true -%> +<% if @disable_monitor == true -%> # Disabling monitor - https://isc.sans.edu/diary/NTP+reflection+attack/17300 disable monitor diff --git a/templates/sysconfig.suse11.erb b/templates/sysconfig.suse11.erb index a223a63..7a3994c 100644 --- a/templates/sysconfig.suse11.erb +++ b/templates/sysconfig.suse11.erb @@ -3,7 +3,7 @@ NTPD_OPTIONS="<%= @sysconfig_options_real %>" -<% if @operatingsystemrelease == '11.4' -%> +<% if @facts['os']['release']['full'] == '11.4' -%> NTPD_RUN_CHROOTED="no" <% else -%> NTPD_RUN_CHROOTED="yes" @@ -14,7 +14,7 @@ NTPD_CHROOT_FILES="" NTP_PARSE_LINK="" NTP_PARSE_DEVICE="" -<% if @operatingsystemrelease != '11.0' %> +<% if @facts['os']['release']['full'] != '11.0' %> NTPD_FORCE_SYNC_ON_STARTUP="no" NTPD_FORCE_SYNC_HWCLOCK_ON_STARTUP="no" diff --git a/tests/init.pp b/tests/init.pp index 2b6eff9..9f87de7 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -1 +1 @@ -include ::ntp +include ntp