puppet_litmus 0.17.0 → 0.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -16
- data/lib/puppet_litmus/inventory_manipulation.rb +10 -2
- data/lib/puppet_litmus/puppet_helpers.rb +44 -40
- data/lib/puppet_litmus/rake_helper.rb +146 -71
- data/lib/puppet_litmus/rake_tasks.rb +95 -101
- data/lib/puppet_litmus/spec_helper_acceptance.rb +1 -1
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/lib/puppet_litmus/inventory_manipulation_spec.rb +16 -16
- data/spec/lib/puppet_litmus/puppet_helpers_spec.rb +99 -108
- data/spec/lib/puppet_litmus/rake_helper_spec.rb +28 -23
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +14 -12
- data/spec/spec_helper.rb +7 -6
- metadata +27 -22
@@ -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.
|
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
|
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.
|
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['
|
60
|
+
failed_image_message += "=====\n#{result.first['target']}\n#{result.first['value']['_output']}\n#{result.inspect}"
|
61
61
|
else
|
62
|
-
STDOUT.puts "#{result.first['
|
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
|
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['
|
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
|
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['
|
123
|
-
raise "Failed on #{result['
|
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['
|
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['
|
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 '
|
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
|
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 '
|
174
|
-
task :
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
raise "
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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
|
-
#
|
193
|
+
# Install the puppet modules from a source directory to nodes. It does not install dependencies.
|
210
194
|
#
|
211
|
-
# @param :
|
212
|
-
|
213
|
-
|
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
|
-
|
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
|
-
#
|
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
|
-
|
227
|
-
|
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
|
-
|
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
|
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['
|
244
|
+
puts "#{node['target']} failed #{node['value']}" if node['status'] != 'success'
|
247
245
|
end
|
248
246
|
|
249
|
-
puts '
|
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 '
|
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 '
|
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['
|
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
|
-
|
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
|
@@ -92,70 +92,70 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'no matching node, raises' do
|
95
|
-
expect {
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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 {
|
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(
|
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(
|
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(
|
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 {
|
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(
|
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 {
|
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(
|
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(
|
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(
|
17
|
-
expect(
|
18
|
-
expect(
|
19
|
-
|
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) { ['
|
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(
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
|
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) { ['
|
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(
|
47
|
-
expect(
|
48
|
-
expect(
|
49
|
-
expect
|
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(
|
56
|
-
expect(
|
57
|
-
expect(
|
58
|
-
|
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(
|
65
|
-
expect(
|
66
|
-
expect(
|
67
|
-
expect
|
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(
|
74
|
-
expect(
|
75
|
-
expect(
|
76
|
-
|
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 {
|
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) { ['
|
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(
|
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(
|
100
|
-
expect(
|
101
|
-
expect(
|
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(
|
111
|
-
expect(
|
112
|
-
expect(
|
113
|
-
expect {
|
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) {[{'
|
124
|
-
let(:result_failure) {[{'
|
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(
|
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(
|
136
|
-
expect(
|
137
|
-
expect(
|
138
|
-
expect {
|
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(
|
145
|
-
expect(
|
146
|
-
expect(
|
147
|
-
expect
|
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(
|
157
|
-
expect(
|
158
|
-
expect(
|
159
|
-
expect {
|
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(
|
166
|
-
expect(
|
167
|
-
expect(
|
168
|
-
method_result =
|
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) { ['
|
170
|
+
let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
178
171
|
|
179
172
|
it 'responds to bolt_run_script' do
|
180
|
-
expect(
|
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(
|
188
|
-
expect(
|
189
|
-
expect(
|
190
|
-
expect
|
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(
|
200
|
-
expect(
|
201
|
-
expect(
|
202
|
-
expect {
|
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(
|
211
|
-
expect(
|
212
|
-
expect(
|
213
|
-
expect
|
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){ [{'
|
226
|
-
let(:result_structured_task_success){ [{'
|
227
|
-
let(:result_failure) {[{'
|
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(
|
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(
|
239
|
-
expect(
|
240
|
-
expect(
|
241
|
-
expect {
|
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(
|
248
|
-
expect(
|
249
|
-
expect(
|
250
|
-
expect {
|
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(
|
257
|
-
expect(
|
258
|
-
expect(
|
259
|
-
method_result =
|
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(
|
267
|
-
expect(
|
268
|
-
expect(
|
269
|
-
method_result =
|
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(
|
281
|
-
expect(
|
282
|
-
expect(
|
283
|
-
expect {
|
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(
|
290
|
-
expect(
|
291
|
-
expect(
|
292
|
-
method_result =
|
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
|