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 193793b..650022e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,60 +1,24 @@ -# Created by .ignore support plugin (hsz.mobi) -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/workspace.xml -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml - -# Sensitive or high-churn files: -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - -# Gradle: -.idea/gradle.xml -.idea/libraries - -# Mongo Explorer plugin: -.idea/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -pkg/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -coverage/ -log/ -.yardoc/ -doc/ +.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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ea59806 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,42 @@ +--- +stages: + - syntax + - unit + +cache: + paths: + - vendor/bundle + +before_script: + - bundle -v + - rm Gemfile.lock || true + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v + - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) + +parallel_spec-Ruby 2.1.9-Puppet ~> 4.0: + stage: unit + image: ruby:2.1.9 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 4.0' + RUBYGEMS_VERSION: '2.7.8' + +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.4.4-Puppet ~> 5.5: + stage: syntax + image: ruby:2.4.4 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 5.5' + +parallel_spec-Ruby 2.4.4-Puppet ~> 5.5: + stage: unit + image: ruby:2.4.4 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 5.5' + diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 0000000..b713b3b --- /dev/null +++ b/.pdkignore @@ -0,0 +1,37 @@ +.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 +/appveyor.yml +/.fixtures.yml +/Gemfile +/.gitattributes +/.gitignore +/.gitlab-ci.yml +/.pdkignore +/Rakefile +/.rspec +/.rubocop.yml +/.travis.yml +/.yardopts +/spec/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..38520df --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,2 @@ +--relative +--no-security_package_pinned_version-check 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..f5a6c2a --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,122 @@ +--- +require: rubocop-rspec +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/DecorateString: + Description: We don't want to decorate test output. + Exclude: + - spec/* +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/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 +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/.sync.yml b/.sync.yml new file mode 100755 index 0000000..3382e09 --- /dev/null +++ b/.sync.yml @@ -0,0 +1,50 @@ +--- + +mock_with: ':rspec' + +.gitlab-ci.yml: + bundler_args: | + --without system_tests --path vendor/bundle + cache: + key: "$CI_JOB_STAGE-$CI_COMMIT_REF_NAME" + paths: + - vendor/bundle + +.travis.yml: + bundler_args: --without system_tests + includes: + - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=no + branches: + - /^\d/ + deploy: false + +Gemfile: + required: + ':development': + - gem: travis + ':puppet_lint': + - gem: puppet-lint-absolute_classname-check + - gem: puppet-lint-absolute_template_path + - gem: puppet-lint-alias-check + - gem: puppet-lint-classes_and_types_beginning_with_digits-check + - gem: puppet-lint-duplicate_class_parameters-check + - gem: puppet-lint-empty_string-check + - gem: puppet-lint-extended + - gem: puppet-lint-file_ensure-check + - gem: puppet-lint-file_source_rights-check + - gem: puppet-lint-leading_zero-check + - gem: puppet-lint-numericvariable + - gem: puppet-lint-resource_reference_syntax + - gem: puppet-lint-security-plugins + - gem: puppet-lint-spaceship_operator_without_tag-check + - gem: puppet-lint-strict_indent-check + - gem: puppet-lint-trailing_comma-check + - gem: puppet-lint-trailing_newline-check + - gem: puppet-lint-undef_in_function-check + - gem: puppet-lint-unquoted_string-check + - gem: puppet-lint-variable_contains_upcase + - gem: puppet-lint-version_comparison-check + +Rakefile: + default_disabled_lint_checks: + - security_package_pinned_version \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 22e0ab4..7687b4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,37 @@ --- -sudo: false +dist: trusty language: ruby cache: bundler -script: "bundle exec rake validate lint spec" -#Inserting below due to the following issue: https://github.com/travis-ci/travis-ci/issues/3531#issuecomment-88311203 before_install: - - gem update bundler + - bundle -v + - rm -f Gemfile.lock + - gem update --system $RUBYGEMS_VERSION + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests +rvm: + - 2.5.1 +env: + global: + - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" matrix: fast_finish: true include: - - rvm: 2.3.4 - dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/ubuntu-16.04 - script: bundle exec rake beaker - services: docker - sudo: required - - rvm: 2.3.4 - dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/centos-7 - script: bundle exec rake beaker - services: docker - sudo: required - - rvm: 2.3.4 - bundler_args: --without system_tests - env: PUPPET_GEM_VERSION="~> 4.0" - - rvm: 2.4.1 - bundler_args: --without system_tests - env: PUPPET_GEM_VERSION="~> 5.0" + - + env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" + - + env: CHECK=parallel_spec + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.4 + - + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=no +branches: + only: + - master + - /^v\d/ + - /^\d/ notifications: email: false diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..6177782 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "jpogran.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..8c68e23 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## Release 0.4.1 + +**Features** + +**Bugfixes** + +**Known Issues** diff --git a/Gemfile b/Gemfile index c26ac3e..8c7489c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,49 +1,95 @@ -source 'https://rubygems.org' +source ENV['GEM_SOURCE'] || 'https://rubygems.org' -gem 'puppetlabs_spec_helper', :groups => [:test] -gem 'rspec-puppet-facts', :groups => [:test] +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} -if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', facterversion.to_s, :require => false, :groups => [:test] -else - gem 'facter', :require => false, :groups => [:test] + 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 -ENV['PUPPET_GEM_VERSION'].nil? ? puppetversion = '~> 4.0' : puppetversion = ENV['PUPPET_GEM_VERSION'].to_s -gem 'puppet', puppetversion, :require => false, :groups => [:test] +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') -gem 'puppet-lint', :require => false, :groups => [:development] -gem 'metadata-json-lint', :require => false, :groups => [:development], :platforms => 'ruby' -gem 'puppet-blacksmith', '>= 3.4.0', :require => false, :groups => [:development], :platforms => 'ruby' -gem 'semantic_puppet' +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 "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "travis", require: false +end +group :puppet_lint do + gem "puppet-lint-absolute_classname-check", require: false + gem "puppet-lint-absolute_template_path", require: false + gem "puppet-lint-alias-check", require: false + gem "puppet-lint-classes_and_types_beginning_with_digits-check", require: false + gem "puppet-lint-duplicate_class_parameters-check", require: false + gem "puppet-lint-empty_string-check", require: false + gem "puppet-lint-extended", require: false + gem "puppet-lint-file_ensure-check", require: false + gem "puppet-lint-file_source_rights-check", require: false + gem "puppet-lint-leading_zero-check", require: false + gem "puppet-lint-numericvariable", require: false + gem "puppet-lint-resource_reference_syntax", require: false + gem "puppet-lint-security-plugins", require: false + gem "puppet-lint-spaceship_operator_without_tag-check", require: false + gem "puppet-lint-strict_indent-check", require: false + gem "puppet-lint-trailing_comma-check", require: false + gem "puppet-lint-trailing_newline-check", require: false + gem "puppet-lint-undef_in_function-check", require: false + gem "puppet-lint-unquoted_string-check", require: false + gem "puppet-lint-variable_contains_upcase", require: false + gem "puppet-lint-version_comparison-check", require: false +end -# Find a location or specific version for a gem. place_or_version can be a -# version, which is most often used. It can also be git, which is specified as -# `git://somewhere.git#branch`. You can also use a file source location, which -# is specified as `file://some/location/on/disk`. -def location_for(place_or_version, fake_version = nil) - if place_or_version =~ /^(git[:@][^#]*)#(.*)/ - [fake_version, { :git => $1, :branch => $2, :require => false }].compact - elsif place_or_version =~ /^file:\/\/(.*)/ - ['>= 0', { :path => File.expand_path($1), :require => false }] - else - [place_or_version, { :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 + +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 -# Used for gem conditionals -supports_windows = false - -group :system_tests do - gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '~> 2.20') if supports_windows - gem 'beaker', *location_for(ENV['BEAKER_VERSION']) if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') and ! supports_windows - gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '< 3') if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.3.0') and ! supports_windows - gem 'beaker-pe', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') - gem 'beaker-rspec', :require => false - gem 'beaker-puppet_install_helper', :require => false - gem 'beaker-module_install_helper', :require => false - gem 'master_manipulator', :require => false - gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION']) - gem 'beaker-abs', *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1') - gem 'beaker-docker' +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params +end + +# Evaluate Gemfile.local and ~/.gemfile if they exist +extra_gemfiles = [ + "#{__FILE__}.local", + File.join(Dir.home, '.gemfile'), +] + +extra_gemfiles.each do |gemfile| + if File.file?(gemfile) && File.readable?(gemfile) + eval(File.read(gemfile), binding) + end end +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 7b3c711..28054d6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,77 @@ -require 'puppet-lint/tasks/puppet-lint' require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet_blacksmith/rake_tasks' +require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? +require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? +require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? + +def changelog_user + return unless Rake.application.top_level_tasks.include? "changelog" + returnVal = 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 || JSON.load(File.read('metadata.json'))['name'] + raise "unable to find the changelog_project in .sync.yml or the name 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 = 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') +PuppetLint.configuration.send('disable_security_package_pinned_version') + +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; GO LABEL THEM" + config.configure_sections = { + "Changed" => { + "prefix" => "### Changed", + "labels" => ["backwards-incompatible"], + }, + "Added" => { + "prefix" => "### Added", + "labels" => ["feature", "enhancement"], + }, + "Fixed" => { + "prefix" => "### Fixed", + "labels" => ["bugfix"], + }, + } + end +else + desc 'Generate a Changelog from GitHub' + task :changelog do + raise <= Gem::Version.new('2.2.2')" +EOM + end +end -PuppetLint.configuration.send('relative') -PuppetLint.configuration.send('disable_documentation') -PuppetLint.configuration.send('disable_single_quote_string_with_variables') \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..e10ba3b --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,55 @@ +--- +version: 1.1.x.{build} +branches: + only: + - master +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..ed97d53 --- /dev/null +++ b/data/common.yaml @@ -0,0 +1 @@ +--- diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..545fff3 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,21 @@ +--- +version: 5 + +defaults: # Used for any hierarchy level that omits these keys. + datadir: data # This path is relative to hiera.yaml's directory. + data_hash: yaml_data # Use the built-in YAML backend. + +hierarchy: + - name: "osfamily/major release" + paths: + # Used to distinguish between Debian and Ubuntu + - "os/%{facts.os.name}/%{facts.os.release.major}.yaml" + - "os/%{facts.os.family}/%{facts.os.release.major}.yaml" + # Used for Solaris + - "os/%{facts.os.family}/%{facts.kernelrelease}.yaml" + - name: "osfamily" + paths: + - "os/%{facts.os.name}.yaml" + - "os/%{facts.os.family}.yaml" + - name: 'common' + path: 'common.yaml' diff --git a/lib/puppet/provider/jmeter_plugin/jmeterplugins.rb b/lib/puppet/provider/jmeter_plugin/jmeterplugins.rb index d06c3c4..7bde0f0 100644 --- a/lib/puppet/provider/jmeter_plugin/jmeterplugins.rb +++ b/lib/puppet/provider/jmeter_plugin/jmeterplugins.rb @@ -26,7 +26,7 @@ def self.instances plugins.map do |name, _versions| plugin = { ensure: :present, - name: name + name: name, } resources << new(plugin) if plugin[:name] end diff --git a/metadata.json b/metadata.json index 3815c65..24839e5 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "dduvnjak-jmeter", - "version": "0.4.1", + "version": "0.5.0", "author": "dduvnjak", "summary": "Module for JMeter configuration", "license": "Apache-2.0", @@ -14,13 +14,7 @@ }, { "name": "puppet-archive", - "version_requirement": ">= 1.3.0 <= 2.0.0" - } - ], - "requirements": [ - { - "name": "puppet", - "version_requirement": ">= 4.7.1 < 6.0.0" + "version_requirement": ">= 1.3.0 <= 4.4.0" } ], "operatingsystem_support": [ @@ -53,5 +47,14 @@ "16.04" ] } - ] + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.7.1 < 6.0.0" + } + ], + "pdk-version": "1.17.0", + "template-url": "https://github.com/puppetlabs/pdk-templates#1.9.0", + "template-ref": "tags/1.9.0-0-g7281db5" } diff --git a/spec/classes/jmeter_spec.rb b/spec/classes/jmeter_spec.rb index 203a256..096f316 100644 --- a/spec/classes/jmeter_spec.rb +++ b/spec/classes/jmeter_spec.rb @@ -7,7 +7,7 @@ context 'on unsupported distributions' do let(:facts) do { - os: { name: 'Unsupported', family: 'Unsupported' } + os: { name: 'Unsupported', family: 'Unsupported' }, } end @@ -56,12 +56,12 @@ context 'jmeter::install' do it do is_expected.to contain_archive("/tmp/apache-jmeter-#{jmeter_version}.tgz").with( - 'source' => "http://archive.apache.org/dist/jmeter/binaries/apache-jmeter-#{jmeter_version}.tgz" + 'source' => "http://archive.apache.org/dist/jmeter/binaries/apache-jmeter-#{jmeter_version}.tgz", ) end it do is_expected.to contain_file('/usr/share/jmeter').with( - ensure: 'link' + ensure: 'link', ) end @@ -74,20 +74,20 @@ is_expected.to contain_archive("/usr/share/jmeter/lib/ext/jmeter-plugins-manager-#{plugin_manager_version}.jar").with( 'source' => "http://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-manager/#{plugin_manager_version}/jmeter-plugins-manager-#{plugin_manager_version}.jar", 'creates' => "/usr/share/jmeter/lib/ext/jmeter-plugins-manager-#{plugin_manager_version}.jar", - 'cleanup' => :false + 'cleanup' => :false, ) end it do is_expected.to contain_archive("/usr/share/jmeter/lib/cmdrunner-#{cmdrunner_version}.jar").with( 'source' => "http://search.maven.org/remotecontent?filepath=kg/apc/cmdrunner/#{cmdrunner_version}/cmdrunner-#{cmdrunner_version}.jar", 'creates' => "/usr/share/jmeter/lib/cmdrunner-#{cmdrunner_version}.jar", - 'cleanup' => :false + 'cleanup' => :false, ) end it do is_expected.to contain_exec('install_cmdrunner').with( 'command' => "java -cp /usr/share/jmeter/lib/ext/jmeter-plugins-manager-#{plugin_manager_version}.jar org.jmeterplugins.repository.PluginManagerCMDInstaller", - 'creates' => '/usr/share/jmeter/bin/PluginsManagerCMD.sh' + 'creates' => '/usr/share/jmeter/bin/PluginsManagerCMD.sh', ) end end @@ -97,19 +97,19 @@ { plugins: { 'foo' => { 'ensure' => 'present' }, - 'woozle' => { 'ensure' => 'absent' } - } + 'woozle' => { 'ensure' => 'absent' }, + }, } end it do is_expected.to contain_jmeter_plugin('foo').with( - 'ensure' => 'present' + 'ensure' => 'present', ) end it do is_expected.to contain_jmeter_plugin('woozle').with( - 'ensure' => 'absent' + 'ensure' => 'absent', ) end end @@ -121,7 +121,7 @@ it { is_expected.to contain_class('jmeter::service') } it do is_expected.to contain_service('jmeter').with( - 'ensure' => 'running', 'enable' => 'true' + 'ensure' => 'running', 'enable' => 'true', ) end end @@ -137,7 +137,7 @@ it do is_expected.to contain_file('/etc/systemd/system/jmeter.service').with_content( - %r{\s-Djava.rmi.server.hostname=10\.5\.32\.9\s} + %r{\s-Djava.rmi.server.hostname=10\.5\.32\.9\s}, ) end end @@ -147,7 +147,7 @@ it do is_expected.to contain_file('/etc/systemd/system/jmeter.service').with_content( - %r{\s-Dserver_port=8832\s} + %r{\s-Dserver_port=8832\s}, ) end end @@ -164,7 +164,7 @@ it do is_expected.to contain_file('/etc/init.d/jmeter').with_content( - %r{\s-Djava.rmi.server.hostname=10\.5\.32\.9\s} + %r{\s-Djava.rmi.server.hostname=10\.5\.32\.9\s}, ) end end @@ -174,7 +174,7 @@ it do is_expected.to contain_file('/etc/init.d/jmeter').with_content( - %r{\s-Dserver_port=8832\s} + %r{\s-Dserver_port=8832\s}, ) end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..ea1e480 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,7 @@ +# 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" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1ffdf17..7dfbc49 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,51 @@ +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))) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end +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 + end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + end +end + +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/spec/unit/puppet/provider/jmeter_plugin/jmeterplugins.rb b/spec/unit/puppet/provider/jmeter_plugin/jmeterplugins.rb index cc0a8cf..1349aed 100644 --- a/spec/unit/puppet/provider/jmeter_plugin/jmeterplugins.rb +++ b/spec/unit/puppet/provider/jmeter_plugin/jmeterplugins.rb @@ -34,9 +34,9 @@ at org.jmeterplugins.repository.PluginManagerCMD.processParams(PluginManagerCMD.java:52) at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:66) EOT - expect do + expect { provider_class.instances - end.to raise_error(Puppet::Error, %r{Cannot get plugin status}) + }.to raise_error(Puppet::Error, %r{Cannot get plugin status}) end it 'calls jmeterplugins to create' do diff --git a/spec/unit/puppet/type/jmeter_plugin_spec.rb b/spec/unit/puppet/type/jmeter_plugin_spec.rb index f347210..2e2ebb8 100644 --- a/spec/unit/puppet/type/jmeter_plugin_spec.rb +++ b/spec/unit/puppet/type/jmeter_plugin_spec.rb @@ -9,13 +9,13 @@ expect(plugin[:name]).to eq('plugin-name') end it 'requires a name' do - expect do + expect { Puppet::Type.type(:jmeter_plugin).new({}) - end.to raise_error(Puppet::Error, 'Title or name must be provided') + }.to raise_error(Puppet::Error, 'Title or name must be provided') end it 'does not allow invalid names to be specified' do - expect do + expect { plugin[:name] = 'this has a space' - end.to raise_error(Puppet::Error, %r{Parameter name failed on Jmeter_plugin}) + }.to raise_error(Puppet::Error, %r{Parameter name failed on Jmeter_plugin}) end end