Skip to content

Commit 3a45ca6

Browse files
committed
(MAINT) Fix litmus testing
Currently the litmus based testing is broken due to bugs in both Litmus and Bolt. This commit modifies the acceptance testing to: * Use a fixed fork of Litmus to enable the instal_modules_from_directory rake task * Monkey patches Bolt to be able to used due to Bolt Issue 1614 These parts can be reverted once their related PRs are merged and released.
1 parent be43075 commit 3a45ca6

File tree

3 files changed

+49
-54
lines changed

3 files changed

+49
-54
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ matrix:
3131
before_script:
3232
- bundle exec rake 'litmus:provision[docker, centos:7]'
3333
- bundle exec rake 'litmus:install_agent[puppet6]'
34-
- bundle exec rake litmus:install_module_fixtures
34+
- bundle exec rake 'litmus:install_modules_from_directory[./spec/fixtures/acceptance/modules]'
3535
- bundle exec rake litmus:install_gems
3636
script:
3737
- bundle exec rake litmus:acceptance:parallel

Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ group :test do
2323
end
2424

2525
group :acceptance do
26+
# Litmus has dependencies which require Ruby 2.5 (Puppet 6) or above.
2627
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0')
27-
# Litmus has dependencies which require Ruby 2.5 (Puppet 6) or above.
28-
gem 'puppet_litmus', '~> 0.11', '>= 0.11.1'
28+
# Until https://github.com/puppetlabs/puppet_litmus/pull/248 is merged we need to use the source of the
29+
# of the PR. Not the greatest and prone to error, but without it, all litmus based testing is broken.
30+
# This can be reverted once this PR is merged and Litmus is released with this fix.
31+
gem 'puppet_litmus', git: 'https://github.com/michaeltlombardi/puppet_litmus', ref: 'maint/master/fix-upload-file'
2932
gem 'net-ssh', '~> 5.2'
3033
end
3134
end

Rakefile

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1-
require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any?
1+
if Bundler.rubygems.find_name('puppet_litmus').any?
2+
require 'puppet_litmus/rake_tasks'
3+
4+
# This is a _really_ horrible monkey-patch to fix up https://github.com/puppetlabs/bolt/issues/1614
5+
# Based on resolution https://github.com/puppetlabs/bolt/pull/1620
6+
# This can be removed once this is fixed, released into Bolt and into Litmus
7+
require 'bolt_spec/run'
8+
module BoltSpec
9+
module Run
10+
class BoltRunner
11+
class << self
12+
alias_method :original_with_runner, :with_runner
13+
end
14+
15+
def self.with_runner(config_data, inventory_data)
16+
original_with_runner(deep_duplicate_object(config_data), deep_duplicate_object(inventory_data)) { |runner| yield runner }
17+
end
18+
19+
# From https://github.com/puppetlabs/pdk/blob/master/lib/pdk/util.rb
20+
# Workaround for https://github.com/puppetlabs/bolt/issues/1614
21+
def self.deep_duplicate_object(object)
22+
if object.is_a?(Array)
23+
object.map { |item| deep_duplicate_object(item) }
24+
elsif object.is_a?(Hash)
25+
hash = object.dup
26+
hash.each_pair { |key, value| hash[key] = deep_duplicate_object(value) }
27+
hash
28+
else
29+
object
30+
end
31+
end
32+
end
33+
end
34+
end
35+
end
36+
237
require 'puppetlabs_spec_helper/tasks/fixtures'
338
require 'bundler/gem_tasks'
439
require 'puppet-lint/tasks/puppet-lint'
@@ -25,53 +60,6 @@ task :validate do
2560
end
2661

2762
namespace :litmus do
28-
# Install the puppet module fixture on a collection of nodes
29-
#
30-
# @param :target_node_name [Array] nodes on which to install a puppet module for testing.
31-
desc 'install_module_fixtures - build and install module fixtures'
32-
task :install_module_fixtures, [:target_node_name] do |_task, args|
33-
inventory_hash = inventory_hash_from_inventory_file
34-
target_nodes = find_targets(inventory_hash, args[:target_node_name])
35-
if target_nodes.empty?
36-
puts 'No targets found'
37-
exit 0
38-
end
39-
include BoltSpec::Run
40-
require 'pdk/module/build'
41-
42-
module_fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'fixtures', 'acceptance', 'modules', 'test'))
43-
module_tar = nil
44-
Dir.chdir(module_fixture_dir) do
45-
opts = {}
46-
opts[:force] = true
47-
builder = PDK::Module::Build.new(opts)
48-
module_tar = builder.build
49-
puts 'Built'
50-
module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
51-
raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?
52-
module_tar = File.expand_path(module_tar)
53-
end
54-
55-
target_string = if args[:target_node_name].nil?
56-
'all'
57-
else
58-
args[:target_node_name]
59-
end
60-
# TODO: Currently this is Linux only
61-
tmp_path = '/tmp/'
62-
run_local_command("bundle exec bolt file upload #{module_tar} #{tmp_path}#{File.basename(module_tar)} --nodes #{target_string} --inventoryfile inventory.yaml")
63-
install_module_command = "puppet module install #{tmp_path}#{File.basename(module_tar)}"
64-
result = run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash)
65-
if result.is_a?(Array)
66-
result.each do |node|
67-
puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
68-
end
69-
else
70-
raise "Failed trying to run '#{install_module_command}' against inventory."
71-
end
72-
puts 'Installed'
73-
end
74-
7563
def install_remote_gem(gem_name, target_nodes, inventory_hash)
7664
# TODO: Currently this is Linux only
7765
install_command = "/opt/puppetlabs/puppet/bin/gem install #{gem_name}"
@@ -96,6 +84,7 @@ namespace :litmus do
9684
puts 'No targets found'
9785
exit 0
9886
end
87+
require 'bolt_spec/run'
9988
include BoltSpec::Run
10089

10190
# Build the gem
@@ -113,15 +102,18 @@ namespace :litmus do
113102
else
114103
args[:target_node_name]
115104
end
116-
# TODO: Currently this is Linux only
105+
# TODO: Currently this is Linux targets only. no windows localhost
117106
tmp_path = '/tmp/'
118-
run_local_command("bundle exec bolt file upload #{gem_tar} #{tmp_path}#{File.basename(gem_tar)} --nodes #{target_string} --inventoryfile inventory.yaml")
119-
107+
puts 'Copying gem to targets...'
108+
run_local_command("bolt file upload #{gem_tar} #{tmp_path}#{File.basename(gem_tar)} --targets #{target_string} --inventoryfile inventory.yaml")
120109

121110
# Install dependent gems
111+
puts 'Installing yard gem...'
122112
install_remote_gem('yard', target_nodes, inventory_hash)
113+
puts 'Installing rgen gem...'
123114
install_remote_gem('rgen', target_nodes, inventory_hash)
124115
# Install puppet-strings
116+
puts 'Installing puppet-strings gem...'
125117
install_remote_gem(tmp_path + File.basename(gem_tar), target_nodes, inventory_hash)
126118
puts 'Installed'
127119
end

0 commit comments

Comments
 (0)