puppet_litmus 0.36.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9a130b9a5ccaf0b18f53a163b9e65dd207eef1fbe23db2921df3b4b534f44ab
4
- data.tar.gz: b2f1d8367e536d2f83104b839438e26e7cfc4da9f06ba714730e7dbbb2de6f6c
3
+ metadata.gz: 8f2e5cb7497ccf31dbdb164f7a408c92940831f6e46b5ec5dc6b369bc39b8277
4
+ data.tar.gz: 1f38af54816bb26cd8787c9e209afe7b3f1589355cb324c60eb3ca9fcde05dc4
5
5
  SHA512:
6
- metadata.gz: 9e5852a7557b51cf4ee81a50d169d58a7de90aebb6f4c0f53258274632b49f7e8d93175176b60b3435023326df6cabf27f68d10209d5bfdf100911f32a438869
7
- data.tar.gz: 4c70b9fb01b6a32b374e287d2a8444896d31d9d38a0a8b7e18cc1cc10f5b531fcfad811a8269f707b9cc05f7085a5f94f94c28acf84a0a5858ebe5ef43db1e4f
6
+ metadata.gz: 0cdcccf05f113f0ea462ceac7709c5299a622b1343d6ed8fd1f26dc51122e7068bb7f7ab5808fd5f052e83d4f9efc1631b7a69d933e3078b32fbec335ea91de6
7
+ data.tar.gz: 12f93057558409cad13d67b705f1a7a021d470f8885e4fe8421591eb091dc1a8869e2637d95991a5efb77348c0a96abecda1d22ad047aa8ae5be75a61cfa78a7
@@ -31,7 +31,7 @@ IMAGE_TABLE = {
31
31
  'SLES-15' => 'sles-15',
32
32
  'Windows-2012 R2' => 'windows-2012-r2-core',
33
33
  'Windows-2016' => 'windows-2016',
34
- 'Windows-2019' => 'windows-2019-core',
34
+ 'Windows-2019' => 'windows-2019-core'
35
35
  }.freeze
36
36
 
37
37
  DOCKER_PLATFORMS = [
@@ -48,26 +48,26 @@ DOCKER_PLATFORMS = [
48
48
  'Ubuntu-14.04',
49
49
  'Ubuntu-16.04',
50
50
  'Ubuntu-18.04',
51
- 'Ubuntu-20.04',
51
+ 'Ubuntu-20.04'
52
52
  ].freeze
53
53
 
54
54
  # This table uses the latest version in each collection for accurate
55
55
  # comparison when evaluating puppet requirements from the metadata
56
56
  COLLECTION_TABLE = {
57
57
  '6.21.0' => 'puppet6-nightly',
58
- '7.4.0' => 'puppet7-nightly',
58
+ '7.4.0' => 'puppet7-nightly'
59
59
  }.freeze
60
60
 
61
61
  matrix = {
62
62
  platform: [],
63
- collection: [],
63
+ collection: []
64
64
  }
65
65
 
66
66
  metadata = JSON.parse(File.read('metadata.json'))
67
67
  # Set platforms based on declared operating system support
68
68
  metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
69
69
  os = sup['operatingsystem']
70
- sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
70
+ sup['operatingsystemrelease'].sort_by(&:to_i).each do |ver|
71
71
  image_key = "#{os}-#{ver}"
72
72
  if IMAGE_TABLE.key? image_key
73
73
  matrix[:platform] << IMAGE_TABLE[image_key]
@@ -84,7 +84,7 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
84
84
  metadata['requirements'].each do |req|
85
85
  next unless req.key?('name') && req.key?('version_requirement') && req['name'] == 'puppet'
86
86
 
87
- ver_regexp = %r{^([>=<]{1,2})\s*([\d.]+)\s+([>=<]{1,2})\s*([\d.]+)$}
87
+ ver_regexp = /^([>=<]{1,2})\s*([\d.]+)\s+([>=<]{1,2})\s*([\d.]+)$/
88
88
  match = ver_regexp.match(req['version_requirement'])
89
89
  if match.nil?
90
90
  puts "::warning::Didn't recognize version_requirement '#{req['version_requirement']}'"
@@ -95,17 +95,13 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
95
95
  reqs = ["#{cmp_one} #{ver_one}", "#{cmp_two} #{ver_two}"]
96
96
 
97
97
  COLLECTION_TABLE.each do |key, val|
98
- if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
99
- matrix[:collection] << val
100
- end
98
+ matrix[:collection] << val if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
101
99
  end
102
100
  end
103
101
  end
104
102
 
105
103
  # Set to defaults (all collections) if no matches are found
106
- if matrix[:collection].empty?
107
- matrix[:collection] = COLLECTION_TABLE.values
108
- end
104
+ matrix[:collection] = COLLECTION_TABLE.values if matrix[:collection].empty?
109
105
 
110
106
  # Just to make sure there aren't any duplicates
111
107
  matrix[:platform] = matrix[:platform].uniq.sort
@@ -32,7 +32,7 @@ IMAGE_TABLE = {
32
32
  'SLES-15' => 'sles-15',
33
33
  'Windows-2016' => 'windows-2016',
34
34
  'Windows-2019' => 'windows-2019',
35
- 'Windows-2022' => 'windows-2022',
35
+ 'Windows-2022' => 'windows-2022'
36
36
  }.freeze
37
37
 
38
38
  DOCKER_PLATFORMS = {
@@ -53,44 +53,40 @@ DOCKER_PLATFORMS = {
53
53
  # 'Ubuntu-16.04' => 'litmusimage/ubuntu:16.04', Support Dropped
54
54
  'Ubuntu-18.04' => 'litmusimage/ubuntu:18.04',
55
55
  'Ubuntu-20.04' => 'litmusimage/ubuntu:20.04',
56
- 'Ubuntu-22.04' => 'litmusimage/ubuntu:22.04',
56
+ 'Ubuntu-22.04' => 'litmusimage/ubuntu:22.04'
57
57
  }.freeze
58
58
 
59
59
  # This table uses the latest version in each collection for accurate
60
60
  # comparison when evaluating puppet requirements from the metadata
61
61
  COLLECTION_TABLE = [
62
- {
63
- puppet_maj_version: 6,
64
- ruby_version: 2.5,
65
- },
66
62
  {
67
63
  puppet_maj_version: 7,
68
- ruby_version: 2.7,
64
+ ruby_version: 2.7
69
65
  },
70
66
  {
71
67
  puppet_maj_version: 8,
72
- ruby_version: 3.2,
73
- },
68
+ ruby_version: 3.2
69
+ }
74
70
  ].freeze
75
71
 
76
72
  matrix = {
77
73
  platforms: [],
78
- collection: [],
74
+ collection: []
79
75
  }
80
76
 
81
77
  spec_matrix = {
82
- include: [],
78
+ include: []
83
79
  }
84
80
 
85
81
  if ARGV.include?('--exclude-platforms')
86
- exclude_platforms_occurencies = ARGV.select { |arg| arg == '--exclude-platforms' }.length
82
+ exclude_platforms_occurencies = ARGV.count { |arg| arg == '--exclude-platforms' }
87
83
  raise '--exclude-platforms argument should be present just one time in the command' unless exclude_platforms_occurencies <= 1
88
84
 
89
85
  exclude_platforms_list = ARGV[ARGV.find_index('--exclude-platforms') + 1]
90
86
  raise 'you need to provide a list of platforms in JSON format' if exclude_platforms_list.nil?
91
87
 
92
88
  begin
93
- exclude_list = JSON.parse(exclude_platforms_list).map { |platform| platform.downcase }
89
+ exclude_list = JSON.parse(exclude_platforms_list).map(&:downcase)
94
90
  rescue JSON::ParserError
95
91
  raise 'the exclude platforms list must valid JSON'
96
92
  end
@@ -103,20 +99,20 @@ metadata = JSON.parse(File.read(metadata_path))
103
99
  # Set platforms based on declared operating system support
104
100
  metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
105
101
  os = sup['operatingsystem']
106
- sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
102
+ sup['operatingsystemrelease'].sort_by(&:to_i).each do |ver|
107
103
  image_key = "#{os}-#{ver}"
108
104
 
109
105
  if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase)
110
106
  matrix[:platforms] << {
111
107
  label: image_key,
112
108
  provider: 'provision::provision_service',
113
- image: IMAGE_TABLE[image_key],
109
+ image: IMAGE_TABLE[image_key]
114
110
  }
115
111
  elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase)
116
112
  matrix[:platforms] << {
117
113
  label: image_key,
118
114
  provider: 'provision::docker',
119
- image: DOCKER_PLATFORMS[image_key],
115
+ image: DOCKER_PLATFORMS[image_key]
120
116
  }
121
117
  else
122
118
  puts "::warning::#{image_key} was excluded from testing" if exclude_list.include?(image_key.downcase)
@@ -130,7 +126,7 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
130
126
  metadata['requirements'].each do |req|
131
127
  next unless req.key?('name') && req.key?('version_requirement') && req['name'] == 'puppet'
132
128
 
133
- ver_regexp = %r{^([>=<]{1,2})\s*([\d.]+)\s+([>=<]{1,2})\s*([\d.]+)$}
129
+ ver_regexp = /^([>=<]{1,2})\s*([\d.]+)\s+([>=<]{1,2})\s*([\d.]+)$/
134
130
  match = ver_regexp.match(req['version_requirement'])
135
131
  if match.nil?
136
132
  puts "::warning::Didn't recognize version_requirement '#{req['version_requirement']}'"
@@ -156,12 +152,10 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
156
152
  end
157
153
 
158
154
  # Set to defaults (all collections) if no matches are found
159
- if matrix[:collection].empty?
160
- matrix[:collection] = COLLECTION_TABLE.map { |collection| "puppet#{collection[:puppet_maj_version]}-nightly" }
161
- end
155
+ matrix[:collection] = COLLECTION_TABLE.map { |collection| "puppet#{collection[:puppet_maj_version]}-nightly" } if matrix[:collection].empty?
162
156
 
163
157
  # Just to make sure there aren't any duplicates
164
- matrix[:platforms] = matrix[:platforms].uniq.sort { |a, b| a[:label] <=> b[:label] }
158
+ matrix[:platforms] = matrix[:platforms].uniq.sort_by { |a| a[:label] }
165
159
  matrix[:collection] = matrix[:collection].uniq.sort
166
160
 
167
161
  set_output('matrix', JSON.generate(matrix))
@@ -32,11 +32,11 @@ module PuppetLitmus::InventoryManipulation
32
32
  {
33
33
  'uri' => 'litmus_localhost',
34
34
  'config' => { 'transport' => 'local' },
35
- 'feature' => 'puppet-agent',
36
- },
37
- ],
38
- },
39
- ],
35
+ 'feature' => 'puppet-agent'
36
+ }
37
+ ]
38
+ }
39
+ ]
40
40
  }
41
41
  end
42
42
 
@@ -47,7 +47,7 @@ module PuppetLitmus::InventoryManipulation
47
47
  # @return [Array] array of targets.
48
48
  def find_targets(inventory_hash, targets)
49
49
  if targets.nil?
50
- inventory_hash.to_s.scan(%r{uri"=>"(\S*)"}).flatten
50
+ inventory_hash.to_s.scan(/uri"=>"(\S*)"/).flatten
51
51
  else
52
52
  [targets]
53
53
  end
@@ -62,7 +62,7 @@ module PuppetLitmus::InventoryManipulation
62
62
  def groups_in_inventory(inventory_hash, &block)
63
63
  inventory_hash['groups'].flat_map do |group|
64
64
  output_collector = []
65
- output_collector << if block_given?
65
+ output_collector << if block
66
66
  yield group
67
67
  else
68
68
  group['name'].downcase
@@ -104,7 +104,7 @@ module PuppetLitmus::InventoryManipulation
104
104
  targets_in_inventory(inventory) do |target|
105
105
  vars = target['vars']
106
106
  roles = [(vars['role'] || vars['roles'])].flatten
107
- roles = roles.map { |r| r.downcase }
107
+ roles = roles.map(&:downcase)
108
108
  output_collector << target['uri'] if roles.include? role.downcase
109
109
  end
110
110
  output_collector unless output_collector.empty?
@@ -166,7 +166,7 @@ module PuppetLitmus::InventoryManipulation
166
166
  # @return [Hash] config for node of name node_name
167
167
  def config_from_node(inventory_hash, node_name)
168
168
  config = targets_in_inventory(inventory_hash) do |target|
169
- next unless target['uri'].downcase == node_name.downcase
169
+ next unless target['uri'].casecmp(node_name).zero?
170
170
 
171
171
  return target['config'] unless target['config'].nil?
172
172
  end
@@ -181,7 +181,7 @@ module PuppetLitmus::InventoryManipulation
181
181
  # @return [Hash] facts for node of name node_name
182
182
  def facts_from_node(inventory_hash, node_name)
183
183
  facts = targets_in_inventory(inventory_hash) do |target|
184
- next unless target['uri'].downcase == node_name.downcase
184
+ next unless target['uri'].casecmp(node_name).zero?
185
185
 
186
186
  target['facts'] unless target['facts'].nil?
187
187
  end
@@ -196,7 +196,7 @@ module PuppetLitmus::InventoryManipulation
196
196
  # @return [Hash] vars for node of name node_name
197
197
  def vars_from_node(inventory_hash, node_name)
198
198
  vars = targets_in_inventory(inventory_hash) do |target|
199
- next unless target['uri'].downcase == node_name.downcase
199
+ next unless target['uri'].casecmp(node_name).zero?
200
200
 
201
201
  target['vars'] unless target['vars'].nil?
202
202
  end
@@ -213,9 +213,7 @@ module PuppetLitmus::InventoryManipulation
213
213
  # check if group exists
214
214
  if inventory_hash['groups'].any? { |g| g['name'] == group_name }
215
215
  inventory_hash['groups'].each do |group|
216
- if group['name'] == group_name
217
- group['targets'].push node
218
- end
216
+ group['targets'].push node if group['name'] == group_name
219
217
  end
220
218
  else
221
219
  # add new group
@@ -248,9 +246,7 @@ module PuppetLitmus::InventoryManipulation
248
246
  i = 0
249
247
  inventory_hash['groups'].each do |group|
250
248
  if group['name'] == group_name
251
- if group['features'].nil? == true
252
- group = group.merge('features' => [])
253
- end
249
+ group = group.merge('features' => []) if group['features'].nil? == true
254
250
  group['features'].push feature_name unless group['features'].include?(feature_name)
255
251
  inventory_hash['groups'][i] = group
256
252
  end
@@ -268,9 +264,7 @@ module PuppetLitmus::InventoryManipulation
268
264
  # @return [Hash] inventory_hash with feature added to group if group_name exists in inventory hash.
269
265
  def remove_feature_from_group(inventory_hash, feature_name, group_name)
270
266
  inventory_hash['groups'].each do |group|
271
- if group['name'] == group_name && group['features'].nil? != true
272
- group['features'].delete(feature_name)
273
- end
267
+ group['features'].delete(feature_name) if group['name'] == group_name && group['features'].nil? != true
274
268
  end
275
269
  inventory_hash
276
270
  end
@@ -288,9 +282,7 @@ module PuppetLitmus::InventoryManipulation
288
282
  node_index = 0
289
283
  group['targets'].each do |node|
290
284
  if node['uri'] == node_name
291
- if node['features'].nil? == true
292
- node = node.merge('features' => [])
293
- end
285
+ node = node.merge('features' => []) if node['features'].nil? == true
294
286
  node['features'].push feature_name unless node['features'].include?(feature_name)
295
287
  inventory_hash['groups'][group_index]['targets'][node_index] = node
296
288
  end
@@ -311,9 +303,7 @@ module PuppetLitmus::InventoryManipulation
311
303
  def remove_feature_from_node(inventory_hash, feature_name, node_name)
312
304
  inventory_hash['groups'].each do |group|
313
305
  group['targets'].each do |node|
314
- if node['uri'] == node_name && node['features'].nil? != true
315
- node['features'].delete(feature_name)
316
- end
306
+ node['features'].delete(feature_name) if node['uri'] == node_name && node['features'].nil? != true
317
307
  end
318
308
  end
319
309
  inventory_hash
@@ -54,7 +54,7 @@ module PuppetLitmus::PuppetHelpers
54
54
  span.add_field('litmus.manifest', manifest)
55
55
  span.add_field('litmus.opts', opts)
56
56
 
57
- target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
57
+ target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV.fetch('TARGET_HOST', nil)
58
58
  raise 'manifest and manifest_file_location in the opts hash are mutually exclusive arguments, pick one' if !manifest.nil? && !opts[:manifest_file_location].nil?
59
59
  raise 'please pass a manifest or the manifest_file_location in the opts hash' if (manifest.nil? || manifest == '') && opts[:manifest_file_location].nil?
60
60
  raise 'please specify only one of `catch_changes`, `expect_changes`, `catch_failures` or `expect_failures`' if
@@ -92,10 +92,10 @@ module PuppetLitmus::PuppetHelpers
92
92
  add_node_fields_to_span(span, target_node_name, inventory_hash)
93
93
 
94
94
  # Forcibly set the locale of the command
95
- locale = if os[:family] != 'windows'
96
- 'LC_ALL=en_US.UTF-8 '
97
- else
95
+ locale = if os[:family] == 'windows'
98
96
  ''
97
+ else
98
+ 'LC_ALL=en_US.UTF-8 '
99
99
  end
100
100
  command_to_run = "#{locale}#{opts[:prefix_command]} puppet apply #{manifest_file_location}"
101
101
  command_to_run += ' --trace' if !opts[:trace].nil? && (opts[:trace] == true)
@@ -154,7 +154,7 @@ module PuppetLitmus::PuppetHelpers
154
154
  span.add_field('litmus.manifest', manifest)
155
155
 
156
156
  require 'tmpdir'
157
- target_node_name = ENV['TARGET_HOST']
157
+ target_node_name = ENV.fetch('TARGET_HOST', nil)
158
158
  tmp_filename = File.join(Dir.tmpdir, "manifest_#{Time.now.strftime('%Y%m%d')}_#{Process.pid}_#{rand(0x100000000).to_s(36)}.pp")
159
159
  manifest_file = File.open(tmp_filename, 'w')
160
160
  manifest_file.write(manifest)
@@ -193,7 +193,7 @@ module PuppetLitmus::PuppetHelpers
193
193
 
194
194
  require 'tmpdir'
195
195
  inventory_hash = inventory_hash_from_inventory_file
196
- target_node_name = ENV['TARGET_HOST']
196
+ target_node_name = ENV.fetch('TARGET_HOST', nil)
197
197
  target_option = opts['targets'] || opts[:targets]
198
198
  target_node_name = search_for_target(target_option, inventory_hash) unless target_option.nil?
199
199
 
@@ -234,7 +234,7 @@ module PuppetLitmus::PuppetHelpers
234
234
 
235
235
  target_option = opts['targets'] || opts[:targets]
236
236
  if target_option.nil?
237
- target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
237
+ target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV.fetch('TARGET_HOST', nil)
238
238
  raise "Target '#{target_node_name}' not found in spec/fixtures/litmus_inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
239
239
  else
240
240
  target_node_name = search_for_target(target_option, inventory_hash)
@@ -245,9 +245,7 @@ module PuppetLitmus::PuppetHelpers
245
245
  bolt_result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
246
246
  span.add_field('litmus.bolt_result', bolt_result)
247
247
 
248
- if bolt_result.first['value']['exit_code'] != 0 && opts[:expect_failures] != true
249
- raise "shell failed\n`#{command_to_run}`\n======\n#{bolt_result}"
250
- end
248
+ raise "shell failed\n`#{command_to_run}`\n======\n#{bolt_result}" if bolt_result.first['value']['exit_code'] != 0 && opts[:expect_failures] != true
251
249
 
252
250
  result = OpenStruct.new(exit_code: bolt_result.first['value']['exit_code'],
253
251
  exit_status: bolt_result.first['value']['exit_code'],
@@ -277,7 +275,7 @@ module PuppetLitmus::PuppetHelpers
277
275
  inventory_hash = File.exist?('spec/fixtures/litmus_inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
278
276
  target_option = opts['targets'] || opts[:targets]
279
277
  if target_option.nil?
280
- target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
278
+ target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV.fetch('TARGET_HOST', nil)
281
279
  raise "Target '#{target_node_name}' not found in spec/fixtures/litmus_inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
282
280
  else
283
281
  target_node_name = search_for_target(target_option, inventory_hash)
@@ -292,7 +290,7 @@ module PuppetLitmus::PuppetHelpers
292
290
  exit_code: 0,
293
291
  stdout: bolt_result.first['value']['_output'],
294
292
  stderr: nil,
295
- result: bolt_result.first['value'],
293
+ result: bolt_result.first['value']
296
294
  }
297
295
 
298
296
  if bolt_result.first['status'] != 'success'
@@ -330,7 +328,7 @@ module PuppetLitmus::PuppetHelpers
330
328
  span.add_field('litmus.opts', opts)
331
329
 
332
330
  config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
333
- target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
331
+ target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV.fetch('TARGET_HOST', nil)
334
332
  inventory_hash = if !opts[:inventory_file].nil? && File.exist?(opts[:inventory_file])
335
333
  inventory_hash_from_inventory_file(opts[:inventory_file])
336
334
  elsif File.exist?('spec/fixtures/litmus_inventory.yaml')
@@ -353,7 +351,7 @@ module PuppetLitmus::PuppetHelpers
353
351
  exit_code: 0,
354
352
  stdout: nil,
355
353
  stderr: nil,
356
- result: bolt_result.first['value'],
354
+ result: bolt_result.first['value']
357
355
  }
358
356
 
359
357
  if bolt_result.first['status'] == 'success'
@@ -402,7 +400,7 @@ module PuppetLitmus::PuppetHelpers
402
400
  span.add_field('litmus.opts', opts)
403
401
  span.add_field('litmus.arguments', arguments)
404
402
 
405
- target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
403
+ target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV.fetch('TARGET_HOST', nil)
406
404
  inventory_hash = File.exist?('spec/fixtures/litmus_inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
407
405
  target_option = opts['targets'] || opts[:targets]
408
406
  if target_option.nil?
@@ -5,11 +5,9 @@ require 'honeycomb-beeline'
5
5
  require 'puppet_litmus/version'
6
6
  Honeycomb.configure do |config|
7
7
  # override client if no configuration is provided, so that the pesky libhoney warning about lack of configuration is not shown
8
- unless ENV['HONEYCOMB_WRITEKEY'] && ENV['HONEYCOMB_DATASET']
9
- config.client = Libhoney::NullClient.new
10
- end
8
+ config.client = Libhoney::NullClient.new unless ENV['HONEYCOMB_WRITEKEY'] && ENV['HONEYCOMB_DATASET']
11
9
  end
12
- process_span = Honeycomb.start_span(name: "litmus: #{([$PROGRAM_NAME] + ($ARGV || [])).join(' ')}", serialized_trace: ENV['HONEYCOMB_TRACE'])
10
+ process_span = Honeycomb.start_span(name: "litmus: #{([$PROGRAM_NAME] + ($ARGV || [])).join(' ')}", serialized_trace: ENV.fetch('HONEYCOMB_TRACE', nil))
13
11
  ENV['HONEYCOMB_TRACE'] = process_span.to_trace_header
14
12
  Honeycomb.add_field_to_trace('litmus.pid', Process.pid)
15
13
  if defined? PuppetLitmus::VERSION
@@ -18,27 +16,27 @@ else
18
16
  Honeycomb.add_field_to_trace('litmus.version', 'undefined')
19
17
  end
20
18
  if ENV['CI'] == 'true' && ENV['TRAVIS'] == 'true'
21
- Honeycomb.add_field_to_trace('module_name', ENV['TRAVIS_REPO_SLUG'])
19
+ Honeycomb.add_field_to_trace('module_name', ENV.fetch('TRAVIS_REPO_SLUG', nil))
22
20
  Honeycomb.add_field_to_trace('ci.provider', 'travis')
23
- Honeycomb.add_field_to_trace('ci.build_id', ENV['TRAVIS_BUILD_ID'])
24
- Honeycomb.add_field_to_trace('ci.build_url', ENV['TRAVIS_BUILD_WEB_URL'])
25
- Honeycomb.add_field_to_trace('ci.job_url', ENV['TRAVIS_JOB_WEB_URL'])
26
- Honeycomb.add_field_to_trace('ci.commit_message', ENV['TRAVIS_COMMIT_MESSAGE'])
27
- Honeycomb.add_field_to_trace('ci.sha', ENV['TRAVIS_PULL_REQUEST_SHA'] || ENV['TRAVIS_COMMIT'])
21
+ Honeycomb.add_field_to_trace('ci.build_id', ENV.fetch('TRAVIS_BUILD_ID', nil))
22
+ Honeycomb.add_field_to_trace('ci.build_url', ENV.fetch('TRAVIS_BUILD_WEB_URL', nil))
23
+ Honeycomb.add_field_to_trace('ci.job_url', ENV.fetch('TRAVIS_JOB_WEB_URL', nil))
24
+ Honeycomb.add_field_to_trace('ci.commit_message', ENV.fetch('TRAVIS_COMMIT_MESSAGE', nil))
25
+ Honeycomb.add_field_to_trace('ci.sha', ENV['TRAVIS_PULL_REQUEST_SHA'] || ENV.fetch('TRAVIS_COMMIT', nil))
28
26
  elsif ENV['CI'] == 'True' && ENV['APPVEYOR'] == 'True'
29
- Honeycomb.add_field_to_trace('module_name', ENV['APPVEYOR_PROJECT_SLUG'])
27
+ Honeycomb.add_field_to_trace('module_name', ENV.fetch('APPVEYOR_PROJECT_SLUG', nil))
30
28
  Honeycomb.add_field_to_trace('ci.provider', 'appveyor')
31
- Honeycomb.add_field_to_trace('ci.build_id', ENV['APPVEYOR_BUILD_ID'])
32
- Honeycomb.add_field_to_trace('ci.build_url', "https://ci.appveyor.com/project/#{ENV['APPVEYOR_REPO_NAME']}/builds/#{ENV['APPVEYOR_BUILD_ID']}")
33
- Honeycomb.add_field_to_trace('ci.job_url', "https://ci.appveyor.com/project/#{ENV['APPVEYOR_REPO_NAME']}/build/job/#{ENV['APPVEYOR_JOB_ID']}")
34
- Honeycomb.add_field_to_trace('ci.commit_message', ENV['APPVEYOR_REPO_COMMIT_MESSAGE'])
35
- Honeycomb.add_field_to_trace('ci.sha', ENV['APPVEYOR_PULL_REQUEST_HEAD_COMMIT'] || ENV['APPVEYOR_REPO_COMMIT'])
29
+ Honeycomb.add_field_to_trace('ci.build_id', ENV.fetch('APPVEYOR_BUILD_ID', nil))
30
+ Honeycomb.add_field_to_trace('ci.build_url', "https://ci.appveyor.com/project/#{ENV.fetch('APPVEYOR_REPO_NAME', nil)}/builds/#{ENV.fetch('APPVEYOR_BUILD_ID', nil)}")
31
+ Honeycomb.add_field_to_trace('ci.job_url', "https://ci.appveyor.com/project/#{ENV.fetch('APPVEYOR_REPO_NAME', nil)}/build/job/#{ENV.fetch('APPVEYOR_JOB_ID', nil)}")
32
+ Honeycomb.add_field_to_trace('ci.commit_message', ENV.fetch('APPVEYOR_REPO_COMMIT_MESSAGE', nil))
33
+ Honeycomb.add_field_to_trace('ci.sha', ENV['APPVEYOR_PULL_REQUEST_HEAD_COMMIT'] || ENV.fetch('APPVEYOR_REPO_COMMIT', nil))
36
34
  elsif ENV['GITHUB_ACTIONS'] == 'true'
37
- Honeycomb.add_field_to_trace('module_name', ENV['GITHUB_REPOSITORY'])
35
+ Honeycomb.add_field_to_trace('module_name', ENV.fetch('GITHUB_REPOSITORY', nil))
38
36
  Honeycomb.add_field_to_trace('ci.provider', 'github')
39
- Honeycomb.add_field_to_trace('ci.build_id', ENV['GITHUB_RUN_ID'])
40
- Honeycomb.add_field_to_trace('ci.build_url', "https://github.com/#{ENV['GITHUB_REPOSITORY']}/actions/runs/#{ENV['GITHUB_RUN_ID']}")
41
- Honeycomb.add_field_to_trace('ci.sha', ENV['GITHUB_SHA'])
37
+ Honeycomb.add_field_to_trace('ci.build_id', ENV.fetch('GITHUB_RUN_ID', nil))
38
+ Honeycomb.add_field_to_trace('ci.build_url', "https://github.com/#{ENV.fetch('GITHUB_REPOSITORY', nil)}/actions/runs/#{ENV.fetch('GITHUB_RUN_ID', nil)}")
39
+ Honeycomb.add_field_to_trace('ci.sha', ENV.fetch('GITHUB_SHA', nil))
42
40
  end
43
41
  at_exit do
44
42
  if $ERROR_INFO.is_a?(SystemExit)
@@ -54,8 +52,8 @@ end
54
52
  # helper methods for the litmus rake tasks
55
53
  module PuppetLitmus::RakeHelper
56
54
  # DEFAULT_CONFIG_DATA should be frozen for our safety, but it needs to work around https://github.com/puppetlabs/bolt/pull/1696
57
- DEFAULT_CONFIG_DATA ||= { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } # .freeze # rubocop:disable Style/MutableConstant
58
- SUPPORTED_PROVISIONERS ||= %w[abs docker docker_exp provision_service vagrant vmpooler].freeze
55
+ DEFAULT_CONFIG_DATA = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } # .freeze # rubocop:disable Style/MutableConstant
56
+ SUPPORTED_PROVISIONERS = %w[abs docker docker_exp provision_service vagrant vmpooler].freeze
59
57
 
60
58
  # Gets a string representing the operating system and version.
61
59
  #
@@ -318,7 +316,7 @@ module PuppetLitmus::RakeHelper
318
316
 
319
317
  module_repository_opts = "--module_repository '#{module_repository}'" unless module_repository.nil?
320
318
  install_module_command = "puppet module install #{module_repository_opts} #{File.basename(module_tar)}"
321
- install_module_command += ' --ignore-dependencies --force' if ignore_dependencies.to_s.downcase == 'true'
319
+ install_module_command += ' --ignore-dependencies --force' if ignore_dependencies.to_s.casecmp('true').zero?
322
320
  span.add_field('litmus.install_module_command', install_module_command)
323
321
 
324
322
  bolt_result = run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash.clone)
@@ -428,7 +426,7 @@ module PuppetLitmus::RakeHelper
428
426
  end
429
427
 
430
428
  def start_spinner(message)
431
- if (ENV['CI'] || '').downcase == 'true'
429
+ if (ENV['CI'] || '').casecmp('true').zero?
432
430
  puts message
433
431
  spinner = Thread.new do
434
432
  # CI systems are strange beasts, we only output a '.' every wee while to keep the terminal alive.
@@ -446,7 +444,7 @@ module PuppetLitmus::RakeHelper
446
444
  end
447
445
 
448
446
  def stop_spinner(spinner)
449
- if (ENV['CI'] || '').downcase == 'true'
447
+ if (ENV['CI'] || '').casecmp('true').zero?
450
448
  Thread.kill(spinner)
451
449
  else
452
450
  spinner.success
@@ -42,10 +42,10 @@ namespace :litmus do
42
42
  stop_spinner(spinner)
43
43
  end
44
44
 
45
- if result.first['status'] != 'success'
46
- failed_image_message += "=====\n#{result.first['target']}\n#{result.first['value']['_output']}\n#{result.inspect}"
47
- else
45
+ if result.first['status'] == 'success'
48
46
  $stdout.puts 'Success'
47
+ else
48
+ failed_image_message += "=====\n#{result.first['target']}\n#{result.first['value']['_output']}\n#{result.inspect}"
49
49
  end
50
50
  else
51
51
  provision_hash[args[:key]]['images'].each do |image|
@@ -56,10 +56,10 @@ namespace :litmus do
56
56
  stop_spinner(spinner)
57
57
  end
58
58
 
59
- if result.first['status'] != 'success'
60
- failed_image_message += "=====\n#{result.first['target']}\n#{result.first['value']['_output']}\n#{result.inspect}"
61
- else
59
+ if result.first['status'] == 'success'
62
60
  $stdout.puts "#{result.first['value']['node_name']}, #{image}"
61
+ else
62
+ failed_image_message += "=====\n#{result.first['target']}\n#{result.first['value']['_output']}\n#{result.inspect}"
63
63
  end
64
64
  end
65
65
  end
@@ -80,9 +80,7 @@ namespace :litmus do
80
80
 
81
81
  results = provision(args[:provisioner], args[:platform], args[:inventory_vars])
82
82
 
83
- unless results.first['status'] == 'success'
84
- raise "Failed provisioning #{args[:platform]} using #{args[:provisioner]}\n#{results.first}"
85
- end
83
+ raise "Failed provisioning #{args[:platform]} using #{args[:provisioner]}\n#{results.first}" unless results.first['status'] == 'success'
86
84
 
87
85
  puts "Successfully provisioned #{args[:platform]} using #{args[:provisioner]}\n"
88
86
 
@@ -320,10 +318,10 @@ namespace :litmus do
320
318
  bad_results = []
321
319
  results = tear_down_nodes(targets, inventory_hash)
322
320
  results.each do |node, result|
323
- if result.first['status'] != 'success'
324
- bad_results << "#{node}, #{result.first['value']['_error']['msg']}"
325
- else
321
+ if result.first['status'] == 'success'
326
322
  puts "#{node}: #{result.first['status']}"
323
+ else
324
+ bad_results << "#{node}, #{result.first['value']['_error']['msg']}"
327
325
  end
328
326
  end
329
327
  puts ''
@@ -361,8 +359,8 @@ namespace :litmus do
361
359
  title = "#{target}, #{facts_from_node(inventory_hash, target)['platform']}"
362
360
  options = {
363
361
  env: {
364
- 'TARGET_HOST' => target,
365
- },
362
+ 'TARGET_HOST' => target
363
+ }
366
364
  }
367
365
  payloads << [title, test, options]
368
366
  end
@@ -395,9 +393,9 @@ namespace :litmus do
395
393
  # because we cannot modify variables inside of Parallel
396
394
  results.each do |result|
397
395
  if result.last.to_i.zero?
398
- success_list.push(result.first.scan(%r{.*})[3])
396
+ success_list.push(result.first.scan(/.*/)[3])
399
397
  else
400
- failure_list.push(result.first.scan(%r{.*})[3])
398
+ failure_list.push(result.first.scan(/.*/)[3])
401
399
  end
402
400
  end
403
401
  Thread.kill(progress)
@@ -22,13 +22,13 @@ module PuppetLitmus
22
22
  else
23
23
  # load inventory
24
24
  inventory_hash = inventory_hash_from_inventory_file
25
- node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])
25
+ node_config = config_from_node(inventory_hash, ENV.fetch('TARGET_HOST', nil))
26
26
 
27
- if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes')
28
- host = ENV['TARGET_HOST']
27
+ if target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'docker_nodes')
28
+ host = ENV.fetch('TARGET_HOST', nil)
29
29
  set :backend, :docker
30
30
  set :docker_container, host
31
- elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
31
+ elsif target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'ssh_nodes')
32
32
  set :backend, :ssh
33
33
  options = Net::SSH::Config.for(host)
34
34
  options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
@@ -70,14 +70,14 @@ module PuppetLitmus
70
70
  set :request_pty, false
71
71
  set :sudo_password, options[:password] if run_as
72
72
  puts "Running tests as #{run_as}" if run_as
73
- elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
73
+ elsif target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'winrm_nodes')
74
74
  require 'winrm'
75
75
 
76
76
  set :backend, :winrm
77
77
  set :os, family: 'windows'
78
78
  user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
79
79
  pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
80
- endpoint = URI("http://#{ENV['TARGET_HOST']}")
80
+ endpoint = URI("http://#{ENV.fetch('TARGET_HOST', nil)}")
81
81
  endpoint.port = 5985 if endpoint.port == 80
82
82
  endpoint.path = '/wsman'
83
83
 
@@ -85,7 +85,7 @@ module PuppetLitmus
85
85
  user: user,
86
86
  password: pass,
87
87
  endpoint: endpoint,
88
- operation_timeout: 300,
88
+ operation_timeout: 300
89
89
  }
90
90
 
91
91
  winrm = WinRM::Connection.new opts
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.36.1'
5
+ VERSION = '1.0.0'
6
6
  end
@@ -8,7 +8,7 @@ RSpec.describe 'matrix_from_metadata_v2' do
8
8
  let(:github_output_content) { github_output.read }
9
9
  let(:result) { run_matrix_from_metadata_v2 }
10
10
 
11
- before(:each) do
11
+ before do
12
12
  ENV['GITHUB_OUTPUT'] = github_output.path
13
13
  end
14
14
 
@@ -29,11 +29,11 @@ RSpec.describe 'matrix_from_metadata_v2' do
29
29
  '"collection":[',
30
30
  '"puppet7-nightly","puppet8-nightly"',
31
31
  ']',
32
- '}',
33
- ].join,
32
+ '}'
33
+ ].join
34
34
  )
35
35
  expect(github_output_content).to include(
36
- 'spec_matrix={"include":[{"puppet_version":"~> 7.0","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}',
36
+ 'spec_matrix={"include":[{"puppet_version":"~> 7.0","ruby_version":2.7},{"puppet_version":"https://github.com/puppetlabs/puppet","ruby_version":3.2}]}'
37
37
  )
38
38
  expect(result.stdout).to include("Created matrix with 8 cells:\n - Acceptance Test Cells: 6\n - Spec Test Cells: 2")
39
39
  end
@@ -44,7 +44,7 @@ RSpec.describe 'matrix_from_metadata_v2' do
44
44
  let(:github_output_content) { github_output.read }
45
45
  let(:result) { run_matrix_from_metadata_v2({ '--exclude-platforms' => ['ubuntu-18.04'] }) }
46
46
 
47
- before(:each) do
47
+ before do
48
48
  ENV['GITHUB_OUTPUT'] = github_output.path
49
49
  end
50
50
 
@@ -65,11 +65,11 @@ RSpec.describe 'matrix_from_metadata_v2' do
65
65
  '"collection":[',
66
66
  '"puppet7-nightly","puppet8-nightly"',
67
67
  ']',
68
- '}',
69
- ].join,
68
+ '}'
69
+ ].join
70
70
  )
71
71
  expect(github_output_content).to include(
72
- 'spec_matrix={"include":[{"puppet_version":"~> 7.0","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}',
72
+ 'spec_matrix={"include":[{"puppet_version":"~> 7.0","ruby_version":2.7},{"puppet_version":"https://github.com/puppetlabs/puppet","ruby_version":3.2}]}'
73
73
  )
74
74
  expect(result.stdout).to include("Created matrix with 6 cells:\n - Acceptance Test Cells: 4\n - Spec Test Cells: 2")
75
75
  end
@@ -80,7 +80,7 @@ RSpec.describe 'matrix_from_metadata_v2' do
80
80
  let(:github_output_content) { github_output.read }
81
81
  let(:result) { run_matrix_from_metadata_v2({ '--exclude-platforms' => ['ubuntu-18.04', 'redhat-8'] }) }
82
82
 
83
- before(:each) do
83
+ before do
84
84
  ENV['GITHUB_OUTPUT'] = github_output.path
85
85
  end
86
86
 
@@ -101,11 +101,11 @@ RSpec.describe 'matrix_from_metadata_v2' do
101
101
  '"collection":[',
102
102
  '"puppet7-nightly","puppet8-nightly"',
103
103
  ']',
104
- '}',
105
- ].join,
104
+ '}'
105
+ ].join
106
106
  )
107
107
  expect(github_output_content).to include(
108
- 'spec_matrix={"include":[{"puppet_version":"~> 7.0","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}',
108
+ 'spec_matrix={"include":[{"puppet_version":"~> 7.0","ruby_version":2.7},{"puppet_version":"https://github.com/puppetlabs/puppet","ruby_version":3.2}]}'
109
109
  )
110
110
  expect(result.stdout).to include("Created matrix with 4 cells:\n - Acceptance Test Cells: 2\n - Spec Test Cells: 2")
111
111
  end
@@ -8,11 +8,11 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
8
8
 
9
9
  context 'with config_from_node' do
10
10
  it 'no matching node, returns nil' do
11
- expect(config_from_node(config_hash, 'not.here')).to eq(nil)
11
+ expect(config_from_node(config_hash, 'not.here')).to be_nil
12
12
  end
13
13
 
14
14
  it 'no config section, returns nil' do
15
- expect(config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
15
+ expect(config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to be_nil
16
16
  end
17
17
 
18
18
  it 'config exists, and returns' do
@@ -82,9 +82,7 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
82
82
 
83
83
  it 'applies a code block to groups' do
84
84
  counts = groups_in_inventory(complex_inventory) do |group|
85
- if group.key? 'targets'
86
- group['targets'].count
87
- end
85
+ group['targets'].count if group.key? 'targets'
88
86
  end
89
87
  expect(counts.sum).to be 4
90
88
  end
@@ -133,7 +131,7 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
133
131
  end
134
132
 
135
133
  it 'searches for roles as symbols' do
136
- expect(search_for_target([:iis, :nginx], complex_inventory)).to eql ['test4.delivery.puppetlabs.net', 'test3.delivery.puppetlabs.net']
134
+ expect(search_for_target(%i[iis nginx], complex_inventory)).to eql ['test4.delivery.puppetlabs.net', 'test3.delivery.puppetlabs.net']
137
135
  end
138
136
 
139
137
  it 'raises an error if target not found' do
@@ -33,7 +33,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
33
33
  let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
34
34
  let :os do
35
35
  {
36
- family: 'redhat',
36
+ family: 'redhat'
37
37
  }
38
38
  end
39
39
  let(:command) { "LC_ALL=en_US.UTF-8 puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --hiera_config='/hiera.yaml'" }
@@ -54,7 +54,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
54
54
  let(:command) { "LC_ALL=en_US.UTF-8 puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --detailed-exitcodes" }
55
55
  let :os do
56
56
  {
57
- family: 'redhat',
57
+ family: 'redhat'
58
58
  }
59
59
  end
60
60
 
@@ -176,7 +176,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
176
176
  expect(self).to receive(:target_in_inventory?).and_return(true)
177
177
  expect(self).to receive(:target_in_inventory?).and_return(true)
178
178
  expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
179
- expect { bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
179
+ expect { bolt_upload_file(local, remote) }.to raise_error(RuntimeError, /upload file failed/)
180
180
  end
181
181
 
182
182
  it 'returns the exit code and error message when expecting failure' do
@@ -307,7 +307,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
307
307
  expect(self).to receive(:target_in_inventory?).and_return(true)
308
308
  expect(self).to receive(:target_in_inventory?).and_return(true)
309
309
  expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
310
- expect { run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
310
+ expect { run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, /task failed/)
311
311
  end
312
312
 
313
313
  it 'returns the exit code and error message when expecting failure' do
@@ -330,7 +330,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
330
330
  let(:owner) { 'foo:foo' }
331
331
  let(:local_path) { '/tmp/local_foo' }
332
332
 
333
- before(:each) do
333
+ before do
334
334
  allow_any_instance_of(File).to receive(:path).and_return(local_path)
335
335
  end
336
336
 
@@ -342,9 +342,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
342
342
  it 'call upload file with the correct params' do
343
343
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
344
344
  expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
345
- result = instance_double('result')
346
- allow(result).to receive(:first).and_return({ 'status' => 'success' })
347
- expect(self).to receive(:upload_file).with(local_path, destination, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result)
345
+
346
+ expected_result = [{ 'status' => 'success' }]
347
+ expect(self).to receive(:upload_file).with(local_path, destination, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(expected_result)
348
+
348
349
  result = write_file(content, destination)
349
350
  expect(result).to be true
350
351
  end
@@ -354,9 +355,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
354
355
  it 'call upload file with the correct params' do
355
356
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
356
357
  expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
357
- result = instance_double('result')
358
- allow(result).to receive(:first).and_return({ 'status' => 'failure', 'value' => 'foo error' })
359
- expect(self).to receive(:upload_file).with(local_path, destination, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result)
358
+
359
+ expected_result = [{ 'status' => 'failure', 'value' => 'foo error' }]
360
+ expect(self).to receive(:upload_file).with(local_path, destination, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(expected_result)
361
+
360
362
  expect { write_file(content, destination) }.to raise_error 'foo error'
361
363
  end
362
364
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe PuppetLitmus do
6
6
  it 'has a version number' do
7
- expect(described_class::VERSION).not_to be nil
8
- expect(described_class::VERSION).to be_a_kind_of(String)
7
+ expect(described_class::VERSION).not_to be_nil
8
+ expect(described_class::VERSION).to be_a(String)
9
9
  end
10
10
  end
@@ -42,7 +42,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
42
42
  inventory_vars: nil,
43
43
  provision_hash: { 'default' => { 'provisioner' => 'docker', 'images' => ['waffleimage/centos7'] } },
44
44
  results: [],
45
- params: { 'action' => 'provision', 'platform' => 'waffleimage/centos7', 'inventory' => Dir.pwd },
45
+ params: { 'action' => 'provision', 'platform' => 'waffleimage/centos7', 'inventory' => Dir.pwd }
46
46
  },
47
47
  {
48
48
  provisioner: 'vagrant',
@@ -50,8 +50,8 @@ RSpec.describe PuppetLitmus::RakeHelper do
50
50
  inventory_vars: nil,
51
51
  provision_hash: { 'default' => { 'provisioner' => 'vagrant', 'images' => ['centos7'] } },
52
52
  results: [],
53
- params: { 'action' => 'provision', 'platform' => 'centos7', 'inventory' => Dir.pwd },
54
- },
53
+ params: { 'action' => 'provision', 'platform' => 'centos7', 'inventory' => Dir.pwd }
54
+ }
55
55
  ].freeze
56
56
 
57
57
  examples.each do |e|
@@ -85,7 +85,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
85
85
  { 'uri' => 'one.host', 'facts' => { 'provisioner' => 'abs', 'platform' => 'ubuntu-1604-x86_64', 'job_id' => 'iac-task-pid-21648' } },
86
86
  { 'uri' => 'two.host', 'facts' => { 'provisioner' => 'abs', 'platform' => 'ubuntu-1804-x86_64', 'job_id' => 'iac-task-pid-21648' } },
87
87
  { 'uri' => 'three.host', 'facts' => { 'provisioner' => 'abs', 'platform' => 'ubuntu-2004-x86_64', 'job_id' => 'iac-task-pid-21648' } },
88
- { 'uri' => 'four.host', 'facts' => { 'provisioner' => 'abs', 'platform' => 'ubuntu-2004-x86_64', 'job_id' => 'iac-task-pid-21649' } },
88
+ { 'uri' => 'four.host', 'facts' => { 'provisioner' => 'abs', 'platform' => 'ubuntu-2004-x86_64', 'job_id' => 'iac-task-pid-21649' } }
89
89
  ] }] }
90
90
  end
91
91
  let(:targets) { ['one.host'] }
@@ -103,7 +103,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
103
103
  'removed' =>
104
104
  ['one.host',
105
105
  'two.host',
106
- 'three.host'] } }],
106
+ 'three.host'] } }]
107
107
  )
108
108
  results = tear_down_nodes(targets, inventory_hash)
109
109
  expect(results.keys).to eq(['one.host', 'two.host', 'three.host'])
@@ -170,7 +170,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
170
170
 
171
171
  it 'node unavailable' do
172
172
  allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(command, targets, config: nil, inventory: inventory_hash).and_return([{ 'target' => 'some.host', 'status' => 'failure' }])
173
- expect { check_connectivity?(inventory_hash, 'some.host') }.to raise_error(RuntimeError, %r{Connectivity has failed on:})
173
+ expect { check_connectivity?(inventory_hash, 'some.host') }.to raise_error(RuntimeError, /Connectivity has failed on:/)
174
174
  end
175
175
  end
176
176
 
@@ -59,6 +59,13 @@ describe 'litmus rake tasks' do
59
59
  end
60
60
 
61
61
  context 'with litmus:provision task' do
62
+ let(:expected_output) do
63
+ <<~OUTPUT
64
+ Successfully provisioned centos:7 using docker
65
+ localhost:2222, centos:7
66
+ OUTPUT
67
+ end
68
+
62
69
  it 'happy path' do
63
70
  results = [{ 'target' => 'localhost',
64
71
  'action' => 'task',
@@ -71,11 +78,7 @@ describe 'litmus rake tasks' do
71
78
  allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).with(any_args).and_return({})
72
79
  allow_any_instance_of(PuppetLitmus::RakeHelper).to receive(:check_connectivity?).with(any_args).and_return(true)
73
80
 
74
- expect($stdout).to receive(:puts).with('Provisioning centos:7 using docker provisioner.')
75
- expect($stdout).to receive(:puts).with("Successfully provisioned centos:7 using docker\n")
76
- expect($stdout).to receive(:puts).with('localhost:2222, centos:7')
77
-
78
- Rake::Task['litmus:provision'].invoke('docker', 'centos:7')
81
+ expect { Rake::Task['litmus:provision'].invoke('docker', 'centos:7') }.to output(expected_output).to_stdout
79
82
  end
80
83
  end
81
84
 
@@ -86,7 +89,7 @@ describe 'litmus rake tasks' do
86
89
  it 'no key in provision file' do
87
90
  allow(File).to receive(:file?).with(any_args).and_return(true)
88
91
  expect(YAML).to receive(:load_file).with(provision_file).and_return(provision_hash)
89
- expect { Rake::Task['litmus:provision_list'].invoke('deet') }.to raise_error(%r{deet})
92
+ expect { Rake::Task['litmus:provision_list'].invoke('deet') }.to raise_error(/deet/)
90
93
  end
91
94
  end
92
95
 
@@ -6,10 +6,10 @@ load File.expand_path('../../../lib/puppet_litmus/util.rb', __dir__)
6
6
  RSpec.describe PuppetLitmus::Util do
7
7
  context 'when using interpolate_powershell' do
8
8
  it 'interpolates the command' do
9
- expect(described_class.interpolate_powershell('foo')).to match(%r{powershell\.exe})
10
- expect(described_class.interpolate_powershell('foo')).to match(%r{NoProfile})
11
- expect(described_class.interpolate_powershell('foo')).to match(%r{EncodedCommand})
12
- expect(described_class.interpolate_powershell('foo')).not_to match(%r{foo})
9
+ expect(described_class.interpolate_powershell('foo')).to match(/powershell\.exe/)
10
+ expect(described_class.interpolate_powershell('foo')).to match(/NoProfile/)
11
+ expect(described_class.interpolate_powershell('foo')).to match(/EncodedCommand/)
12
+ expect(described_class.interpolate_powershell('foo')).not_to match(/foo/)
13
13
  end
14
14
  end
15
15
  end
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ if ENV['COVERAGE'] == 'yes'
12
12
  SimpleCov.formatter = SimpleCov::Formatter::Codecov
13
13
  else
14
14
  SimpleCov.formatters = [
15
- SimpleCov::Formatter::HTMLFormatter,
15
+ SimpleCov::Formatter::HTMLFormatter
16
16
  ]
17
17
  end
18
18
  SimpleCov.start do
@@ -41,7 +41,7 @@ def run_matrix_from_metadata_v2(options = {})
41
41
  OpenStruct.new(
42
42
  stdout: result[0],
43
43
  stderr: result[1],
44
- status_code: result[2],
44
+ status_code: result[2]
45
45
  )
46
46
  end
47
47
 
@@ -7,7 +7,7 @@ def no_config_hash
7
7
  'targets' =>
8
8
  [{ 'uri' => 'test.delivery.puppetlabs.net',
9
9
  'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
10
- { 'name' => 'winrm_nodes', 'targets' => [] },
10
+ { 'name' => 'winrm_nodes', 'targets' => [] }
11
11
  ] }
12
12
  end
13
13
 
@@ -99,21 +99,21 @@ def complex_inventory
99
99
  'uri' => 'test.delivery.puppetlabs.net',
100
100
  'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
101
101
  'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
102
- 'vars' => { 'role' => 'agent' },
102
+ 'vars' => { 'role' => 'agent' }
103
103
  },
104
104
  {
105
105
  'uri' => 'test2.delivery.puppetlabs.net',
106
106
  'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
107
107
  'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
108
- 'vars' => { 'role' => 'server' },
108
+ 'vars' => { 'role' => 'server' }
109
109
  },
110
110
  {
111
111
  'uri' => 'test3.delivery.puppetlabs.net',
112
112
  'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
113
- 'vars' => { 'roles' => %w[agent nginx webserver] },
114
- },
115
- ] },
116
- ],
113
+ 'vars' => { 'roles' => %w[agent nginx webserver] }
114
+ }
115
+ ] }
116
+ ]
117
117
  },
118
118
  {
119
119
  'name' => 'winrm_nodes',
@@ -122,9 +122,9 @@ def complex_inventory
122
122
  'uri' => 'test4.delivery.puppetlabs.net',
123
123
  'config' => { 'transport' => 'winrm', 'winrm' => { 'user' => 'admin', 'password' => 'Qu@lity!' } },
124
124
  'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
125
- 'vars' => { 'roles' => %w[agent iis webserver] },
126
- },
127
- ],
128
- },
125
+ 'vars' => { 'roles' => %w[agent iis webserver] }
126
+ }
127
+ ]
128
+ }
129
129
  ] }
130
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_litmus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-28 00:00:00.000000000 Z
11
+ date: 2023-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bolt
@@ -25,93 +25,87 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: puppet-modulebuilder
28
+ name: docker-api
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.1
33
+ version: '1.34'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 1.0.0
36
+ version: 3.0.0
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.2.1
43
+ version: '1.34'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.0.0
46
+ version: 3.0.0
47
47
  - !ruby/object:Gem::Dependency
48
- name: tty-spinner
48
+ name: honeycomb-beeline
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.5.0
54
- - - "<"
55
- - !ruby/object:Gem::Version
56
- version: 1.0.0
53
+ version: '0'
57
54
  type: :runtime
58
55
  prerelease: false
59
56
  version_requirements: !ruby/object:Gem::Requirement
60
57
  requirements:
61
58
  - - ">="
62
59
  - !ruby/object:Gem::Version
63
- version: 0.5.0
64
- - - "<"
65
- - !ruby/object:Gem::Version
66
- version: 1.0.0
60
+ version: '0'
67
61
  - !ruby/object:Gem::Dependency
68
- name: docker-api
62
+ name: parallel
69
63
  requirement: !ruby/object:Gem::Requirement
70
64
  requirements:
71
65
  - - ">="
72
66
  - !ruby/object:Gem::Version
73
- version: '1.34'
74
- - - "<"
75
- - !ruby/object:Gem::Version
76
- version: 3.0.0
67
+ version: '0'
77
68
  type: :runtime
78
69
  prerelease: false
79
70
  version_requirements: !ruby/object:Gem::Requirement
80
71
  requirements:
81
72
  - - ">="
82
73
  - !ruby/object:Gem::Version
83
- version: '1.34'
84
- - - "<"
85
- - !ruby/object:Gem::Version
86
- version: 3.0.0
74
+ version: '0'
87
75
  - !ruby/object:Gem::Dependency
88
- name: retryable
76
+ name: puppet-modulebuilder
89
77
  requirement: !ruby/object:Gem::Requirement
90
78
  requirements:
91
- - - "~>"
79
+ - - ">="
92
80
  - !ruby/object:Gem::Version
93
- version: '3.0'
81
+ version: 0.2.1
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.0.0.rc
94
85
  type: :runtime
95
86
  prerelease: false
96
87
  version_requirements: !ruby/object:Gem::Requirement
97
88
  requirements:
98
- - - "~>"
89
+ - - ">="
99
90
  - !ruby/object:Gem::Version
100
- version: '3.0'
91
+ version: 0.2.1
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.0.0.rc
101
95
  - !ruby/object:Gem::Dependency
102
- name: parallel
96
+ name: retryable
103
97
  requirement: !ruby/object:Gem::Requirement
104
98
  requirements:
105
- - - ">="
99
+ - - "~>"
106
100
  - !ruby/object:Gem::Version
107
- version: '0'
101
+ version: '3.0'
108
102
  type: :runtime
109
103
  prerelease: false
110
104
  version_requirements: !ruby/object:Gem::Requirement
111
105
  requirements:
112
- - - ">="
106
+ - - "~>"
113
107
  - !ruby/object:Gem::Version
114
- version: '0'
108
+ version: '3.0'
115
109
  - !ruby/object:Gem::Dependency
116
110
  name: rspec
117
111
  requirement: !ruby/object:Gem::Requirement
@@ -127,7 +121,7 @@ dependencies:
127
121
  - !ruby/object:Gem::Version
128
122
  version: '0'
129
123
  - !ruby/object:Gem::Dependency
130
- name: honeycomb-beeline
124
+ name: rspec_honeycomb_formatter
131
125
  requirement: !ruby/object:Gem::Requirement
132
126
  requirements:
133
127
  - - ">="
@@ -141,19 +135,25 @@ dependencies:
141
135
  - !ruby/object:Gem::Version
142
136
  version: '0'
143
137
  - !ruby/object:Gem::Dependency
144
- name: rspec_honeycomb_formatter
138
+ name: tty-spinner
145
139
  requirement: !ruby/object:Gem::Requirement
146
140
  requirements:
147
141
  - - ">="
148
142
  - !ruby/object:Gem::Version
149
- version: '0'
143
+ version: 0.5.0
144
+ - - "<"
145
+ - !ruby/object:Gem::Version
146
+ version: 1.0.0
150
147
  type: :runtime
151
148
  prerelease: false
152
149
  version_requirements: !ruby/object:Gem::Requirement
153
150
  requirements:
154
151
  - - ">="
155
152
  - !ruby/object:Gem::Version
156
- version: '0'
153
+ version: 0.5.0
154
+ - - "<"
155
+ - !ruby/object:Gem::Version
156
+ version: 1.0.0
157
157
  description: " Providing a simple command line tool for puppet content creators,
158
158
  to enable simple and complex test deployments.\n"
159
159
  email:
@@ -202,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
203
  - - ">="
204
204
  - !ruby/object:Gem::Version
205
- version: 2.5.0
205
+ version: 2.7.0
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
208
  - - ">="
@@ -214,18 +214,4 @@ signing_key:
214
214
  specification_version: 4
215
215
  summary: Providing a simple command line tool for puppet content creators, to enable
216
216
  simple and complex test deployments.
217
- test_files:
218
- - spec/exe/matrix_from_metadata_v2_spec.rb
219
- - spec/exe/fake_metadata.json
220
- - spec/lib/puppet_litmus/util_spec.rb
221
- - spec/lib/puppet_litmus/inventory_manipulation_spec.rb
222
- - spec/lib/puppet_litmus/rake_tasks_spec.rb
223
- - spec/lib/puppet_litmus/puppet_helpers_spec.rb
224
- - spec/lib/puppet_litmus/rake_helper_spec.rb
225
- - spec/lib/puppet_litmus/puppet_litmus_version_spec.rb
226
- - spec/spec_helper.rb
227
- - spec/support/inventorytesting.yaml
228
- - spec/support/inventory.rb
229
- - spec/data/doot.tar.gz
230
- - spec/data/inventory.yaml
231
- - spec/data/jim.yaml
217
+ test_files: []