Skip to content

Commit 8941b63

Browse files
Merge pull request #238 from DavidS/ruby27
(IAC-859) Add ruby 2.7 testing; update litmus gem
2 parents 1dca520 + 53507c6 commit 8941b63

File tree

7 files changed

+38
-95
lines changed

7 files changed

+38
-95
lines changed

.travis.yml

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2+
os: linux
3+
dist: xenial
24
language: ruby
35

4-
sudo: false
5-
66
bundler_args: --without development acceptance
77

88
notifications:
@@ -11,31 +11,29 @@ notifications:
1111
before_install:
1212
- gem update bundler
1313

14-
matrix:
14+
script: 'SPEC_OPTS="--format documentation" COVERAGE="yes" bundle exec rake $CHECK'
15+
16+
jobs:
1517
fast_finish: true
1618
include:
17-
- rvm: 2.1.9
18-
env: PUPPET_GEM_VERSION="~> 4" CHECK=spec
19-
- rvm: 2.4.1
20-
env: PUPPET_GEM_VERSION="~> 4" CHECK=spec
21-
- rvm: 2.4.1
22-
env: PUPPET_GEM_VERSION="~> 5" CHECK=spec
23-
- rvm: 2.5
24-
env: PUPPET_GEM_VERSION="~> 6" CHECK=spec
25-
- rvm: 2.1.9
26-
env: PUPPET_GEM_VERSION="~> 4" CHECK=rubocop
27-
-
28-
bundler_args: ""
29-
dist: trusty
30-
rvm: 2.5
31-
before_script:
32-
- bundle exec rake 'litmus:provision[docker, centos:7]'
33-
- bundle exec rake 'litmus:install_agent[puppet6]'
34-
- bundle exec rake 'litmus:install_modules_from_directory[./spec/fixtures/acceptance/modules]'
35-
- bundle exec rake litmus:install_gems
36-
script:
37-
- bundle exec rake litmus:acceptance:parallel
38-
services: docker
39-
sudo: required
40-
41-
script: 'SPEC_OPTS="--format documentation" COVERAGE="yes" bundle exec rake $CHECK'
19+
- rvm: 2.1.9
20+
env: PUPPET_GEM_VERSION="~> 4" CHECK=spec
21+
- rvm: 2.4.1
22+
env: PUPPET_GEM_VERSION="~> 4" CHECK=spec
23+
- rvm: 2.4.1
24+
env: PUPPET_GEM_VERSION="~> 5" CHECK=spec
25+
- rvm: 2.5
26+
env: PUPPET_GEM_VERSION="~> 6" CHECK=spec
27+
- rvm: 2.7
28+
env: PUPPET_GEM_VERSION="~> 6" CHECK=spec
29+
- rvm: 2.1.9
30+
env: PUPPET_GEM_VERSION="~> 4" CHECK=rubocop
31+
- bundler_args: ""
32+
rvm: 2.5
33+
before_script:
34+
- bundle exec rake 'litmus:provision[docker, centos:7]'
35+
- bundle exec rake 'litmus:install_agent[puppet6]'
36+
- bundle exec rake 'litmus:install_modules_from_directory[./spec/fixtures/acceptance/modules]'
37+
- bundle exec rake litmus:install_gems
38+
script:
39+
- bundle exec rake litmus:acceptance:parallel

Gemfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ end
2626
group :acceptance do
2727
# Litmus has dependencies which require Ruby 2.5 (Puppet 6) or above.
2828
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0')
29-
# Can't use puppet_litmus 0.18.0 until https://github.com/puppetlabs/puppet_litmus/issues/300 is fixed.
30-
gem 'puppet_litmus', '~> 0.17.0'
29+
gem 'puppet_litmus', '~> 0.18'
3130
gem 'net-ssh', '~> 5.2'
3231
end
3332
end
3433

3534
group :development do
36-
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')
35+
gem 'github_changelog_generator', '~> 1.15' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')
3736
gem 'pry'
3837
gem 'pry-byebug'
3938
end

Rakefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ namespace :litmus do
104104
else
105105
args[:target_node_name]
106106
end
107-
# TODO: Currently this is Linux targets only. no windows localhost
108-
tmp_path = '/tmp/'
109107
puts 'Copying gem to targets...'
110-
run_local_command("bolt file upload #{gem_tar} #{tmp_path}#{File.basename(gem_tar)} --targets #{target_string} --inventoryfile inventory.yaml")
108+
upload_file(gem_tar, File.basename(gem_tar), target_string, inventory: inventory_hash)
111109

112110
# Install dependent gems
113111
puts 'Installing yard gem...'
@@ -116,7 +114,7 @@ namespace :litmus do
116114
install_remote_gem('rgen', target_nodes, inventory_hash)
117115
# Install puppet-strings
118116
puts 'Installing puppet-strings gem...'
119-
install_remote_gem(tmp_path + File.basename(gem_tar), target_nodes, inventory_hash)
117+
install_remote_gem(File.basename(gem_tar), target_nodes, inventory_hash)
120118
puts 'Installed'
121119
end
122120
end

lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
3232

3333
return unless (statement.count > 1) && (statement[0].children.count > 2)
3434
module_name = statement[0].children[0].source
35-
method1_name = statement[0].children[1].source
35+
method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
3636
return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type'
3737

3838
typename = get_name(statement[0], 'Puppet::Type.type')

spec/acceptance/emit_json_options_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
{ :title => '--emit-json-stdout', :cmd_line => '--emit-json-stdout' }
5050
].each do |testcase|
5151
it "should emit JSON to stdout when using #{testcase[:title]}" do
52-
output = PuppetLitmus::PuppetHelpers.run_shell("puppet strings generate #{testcase[:cmd_line]} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp
52+
output = run_shell("puppet strings generate #{testcase[:cmd_line]} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp
5353
expect(JSON.parse(output)).to eq(expected)
5454
end
5555
end
@@ -61,7 +61,7 @@
6161
it "should write JSON to a file when using #{testcase[:title]}" do
6262
tmpfile = File.join(@remote_tmp_path, 'json_output.json')
6363
cmd = "puppet strings generate #{testcase[:cmd_line].gsub('TMPFILE', tmpfile)} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\""
64-
PuppetLitmus::PuppetHelpers.run_shell(cmd)
64+
run_shell(cmd)
6565
output = JSON.parse(file(tmpfile).content)
6666
expect(output).to eq(expected)
6767
end

spec/spec_helper_acceptance.rb

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,6 @@
1-
require 'serverspec'
2-
require 'puppet_litmus'
3-
include PuppetLitmus # rubocop:disable Style/MixinUsage This is fine
4-
5-
if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
6-
puts 'Running tests against this machine !'
7-
if Gem.win_platform?
8-
set :backend, :cmd
9-
else
10-
set :backend, :exec
11-
end
12-
else
13-
# load inventory
14-
inventory_hash = inventory_hash_from_inventory_file
15-
node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])
16-
17-
if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes')
18-
host = ENV['TARGET_HOST']
19-
set :backend, :docker
20-
set :docker_container, host
21-
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
22-
set :backend, :ssh
23-
options = Net::SSH::Config.for(host)
24-
options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
25-
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
26-
options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil?
27-
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
28-
options[:verify_host_key] = Net::SSH::Verifiers::Never.new unless node_config.dig('ssh', 'host-key-check').nil?
29-
host = if ENV['TARGET_HOST'].include?(':')
30-
ENV['TARGET_HOST'].split(':').first
31-
else
32-
ENV['TARGET_HOST']
33-
end
34-
set :host, options[:host_name] || host
35-
set :ssh_options, options
36-
set :request_pty, true
37-
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
38-
require 'winrm'
39-
40-
set :backend, :winrm
41-
set :os, family: 'windows'
42-
user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
43-
pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
44-
endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"
45-
46-
opts = {
47-
user: user,
48-
password: pass,
49-
endpoint: endpoint,
50-
operation_timeout: 300,
51-
}
52-
53-
winrm = WinRM::Connection.new opts
54-
Specinfra.configuration.winrm = winrm
55-
end
56-
end
1+
# frozen_string_literal: true
572

3+
require 'puppet_litmus'
584
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
5+
6+
PuppetLitmus.configure!

spec/spec_helper_acceptance_local.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def sut_module_path(module_regex)
2-
modules = JSON.parse(PuppetLitmus::PuppetHelpers.run_shell('puppet module list --render-as json').stdout)
2+
modules = JSON.parse(run_shell('puppet module list --render-as json').stdout)
33
test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex }
44
test_module_info.match(/\(([^)]*)\)/)[1]
55
end

0 commit comments

Comments
 (0)