From 7f53800a944e2516eb73b859bc24ce5ec7c48d70 Mon Sep 17 00:00:00 2001 From: Tony Green Date: Mon, 7 Jan 2019 15:20:02 +1100 Subject: [PATCH 1/2] pdk updates --- .gitattributes | 1 + .gitignore | 1 - .rubocop.yml | 8 ++++-- .travis.yml | 60 ++++++++++++++++++++++++++++-------------- Gemfile | 22 +++++----------- Rakefile | 1 + appveyor.yml | 11 ++++++++ metadata.json | 6 ++--- spec/default_facts.yml | 1 - spec/spec_helper.rb | 28 ++++++++++---------- 10 files changed, 83 insertions(+), 56 deletions(-) diff --git a/.gitattributes b/.gitattributes index 543dd6ad..9032a014 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ *.erb eol=lf *.pp eol=lf *.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore index 35e28b47..650022e5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,3 @@ /convert_report.txt /update_report.txt .DS_Store -.Puppetfile.pdqtest diff --git a/.rubocop.yml b/.rubocop.yml index 40e28503..f5a6c2a4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,6 +19,10 @@ AllCops: 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. @@ -49,7 +53,7 @@ Style/Lambda: EnforcedStyle: literal Style/RegexpLiteral: Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 - EnforcedStyle: mixed + 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 @@ -64,7 +68,7 @@ Style/TrailingCommaInLiteral: and re-ordering nicer. EnforcedStyleForMultiline: comma Style/SymbolArray: - Description: Using style obscures symbolic intent of array's contents. + Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets RSpec/MessageSpies: EnforcedStyle: receive diff --git a/.travis.yml b/.travis.yml index 6890af43..6664271c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,47 @@ -# .travis.yml -# -# To debug travis locally: -# https://docs.travis-ci.com/user/common-build-problems/#Running-a-Container-Based-Docker-Image-Locally --- sudo: false - -# Don't process the PDK Gemfile - causes big problems! -gemfile: .pdqtest/Gemfile - -bundler_args: --path .pdqtest +dist: trusty language: ruby -services: - - docker cache: bundler before_install: - - wget https://apt.puppetlabs.com/puppet5-release-trusty.deb - - sudo dpkg -i puppet5-release-trusty.deb - - sudo apt-get update - - sudo apt install -y pdk - -# travis itself does the bundle isntall for us, so we are ready to run now + - bundle -v + - rm -f Gemfile.lock + - gem update --system + - gem --version + - bundle -v script: - - make setup - - make + - 'bundle exec rake $CHECK' +bundler_args: --without system_tests rvm: - - 2.4.1 + - 2.5.1 +env: + global: + - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" +matrix: + fast_finish: true + include: + - + 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="~> 4.0" CHECK=parallel_spec + rvm: 2.1.9 +branches: + only: + - master + - /^v\d/ +notifications: + email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "" + on: + tags: true + all_branches: true + condition: "$DEPLOY_TO_FORGE = yes" diff --git a/Gemfile b/Gemfile index 5cda86e3..626d661b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,22 +1,15 @@ 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 + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} -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 + 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 - :gem + [place_or_version, { require: false }] end end @@ -36,7 +29,6 @@ group :development do 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'] diff --git a/Rakefile b/Rakefile index 204fb18c..a6b14c56 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ 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? def changelog_user return unless Rake.application.top_level_tasks.include? "changelog" diff --git a/appveyor.yml b/appveyor.yml index 4a5b2275..f14e28d9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,8 @@ --- version: 1.1.x.{build} +branches: + only: + - master skip_commits: message: /^\(?doc\)?.*/ clone_depth: 10 @@ -30,6 +33,14 @@ environment: 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: diff --git a/metadata.json b/metadata.json index ac8ea911..0f413fb5 100644 --- a/metadata.json +++ b/metadata.json @@ -64,7 +64,7 @@ "version_requirement": ">= 5.3.2 < 6.0.0" } ], - "pdk-version": "1.7.0", + "pdk-version": "1.8.0", "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", - "template-ref": "1.7.0-0-g57412ed" -} + "template-ref": "1.8.0-0-g0d9da00" +} \ No newline at end of file diff --git a/spec/default_facts.yml b/spec/default_facts.yml index 3248be5a..ea1e4808 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -2,7 +2,6 @@ # # 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 5e721b7f..35654b3d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,7 @@ 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 +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) include RspecPuppetFacts @@ -14,15 +10,19 @@ 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')) +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')), +] -if File.exist?(default_facts_path) && File.readable?(default_facts_path) - default_facts.merge!(YAML.safe_load(File.read(default_facts_path))) -end +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) -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))) + 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| @@ -36,8 +36,8 @@ 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) - last_module.const_get(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 From 7513454f4817bea9ccad9136d91fbbeba6e2a4ab Mon Sep 17 00:00:00 2001 From: Tony Green Date: Mon, 7 Jan 2019 15:49:12 +1100 Subject: [PATCH 2/2] pdq and rubocop fixen --- .rubocop.yml | 4 +++- lib/facter/os_patching.rb | 10 ++++++---- spec/mock/facts_face.rb | 24 ++++++++++++++---------- tasks/clean_cache.rb | 2 +- tasks/patch_server.rb | 9 ++++----- tasks/refresh_fact.rb | 3 +-- 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f5a6c2a4..c1fd409d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -53,7 +53,7 @@ Style/Lambda: EnforcedStyle: literal Style/RegexpLiteral: Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 - EnforcedStyle: percent_r + EnforcedStyle: mixed Style/TernaryParentheses: Description: Checks for use of parentheses around ternary conditions. Enforce parentheses on complex expressions for better readability, but seriously consider breaking @@ -82,6 +82,8 @@ Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: Enabled: true +Style/HashSyntax: + Enabled: false Style/StringMethods: Enabled: true Layout/EndOfLine: diff --git a/lib/facter/os_patching.rb b/lib/facter/os_patching.rb index e1956b71..837a4dd1 100644 --- a/lib/facter/os_patching.rb +++ b/lib/facter/os_patching.rb @@ -9,7 +9,7 @@ end else Facter.add('os_patching', :type => :aggregate) do - confine { Facter.value(:kernel) == 'windows' or Facter.value(:kernel) == 'Linux' } + confine { Facter.value(:kernel) == 'windows' || Facter.value(:kernel) == 'Linux' } require 'time' now = Time.now.iso8601 warnings = {} @@ -32,7 +32,7 @@ updates = File.open(updatefile, 'r').read updates.each_line do |line| next unless line =~ /[A-Za-z0-9]+/ - next if line.match(/^#|^$/) + next if line =~ /^#|^$/ line.sub! 'Title : ', '' updatelist.push line.chomp end @@ -55,7 +55,7 @@ secupdates = File.open(secupdatefile, 'r').read secupdates.each_line do |line| next if line.empty? - next if line.match(/^#|^$/) + next if line =~ /^#|^$/ secupdatelist.push line.chomp end else @@ -77,9 +77,10 @@ blackouts = File.open(blackoutfile, 'r').read blackouts.each_line do |line| next if line.empty? - next if line.match(/^#|^$/) + next if line =~ /^#|^$/ matchdata = line.match(/^([\w ]*),(\d{,4}-\d{1,2}-\d{1,2}T\d{,2}:\d{,2}:\d{,2}\+\d{,2}:\d{,2}),(\d{,4}-\d{1,2}-\d{1,2}T\d{,2}:\d{,2}:\d{,2}[-\+]\d{,2}:\d{,2})$/) if matchdata + # rubocop:disable Metrics/BlockNesting arraydata[matchdata[1]] = {} unless arraydata[matchdata[1]] if matchdata[2] > matchdata[3] arraydata[matchdata[1]]['start'] = 'Start date after end date' @@ -94,6 +95,7 @@ data['blocked'] = true data['blocked_reasons'].push matchdata[1] end + # rubocop:enable Metrics/BlockNesting else warnings['blackouts'] = "Invalid blackout entry : #{line}" data['blocked'] = true diff --git a/spec/mock/facts_face.rb b/spec/mock/facts_face.rb index 6f75bf31..f12c8e90 100644 --- a/spec/mock/facts_face.rb +++ b/spec/mock/facts_face.rb @@ -5,10 +5,10 @@ require 'puppet/node/facts' Puppet::Indirector::Face.define(:facts, '0.0.1') do - copyright "Puppet Inc.", 2011 - license _("Apache 2 license; see COPYING") + copyright 'Puppet Inc.', 2011 + license _('Apache 2 license; see COPYING') - summary _("Retrieve and store facts.") + summary _('Retrieve and store facts.') description <<-'EOT' This subcommand manages facts, which are collections of normalized system information used by Puppet. It can read facts directly from the local system @@ -16,10 +16,10 @@ EOT find = get_action(:find) - find.summary _("Retrieve a node's facts.") - find.arguments _("[]") + find.summary _('Retrieve a nodes facts.') + find.arguments _('[]') find.returns <<-'EOT' - A hash containing some metadata and (under the "values" key) the set + A hash containing some metadata and (under the 'values' key) the set of facts for the requested node. When used from the Ruby API: A Puppet::Node::Facts object. @@ -40,12 +40,12 @@ deactivate_action(:search) action(:upload) do - summary _("Upload local facts to the puppet master.") + summary _('Upload local facts to the puppet master.') description <<-'EOT' Reads facts from the local system using the `facter` terminus, then saves the returned facts using the rest terminus. EOT - returns "Nothing." + returns 'Nothing.' notes <<-'EOT' This action requires that the puppet master's `auth.conf` file allow `PUT` or `save` access to the `/puppet/v3/facts` API endpoint. @@ -66,7 +66,9 @@ render_as :json + # rubocop:disable Lint/UnusedBlockArgument when_invoked do |options| + # rubocop:enable Lint/UnusedBlockArgument # Use `agent` sections settings for certificates, Puppet Server URL, # etc. instead of `user` section settings. Puppet.settings.preferred_run_mode = :agent @@ -80,13 +82,15 @@ Puppet::Node::Facts.indirection.terminus_class = :rest server = Puppet::Node::Facts::Rest.server + # rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/MultilineHashBraceLayout, Layout/IndentHash Puppet.notice(_("Uploading facts for '%{node}' to: '%{server}'") % { node: Puppet[:node_name_value], server: server}) + # rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/MultilineHashBraceLayout, Layout/IndentHash - Puppet.notice("Not really uploading facts (JKS - LOL) - mock version!") + Puppet.notice('Not really uploading facts (JKS - LOL) - mock version!') # do not upload to non-existant puppet server - #Puppet::Node::Facts.indirection.save(facts) + # Puppet::Node::Facts.indirection.save(facts) end end end diff --git a/tasks/clean_cache.rb b/tasks/clean_cache.rb index b4e9d0d0..5429310f 100755 --- a/tasks/clean_cache.rb +++ b/tasks/clean_cache.rb @@ -75,5 +75,5 @@ def err(code, kind, message, starttime) # Clean that cache! clean_out, stderr, status = Open3.capture3(clean_cache) err(status, 'os_patching/clean_cache', stderr, starttime) if status != 0 -output(status,'Cache cleaned',clean_out,starttime) +output(status, 'Cache cleaned', clean_out, starttime) log.info 'Cache cleaned' diff --git a/tasks/patch_server.rb b/tasks/patch_server.rb index a928ccfe..2c404b11 100755 --- a/tasks/patch_server.rb +++ b/tasks/patch_server.rb @@ -66,7 +66,7 @@ def run_with_timeout(command, timeout, tick) stderrout.close if stderrout status = thread.value.exitstatus end - return status, output + [status, output] end # Default output function @@ -157,9 +157,9 @@ def reboot_required(family, release, reboot) begin raw = STDIN.read params = JSON.parse(raw) -#rescue JSON::ParserError => e +# rescue JSON::ParserError => e rescue JSON::ParserError - err(400,"os_patching/input", "Invalid JSON received: '#{raw}'", starttime) + err(400, 'os_patching/input', "Invalid JSON received: '#{raw}'", starttime) end # Cache fact data to speed things up @@ -204,7 +204,6 @@ def reboot_required(family, release, reboot) _fact_out, stderr, status = Open3.capture3(fact_generation) err(status, 'os_patching/fact_refresh', stderr, starttime) if status != 0 - # Let's figure out the reboot gordian knot # # If the override is set, it doesn't matter that anything else is set to at this point @@ -409,7 +408,7 @@ def reboot_required(family, release, reboot) pkg_list = [] if security_only == true pkg_list = facts['values']['os_patching']['security_package_updates'] - apt_mode = "install " + pkg_list.join(" ") + apt_mode = 'install ' + pkg_list.join(' ') else pkg_list = facts['values']['os_patching']['package_updates'] apt_mode = 'dist-upgrade' diff --git a/tasks/refresh_fact.rb b/tasks/refresh_fact.rb index af19a591..ffa908d9 100755 --- a/tasks/refresh_fact.rb +++ b/tasks/refresh_fact.rb @@ -55,9 +55,8 @@ def err(code, kind, message, starttime) exit(exitcode.to_i) end - # Update the fact cache clean_out, stderr, status = Open3.capture3('/usr/local/bin/os_patching_fact_generation.sh') err(status, 'os_patching/fact_cache_update', stderr, starttime) if status != 0 -output(status,'Patching fact cache updated',clean_out,starttime) +output(status, 'Patching fact cache updated', clean_out, starttime) log.info 'Patching fact cache updated'