From ebcbe7c32600d1f328d9f811f1213141024d2694 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 11 Jun 2020 23:14:08 +0100 Subject: [PATCH 1/6] (maint) update Gemfile to current versions of litmus and GCG --- Gemfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index d4d35208a..f95de9ef0 100644 --- a/Gemfile +++ b/Gemfile @@ -26,14 +26,13 @@ end group :acceptance do # Litmus has dependencies which require Ruby 2.5 (Puppet 6) or above. if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0') - # Can't use puppet_litmus 0.18.0 until https://github.com/puppetlabs/puppet_litmus/issues/300 is fixed. - gem 'puppet_litmus', '~> 0.17.0' + gem 'puppet_litmus', '~> 0.18' gem 'net-ssh', '~> 5.2' end end group :development do - gem 'github_changelog_generator', git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') + gem 'github_changelog_generator', '~> 1.15' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') gem 'pry' gem 'pry-byebug' end From 7d82abca977c3212d8b3e5cc1c2f28a22169169f Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 11 Jun 2020 23:20:37 +0100 Subject: [PATCH 2/6] (maint) Update and reformat travis.yml * Reformat YAML * address build config validation warnings * remove outdated config options * specify modern build environment --- .travis.yml | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 889e9ed4e..579270ee0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ --- +os: linux +dist: xenial language: ruby -sudo: false - bundler_args: --without development acceptance notifications: @@ -11,31 +11,27 @@ notifications: before_install: - gem update bundler -matrix: +script: 'SPEC_OPTS="--format documentation" COVERAGE="yes" bundle exec rake $CHECK' + +jobs: fast_finish: true include: - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4" CHECK=spec - - rvm: 2.4.1 - env: PUPPET_GEM_VERSION="~> 4" CHECK=spec - - rvm: 2.4.1 - env: PUPPET_GEM_VERSION="~> 5" CHECK=spec - - rvm: 2.5 - env: PUPPET_GEM_VERSION="~> 6" CHECK=spec - - rvm: 2.1.9 - env: PUPPET_GEM_VERSION="~> 4" CHECK=rubocop - - - bundler_args: "" - dist: trusty - rvm: 2.5 - before_script: - - bundle exec rake 'litmus:provision[docker, centos:7]' - - bundle exec rake 'litmus:install_agent[puppet6]' - - bundle exec rake 'litmus:install_modules_from_directory[./spec/fixtures/acceptance/modules]' - - bundle exec rake litmus:install_gems - script: - - bundle exec rake litmus:acceptance:parallel - services: docker - sudo: required - -script: 'SPEC_OPTS="--format documentation" COVERAGE="yes" bundle exec rake $CHECK' + - rvm: 2.1.9 + env: PUPPET_GEM_VERSION="~> 4" CHECK=spec + - rvm: 2.4.1 + env: PUPPET_GEM_VERSION="~> 4" CHECK=spec + - rvm: 2.4.1 + env: PUPPET_GEM_VERSION="~> 5" CHECK=spec + - rvm: 2.5 + env: PUPPET_GEM_VERSION="~> 6" CHECK=spec + - rvm: 2.1.9 + env: PUPPET_GEM_VERSION="~> 4" CHECK=rubocop + - bundler_args: "" + rvm: 2.5 + before_script: + - bundle exec rake 'litmus:provision[docker, centos:7]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake 'litmus:install_modules_from_directory[./spec/fixtures/acceptance/modules]' + - bundle exec rake litmus:install_gems + script: + - bundle exec rake litmus:acceptance:parallel From aa28a151c8a6e1ddaecf0d328e8daab2db06b7e7 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 11 Jun 2020 23:21:20 +0100 Subject: [PATCH 3/6] (IAC-859) Add ruby2.7 testing --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 579270ee0..db5b72e92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,8 @@ jobs: env: PUPPET_GEM_VERSION="~> 5" CHECK=spec - rvm: 2.5 env: PUPPET_GEM_VERSION="~> 6" CHECK=spec + - rvm: 2.7 + env: PUPPET_GEM_VERSION="~> 6" CHECK=spec - rvm: 2.1.9 env: PUPPET_GEM_VERSION="~> 4" CHECK=rubocop - bundler_args: "" From dfa4c0ce475e9fb98f4b1771a46197d04e10e6a2 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 12 Jun 2020 11:44:23 +0100 Subject: [PATCH 4/6] (maint) use `upload_file` instead of calling external bolt --- Rakefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 36556685c..e72db0c78 100644 --- a/Rakefile +++ b/Rakefile @@ -104,10 +104,8 @@ namespace :litmus do else args[:target_node_name] end - # TODO: Currently this is Linux targets only. no windows localhost - tmp_path = '/tmp/' puts 'Copying gem to targets...' - run_local_command("bolt file upload #{gem_tar} #{tmp_path}#{File.basename(gem_tar)} --targets #{target_string} --inventoryfile inventory.yaml") + upload_file(gem_tar, File.basename(gem_tar), target_string, inventory: inventory_hash) # Install dependent gems puts 'Installing yard gem...' @@ -116,7 +114,7 @@ namespace :litmus do install_remote_gem('rgen', target_nodes, inventory_hash) # Install puppet-strings puts 'Installing puppet-strings gem...' - install_remote_gem(tmp_path + File.basename(gem_tar), target_nodes, inventory_hash) + install_remote_gem(File.basename(gem_tar), target_nodes, inventory_hash) puts 'Installed' end end From 8cd8c07119c73a90a50fa6fc1bf2a113362c491e Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 12 Jun 2020 11:59:19 +0100 Subject: [PATCH 5/6] (maint) use condensed litmus spec_helper_acceptance; fixup tests --- spec/acceptance/emit_json_options_spec.rb | 4 +- spec/spec_helper_acceptance.rb | 60 ++--------------------- spec/spec_helper_acceptance_local.rb | 2 +- 3 files changed, 7 insertions(+), 59 deletions(-) diff --git a/spec/acceptance/emit_json_options_spec.rb b/spec/acceptance/emit_json_options_spec.rb index 3c8663583..c51b646db 100644 --- a/spec/acceptance/emit_json_options_spec.rb +++ b/spec/acceptance/emit_json_options_spec.rb @@ -49,7 +49,7 @@ { :title => '--emit-json-stdout', :cmd_line => '--emit-json-stdout' } ].each do |testcase| it "should emit JSON to stdout when using #{testcase[:title]}" do - output = PuppetLitmus::PuppetHelpers.run_shell("puppet strings generate #{testcase[:cmd_line]} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp + output = run_shell("puppet strings generate #{testcase[:cmd_line]} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp expect(JSON.parse(output)).to eq(expected) end end @@ -61,7 +61,7 @@ it "should write JSON to a file when using #{testcase[:title]}" do tmpfile = File.join(@remote_tmp_path, 'json_output.json') cmd = "puppet strings generate #{testcase[:cmd_line].gsub('TMPFILE', tmpfile)} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"" - PuppetLitmus::PuppetHelpers.run_shell(cmd) + run_shell(cmd) output = JSON.parse(file(tmpfile).content) expect(output).to eq(expected) end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e73e8d387..4ac8d7e0f 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,58 +1,6 @@ -require 'serverspec' -require 'puppet_litmus' -include PuppetLitmus # rubocop:disable Style/MixinUsage This is fine - -if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost' - puts 'Running tests against this machine !' - if Gem.win_platform? - set :backend, :cmd - else - set :backend, :exec - end -else - # load inventory - inventory_hash = inventory_hash_from_inventory_file - node_config = config_from_node(inventory_hash, ENV['TARGET_HOST']) - - if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes') - host = ENV['TARGET_HOST'] - set :backend, :docker - set :docker_container, host - elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes') - set :backend, :ssh - options = Net::SSH::Config.for(host) - options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil? - options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil? - options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil? - options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil? - options[:verify_host_key] = Net::SSH::Verifiers::Never.new unless node_config.dig('ssh', 'host-key-check').nil? - host = if ENV['TARGET_HOST'].include?(':') - ENV['TARGET_HOST'].split(':').first - else - ENV['TARGET_HOST'] - end - set :host, options[:host_name] || host - set :ssh_options, options - set :request_pty, true - elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes') - require 'winrm' - - set :backend, :winrm - set :os, family: 'windows' - user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil? - pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil? - endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" - - opts = { - user: user, - password: pass, - endpoint: endpoint, - operation_timeout: 300, - } - - winrm = WinRM::Connection.new opts - Specinfra.configuration.winrm = winrm - end -end +# frozen_string_literal: true +require 'puppet_litmus' require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) + +PuppetLitmus.configure! diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index cd90ed8c2..2f350f1b7 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1,5 +1,5 @@ def sut_module_path(module_regex) - modules = JSON.parse(PuppetLitmus::PuppetHelpers.run_shell('puppet module list --render-as json').stdout) + modules = JSON.parse(run_shell('puppet module list --render-as json').stdout) test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex } test_module_info.match(/\(([^)]*)\)/)[1] end From 53507c68d1e63cc25081ed5c309000e631a34f08 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 12 Jun 2020 17:16:22 +0100 Subject: [PATCH 6/6] Make the TypeExtrasHandler more robust Ruby 2.7's AST has added an entry for `:period` between the function call and the const reference. This change makes it so the method1_name parsing can deal with that. Ruby 2.5: ``` [1] pry(#)> statement[0].children => [s(:const_path_ref, s(:var_ref, s(:const, "Puppet", line: 1..1, source: 2..7), line: 1..1, source: 2..7), s(:const, "Type", line: 1..1, source: 10..13), line: 1..1, source: 2..13), s(:ident, "type", line: 1..1, source: 15..18), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "file", line: 1..1, source: 21..24), line: 1..1, source: 20..24), line: 1..1, source: 20..24), false), line: 1..1, source: 19..25)] [2] pry(#)> ``` Ruby 2.7: ``` [4] pry(#)> statement[0].children => [s(:const_path_ref, s(:var_ref, s(:const, "Puppet", line: 1..1, source: 2..7), line: 1..1, source: 2..7), s(:const, "Type", line: 1..1, source: 10..13), line: 1..1, source: 2..13), s(:period, ".", line: 1..1, source: 14..14), s(:ident, "type", line: 1..1, source: 15..18), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "file", line: 1..1, source: 21..24), line: 1..1, source: 20..24), line: 1..1, source: 20..24), false), line: 1..1, source: 19..25)] [5] pry(#)> ``` --- lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb b/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb index 7e8fc81de..28aae1bb6 100644 --- a/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb @@ -32,7 +32,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya return unless (statement.count > 1) && (statement[0].children.count > 2) module_name = statement[0].children[0].source - method1_name = statement[0].children[1].source + method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type' typename = get_name(statement[0], 'Puppet::Type.type')