Skip to content

(IAC-859) Add ruby 2.7 testing; update litmus gem #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
os: linux
dist: xenial
language: ruby

sudo: false

bundler_args: --without development acceptance

notifications:
Expand All @@ -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
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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...'
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/emit_json_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
60 changes: 4 additions & 56 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -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!
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance_local.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down