diff --git a/.travis.yml b/.travis.yml index 889e9ed4e..db5b72e92 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,29 @@ 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.7 + 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 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 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 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') 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