diff --git a/.gitignore b/.gitignore index fd2146b..68b1366 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,21 @@ -.*.sw? -pkg -spec/fixtures/* -!spec/fixtures/hiera* -.rspec_system -.vagrant -.bundle -vendor -.idea +.*.sw[op] +.metadata +.yardoc +.yardwarns *.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store diff --git a/.rspec b/.rspec index 8c18f1a..16f9cdb 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ ---format documentation --color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..40a58e0 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,107 @@ +--- +require: rubocop-rspec +AllCops: + DisplayCopNames: true + TargetRubyVersion: '2.1' + Include: + - "./**/*.rb" + Exclude: + - bin/* + - ".vendor/**/*" + - Gemfile + - Rakefile + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* +Metrics/LineLength: + Description: People have wide screens, use them. + Max: 200 +RSpec/BeforeAfterAll: + Description: Beware of using after(:all) as it may cause state to leak between tests. + A necessary evil in acceptance testing. + Exclude: + - spec/acceptance/**/*.rb +RSpec/HookArgument: + Description: Prefer explicit :each argument, matching existing module's style + EnforcedStyle: each +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/CollectionMethods: + Enabled: true +Style/MethodCalledOnDoEndBlock: + Enabled: true +Style/StringMethods: + Enabled: true +Layout/EndOfLine: + 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 100644 index 0000000..ab23260 --- /dev/null +++ b/.sync.yml @@ -0,0 +1,20 @@ +--- +Gemfile: + required: + ':development': + - gem: hiera-eyaml +spec/spec_helper.rb: + mock_with: ':mocha' + hiera_config: "'spec/fixtures/hiera.yaml'" +.gitlab-ci.yml: + delete: true +.pdkignore: + delete: true +.project: + delete: true +.travis.yml: + delete: true +appveyor.yml: + delete: true +.gitignore: + unmanaged: true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0f259d1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -language: ruby -bundler_args: --without development system_tests -before_install: rm Gemfile.lock || true -rvm: - - 2.1.0 - - 2.2.0 -script: bundle exec rake test -env: - - PUPPET_VERSION="~> 4.5.0" STRICT_VARIABLES=yes -matrix: - exclude: - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 4.5.0" 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 942a170..b675bb5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,26 +1,80 @@ -source "https://rubygems.org" - -gem "hiera-eyaml" - -group :test do - gem "rake" - gem "puppet", ENV['PUPPET_VERSION'] || '~> 4.5.0' - gem "rspec", '< 3.2.0' - gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git' - gem "puppetlabs_spec_helper" - gem "metadata-json-lint" - gem "rspec-puppet-facts" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +def location_for(place_or_version, fake_version = nil) + if place_or_version =~ %r{\A(git[:@][^#]*)#(.*)} + [fake_version, { git: Regexp.last_match(1), branch: Regexp.last_match(2), require: false }].compact + elsif place_or_version =~ %r{\Afile:\/\/(.*)} + ['>= 0', { path: File.expand_path(Regexp.last_match(1)), require: false }] + else + [place_or_version, { require: false }] + end +end + +def gem_type(place_or_version) + if place_or_version =~ %r{\Agit[:@]} + :git + elsif !place_or_version.nil? && place_or_version.start_with?('file:') + :file + else + :gem + end end +ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments +minor_version = ruby_version_segments[0..1].join('.') + group :development do -# gem "travis" -# gem "travis-lint" -# gem "vagrant-wrapper" -# gem "puppet-blacksmith" -# gem "guard-rake" + 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::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4') + 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 "puppet-blacksmith", '~> 3.4', require: false, platforms: [:ruby] + gem "hiera-eyaml", require: false +end + +puppet_version = ENV['PUPPET_GEM_VERSION'] +puppet_type = gem_type(puppet_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 :system_tests do - gem "beaker" - gem "beaker-rspec" +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/Gemfile.lock b/Gemfile.lock index 9a27a91..66e3a7e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,142 +1,184 @@ -GIT - remote: https://github.com/rodjek/rspec-puppet.git - revision: 68c2bcb7e6127e85066aba5ad7018a0b4b044c81 - specs: - rspec-puppet (2.4.0) - rspec - GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.2.8) - beaker (1.0.0) - blimpy - fission - inifile - json - net-scp - net-ssh - nokogiri (= 1.5.10) - rbvmomi - unf - beaker-rspec (2.0.0) - beaker - rspec - blimpy (0.6.7) - fog - minitar - thor - builder (3.2.2) - diff-lcs (1.2.5) - excon (0.31.0) - facter (2.4.6) - CFPropertyList (~> 2.2.6) - facterdb (0.3.6) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ast (2.4.0) + coderay (1.1.2) + diff-lcs (1.3) + docile (1.3.1) + domain_name (0.5.20180417) + unf (>= 0.0.5, < 1.0.0) + facter (2.5.1) + facterdb (0.5.2) facter jgrep - fission (0.5.0) - CFPropertyList (~> 2.2) - fog (1.19.0) - builder - excon (~> 0.31.0) - formatador (~> 0.2.0) - mime-types - multi_json (~> 1.0) - net-scp (~> 1.1) - net-ssh (>= 2.1.3) - nokogiri (~> 1.5) - ruby-hmac - formatador (0.2.5) - hiera (3.2.1) + fast_gettext (1.1.2) + gettext (3.2.9) + locale (>= 2.0.5) + text (>= 1.3.0) + gettext-setup (0.30) + fast_gettext (~> 1.1.0) + gettext (>= 3.0.2) + locale + hiera (3.4.3) hiera-eyaml (2.1.0) highline (~> 1.6.19) trollop (~> 2.0) highline (1.6.21) - inifile (3.0.0) - jgrep (1.4.1) - json - json (2.0.2) - json_pure (2.0.2) - mcollective-client (2.9.0) + http-cookie (1.0.3) + domain_name (~> 0.5) + jgrep (1.5.0) + json (2.0.4) + json-schema (2.8.0) + addressable (>= 2.4) + locale (2.1.2) + mcollective-client (2.12.1) json stomp systemu metaclass (0.0.4) - metadata-json-lint (0.0.11) - json + metadata-json-lint (2.1.0) + json-schema (~> 2.8) spdx-licenses (~> 1.0) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - minitar (0.5.4) + method_source (0.8.2) + mime-types (2.99.3) mocha (1.1.0) metaclass (~> 0.0.1) - multi_json (1.12.1) + multi_json (1.13.1) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (3.2.0) - nokogiri (1.5.10) - puppet (4.5.3) - CFPropertyList (~> 2.2.6) - facter (> 2.0, < 4) - hiera (>= 2.0, < 4) - json_pure - puppet-lint (2.0.2) - puppet-syntax (2.1.0) + net-ssh (4.2.0) + net-telnet (0.1.1) + netrc (0.11.0) + parallel (1.12.1) + parallel_tests (2.14.2) + parallel + parser (2.5.1.0) + ast (~> 2.4.0) + powerpack (0.1.1) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + public_suffix (3.0.2) + puppet (5.5.1) + facter (> 2.0.1, < 4) + fast_gettext (~> 1.1.2) + hiera (>= 3.2.1, < 4) + locale (~> 2.1) + multi_json (~> 1.10) + puppet-blacksmith (3.4.0) + puppet (>= 2.7.16) + rest-client (~> 1.8.0) + puppet-lint (2.3.5) + puppet-module-posix-default-r2.4 (0.3.3) + puppet-module-posix-dev-r2.4 (0.3.3) + gettext-setup (~> 0.26) + metadata-json-lint (>= 2.0.2, < 3.0.0) + mocha (>= 1.0.0, < 1.2.0) + parallel_tests (>= 2.14.1, < 2.14.3) + pry (~> 0.10.4) + puppet-blacksmith (>= 3.4.0) + puppet-lint (>= 2.3.0, < 3.0.0) + puppet-syntax (>= 2.4.1, < 3.0.0) + puppet_pot_generator (~> 1.0) + puppetlabs_spec_helper (>= 2.7.0, < 3.0.0) + rainbow (~> 2.0) + rspec-puppet (>= 2.3.2, < 3.0.0) + rspec-puppet-facts (~> 1.8) + rspec_junit_formatter (~> 0.2) + rubocop (~> 0.49.0) + rubocop-i18n (~> 1.2.0) + rubocop-rspec (~> 1.16.0) + simplecov (>= 0.14.1, < 1.0.0) + specinfra (= 2.67.3) + puppet-syntax (2.4.1) rake - puppetlabs_spec_helper (1.2.2) + puppet_pot_generator (1.0.1) + puppet + puppetlabs_spec_helper (2.8.0) mocha (~> 1.0) puppet-lint (~> 2.0) puppet-syntax (~> 2.0) rspec-puppet (~> 2.0) - rake (11.2.2) - rbvmomi (1.9.2) - builder (~> 3.2) - json (>= 1.8) - nokogiri (~> 1.5) - trollop (~> 2.1) - rspec (3.1.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) - rspec-core (3.1.7) - rspec-support (~> 3.1.0) - rspec-expectations (3.1.2) + rainbow (2.2.2) + rake + rake (12.3.1) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-mocks (3.1.3) - rspec-support (~> 3.1.0) - rspec-puppet-facts (1.6.1) + rspec-support (~> 3.7.0) + rspec-mocks (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-puppet (2.6.11) + rspec + rspec-puppet-facts (1.9.0) facter - facterdb (>= 0.3.0) + facterdb (>= 0.5.0) json mcollective-client puppet - rspec-support (3.1.2) - ruby-hmac (0.4.0) - spdx-licenses (1.1.0) - stomp (1.4.3) + rspec-support (3.7.1) + rspec_junit_formatter (0.4.1) + rspec-core (>= 2, < 4, != 2.12.0) + rubocop (0.49.1) + parallel (~> 1.10) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + rubocop-i18n (1.2.0) + rubocop (~> 0.49.0) + rubocop-rspec (1.16.0) + rubocop (>= 0.49.0) + ruby-progressbar (1.9.0) + sfl (2.3) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + slop (3.6.0) + spdx-licenses (1.2.0) + specinfra (2.67.3) + net-scp + net-ssh (>= 2.7, < 5.0) + net-telnet + sfl + stomp (1.4.4) systemu (2.6.5) - thor (0.19.1) + text (1.3.1) trollop (2.1.2) unf (0.1.4) unf_ext - unf_ext (0.0.7.2) + unf_ext (0.0.7.5) + unicode-display_width (1.3.3) PLATFORMS ruby DEPENDENCIES - beaker - beaker-rspec + fast_gettext hiera-eyaml - metadata-json-lint - puppet (~> 4.5.0) - puppetlabs_spec_helper - rake - rspec (< 3.2.0) - rspec-puppet! - rspec-puppet-facts + json (<= 2.0.4) + puppet + puppet-blacksmith (~> 3.4) + puppet-module-posix-default-r2.4 + puppet-module-posix-dev-r2.4 + puppet-module-win-default-r2.4 + puppet-module-win-dev-r2.4 BUNDLED WITH - 1.12.5 + 1.16.1 diff --git a/Rakefile b/Rakefile index 1778d2a..fb58663 100644 --- a/Rakefile +++ b/Rakefile @@ -1,56 +1,5 @@ require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet/version' -require 'puppet/vendor/semantic/lib/semantic' unless Puppet.version.to_f < 3.6 -require 'puppet-lint/tasks/puppet-lint' require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? -# These gems aren't always present, for instance -# on Travis with --without development -begin - require 'puppet_blacksmith/rake_tasks' -rescue LoadError -end - -Rake::Task[:lint].clear - -PuppetLint.configuration.relative = true -PuppetLint.configuration.send("disable_80chars") -PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" -PuppetLint.configuration.fail_on_warnings = true - -# Forsake support for Puppet 2.6.2 for the benefit of cleaner code. -# http://puppet-lint.com/checks/class_parameter_defaults/ -PuppetLint.configuration.send('disable_class_parameter_defaults') -# http://puppet-lint.com/checks/class_inherits_from_params_class/ -PuppetLint.configuration.send('disable_class_inherits_from_params_class') - -exclude_paths = [ - "bundle/**/*", - "pkg/**/*", - "vendor/**/*", - "spec/**/*", -] -PuppetLint.configuration.ignore_paths = exclude_paths -PuppetSyntax.exclude_paths = exclude_paths - -desc "Run acceptance tests" -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' -end - -desc "Populate CONTRIBUTORS file" -task :contributors do - system("git log --format='%aN' | sort -u > CONTRIBUTORS") -end - -task :metadata do - sh "metadata-json-lint metadata.json" -end - -desc "Run syntax, lint, and spec tests." -task :test => [ - :syntax, - :lint, - :spec, - :metadata, -] +PuppetLint.configuration.send('relative') diff --git a/metadata.json b/metadata.json index 94c50f9..ebaeb3e 100644 --- a/metadata.json +++ b/metadata.json @@ -1,16 +1,38 @@ { - "name": "UniversityOfWarwick-eyaml_tools", - "version": "1.0", - "author": "UniversityOfWarwick", + "name": "universityofwarwick-eyaml_tools", + "version": "2.0.0", + "author": "University of Warwick", "summary": "Exposes hiera-eyaml's decryption as Puppet functions.", - "license": "Apache 2.0", + "license": "proprietary", "source": "", - "project_page": "", - "issues_url": "", "dependencies": [ { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.0.0" + "name": "puppetlabs-stdlib", + "version_requirement": ">= 4.25.1 < 5.0.0" } - ] + ], + "operatingsystem_support": [ + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Solaris", + "operatingsystemrelease": [ + "11" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.7.0 < 6.0.0" + } + ], + "pdk-version": "1.5.0", + "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", + "template-ref": "1.5.0-0-gd1b3eca" } diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..3248be5 --- /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. +--- +concat_basedir: "/tmp" +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 0eddb72..2330d4d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,40 @@ +RSpec.configure do |c| + c.mock_with :mocha +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' + +begin + require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) +rescue LoadError => loaderror + warn "Could not require spec_helper_local: #{loaderror.message}" +end + include RspecPuppetFacts +default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version, +} + +default_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')) +default_module_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')) + +if File.exist?(default_facts_path) && File.readable?(default_facts_path) + default_facts.merge!(YAML.safe_load(File.read(default_facts_path))) +end + +if File.exist?(default_module_facts_path) && File.readable?(default_module_facts_path) + default_facts.merge!(YAML.safe_load(File.read(default_module_facts_path))) +end + RSpec.configure do |c| + c.default_facts = default_facts c.hiera_config = 'spec/fixtures/hiera.yaml' - c.parser = 'future' - - #Puppet.settings[:hiera_config] -end \ No newline at end of file + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + end +end