puppet_litmus 0.17.0 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,15 +17,15 @@ namespace :litmus do
17
17
  end
18
18
 
19
19
  # Provisions a list of OSes from provision.yaml file e.g. 'bundle exec rake litmus:provision_list[default]'.
20
- # @See https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus#provisioning-via-yaml
20
+ # @See https://puppetlabs.github.io/litmus/Litmus-core-commands.html#provisioning-via-yaml
21
21
  #
22
22
  # @param :key [String] key that maps to a value for a provisioner and an image to be used for each OS provisioned.
23
- desc "provision list of machines from provision.yaml file. 'bundle exec rake 'litmus:provision_list[default]'"
23
+ desc 'provision list of machines from provision.yaml file'
24
24
  task :provision_list, [:key] do |_task, args|
25
25
  raise 'Cannot find provision.yaml file' unless File.file?('./provision.yaml')
26
26
 
27
27
  provision_hash = YAML.load_file('./provision.yaml')
28
- raise "No key #{args[:key]} in ./provision.yaml, see https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus#provisioning-via-yaml for examples" if provision_hash[args[:key]].nil?
28
+ raise "No key #{args[:key]} in ./provision.yaml, see https://puppetlabs.github.io/litmus/Litmus-core-commands.html#provisioning-via-yaml for examples" if provision_hash[args[:key]].nil?
29
29
 
30
30
  Rake::Task['spec_prep'].invoke
31
31
 
@@ -57,9 +57,9 @@ namespace :litmus do
57
57
  end
58
58
 
59
59
  if result.first['status'] != 'success'
60
- failed_image_message += "=====\n#{result.first['node']}\n#{result.first['result']['_output']}\n#{result.inspect}"
60
+ failed_image_message += "=====\n#{result.first['target']}\n#{result.first['value']['_output']}\n#{result.inspect}"
61
61
  else
62
- STDOUT.puts "#{result.first['result']['node_name']}, #{image}"
62
+ STDOUT.puts "#{result.first['value']['node_name']}, #{image}"
63
63
  end
64
64
  results << result
65
65
  end
@@ -71,7 +71,7 @@ namespace :litmus do
71
71
  #
72
72
  # @param :provisioner [String] provisioner to use in provisioning given platform.
73
73
  # @param :platform [String] OS platform for container or VM to use.
74
- desc "provision container/VM - abs/docker/vagrant/vmpooler eg 'bundle exec rake 'litmus:provision[vmpooler, ubuntu-1604-x86_64]'"
74
+ desc 'provision a test system using the given provisioner and platform name. See the puppetlabs-provision module tasks for more documentation'
75
75
  task :provision, [:provisioner, :platform, :inventory_vars] do |_task, args|
76
76
  Rake::Task['spec_prep'].invoke
77
77
  if (ENV['CI'] == 'true') || !ENV['DISTELLI_BUILDNUM'].nil?
@@ -96,14 +96,14 @@ namespace :litmus do
96
96
  else
97
97
  spinner.success
98
98
  end
99
- puts "#{results.first['result']['node_name']}, #{args[:platform]}"
99
+ puts "#{results.first['value']['node_name']}, #{args[:platform]}"
100
100
  end
101
101
 
102
102
  # Install puppet agent on a collection of nodes
103
103
  #
104
104
  # @param :collection [String] parameters to pass to the puppet agent install command.
105
105
  # @param :target_node_name [Array] nodes on which to install puppet agent.
106
- desc 'install puppet agent, [:collection, :target_node_name]'
106
+ desc 'install a puppet agent to all or a specified set of targets'
107
107
  task :install_agent, [:collection, :target_node_name] do |_task, args|
108
108
  inventory_hash = inventory_hash_from_inventory_file
109
109
  targets = find_targets(inventory_hash, args[:target_node_name])
@@ -119,11 +119,11 @@ namespace :litmus do
119
119
  results = install_agent(args[:collection], targets, inventory_hash)
120
120
  results.each do |result|
121
121
  if result['status'] != 'success'
122
- command_to_run = "bolt task run puppet_agent::install --targets #{result['node']} --inventoryfile inventory.yaml --modulepath #{DEFAULT_CONFIG_DATA['modulepath']}"
123
- raise "Failed on #{result['node']}\n#{result}\ntry running '#{command_to_run}'"
122
+ command_to_run = "bolt task run puppet_agent::install --targets #{result['target']} --inventoryfile inventory.yaml --modulepath #{DEFAULT_CONFIG_DATA['modulepath']}"
123
+ raise "Failed on #{result['target']}\n#{result}\ntry running '#{command_to_run}'"
124
124
  else
125
125
  # add puppet-agent feature to successful nodes
126
- inventory_hash = add_feature_to_node(inventory_hash, 'puppet-agent', result['node'])
126
+ inventory_hash = add_feature_to_node(inventory_hash, 'puppet-agent', result['target'])
127
127
  end
128
128
  end
129
129
  # update the inventory with the puppet-agent feature set per node
@@ -134,7 +134,7 @@ namespace :litmus do
134
134
 
135
135
  results.each do |result|
136
136
  if result['status'] != 'success'
137
- puts "Failed on #{result['node']}\n#{result}"
137
+ puts "Failed on #{result['target']}\n#{result}"
138
138
  end
139
139
  end
140
140
  end
@@ -143,7 +143,7 @@ namespace :litmus do
143
143
  #
144
144
  # @param :target_node_name [Array] nodes on which to add the feature.
145
145
  # @param :added_feature [String] the feature which you wish to add.
146
- desc 'add_feature, [:added_feature, :target_node_name]'
146
+ desc 'add a feature tag to a node'
147
147
  task :add_feature, [:added_feature, :target_node_name] do |_task, args|
148
148
  inventory_hash = inventory_hash_from_inventory_file
149
149
  targets = find_targets(inventory_hash, args[:target_node_name])
@@ -166,65 +166,69 @@ namespace :litmus do
166
166
  puts 'Feature added'
167
167
  end
168
168
 
169
- # Install the puppet modules from a source directory to nodes. It does not install dependencies.
169
+ # Install the puppet module under test on a collection of nodes
170
170
  #
171
- # @param :source [String] source directory to look in (ignores symlinks) defaults do './spec/fixtures/modules'.
172
171
  # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
173
- desc 'install_module - build and install module'
174
- task :install_modules_from_directory, [:source, :target_node_name] do |_task, args|
172
+ desc 'build the module under test and install it onto targets'
173
+ task :install_module, [:target_node_name, :module_repository] do |_task, args|
174
+ args.with_defaults(target_node_name: nil, module_repository: nil)
175
175
  inventory_hash = inventory_hash_from_inventory_file
176
176
  target_nodes = find_targets(inventory_hash, args[:target_node_name])
177
177
  if target_nodes.empty?
178
178
  puts 'No targets found'
179
179
  exit 0
180
180
  end
181
- source_folder = if args[:source].nil?
182
- './spec/fixtures/modules'
183
- else
184
- File.expand_path(args[:source])
185
- end
186
- raise "Source folder doesnt exist #{source_folder}" unless File.directory?(source_folder)
187
-
188
- module_tars = build_modules_in_folder(source_folder)
189
- puts 'Building'
190
- module_tars.each do |module_tar|
191
- print "#{File.basename(module_tar)} "
192
- end
193
- require 'bolt_spec/run'
194
- include BoltSpec::Run
195
- puts "\nSending"
196
- module_tars.each do |module_tar|
197
- upload_file(module_tar.path, "/tmp/#{File.basename(module_tar)}", target_nodes, options: {}, config: nil, inventory: inventory_hash)
198
- print "#{File.basename(module_tar)} "
199
- end
200
- puts "\nInstalling"
201
- module_tars.each do |module_tar|
202
- # install_module
203
- install_module_command = "puppet module install --force /tmp/#{File.basename(module_tar)}"
204
- run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash)
205
- print "#{File.basename(module_tar)} "
206
- end
181
+
182
+ module_tar = build_module
183
+ puts "Built '#{module_tar}'"
184
+
185
+ # module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
186
+ raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?
187
+
188
+ install_module(inventory_hash, args[:target_node_name], module_tar, args[:module_repository])
189
+
190
+ puts "Installed '#{module_tar}' on #{args[:target_node_name]}"
207
191
  end
208
192
 
209
- # Check that the nodes in the inventory are still contactable
193
+ # Install the puppet modules from a source directory to nodes. It does not install dependencies.
210
194
  #
211
- # @param :target_node_name [Array] nodes on which to check connnectivity
212
- desc 'check_connectivity - build and install module'
213
- task :check_connectivity, [:target_node_name] do |_task, args|
195
+ # @param :source [String] source directory to look in (ignores symlinks) defaults do './spec/fixtures/modules'.
196
+ # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
197
+ desc 'build and install all modules from a directory'
198
+ task :install_modules_from_directory, [:source, :target_node_name, :module_repository] do |_task, args|
199
+ args.with_defaults(source: nil, target_node_name: nil, module_repository: nil)
214
200
  inventory_hash = inventory_hash_from_inventory_file
215
201
  target_nodes = find_targets(inventory_hash, args[:target_node_name])
216
202
  if target_nodes.empty?
217
203
  puts 'No targets found'
218
204
  exit 0
219
205
  end
220
- check_connectivity?(inventory_hash, args[:target_node_name])
206
+ source_dir = if args[:source].nil?
207
+ './spec/fixtures/modules'
208
+ else
209
+ File.expand_path(args[:source])
210
+ end
211
+ raise "Source directory doesn't exist #{source_dir}" unless File.directory?(source_dir)
212
+
213
+ puts "Building all modules in #{source_dir.inspect}"
214
+ module_tars = build_modules_in_dir(source_dir)
215
+ require 'bolt_spec/run'
216
+ include BoltSpec::Run
217
+ module_tars.each do |module_tar|
218
+ puts "Installing '#{module_tar}'"
219
+ target_nodes.each do |target_node_name|
220
+ install_module(inventory_hash, target_node_name, module_tar, args[:module_repository])
221
+ puts "Installed '#{module_tar}' on #{target_node_name}"
222
+ end
223
+ end
221
224
  end
222
225
 
223
- # Install the puppet module under test on a collection of nodes
226
+ # Uninstall the puppet module under test on a collection of nodes
224
227
  #
225
228
  # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
226
- desc 'install_module - build and install module'
227
- task :install_module, [:target_node_name] do |_task, args|
229
+ # @param :module_name [String] module name to be uninstalled
230
+ desc 'uninstall a specific module'
231
+ task :uninstall_module, [:target_node_name, :module_name] do |_task, args|
228
232
  inventory_hash = inventory_hash_from_inventory_file
229
233
  target_nodes = find_targets(inventory_hash, args[:target_node_name])
230
234
  if target_nodes.empty?
@@ -232,39 +236,58 @@ namespace :litmus do
232
236
  exit 0
233
237
  end
234
238
 
235
- module_tar = build_module
236
- puts 'Built'
237
-
238
- # module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
239
- raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?
240
-
241
- result = install_module(inventory_hash, args[:target_node_name], module_tar)
239
+ result = uninstall_module(inventory_hash, args[:target_node_name], args[:module_name])
242
240
 
243
- raise "Failed trying to run 'puppet module install /tmp/#{File.basename(module_tar)}' against inventory." unless result.is_a?(Array)
241
+ raise "Failed trying to run 'puppet module uninstall #{module_name}' against inventory." unless result.is_a?(Array)
244
242
 
245
243
  result.each do |node|
246
- puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
244
+ puts "#{node['target']} failed #{node['value']}" if node['status'] != 'success'
247
245
  end
248
246
 
249
- puts 'Installed'
247
+ puts 'Uninstalled'
248
+ end
249
+
250
+ # Reinstall the puppet module under test on a collection of nodes
251
+ #
252
+ # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
253
+ desc 'reinstall the module under test'
254
+ task :reinstall_module, [:target_node_name, :module_repository] do |_task, args|
255
+ args.with_defaults(target_node_name: nil, module_repository: nil)
256
+ Rake::Task['litmus:uninstall_module'].invoke(args[:target_node_name])
257
+ Rake::Task['litmus:install_module'].invoke(args[:target_node_name], args[:module_repository])
258
+ end
259
+
260
+ # Check that the nodes in the inventory are still contactable
261
+ #
262
+ # @param :target_node_name [Array] nodes on which to check connnectivity
263
+ desc 'check the connectivity to all provisioned targets'
264
+ task :check_connectivity, [:target_node_name] do |_task, args|
265
+ inventory_hash = inventory_hash_from_inventory_file
266
+ target_nodes = find_targets(inventory_hash, args[:target_node_name])
267
+ if target_nodes.empty?
268
+ puts 'No targets found'
269
+ exit 0
270
+ end
271
+ check_connectivity?(inventory_hash, args[:target_node_name])
250
272
  end
251
273
 
252
274
  # Provision a list of machines, install a puppet agent, and install the puppet module under test on a collection of nodes
253
275
  #
254
276
  # @param :key [String] key that maps to a value for a provisioner and an image to be used for each OS provisioned.
255
277
  # @param :collection [String] parameters to pass to the puppet agent install command.
256
- desc 'provision_install - provision a list of machines, install an agent, and the module.'
257
- task :provision_install, [:key, :collection] do |_task, args|
278
+ desc 'provision a list of machines, install an agent, and the module.'
279
+ task :provision_install, [:key, :collection, :module_repository] do |_task, args|
280
+ args.with_defaults(module_repository: nil)
258
281
  Rake::Task['spec_prep'].invoke
259
282
  Rake::Task['litmus:provision_list'].invoke(args[:key])
260
283
  Rake::Task['litmus:install_agent'].invoke(args[:collection])
261
- Rake::Task['litmus:install_module'].invoke
284
+ Rake::Task['litmus:install_module'].invoke(nil, args[:module_repository])
262
285
  end
263
286
 
264
287
  # Decommissions test machines.
265
288
  #
266
289
  # @param :target [Array] nodes to remove from test environemnt and decommission.
267
- desc 'tear-down - decommission machines'
290
+ desc 'destroy provisioned targets'
268
291
  task :tear_down, [:target] do |_task, args|
269
292
  inventory_hash = inventory_hash_from_inventory_file
270
293
  targets = find_targets(inventory_hash, args[:target])
@@ -277,7 +300,7 @@ namespace :litmus do
277
300
  results = tear_down_nodes(targets, inventory_hash)
278
301
  results.each do |node, result|
279
302
  if result.first['status'] != 'success'
280
- bad_results << "#{node}, #{result.first['result']['_error']['msg']}"
303
+ bad_results << "#{node}, #{result.first['value']['_error']['msg']}"
281
304
  else
282
305
  puts "#{node}: #{result.first['status']}"
283
306
  end
@@ -290,39 +313,6 @@ namespace :litmus do
290
313
  end
291
314
  end
292
315
 
293
- # Uninstall the puppet module under test on a collection of nodes
294
- #
295
- # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
296
- # @param :module_name [String] module name to be uninstalled
297
- desc 'uninstall_module - uninstall module'
298
- task :uninstall_module, [:target_node_name, :module_name] do |_task, args|
299
- inventory_hash = inventory_hash_from_inventory_file
300
- target_nodes = find_targets(inventory_hash, args[:target_node_name])
301
- if target_nodes.empty?
302
- puts 'No targets found'
303
- exit 0
304
- end
305
-
306
- result = uninstall_module(inventory_hash, args[:target_node_name], args[:module_name])
307
-
308
- raise "Failed trying to run 'puppet module uninstall #{module_name}' against inventory." unless result.is_a?(Array)
309
-
310
- result.each do |node|
311
- puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
312
- end
313
-
314
- puts 'Uninstalled'
315
- end
316
-
317
- # Reinstall the puppet module under test on a collection of nodes
318
- #
319
- # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
320
- desc 'reinstall_module - reinstall module'
321
- task :reinstall_module, [:target_node_name] do |_task, args|
322
- Rake::Task['litmus:uninstall_module'].invoke(args[:target_node_name])
323
- Rake::Task['litmus:install_module'].invoke(args[:target_node_name])
324
- end
325
-
326
316
  namespace :acceptance do
327
317
  require 'rspec/core/rake_task'
328
318
  if File.file?('inventory.yaml')
@@ -365,8 +355,12 @@ namespace :litmus do
365
355
 
366
356
  require 'parallel'
367
357
  results = Parallel.map(payloads) do |title, test, options|
358
+ # avoid sending the parent process' main span in the sub-processes
359
+ # https://www.ruby-forum.com/t/at-exit-inherited-across-fork/122473/2
360
+ at_exit { exit! }
361
+
368
362
  env = options[:env].nil? ? {} : options[:env]
369
- ENV['HTTP_X_HONEYCOMB_TRACE'] = Honecomb.current_span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
363
+ env['HTTP_X_HONEYCOMB_TRACE'] = Honeycomb.current_span.to_trace_header
370
364
  stdout, stderr, status = Open3.capture3(env, test)
371
365
  ["\n================\n#{title}\n", stdout, stderr, status]
372
366
  end
@@ -384,8 +378,8 @@ namespace :litmus do
384
378
  spinners = TTY::Spinner::Multi.new("[:spinner] Running against #{targets.size} targets.")
385
379
  payloads.each do |title, test, options|
386
380
  env = options[:env].nil? ? {} : options[:env]
381
+ env['HTTP_X_HONEYCOMB_TRACE'] = Honeycomb.current_span.to_trace_header
387
382
  spinners.register("[:spinner] #{title}") do |sp|
388
- ENV['HTTP_X_HONEYCOMB_TRACE'] = Honecomb.current_span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
389
383
  stdout, stderr, status = Open3.capture3(env, test)
390
384
  if status.to_i.zero?
391
385
  sp.success
@@ -66,7 +66,7 @@ module PuppetLitmus
66
66
  end
67
67
  set :host, options[:host_name] || host
68
68
  set :ssh_options, options
69
- set :request_pty, true
69
+ set :request_pty, false
70
70
  elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
71
71
  require 'winrm'
72
72
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.17.0'
5
+ VERSION ||= '0.18.4'
6
6
  end
@@ -92,70 +92,70 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
92
92
  end
93
93
 
94
94
  it 'no matching node, raises' do
95
- expect { described_class.config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
95
+ expect { config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
96
96
  end
97
97
 
98
98
  it 'no config section, returns nil' do
99
- expect(described_class.config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
99
+ expect(config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
100
100
  end
101
101
 
102
102
  it 'config exists, and returns' do
103
- expect(described_class.config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
103
+ expect(config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
104
104
  { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false })
105
105
  end
106
106
 
107
107
  it 'facts exists, and returns' do
108
- expect(described_class.facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
108
+ expect(facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
109
109
  end
110
110
 
111
111
  it 'vars exists, and returns' do
112
- expect(described_class.vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
112
+ expect(vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
113
113
  end
114
114
 
115
115
  it 'no feature exists for the group, and returns hash with feature added' do
116
- expect(described_class.add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
116
+ expect(add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
117
117
  end
118
118
 
119
119
  it 'feature exists for the group, and returns hash with feature removed' do
120
- expect(described_class.remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
120
+ expect(remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
121
121
  end
122
122
 
123
123
  it 'write from inventory_hash to inventory_yaml file feature_hash_group' do
124
- expect { described_class.write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
124
+ expect { write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
125
125
  end
126
126
 
127
127
  it 'empty feature exists for the group, and returns hash with feature added' do
128
- expect(described_class.add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
128
+ expect(add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
129
129
  end
130
130
 
131
131
  it 'no feature exists for the node, and returns hash with feature added' do
132
- expect(described_class.add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
132
+ expect(add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
133
133
  end
134
134
 
135
135
  it 'feature exists for the node, and returns hash with feature removed' do
136
- expect(described_class.remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
136
+ expect(remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
137
137
  end
138
138
 
139
139
  it 'write from inventory_hash to inventory_yaml file feature_hash_node' do
140
- expect { described_class.write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
140
+ expect { write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
141
141
  end
142
142
 
143
143
  it 'empty feature exists for the node, and returns hash with feature added' do
144
- expect(described_class.add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
144
+ expect(add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
145
145
  end
146
146
 
147
147
  it 'write from inventory_hash to inventory_yaml file no feature_hash' do
148
148
  expect(File).to exist(inventory_full_path)
149
- expect { described_class.write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
149
+ expect { write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
150
150
  end
151
151
 
152
152
  it 'group does not exist in inventory, and returns hash with group added' do
153
- expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
153
+ expect(add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
154
154
  [{ 'name' => 'ssh_nodes', 'targets' => [] }, { 'name' => 'winrm_nodes', 'targets' => [] }, { 'name' => 'docker_nodes', 'targets' => [foo_node] }])
155
155
  end
156
156
 
157
157
  it 'group exists in inventory, and returns hash with node added' do
158
- expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
158
+ expect(add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
159
159
  [{ 'name' => 'ssh_nodes', 'targets' => [foo_node] }, { 'name' => 'winrm_nodes', 'targets' => [] }])
160
160
  end
161
161
  end
@@ -13,72 +13,67 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
13
13
  end
14
14
 
15
15
  it 'calls all functions' do
16
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
17
- expect(described_class).to receive(:apply_manifest).with(nil, expect_failures: false, manifest_file_location: '/bla.pp')
18
- expect(described_class).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
19
- described_class.idempotent_apply(manifest)
16
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
17
+ expect(self).to receive(:apply_manifest).with(nil, expect_failures: false, manifest_file_location: '/bla.pp')
18
+ expect(self).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
19
+ idempotent_apply(manifest)
20
20
  end
21
21
  end
22
22
 
23
23
  describe '.apply_manifest' do
24
24
  context 'when specifying a hiera config' do
25
25
  let(:manifest) { "include '::doot'" }
26
- let(:result) { ['result' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
27
- let(:command) { " puppet apply /bla.pp --modulepath #{Dir.pwd}/spec/fixtures/modules --hiera_config='/hiera.yaml'" }
26
+ let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
27
+ let(:command) { " puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --hiera_config='/hiera.yaml'" }
28
28
 
29
29
  it 'passes the --hiera_config flag if the :hiera_config opt is specified' do
30
30
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
31
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
32
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
33
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
34
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
35
- described_class.apply_manifest(manifest, hiera_config: '/hiera.yaml')
31
+ expect(self).to receive(:target_in_inventory?).and_return(true)
32
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
33
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
34
+ apply_manifest(manifest, hiera_config: '/hiera.yaml')
36
35
  end
37
36
  end
38
37
 
39
38
  context 'when using detailed-exitcodes' do
40
39
  let(:manifest) { "include '::doot'" }
41
- let(:result) { ['result' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
42
- let(:command) { " puppet apply /bla.pp --modulepath #{Dir.pwd}/spec/fixtures/modules --detailed-exitcodes" }
40
+ let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
41
+ let(:command) { " puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --detailed-exitcodes" }
43
42
 
44
43
  it 'uses detailed-exitcodes with expect_failures' do
45
44
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
46
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
47
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
48
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
49
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
50
- expect { described_class.apply_manifest(manifest, expect_failures: true) }.to raise_error(RuntimeError)
45
+ expect(self).to receive(:target_in_inventory?).and_return(true)
46
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
47
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
48
+ expect { apply_manifest(manifest, expect_failures: true) }.to raise_error(RuntimeError)
51
49
  end
52
50
 
53
51
  it 'uses detailed-exitcodes with catch_failures' do
54
52
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
55
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
56
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
57
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
58
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
59
- described_class.apply_manifest(manifest, catch_failures: true)
53
+ expect(self).to receive(:target_in_inventory?).and_return(true)
54
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
55
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
56
+ apply_manifest(manifest, catch_failures: true)
60
57
  end
61
58
 
62
59
  it 'uses detailed-exitcodes with expect_changes' do
63
60
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
64
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
65
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
66
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
67
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
68
- expect { described_class.apply_manifest(manifest, expect_changes: true) }.to raise_error(RuntimeError)
61
+ expect(self).to receive(:target_in_inventory?).and_return(true)
62
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
63
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
64
+ expect { apply_manifest(manifest, expect_changes: true) }.to raise_error(RuntimeError)
69
65
  end
70
66
 
71
67
  it 'uses detailed-exitcodes with catch_changes' do
72
68
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
73
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
74
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
75
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
76
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
77
- described_class.apply_manifest(manifest, catch_changes: true)
69
+ expect(self).to receive(:target_in_inventory?).and_return(true)
70
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
71
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
72
+ apply_manifest(manifest, catch_changes: true)
78
73
  end
79
74
 
80
75
  it 'uses raises exception for multiple options' do
81
- expect { described_class.apply_manifest(manifest, catch_changes: true, expect_failures: true) }
76
+ expect { apply_manifest(manifest, catch_changes: true, expect_failures: true) }
82
77
  .to raise_error(RuntimeError, 'please specify only one of `catch_changes`, `expect_changes`, `catch_failures` or `expect_failures`')
83
78
  end
84
79
  end
@@ -86,20 +81,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
86
81
 
87
82
  describe '.run_shell' do
88
83
  let(:command_to_run) { "puts 'doot'" }
89
- let(:result) { ['result' => { 'exit_code' => 0, 'exit_status' => 0, 'stdout' => nil, 'stderr' => nil }] }
84
+ let(:result) { ['value' => { 'exit_code' => 0, 'exit_status' => 0, 'stdout' => nil, 'stderr' => nil }] }
90
85
 
91
86
  it 'responds to run_shell' do
92
- expect(described_class).to respond_to(:run_shell).with(1..2).arguments
87
+ expect(self).to respond_to(:run_shell).with(1..2).arguments
93
88
  end
94
89
 
95
90
  context 'when running against localhost and no inventory.yaml file' do
96
91
  it 'does run_shell against localhost without error' do
97
92
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
98
93
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
99
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
100
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
101
- expect(described_class).to receive(:run_command).with(command_to_run, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
102
- expect { described_class.run_shell(command_to_run) }.not_to raise_error
94
+ expect(self).to receive(:target_in_inventory?).and_return(true)
95
+ expect(self).to receive(:run_command).with(command_to_run, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
96
+ expect { run_shell(command_to_run) }.not_to raise_error
103
97
  end
104
98
  end
105
99
 
@@ -107,10 +101,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
107
101
  it 'does run_shell against remote host without error' do
108
102
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
109
103
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
110
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
111
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
112
- expect(described_class).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
113
- expect { described_class.run_shell(command_to_run) }.not_to raise_error
104
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
105
+ expect(self).to receive(:target_in_inventory?).and_return(true)
106
+ expect(self).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
107
+ expect { run_shell(command_to_run) }.not_to raise_error
114
108
  end
115
109
  end
116
110
  end
@@ -120,32 +114,31 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
120
114
  let(:remote) { '/remote_tmp' }
121
115
  # Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
122
116
  # rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
123
- let(:result_success) {[{'node'=>'some.host','target'=>'some.host','action'=>'upload','object'=>'C:\foo\bar.ps1','status'=>'success','result'=>{'_output'=>'Uploaded \'C:\foo\bar.ps1\' to \'some.host:C:\bar\''}}]}
124
- let(:result_failure) {[{'node'=>'some.host','target'=>'some.host','action'=>nil,'object'=>nil,'status'=>'failure','result'=>{'_error'=>{'kind'=>'puppetlabs.tasks/task_file_error','msg'=>'No such file or directory @ rb_sysopen - /nonexistant/file/path','details'=>{},'issue_code'=>'WRITE_ERROR'}}}]}
117
+ let(:result_success) {[{'target'=>'some.host','action'=>'upload','object'=>'C:\foo\bar.ps1','status'=>'success','value'=>{'_output'=>'Uploaded \'C:\foo\bar.ps1\' to \'some.host:C:\bar\''}}]}
118
+ let(:result_failure) {[{'target'=>'some.host','action'=>nil,'object'=>nil,'status'=>'failure','value'=>{'_error'=>{'kind'=>'puppetlabs.tasks/task_file_error','msg'=>'No such file or directory @ rb_sysopen - /nonexistant/file/path','details'=>{},'issue_code'=>'WRITE_ERROR'}}}]}
125
119
  # rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
126
120
 
127
121
  it 'responds to run_shell' do
128
- expect(described_class).to respond_to(:bolt_upload_file).with(2..3).arguments
122
+ expect(self).to respond_to(:bolt_upload_file).with(2..3).arguments
129
123
  end
130
124
 
131
125
  context 'when upload returns success' do
132
126
  it 'does upload_file against remote host without error' do
133
127
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
134
128
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
135
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
136
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
137
- expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
138
- expect { described_class.bolt_upload_file(local, remote) }.not_to raise_error
129
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
130
+ expect(self).to receive(:target_in_inventory?).and_return(true)
131
+ expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
132
+ expect { bolt_upload_file(local, remote) }.not_to raise_error
139
133
  end
140
134
 
141
135
  it 'does upload_file against localhost without error' do
142
136
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
143
137
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
144
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
145
- expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
146
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
147
- expect(described_class).to receive(:upload_file).with(local, remote, 'litmus_localhost', options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result_success)
148
- expect { described_class.bolt_upload_file(local, remote) }.not_to raise_error
138
+ expect(self).not_to receive(:inventory_hash_from_inventory_file)
139
+ expect(self).to receive(:target_in_inventory?).and_return(true)
140
+ expect(self).to receive(:upload_file).with(local, remote, 'litmus_localhost', options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result_success)
141
+ expect { bolt_upload_file(local, remote) }.not_to raise_error
149
142
  end
150
143
  end
151
144
 
@@ -153,19 +146,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
153
146
  it 'does upload_file gives runtime error for failure' do
154
147
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
155
148
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
156
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
157
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
158
- expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
159
- expect { described_class.bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
149
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
150
+ expect(self).to receive(:target_in_inventory?).and_return(true)
151
+ expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
152
+ expect { bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
160
153
  end
161
154
 
162
155
  it 'returns the exit code and error message when expecting failure' do
163
156
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
164
157
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
165
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
166
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
167
- expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
168
- method_result = described_class.bolt_upload_file(local, remote, expect_failures: true)
158
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
159
+ expect(self).to receive(:target_in_inventory?).and_return(true)
160
+ expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
161
+ method_result = bolt_upload_file(local, remote, expect_failures: true)
169
162
  expect(method_result.exit_code).to be(255)
170
163
  expect(method_result.stderr).to be('No such file or directory @ rb_sysopen - /nonexistant/file/path')
171
164
  end
@@ -174,21 +167,20 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
174
167
 
175
168
  describe '.bolt_run_script' do
176
169
  let(:script) { '/tmp/script.sh' }
177
- let(:result) { ['result' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
170
+ let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
178
171
 
179
172
  it 'responds to bolt_run_script' do
180
- expect(described_class).to respond_to(:bolt_run_script).with(1..2).arguments
173
+ expect(self).to respond_to(:bolt_run_script).with(1..2).arguments
181
174
  end
182
175
 
183
176
  context 'when running against localhost and no inventory.yaml file' do
184
177
  it 'does bolt_run_script against localhost without error' do
185
178
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
186
179
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
187
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
188
- expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
189
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
190
- expect(described_class).to receive(:run_script).with(script, 'litmus_localhost', [], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
191
- expect { described_class.bolt_run_script(script) }.not_to raise_error
180
+ expect(self).not_to receive(:inventory_hash_from_inventory_file)
181
+ expect(self).to receive(:target_in_inventory?).and_return(true)
182
+ expect(self).to receive(:run_script).with(script, 'litmus_localhost', [], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
183
+ expect { bolt_run_script(script) }.not_to raise_error
192
184
  end
193
185
  end
194
186
 
@@ -196,10 +188,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
196
188
  it 'does bolt_run_script against remote host without error' do
197
189
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
198
190
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
199
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
200
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
201
- expect(described_class).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: inventory_hash).and_return(result)
202
- expect { described_class.bolt_run_script(script) }.not_to raise_error
191
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
192
+ expect(self).to receive(:target_in_inventory?).and_return(true)
193
+ expect(self).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: inventory_hash).and_return(result)
194
+ expect { bolt_run_script(script) }.not_to raise_error
203
195
  end
204
196
  end
205
197
 
@@ -207,11 +199,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
207
199
  it 'does bolt_run_script with arguments without error' do
208
200
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
209
201
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
210
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
211
- expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
212
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
213
- expect(described_class).to receive(:run_script).with(script, 'litmus_localhost', ['doot'], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
214
- expect { described_class.bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
202
+ expect(self).not_to receive(:inventory_hash_from_inventory_file)
203
+ expect(self).to receive(:target_in_inventory?).and_return(true)
204
+ expect(self).to receive(:run_script).with(script, 'litmus_localhost', ['doot'], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
205
+ expect { bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
215
206
  end
216
207
  end
217
208
  end
@@ -222,51 +213,51 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
222
213
  let(:config_data) { { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } }
223
214
  # Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
224
215
  # rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
225
- let(:result_unstructured_task_success){ [{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'success','result'=>{'_output'=>'SUCCESS!'}}]}
226
- let(:result_structured_task_success){ [{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::structured','status'=>'success','result'=>{'key1'=>'foo','key2'=>'bar'}}]}
227
- let(:result_failure) {[{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'failure','result'=>{'_error'=>{'msg'=>'FAILURE!','kind'=>'puppetlabs.tasks/task-error','details'=>{'exitcode'=>123}}}}]}
216
+ let(:result_unstructured_task_success){ [{'target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'success','value'=>{'_output'=>'SUCCESS!'}}]}
217
+ let(:result_structured_task_success){ [{'target'=>'some.host','action'=>'task','object'=>'testtask::structured','status'=>'success','value'=>{'key1'=>'foo','key2'=>'bar'}}]}
218
+ let(:result_failure) {[{'target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'failure','value'=>{'_error'=>{'msg'=>'FAILURE!','kind'=>'puppetlabs.tasks/task-error','details'=>{'exitcode'=>123}}}}]}
228
219
  # rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
229
220
 
230
221
  it 'responds to bolt_run_task' do
231
- expect(described_class).to respond_to(:run_bolt_task).with(2..3).arguments
222
+ expect(self).to respond_to(:run_bolt_task).with(2..3).arguments
232
223
  end
233
224
 
234
225
  context 'when bolt returns success' do
235
226
  it 'does bolt_task_run gives no runtime error for success' do
236
227
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
237
228
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
238
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
239
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
240
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
241
- expect { described_class.run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
229
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
230
+ expect(self).to receive(:target_in_inventory?).and_return(true)
231
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
232
+ expect { run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
242
233
  end
243
234
 
244
235
  it 'does bolt_task_run gives no runtime error for success, for a named inventory file' do
245
236
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
246
237
  expect(File).to receive(:exist?).with('jim.yaml').and_return(true)
247
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
248
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
249
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
250
- expect { described_class.run_bolt_task(task_name, params, inventory_file: 'jim.yaml') }.not_to raise_error
238
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
239
+ expect(self).to receive(:target_in_inventory?).and_return(true)
240
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
241
+ expect { run_bolt_task(task_name, params, inventory_file: 'jim.yaml') }.not_to raise_error
251
242
  end
252
243
 
253
244
  it 'returns stdout for unstructured-data tasks' do
254
245
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
255
246
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
256
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
257
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
258
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
259
- method_result = described_class.run_bolt_task(task_name, params, opts: {})
247
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
248
+ expect(self).to receive(:target_in_inventory?).and_return(true)
249
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
250
+ method_result = run_bolt_task(task_name, params, opts: {})
260
251
  expect(method_result.stdout).to eq('SUCCESS!')
261
252
  end
262
253
 
263
254
  it 'returns structured output for structured-data tasks' do
264
255
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
265
256
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
266
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
267
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
268
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
269
- method_result = described_class.run_bolt_task(task_name, params, opts: {})
257
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
258
+ expect(self).to receive(:target_in_inventory?).and_return(true)
259
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
260
+ method_result = run_bolt_task(task_name, params, opts: {})
270
261
  expect(method_result.stdout).to eq('{"key1"=>"foo", "key2"=>"bar"}')
271
262
  expect(method_result.result['key1']).to eq('foo')
272
263
  expect(method_result.result['key2']).to eq('bar')
@@ -277,19 +268,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
277
268
  it 'does bolt_task_run gives runtime error for failure' do
278
269
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
279
270
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
280
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
281
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
282
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
283
- expect { described_class.run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
271
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
272
+ expect(self).to receive(:target_in_inventory?).and_return(true)
273
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
274
+ expect { run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
284
275
  end
285
276
 
286
277
  it 'returns the exit code and error message when expecting failure' do
287
278
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
288
279
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
289
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
290
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
291
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
292
- method_result = described_class.run_bolt_task(task_name, params, expect_failures: true)
280
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
281
+ expect(self).to receive(:target_in_inventory?).and_return(true)
282
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
283
+ method_result = run_bolt_task(task_name, params, expect_failures: true)
293
284
  expect(method_result.exit_code).to be(123)
294
285
  expect(method_result.stderr).to be('FAILURE!')
295
286
  end