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+
237require 'puppetlabs_spec_helper/tasks/fixtures'
338require 'bundler/gem_tasks'
439require 'puppet-lint/tasks/puppet-lint'
@@ -25,53 +60,6 @@ task :validate do
2560end
2661
2762namespace :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