From 86c4dae958e700df9f3394d65081b3fc64621c2f Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 13:11:49 +0200 Subject: [PATCH 1/8] PDK convert (1.18.1) --- .gitattributes | 5 ++ .gitignore | 39 ++++++++---- .gitlab-ci.yml | 44 +++++++++++++ .pdkignore | 42 ++++++++++++ .puppet-lint.rc | 1 + .rspec | 2 + .rubocop.yml | 137 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 66 +++++++++++++------ .vscode/extensions.json | 6 ++ .yardopts | 1 + Gemfile | 86 +++++++++++++++++++------ Rakefile | 101 ++++++++++++++++++++++------- appveyor.yml | 56 ++++++++++++++++ data/common.yaml | 1 + hiera.yaml | 21 ++++++ metadata.json | 17 +++-- spec/default_facts.yml | 8 +++ spec/spec_helper.rb | 56 ++++++++++++++++ 18 files changed, 610 insertions(+), 79 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitlab-ci.yml create mode 100644 .pdkignore create mode 100644 .puppet-lint.rc create mode 100644 .rspec create mode 100644 .rubocop.yml create mode 100644 .vscode/extensions.json create mode 100644 .yardopts create mode 100644 appveyor.yml create mode 100644 data/common.yaml create mode 100644 hiera.yaml create mode 100644 spec/default_facts.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore index aadd189..2767022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,27 @@ -.bundle -Gemfile.lock -junit/ -log/ -*.orig -*.patch -pkg/ -*.rej -spec/fixtures/manifests/ -spec/fixtures/modules/ -*.swp -.vagrant +.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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4868bf7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,44 @@ +--- +stages: + - syntax + - unit + +cache: + paths: + - vendor/bundle + +before_script: + - bundle -v + - rm Gemfile.lock || true + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# Set `rubygems_version` in the .sync.yml to set a value" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.7-Puppet ~> 6: + stage: syntax + image: ruby:2.5.7 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.5.7-Puppet ~> 6: + stage: unit + image: ruby:2.5.7 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 6' + +parallel_spec-Ruby 2.4.5-Puppet ~> 5: + stage: unit + image: ruby:2.4.5 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..e6215cd --- /dev/null +++ b/.pdkignore @@ -0,0 +1,42 @@ +.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 +/appveyor.yml +/.fixtures.yml +/Gemfile +/.gitattributes +/.gitignore +/.gitlab-ci.yml +/.pdkignore +/Rakefile +/rakelib/ +/.rspec +/.rubocop.yml +/.travis.yml +/.yardopts +/spec/ +/.vscode/ 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..5307849 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,137 @@ +--- +require: +- rubocop-rspec +- rubocop-i18n +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.1' + Include: + - "./**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - "**/Gemfile" + - "**/Rakefile" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" +Metrics/LineLength: + Description: People have wide screens, use them. + Max: 200 +GetText: + Enabled: false +GetText/DecorateString: + Description: We don't want to decorate test output. + Exclude: + - spec/**/* + Enabled: false +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +Style/BlockDelimiters: + Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + be consistent then. + EnforcedStyle: braces_for_chaining +Style/BracesAroundHashParameters: + Description: Braces are required by Ruby 2.7. Cop removed from RuboCop v0.80.0. + See https://github.com/rubocop-hq/rubocop/pull/7643 + Enabled: true +Style/ClassAndModuleChildren: + Description: Compact style reduces the required amount of indentation. + EnforcedStyle: compact +Style/EmptyElse: + Description: Enforce against empty else clauses, but allow `nil` for clarity. + EnforcedStyle: empty +Style/FormatString: + Description: Following the main puppet project's style, prefer the % format format. + EnforcedStyle: percent +Style/FormatStringToken: + Description: Following the main puppet project's style, prefer the simpler template + tokens over annotated ones. + EnforcedStyle: template +Style/Lambda: + Description: Prefer the keyword for easier discoverability. + EnforcedStyle: literal +Style/RegexpLiteral: + Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 + EnforcedStyle: percent_r +Style/TernaryParentheses: + Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + on complex expressions for better readability, but seriously consider breaking + it up. + EnforcedStyle: require_parentheses_when_complex +Style/TrailingCommaInArguments: + Description: Prefer always trailing comma on multiline argument lists. This makes + diffs, and re-ordering nicer. + EnforcedStyleForMultiline: comma +Style/TrailingCommaInLiteral: + 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 +Style/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +GetText/DecorateFunctionMessage: + Enabled: false +GetText/DecorateStringFormattingUsingInterpolation: + Enabled: false +GetText/DecorateStringFormattingUsingPercent: + Enabled: false +Layout/EndOfLine: + Enabled: false +Layout/IndentHeredoc: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + 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 +RSpec/DescribeClass: + Enabled: false +RSpec/ExampleLength: + Enabled: false +RSpec/MessageExpectation: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false +RSpec/NestedGroups: + Enabled: false +Style/AsciiComments: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/SymbolProc: + Enabled: false diff --git a/.travis.yml b/.travis.yml index bdd70ce..a8239a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,50 @@ -sudo: false +--- +os: linux +dist: xenial language: ruby -bundler_args: --without release beaker +cache: bundler +before_install: + - bundle -v + - rm -f Gemfile.lock + - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" + - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" + - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" + - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests rvm: - - '2.0' - - '2.1' - - '2.2' -env: - - PUPPET_GEM_VERSION="~> 3.7" - - PUPPET_GEM_VERSION="~> 4.9" -matrix: - include: - - rvm: '2.2' - sudo: required - services: docker - env: BEAKER_set="centos-7-docker" - script: travis_retry bundle exec rake beaker - bundler_args: --without release - exclude: - - rvm: '2.2' - env: PUPPET_GEM_VERSION="~> 3.7" - - rvm: '2.0' - env: PUPPET_GEM_VERSION="~> 4.9" + - 2.5.7 +stages: + - static + - spec + - acceptance + - + if: tag =~ ^v\d + name: deploy +jobs: fast_finish: true + include: + - + env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" + stage: static + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.5 + stage: spec + - + env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + rvm: 2.5.7 + stage: spec + - + env: DEPLOY_TO_FORGE=yes + stage: deploy +branches: + only: + - master + - develop + - /^v\d/ notifications: email: false diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2f1e4f7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..29c933b --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +--markup markdown diff --git a/Gemfile b/Gemfile index ee6fa0b..8007ad0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,22 +1,72 @@ -source 'https://rubygems.org' - -gem 'metadata-json-lint', :require => false -gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 4.9', :require => false -gem 'puppetlabs_spec_helper', '~> 1.2', :require => false -gem 'puppet-lint', '~> 2.0', :require => false -gem 'puppet-syntax', :require => false -gem 'rake', :require => false -gem 'rspec-puppet', '~> 2.5.0', :require => false -gem 'travis', '~> 1.8', :require => false - -group :release do - gem 'puppet-blacksmith', :require => false +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] + else + [place_or_version, { require: false }] + end +end + +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') + +group :development do + gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') + gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') + gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') + gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] +end + +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables + +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version + +if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} + # If we're using a Puppet gem on Windows which handles its own win32-xxx gem + # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). + gems['win32-dir'] = ['<= 0.4.9', require: false] + gems['win32-eventlog'] = ['<= 0.6.5', require: false] + gems['win32-process'] = ['<= 0.7.5', require: false] + gems['win32-security'] = ['<= 0.2.5', require: false] + gems['win32-service'] = ['0.8.8', require: false] end -group :beaker do - gem 'beaker-puppet_install_helper', :require => false - gem 'beaker-rspec', '~> 6.0.0', :require => false - gem 'serverspec', :require => false +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params end -# vim:ft=ruby +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] + +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end +end +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index bbeb353..0a5093b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,34 +1,87 @@ +# frozen_string_literal: true + +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? +require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? +require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? -begin - require 'puppet_blacksmith/rake_tasks' -rescue LoadError +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 -PuppetLint.configuration.send("disable_class_inherits_from_params_class") -PuppetLint.configuration.send("disable_80chars") -PuppetLint.configuration.ignore_paths = ['pkg/**/*.pp', 'spec/**/*.pp', 'tests/**/*.pp'] -PuppetSyntax.exclude_paths = ['spec/fixtures/**/*'] +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? -PuppetLint::RakeTask.new :lint do |config| - config.pattern = 'manifests/**/*.pp' - config.fail_on_warnings = true + puts "GitHubChangelogGenerator project:#{returnVal}" + returnVal end -namespace :travis do - desc 'Syntax check travis.yml' - task :lint do - sh "travis lint --exit-code --skip-completion-check" do |ok, res| - unless ok - # exit without verbose rake error message - exit res.exitstatus - end - end +def changelog_future_release + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] + raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator future_release:#{returnVal}" + returnVal +end + +PuppetLint.configuration.send('disable_relative') + +if Bundler.rubygems.find_name('github_changelog_generator').any? + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? + config.user = "#{changelog_user}" + config.project = "#{changelog_project}" + config.future_release = "#{changelog_future_release}" + config.exclude_labels = ['maintenance'] + config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." + config.add_pr_wo_labels = true + config.issues = false + config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["enhancement", "feature"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bug", "documentation", "bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise < 1.15' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" +EOM end end -task :default => [ - :validate, - :lint, - :spec, -] diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ec38949 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,56 @@ +--- +version: 1.1.x.{build} +branches: + only: + - master + - release +skip_commits: + message: /^\(?doc\)?.*/ +clone_depth: 10 +init: + - SET + - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0' + - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0' +environment: + matrix: + - + RUBY_VERSION: 24-x64 + CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 5.0 + RUBY_VERSION: 24-x64 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25 + CHECK: parallel_spec + - + PUPPET_GEM_VERSION: ~> 6.0 + RUBY_VERSION: 25-x64 + CHECK: parallel_spec +matrix: + fast_finish: true +install: + - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% + - bundle install --jobs 4 --retry 2 --without system_tests + - type Gemfile.lock +build: off +test_script: + - bundle exec puppet -V + - ruby -v + - gem -v + - bundle -v + - bundle exec rake %CHECK% +notifications: + - provider: Email + to: + - nobody@nowhere.com + on_build_success: false + on_build_failure: false + on_build_status_changed: false diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..2fbf0ff --- /dev/null +++ b/data/common.yaml @@ -0,0 +1 @@ +--- {} diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..545fff3 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,21 @@ +--- +version: 5 + +defaults: # Used for any hierarchy level that omits these keys. + datadir: data # This path is relative to hiera.yaml's directory. + data_hash: yaml_data # Use the built-in YAML backend. + +hierarchy: + - name: "osfamily/major release" + paths: + # Used to distinguish between Debian and Ubuntu + - "os/%{facts.os.name}/%{facts.os.release.major}.yaml" + - "os/%{facts.os.family}/%{facts.os.release.major}.yaml" + # Used for Solaris + - "os/%{facts.os.family}/%{facts.kernelrelease}.yaml" + - name: "osfamily" + paths: + - "os/%{facts.os.name}.yaml" + - "os/%{facts.os.family}.yaml" + - name: 'common' + path: 'common.yaml' diff --git a/metadata.json b/metadata.json index da27f37..166adaf 100644 --- a/metadata.json +++ b/metadata.json @@ -7,6 +7,12 @@ "source": "https://github.com/jhoblitt/puppet-udev.git", "project_page": "https://github.com/jhoblitt/puppet-udev", "issues_url": "https://github.com/jhoblitt/puppet-udev/issues", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.6.0 < 7.0.0" + } + ], "operatingsystem_support": [ { "operatingsystem": "RedHat", @@ -47,10 +53,13 @@ ] } ], - "dependencies": [ + "requirements": [ { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.6.0 < 7.0.0" + "name": "puppet", + "version_requirement": ">= 4.10.0 < 7.0.0" } - ] + ], + "pdk-version": "1.18.1", + "template-url": "https://github.com/puppetlabs/pdk-templates#1.18.1", + "template-ref": "tags/1.18.1-0-g3d2e75c" } 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 2c6f566..d3778ca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,57 @@ +# frozen_string_literal: true + require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' + +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) + +include RspecPuppetFacts + +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_fact_files = [ + File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), +] + +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) + + begin + default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +end + +# read default_facts and merge them over what is provided by facterdb +default_facts.each do |fact, value| + add_custom_fact fact, value +end + +RSpec.configure do |c| + c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + end +end + +# Ensures that a module is defined +# @param module_name Name of the module +def ensure_module_defined(module_name) + module_name.split('::').reduce(Object) do |last_module, next_module| + last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) + last_module.const_get(next_module, false) + end +end + +# 'spec_overrides' from sync.yml will appear below this line From 4595ab9eaffad8c330c47f748f2427bf698a4cc3 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 13:23:07 +0200 Subject: [PATCH 2/8] Convert to puppet litmus for acceptance tests * Configure litmus in pdk * Run pdk update after litmus config * Configure litmus (acceptance tests) * Add litmus provision file --- .fixtures.yml | 3 + .sync.yml | 11 ++++ .travis.yml | 111 ++++++++++++++++++++++++++++++++- provision.yaml | 16 +++++ spec/acceptance/udev_spec.rb | 56 +++++++++-------- spec/spec_helper_acceptance.rb | 59 ++---------------- 6 files changed, 173 insertions(+), 83 deletions(-) create mode 100644 .sync.yml create mode 100644 provision.yaml diff --git a/.fixtures.yml b/.fixtures.yml index f5d5a11..f6dc38c 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,5 +3,8 @@ fixtures: stdlib: repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' ref: '4.6.0' + facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' + puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' + provision: 'https://github.com/puppetlabs/provision.git' symlinks: "udev": "#{source_dir}" diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..b8732e5 --- /dev/null +++ b/.sync.yml @@ -0,0 +1,11 @@ +--- +.travis.yml: + use_litmus: true + litmus: + provision_list: + - travis_deb + - travis_ub + - ---travis_el + - travis_el6 + - travis_el7 + - travis_el8 diff --git a/.travis.yml b/.travis.yml index a8239a2..d40e2fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,116 @@ stages: jobs: fast_finish: true include: + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_deb]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_deb_puppet5 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_ub]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_ub_puppet5 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el6]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_el6_puppet5 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el7]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_el7_puppet5 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el8]'" + - "bundle exec rake 'litmus:install_agent[puppet5]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_el8_puppet5 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_deb]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_deb_puppet6 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_ub]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_ub_puppet6 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el6]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_el6_puppet6 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el7]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_el7_puppet6 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance + - + before_script: + - "bundle exec rake 'litmus:provision_list[travis_el8]'" + - "bundle exec rake 'litmus:install_agent[puppet6]'" + - "bundle exec rake litmus:install_module" + bundler_args: + env: PLATFORMS=travis_el8_puppet6 + rvm: 2.5.7 + script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] + services: docker + stage: acceptance - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" stage: static @@ -44,7 +154,6 @@ jobs: branches: only: - master - - develop - /^v\d/ notifications: email: false diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 0000000..ef560de --- /dev/null +++ b/provision.yaml @@ -0,0 +1,16 @@ +--- +travis_deb: + provisioner: docker + images: ['litmusimage/debian:8', 'litmusimage/debian:9', 'litmusimage/debian:10'] +travis_ub: + provisioner: docker + images: ['litmusimage/ubuntu:16.04', 'litmusimage/ubuntu:18.04'] +travis_el6: + provisioner: docker + images: ['waffleimage/centos6', 'waffleimage/oraclelinux6', 'waffleimage/scientificlinux6'] +travis_el7: + provisioner: docker + images: ['waffleimage/centos7', 'waffleimage/oraclelinux7', 'waffleimage/scientificlinux7'] +travis_el8: + provisioner: docker + images: ['monolithprojects/systemd-centos8'] diff --git a/spec/acceptance/udev_spec.rb b/spec/acceptance/udev_spec.rb index f822791..ba8c689 100644 --- a/spec/acceptance/udev_spec.rb +++ b/spec/acceptance/udev_spec.rb @@ -8,8 +8,8 @@ end describe 'running puppet code' do - it 'should work with no errors' do - pp = <<-EOS + let(:pp) do + <<-EOS class { 'udev': udev_log => 'debug' } udev::rule { '51-android.rules': @@ -20,36 +20,38 @@ class { 'udev': udev_log => 'debug' } content => 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"', } EOS + end - apply2(pp) + it 'should work with no errors' do + idempotent_apply(pp) end - end - describe package(package_name) do - it { should be_installed } - end + describe package(package_name) do + it { should be_installed } + end - describe file('/etc/udev/udev.conf') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain 'udev_log="debug"' } - end + describe file('/etc/udev/udev.conf') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + it { should be_mode 644 } + it { should contain 'udev_log="debug"' } + end - describe file('/etc/udev/rules.d/51-android.rules') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="4372", MODE="0660", OWNER="vagrant"' } - end + describe file('/etc/udev/rules.d/51-android.rules') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + it { should be_mode 644 } + it { should contain 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="4372", MODE="0660", OWNER="vagrant"' } + end - describe file('/etc/udev/rules.d/60-raw.rules') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"' } + describe file('/etc/udev/rules.d/60-raw.rules') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + it { should be_mode 644 } + it { should contain 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"' } + end end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 59da72b..73a0238 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,57 +1,6 @@ -require 'beaker-rspec/spec_helper' -require 'beaker-rspec/helpers/serverspec' -require 'beaker/puppet_install_helper' +# frozen_string_literal: true -# Install Puppet -unless ENV['RS_PROVISION'] == 'no' - ENV['PUPPET_INSTALL_TYPE'] ||= 'agent' - # puppet_install_helper does not understand pessimistic version constraints - # so we are ignoring PUPPET_VERSION. Use PUPPET_INSTALL_VERSION instead. - ENV.delete 'PUPPET_VERSION' - run_puppet_install_helper -end +require 'puppet_litmus' +PuppetLitmus.configure! -RSpec.configure do |c| - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - # Readable test descriptions - c.formatter = :documentation - - c.before :suite do - # Install module and dependencies - hosts.each do |host| - copy_module_to(host, :source => proj_root, :module_name => 'udev') - - on host, puppet('module', 'install', 'puppetlabs-stdlib'), {:acceptable_exit_codes => [0, 1]} - on host, puppet('module', 'install', 'stahnma-epel'), {:acceptable_exit_codes => [0, 1]} - end - end -end - -def apply(pp, options = {}) - if ENV.key?('PUPPET_DEBUG') - options[:debug] = true - end - - apply_manifest(pp, options) -end - -# Run it twice and test for idempotency -def apply2(pp) - apply(pp, :catch_failures => true) - apply(pp, :catch_changes => true) -end - -# probe stolen from: -# https://github.com/camptocamp/puppet-systemd/blob/master/lib/facter/systemd.rb#L26 -# -# See these issues for an explination of why this is nessicary rather than -# using fact() from beaker-facter in the DSL: -# -# https://tickets.puppetlabs.com/browse/BKR-1040 -# https://tickets.puppetlabs.com/browse/BKR-1041 -# -if shell('ps -p 1 -o comm=').stdout =~ /systemd/ - $systemd = true -else - $systemd = false -end +require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) From 049590f71d61237f8dfc2a5c50d64cd9c948dd34 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 13:32:06 +0200 Subject: [PATCH 3/8] Fix failing spec/acceptance tests * Use old fashioned check for systemd in acceptance tests * Check correct file parameter 'replace' --- spec/acceptance/udev_spec.rb | 10 +++++----- spec/classes/udev_spec.rb | 29 +++++++++++++---------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/spec/acceptance/udev_spec.rb b/spec/acceptance/udev_spec.rb index ba8c689..120472e 100644 --- a/spec/acceptance/udev_spec.rb +++ b/spec/acceptance/udev_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper_acceptance' describe 'udev class' do - if $systemd - package_name = 'systemd' - else - package_name = 'udev' - end + package_name = if run_shell('ps -p 1 -o comm=').stdout =~ %r{systemd} + 'systemd' + else + 'udev' + end describe 'running puppet code' do let(:pp) do diff --git a/spec/classes/udev_spec.rb b/spec/classes/udev_spec.rb index 6c2b5ce..c15bce9 100644 --- a/spec/classes/udev_spec.rb +++ b/spec/classes/udev_spec.rb @@ -1,25 +1,22 @@ require 'spec_helper' -describe 'udev', :type => :class do - +describe 'udev', type: :class do shared_examples 'udev_log_param' do |udev_log, config_file_replace, params| let(:params) { params } it do - should contain_class('udev') - should contain_package('udev').with_ensure('present') - should contain_file('/etc/udev/udev.conf'). - with({ - :ensure => 'file', - :owner => 'root', - :group => 'root', - :mode => '0644', - :config_file_replace => $config_file_replace, - }). - with_content(/udev_log="#{udev_log}"/) - should contain_class('udev::udevadm::trigger') - should contain_class('udev::udevadm::logpriority'). - with_udev_log(udev_log) + is_expected.to contain_class('udev') + is_expected.to contain_package('udev').with_ensure('present') + is_expected.to contain_file('/etc/udev/udev.conf') + .with(ensure: 'file', + owner: 'root', + group: 'root', + mode: '0644', + replace: config_file_replace) + .with_content(%r{udev_log="#{udev_log}"}) + is_expected.to contain_class('udev::udevadm::trigger') + is_expected.to contain_class('udev::udevadm::logpriority') + .with_udev_log(udev_log) end end From 65c6df6a497f2aa9458b2eb885b32a4e9cfe3465 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 13:27:14 +0200 Subject: [PATCH 4/8] Auto correct all rubocop warnings/errors --- spec/acceptance/udev_spec.rb | 34 ++++----- spec/classes/params_spec.rb | 38 +++++----- spec/classes/udev_spec.rb | 52 +++++++------ spec/classes/udevadm/logpriority_spec.rb | 68 ++++++++--------- spec/classes/udevadm/trigger_spec.rb | 34 ++++----- spec/defines/rule_spec.rb | 93 +++++++++++------------- 6 files changed, 146 insertions(+), 173 deletions(-) diff --git a/spec/acceptance/udev_spec.rb b/spec/acceptance/udev_spec.rb index 120472e..8698d56 100644 --- a/spec/acceptance/udev_spec.rb +++ b/spec/acceptance/udev_spec.rb @@ -22,36 +22,36 @@ class { 'udev': udev_log => 'debug' } EOS end - it 'should work with no errors' do + it 'works with no errors' do idempotent_apply(pp) end describe package(package_name) do - it { should be_installed } + it { is_expected.to be_installed } end describe file('/etc/udev/udev.conf') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain 'udev_log="debug"' } + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { is_expected.to be_mode 644 } + it { is_expected.to contain 'udev_log="debug"' } end describe file('/etc/udev/rules.d/51-android.rules') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="4372", MODE="0660", OWNER="vagrant"' } + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { is_expected.to be_mode 644 } + it { is_expected.to contain 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="4372", MODE="0660", OWNER="vagrant"' } end describe file('/etc/udev/rules.d/60-raw.rules') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"' } + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { is_expected.to be_mode 644 } + it { is_expected.to contain 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"' } end end end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index bc3f373..4fd0ab8 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -1,52 +1,50 @@ require 'spec_helper' -describe 'udev::params', :type => :class do +describe 'udev::params', type: :class do describe 'for osfamily RedHat' do let :facts do { - :osfamily => 'RedHat', - :operatingsystemmajrelease => '6', - :operatingsystem => 'RedHat', + osfamily: 'RedHat', + operatingsystemmajrelease: '6', + operatingsystem: 'RedHat', } end - - it { should contain_class('udev::params') } + it { is_expected.to contain_class('udev::params') } end describe 'for osfamily RedHat' do let :facts do { - :osfamily => 'RedHat', - :operatingsystemmajrelease => '4', - :operatingsystem => 'RedHat', + osfamily: 'RedHat', + operatingsystemmajrelease: '4', + operatingsystem: 'RedHat', } end - it 'should fail' do - expect { should contain_class('udev::params') }. - to raise_error(Puppet::Error, /not supported on RedHat release 4/) + it 'fails' do + expect { is_expected.to contain_class('udev::params') } + .to raise_error(Puppet::Error, %r{not supported on RedHat release 4}) end end describe 'for osfamily Debian' do - let(:facts) {{ :osfamily => 'Debian' }} + let(:facts) { { osfamily: 'Debian' } } - it { should contain_class('udev::params') } + it { is_expected.to contain_class('udev::params') } end describe 'unsupported osfamily' do let :facts do { - :osfamily => 'Suse', - :operatingsystem => 'OpenSuSE', + osfamily: 'Suse', + operatingsystem: 'OpenSuSE', } end - it 'should fail' do - expect { should contain_class('udev::params') }. - to raise_error(Puppet::Error, /not supported on OpenSuSE/) + it 'fails' do + expect { is_expected.to contain_class('udev::params') } + .to raise_error(Puppet::Error, %r{not supported on OpenSuSE}) end end - end diff --git a/spec/classes/udev_spec.rb b/spec/classes/udev_spec.rb index c15bce9..110920b 100644 --- a/spec/classes/udev_spec.rb +++ b/spec/classes/udev_spec.rb @@ -23,9 +23,9 @@ describe 'for osfamily RedHat' do let :facts do { - :osfamily => 'RedHat', - :operatingsystemmajrelease => '6', - :operatingsystem => 'RedHat', + osfamily: 'RedHat', + operatingsystemmajrelease: '6', + operatingsystem: 'RedHat', } end @@ -34,60 +34,58 @@ end describe 'udev_log => err, config_file_replace => true' do - it_behaves_like('udev_log_param', 'err', true, { :udev_log => 'err', :config_file_replace => true }) + it_behaves_like('udev_log_param', 'err', true, udev_log: 'err', config_file_replace: true) end describe 'udev_log => info, config_file_replace => true' do - it_behaves_like('udev_log_param', 'info', true, { :udev_log => 'info', :config_file_replace => true }) + it_behaves_like('udev_log_param', 'info', true, udev_log: 'info', config_file_replace: true) end describe 'udev_log => debug, config_file_replace => true' do - it_behaves_like('udev_log_param', 'debug', true, { :udev_log => 'debug', :config_file_replace => true }) + it_behaves_like('udev_log_param', 'debug', true, udev_log: 'debug', config_file_replace: true) end describe 'udev_log => err, config_file_replace => false' do - it_behaves_like('udev_log_param', 'err', false, { :udev_log => 'err', :config_file_replace => false }) + it_behaves_like('udev_log_param', 'err', false, udev_log: 'err', config_file_replace: false) end describe 'udev_log => info, config_file_replace => false' do - it_behaves_like('udev_log_param', 'info', false, { :udev_log => 'info', :config_file_replace => false }) + it_behaves_like('udev_log_param', 'info', false, udev_log: 'info', config_file_replace: false) end describe 'udev_log => debug, config_file_replace => false' do - it_behaves_like('udev_log_param', 'debug', false, { :udev_log => 'debug', :config_file_replace => false }) + it_behaves_like('udev_log_param', 'debug', false, udev_log: 'debug', config_file_replace: false) end describe 'udev_log => invalid' do - let(:params) {{ :udev_log => 'invalid' }} + let(:params) { { udev_log: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /does not match/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{does not match}) end end describe 'config_file_replace => invalid' do - let(:params) {{ :config_file_replace => 'invalid' }} + let(:params) { { config_file_replace: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /is not a boolean/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{is not a boolean}) end end describe 'rule parameter' do - let(:params) {{ 'rules' => { '99-foo.rules' => { 'content' => 'generic_rule' }}}} - it { should contain_file("/etc/udev/rules.d/99-foo.rules").with({ - :owner => 'root', - :group => 'root', - :mode => '0644', - :content => 'generic_rule', - })} - end + let(:params) { { 'rules' => { '99-foo.rules' => { 'content' => 'generic_rule' } } } } + it { + is_expected.to contain_file('/etc/udev/rules.d/99-foo.rules').with(owner: 'root', + group: 'root', + mode: '0644', + content: 'generic_rule') + } + end end - - end diff --git a/spec/classes/udevadm/logpriority_spec.rb b/spec/classes/udevadm/logpriority_spec.rb index 3227cf1..19cf725 100644 --- a/spec/classes/udevadm/logpriority_spec.rb +++ b/spec/classes/udevadm/logpriority_spec.rb @@ -1,17 +1,14 @@ require 'spec_helper' -describe 'udev::udevadm::logpriority', :type => :class do - +describe 'udev::udevadm::logpriority', type: :class do shared_examples 'udev_log_param_redhat_6' do |udev_log, params| let(:params) { params } it do - should contain_class('udev::udevadm::logpriority'). - with_udev_log(udev_log) - should contain_exec("udevadm control --log-priority=#{udev_log}").with({ - :refreshonly => true, - :path => '/sbin', - }) + is_expected.to contain_class('udev::udevadm::logpriority') + .with_udev_log(udev_log) + is_expected.to contain_exec("udevadm control --log-priority=#{udev_log}").with(refreshonly: true, + path: '/sbin') end end @@ -19,21 +16,18 @@ let(:params) { params } it do - should contain_class('udev::udevadm::logpriority'). - with_udev_log(udev_log) - should contain_exec("udevcontrol log_priority=#{udev_log}").with({ - :refreshonly => true, - :path => '/sbin', - }) + is_expected.to contain_class('udev::udevadm::logpriority') + .with_udev_log(udev_log) + is_expected.to contain_exec("udevcontrol log_priority=#{udev_log}").with(refreshonly: true, + path: '/sbin') end end describe 'for osfamily RedHat and operatingsystemmajrelease 6' do let(:facts) do - { :osfamily => 'RedHat', - :operatingsystemmajrelease => '6', - :operatingsystem => 'RedHat', - } + { osfamily: 'RedHat', + operatingsystemmajrelease: '6', + operatingsystem: 'RedHat' } end describe 'no params' do @@ -41,35 +35,33 @@ end describe 'udev_log => err' do - it_behaves_like('udev_log_param_redhat_6', 'err', { :udev_log => 'err' }) + it_behaves_like('udev_log_param_redhat_6', 'err', udev_log: 'err') end describe 'udev_log => info' do - it_behaves_like('udev_log_param_redhat_6', 'info', { :udev_log => 'info' }) + it_behaves_like('udev_log_param_redhat_6', 'info', udev_log: 'info') end describe 'udev_log => debug' do - it_behaves_like('udev_log_param_redhat_6', 'debug', { :udev_log => 'debug' }) + it_behaves_like('udev_log_param_redhat_6', 'debug', udev_log: 'debug') end describe 'udev_log => invalid' do - let(:params) {{ :udev_log => 'invalid' }} + let(:params) { { udev_log: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev::udevadm::logpriority') - }.to raise_error(Puppet::Error, /does not match/) + is_expected.to contain_class('udev::udevadm::logpriority') + }.to raise_error(Puppet::Error, %r{does not match}) end end - end describe 'for osfamily RedHat and operatingsystemmajrelease 5' do let(:facts) do - { :osfamily => 'RedHat', - :operatingsystemmajrelease => '5', - :operatingsystem => 'RedHat', - } + { osfamily: 'RedHat', + operatingsystemmajrelease: '5', + operatingsystem: 'RedHat' } end describe 'no params' do @@ -77,27 +69,25 @@ end describe 'udev_log => err' do - it_behaves_like('udev_log_param_redhat_5', 'err', { :udev_log => 'err' }) + it_behaves_like('udev_log_param_redhat_5', 'err', udev_log: 'err') end describe 'udev_log => info' do - it_behaves_like('udev_log_param_redhat_5', 'info', { :udev_log => 'info' }) + it_behaves_like('udev_log_param_redhat_5', 'info', udev_log: 'info') end describe 'udev_log => debug' do - it_behaves_like('udev_log_param_redhat_5', 'debug', { :udev_log => 'debug' }) + it_behaves_like('udev_log_param_redhat_5', 'debug', udev_log: 'debug') end describe 'udev_log => invalid' do - let(:params) {{ :udev_log => 'invalid' }} + let(:params) { { udev_log: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev::udevadm::logpriority') - }.to raise_error(Puppet::Error, /does not match/) + is_expected.to contain_class('udev::udevadm::logpriority') + }.to raise_error(Puppet::Error, %r{does not match}) end end - end - end diff --git a/spec/classes/udevadm/trigger_spec.rb b/spec/classes/udevadm/trigger_spec.rb index 89308aa..9b9a4fd 100644 --- a/spec/classes/udevadm/trigger_spec.rb +++ b/spec/classes/udevadm/trigger_spec.rb @@ -1,39 +1,31 @@ require 'spec_helper' -describe 'udev::udevadm::trigger', :type => :class do - +describe 'udev::udevadm::trigger', type: :class do describe 'for osfamily RedHat' do let(:facts) do - { :osfamily => 'RedHat', - :operatingsystemmajrelease => '6', - :operatingsystem => 'RedHat', - } + { osfamily: 'RedHat', + operatingsystemmajrelease: '6', + operatingsystem: 'RedHat' } end - it { should contain_class('udev::udevadm::trigger') } + it { is_expected.to contain_class('udev::udevadm::trigger') } it do - should contain_exec('udevadm trigger --action=change').with({ - :refreshonly => true, - :path => ['/sbin'], - }) + is_expected.to contain_exec('udevadm trigger --action=change').with(refreshonly: true, + path: ['/sbin']) end end describe 'for osfamily RedHat' do let(:facts) do - { :osfamily => 'RedHat', - :operatingsystemmajrelease => '5', - :operatingsystem => 'RedHat', - } + { osfamily: 'RedHat', + operatingsystemmajrelease: '5', + operatingsystem: 'RedHat' } end - it { should contain_class('udev::udevadm::trigger') } + it { is_expected.to contain_class('udev::udevadm::trigger') } it do - should contain_exec('udevtrigger').with({ - :refreshonly => true, - :path => ['/sbin'], - }) + is_expected.to contain_exec('udevtrigger').with(refreshonly: true, + path: ['/sbin']) end end - end diff --git a/spec/defines/rule_spec.rb b/spec/defines/rule_spec.rb index a3bd414..a39bc3d 100644 --- a/spec/defines/rule_spec.rb +++ b/spec/defines/rule_spec.rb @@ -1,33 +1,31 @@ require 'spec_helper' -describe 'udev::rule', :type => :define do - +describe 'udev::rule', type: :define do shared_examples 'generic_rule' do |title, state, params| let(:title) { title } let(:params) { params } it do - should contain_class('udev') - should contain_file("/etc/udev/rules.d/#{title}").with({ - :ensure => state, - :owner => 'root', - :group => 'root', - :mode => '0644', - :source => params[:source], - :content => params[:content], + is_expected.to contain_class('udev') + is_expected.to contain_file("/etc/udev/rules.d/#{title}").with( + ensure: state, + owner: 'root', + group: 'root', + mode: '0644', + source: params[:source], + content: params[:content], # XXX figure out how to properly test metaparams... #:notify => 'Class[Udev::Udevadm]{:name=>"Udev::Udevadm"}', - }) + ) end end - describe 'for osfamily RedHat' do let :facts do { - :osfamily => 'RedHat', - :operatingsystemmajrelease => '6', - :operatingsystem => 'RedHat', + osfamily: 'RedHat', + operatingsystemmajrelease: '6', + operatingsystem: 'RedHat', } end @@ -36,7 +34,7 @@ 'generic_rule', '99-foo.rules', 'present', - { :content => 'foo' } + content: 'foo', ) end @@ -45,7 +43,7 @@ 'generic_rule', '99-foo.rules', 'present', - { :ensure => 'present', :content => 'foo' } + ensure: 'present', content: 'foo', ) end @@ -54,7 +52,7 @@ 'generic_rule', '99-foo.rules', 'present', - { :source => 'foo' } + source: 'foo', ) end @@ -63,7 +61,7 @@ 'generic_rule', '99-foo.rules', 'present', - { :ensure => 'present', :source => 'foo' } + ensure: 'present', source: 'foo', ) end @@ -72,19 +70,17 @@ 'generic_rule', '99-foo.rules', 'absent', - { - :ensure => 'absent', - } + ensure: 'absent', ) end describe 'no params' do let(:title) { '99-foo.rules' } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /parameter \$source or \$content is required/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{parameter \$source or \$content is required}) end end @@ -92,15 +88,15 @@ let(:title) { '99-foo.rules' } let :params do { - :content => 'foo', - :source => 'foo', + content: 'foo', + source: 'foo', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /parameters \$source and \$content are mutually exclusive/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{parameters \$source and \$content are mutually exclusive}) end end @@ -108,51 +104,50 @@ let(:title) { '99-foo.rules' } let :params do { - :ensure => 'absent', - :content => 'foo', - :source => 'foo', + ensure: 'absent', + content: 'foo', + source: 'foo', } end - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /parameters \$source and \$content are mutually exclusive/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{parameters \$source and \$content are mutually exclusive}) end end describe 'ensure => invalid' do let(:title) { '99-foo.rules' } - let(:params) {{ :ensure => 'invalid' }} + let(:params) { { ensure: 'invalid' } } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /does not match/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{does not match}) end end describe 'content => true' do let(:title) { '99-foo.rules' } - let(:params) {{ :content => true }} + let(:params) { { content: true } } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /is not a string/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{is not a string}) end end describe 'source => true' do let(:title) { '99-foo.rules' } - let(:params) {{ :source => true }} + let(:params) { { source: true } } - it 'should fail' do + it 'fails' do expect { - should contain_class('udev') - }.to raise_error(Puppet::Error, /is not a string/) + is_expected.to contain_class('udev') + }.to raise_error(Puppet::Error, %r{is not a string}) end end - end end From aa58f6a1234f1c07882474de1a4b0b73d3277c21 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 13:42:11 +0200 Subject: [PATCH 5/8] Fix puppet style (puppet-lint) --- manifests/init.pp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 6412c73..954028d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -27,11 +27,11 @@ validate_re($udev_log, '^err$|^info$|^debug$') validate_bool($config_file_replace) - anchor { 'udev:begin': } -> - package{ $udev::params::udev_package: + anchor { 'udev:begin': } + -> package{ $udev::params::udev_package: ensure => present, - } -> - file { '/etc/udev/udev.conf': + } + -> file { '/etc/udev/udev.conf': ensure => file, content => template("${module_name}/udev.conf.erb"), owner => 'root', @@ -39,16 +39,16 @@ mode => '0644', replace => $config_file_replace, notify => Class['udev::udevadm::logpriority'], - } -> - anchor { 'udev:end': } + } + -> anchor { 'udev:end': } - Anchor['udev:begin'] -> - class { 'udev::udevadm::trigger': } -> - Anchor['udev:end'] + Anchor['udev:begin'] + -> class { 'udev::udevadm::trigger': } + -> Anchor['udev:end'] - Anchor['udev:begin'] -> - class { 'udev::udevadm::logpriority': udev_log => $udev_log } -> - Anchor['udev:end'] + Anchor['udev:begin'] + -> class { 'udev::udevadm::logpriority': udev_log => $udev_log } + -> Anchor['udev:end'] if $rules { create_resources('udev::rule', $rules) From 08ea15428b5828c2d041c32c56de9effd2f009be Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 15:26:51 +0200 Subject: [PATCH 6/8] Bump supported puppet version >= 5.5.0 (drop 4) --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 166adaf..9bc023e 100644 --- a/metadata.json +++ b/metadata.json @@ -56,7 +56,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 4.10.0 < 7.0.0" + "version_requirement": ">= 5.5.0 < 7.0.0" } ], "pdk-version": "1.18.1", From 23c5c41b1b62cf40083f0d3b366ef128798d583d Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 15:47:50 +0200 Subject: [PATCH 7/8] Cleanup old acceptance tests nodesets --- spec/acceptance/nodesets/centos-6-docker.yml | 14 --------- .../nodesets/centos-7-docker.Dockerfile | 29 ------------------- spec/acceptance/nodesets/centos-7-docker.yml | 11 ------- .../nodesets/ubuntu-14.04-docker.yml | 13 --------- 4 files changed, 67 deletions(-) delete mode 100644 spec/acceptance/nodesets/centos-6-docker.yml delete mode 100644 spec/acceptance/nodesets/centos-7-docker.Dockerfile delete mode 100644 spec/acceptance/nodesets/centos-7-docker.yml delete mode 100644 spec/acceptance/nodesets/ubuntu-14.04-docker.yml diff --git a/spec/acceptance/nodesets/centos-6-docker.yml b/spec/acceptance/nodesets/centos-6-docker.yml deleted file mode 100644 index 77306a6..0000000 --- a/spec/acceptance/nodesets/centos-6-docker.yml +++ /dev/null @@ -1,14 +0,0 @@ -HOSTS: - centos-6-x64: - platform: el-6-x86_64 - hypervisor : docker - image: centos:6 - docker_preserve_image: true - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - 'yum install -y crontabs tar wget' - default_apply_opts: - disable_warnings: deprecations -CONFIG: - type: foss - log_level: debug diff --git a/spec/acceptance/nodesets/centos-7-docker.Dockerfile b/spec/acceptance/nodesets/centos-7-docker.Dockerfile deleted file mode 100644 index 5c2ed31..0000000 --- a/spec/acceptance/nodesets/centos-7-docker.Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -FROM centos:7 -ENV container docker - -# beaker default behavior -RUN yum clean all -RUN yum install -y sudo openssh-server openssh-clients curl ntpdate -RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -RUN mkdir -p /var/run/sshd -RUN echo root:root | chpasswd -RUN sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config -RUN sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config -RUN yum install -y crontabs tar wget -EXPOSE 22 - -# based on https://github.com/slafs/dockerfiles/blob/master/centos7-systemd/Dockerfile -RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs -RUN systemctl mask dev-mqueue.mount dev-hugepages.mount \ - systemd-remount-fs.service sys-kernel-config.mount \ - sys-kernel-debug.mount sys-fs-fuse-connections.mount \ - display-manager.service systemd-logind.service -RUN systemctl disable graphical.target; systemctl enable multi-user.target -RUN systemctl enable sshd.service -VOLUME ["/sys/fs/cgroup"] - -# provides /usr/sbin/service required by the service redhat provider -RUN yum install -y initscripts - -CMD ["/usr/lib/systemd/systemd"] diff --git a/spec/acceptance/nodesets/centos-7-docker.yml b/spec/acceptance/nodesets/centos-7-docker.yml deleted file mode 100644 index 1223f52..0000000 --- a/spec/acceptance/nodesets/centos-7-docker.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - centos-7-x64: - platform: el-7-x86_64 - hypervisor : docker - docker_preserve_image: true - dockerfile: spec/acceptance/nodesets/centos-7-docker.Dockerfile - default_apply_opts: - disable_warnings: deprecations -CONFIG: - type: foss - log_level: debug diff --git a/spec/acceptance/nodesets/ubuntu-14.04-docker.yml b/spec/acceptance/nodesets/ubuntu-14.04-docker.yml deleted file mode 100644 index 691c1b1..0000000 --- a/spec/acceptance/nodesets/ubuntu-14.04-docker.yml +++ /dev/null @@ -1,13 +0,0 @@ -HOSTS: - ubuntu-14.04-x64: - platform: ubuntu-14.04-amd64 - hypervisor : docker - #image: ubuntu:14.04 - image: electrical/ubuntu:14.04 - docker_preserve_image: true - docker_cmd: '["/sbin/init"]' - default_apply_opts: - disable_warnings: deprecations -CONFIG: - type: foss - log_level: debug From 6eb47568c90e27ebc0736adc8f871fdb5c1aae52 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Fri, 25 Sep 2020 15:49:32 +0200 Subject: [PATCH 8/8] Disable acceptance tests on el8 --- .sync.yml | 2 +- .travis.yml | 22 ---------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/.sync.yml b/.sync.yml index b8732e5..bbc01cd 100644 --- a/.sync.yml +++ b/.sync.yml @@ -8,4 +8,4 @@ - ---travis_el - travis_el6 - travis_el7 - - travis_el8 + # - travis_el8 # Uncomment after adding el8 support and run pdk update diff --git a/.travis.yml b/.travis.yml index d40e2fc..9171513 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,17 +71,6 @@ jobs: script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el8]'" - - "bundle exec rake 'litmus:install_agent[puppet5]'" - - "bundle exec rake litmus:install_module" - bundler_args: - env: PLATFORMS=travis_el8_puppet5 - rvm: 2.5.7 - script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - before_script: - "bundle exec rake 'litmus:provision_list[travis_deb]'" @@ -126,17 +115,6 @@ jobs: script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] services: docker stage: acceptance - - - before_script: - - "bundle exec rake 'litmus:provision_list[travis_el8]'" - - "bundle exec rake 'litmus:install_agent[puppet6]'" - - "bundle exec rake litmus:install_module" - bundler_args: - env: PLATFORMS=travis_el8_puppet6 - rvm: 2.5.7 - script: ["travis_wait 45 bundle exec rake litmus:acceptance:parallel"] - services: docker - stage: acceptance - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" stage: static