puppet_litmus 0.20.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/matrix_from_metadata +42 -7
- data/lib/puppet_litmus/inventory_manipulation.rb +1 -5
- data/lib/puppet_litmus/puppet_helpers.rb +24 -13
- data/lib/puppet_litmus/rake_helper.rb +37 -12
- data/lib/puppet_litmus/rake_tasks.rb +47 -35
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/lib/puppet_litmus/{version_spec.rb → puppet_litmus_version_spec.rb} +0 -0
- data/spec/lib/puppet_litmus/rake_helper_spec.rb +36 -0
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +4 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8484d287566c6611244f1048285e745ef1ec33c8e06ff6ebea0e517c2bf82647
|
4
|
+
data.tar.gz: 56e1065ea8aabd7851266745f4ccf2ca95c21548b32f7b246835397dc60b28a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d0a8be65d7c13e095479366ba95b7b22bbbeb5518f1fc2da7ede5e248e3e9ae3e3e3a82a388134cb29ab3641ce71b5d189b733cc459f1f7dcb91522e5ad9f49
|
7
|
+
data.tar.gz: d55c84b38566630694ac2605aff7ecd769a2d8e218a70ec26c70dc6c855ab128420757fbd19bc87d69cfdb01dbada14b65cd34c7ffe4da8eb066d336f8df11e8
|
data/exe/matrix_from_metadata
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# this script creates a build matrix for github actions from the claimed supported platforms in metadata.json
|
4
|
+
# this script creates a build matrix for github actions from the claimed supported platforms and puppet versions in metadata.json
|
5
5
|
|
6
6
|
require 'json'
|
7
7
|
|
8
8
|
IMAGE_TABLE = {
|
9
|
-
'RedHat-6' => 'rhel-6',
|
10
9
|
'RedHat-7' => 'rhel-7',
|
11
10
|
'RedHat-8' => 'rhel-8',
|
12
11
|
'SLES-12' => 'sles-12',
|
@@ -33,16 +32,20 @@ DOCKER_PLATFORMS = [
|
|
33
32
|
'Ubuntu-20.04',
|
34
33
|
].freeze
|
35
34
|
|
35
|
+
# This table uses the latest version in each collection for accurate
|
36
|
+
# comparison when evaluating puppet requirements from the metadata
|
37
|
+
COLLECTION_TABLE = {
|
38
|
+
'6.21.0' => 'puppet6-nightly',
|
39
|
+
'7.4.0' => 'puppet7-nightly',
|
40
|
+
}.freeze
|
41
|
+
|
36
42
|
matrix = {
|
37
43
|
platform: [],
|
38
|
-
collection:
|
39
|
-
puppet5
|
40
|
-
puppet6
|
41
|
-
puppet7-nightly
|
42
|
-
],
|
44
|
+
collection: [],
|
43
45
|
}
|
44
46
|
|
45
47
|
metadata = JSON.parse(File.read('metadata.json'))
|
48
|
+
# Set platforms based on declared operating system support
|
46
49
|
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
|
47
50
|
os = sup['operatingsystem']
|
48
51
|
sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
|
@@ -57,6 +60,38 @@ metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do
|
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
63
|
+
# Set collections based on puppet version requirements
|
64
|
+
if metadata.key?('requirements') && metadata['requirements'].length.positive?
|
65
|
+
metadata['requirements'].each do |req|
|
66
|
+
next unless req.key?('name') && req.key?('version_requirement') && req['name'] == 'puppet'
|
67
|
+
|
68
|
+
ver_regexp = %r{^([>=<]{1,2})\s*([\d.]+)\s+([>=<]{1,2})\s*([\d.]+)$}
|
69
|
+
match = ver_regexp.match(req['version_requirement'])
|
70
|
+
if match.nil?
|
71
|
+
puts "::warning::Didn't recognize version_requirement '#{req['version_requirement']}'"
|
72
|
+
break
|
73
|
+
end
|
74
|
+
|
75
|
+
cmp_one, ver_one, cmp_two, ver_two = match.captures
|
76
|
+
reqs = ["#{cmp_one} #{ver_one}", "#{cmp_two} #{ver_two}"]
|
77
|
+
|
78
|
+
COLLECTION_TABLE.each do |key, val|
|
79
|
+
if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
|
80
|
+
matrix[:collection] << val
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Set to defaults (all collections) if no matches are found
|
87
|
+
if matrix[:collection].empty?
|
88
|
+
matrix[:collection] = COLLECTION_TABLE.values
|
89
|
+
end
|
90
|
+
|
91
|
+
# Just to make sure there aren't any duplicates
|
92
|
+
matrix[:platform] = matrix[:platform].uniq.sort
|
93
|
+
matrix[:collection] = matrix[:collection].uniq.sort
|
94
|
+
|
60
95
|
puts "::set-output name=matrix::#{JSON.generate(matrix)}"
|
61
96
|
|
62
97
|
puts "Created matrix with #{matrix[:platform].length * matrix[:collection].length} cells."
|
@@ -17,10 +17,7 @@ module PuppetLitmus::InventoryManipulation
|
|
17
17
|
end
|
18
18
|
raise "There is no inventory file at '#{inventory_full_path}'." unless File.exist?(inventory_full_path)
|
19
19
|
|
20
|
-
|
21
|
-
raise "Inventory file is incompatible (version 2 and up). Try the 'bolt project migrate' command." if inventory_hash['version'].nil? || (inventory_hash['version'] < 2)
|
22
|
-
|
23
|
-
inventory_hash
|
20
|
+
YAML.load_file(inventory_full_path)
|
24
21
|
end
|
25
22
|
|
26
23
|
# Provide a default hash for executing against localhost
|
@@ -28,7 +25,6 @@ module PuppetLitmus::InventoryManipulation
|
|
28
25
|
# @return [Hash] inventory.yaml hash containing only an entry for localhost
|
29
26
|
def localhost_inventory_hash
|
30
27
|
{
|
31
|
-
'version' => 2,
|
32
28
|
'groups' => [
|
33
29
|
{
|
34
30
|
'name' => 'local',
|
@@ -9,9 +9,9 @@ module PuppetLitmus::PuppetHelpers
|
|
9
9
|
# @return [Boolean] The result of the 2 apply manifests.
|
10
10
|
def idempotent_apply(manifest)
|
11
11
|
Honeycomb.start_span(name: 'litmus.idempotent_apply') do |span|
|
12
|
-
ENV['
|
12
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
13
13
|
manifest_file_location = create_manifest_file(manifest)
|
14
|
-
apply_manifest(nil,
|
14
|
+
apply_manifest(nil, catch_failures: true, manifest_file_location: manifest_file_location)
|
15
15
|
apply_manifest(nil, catch_changes: true, manifest_file_location: manifest_file_location)
|
16
16
|
end
|
17
17
|
end
|
@@ -30,7 +30,7 @@ module PuppetLitmus::PuppetHelpers
|
|
30
30
|
# :catch_failures [Boolean] (false) We're after only complete success so allow exit codes 0 and 2 only.
|
31
31
|
# :expect_failures [Boolean] (false) We're after failures specifically so allow exit codes 1, 4, and 6 only.
|
32
32
|
# :manifest_file_location [Path] The place on the target system.
|
33
|
-
# :hiera_config [Path] The path to the hiera.yaml configuration on the
|
33
|
+
# :hiera_config [Path] The path to the hiera.yaml configuration on the target.
|
34
34
|
# :prefix_command [String] prefixes the puppet apply command; eg "export LANGUAGE='ja'".
|
35
35
|
# :trace [Boolean] run puppet apply with the trace flag (defaults to `true`).
|
36
36
|
# :debug [Boolean] run puppet apply with the debug flag.
|
@@ -39,7 +39,7 @@ module PuppetLitmus::PuppetHelpers
|
|
39
39
|
# @return [Object] A result object from the apply.
|
40
40
|
def apply_manifest(manifest, opts = {})
|
41
41
|
Honeycomb.start_span(name: 'litmus.apply_manifest') do |span|
|
42
|
-
ENV['
|
42
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
43
43
|
span.add_field('litmus.manifest', manifest)
|
44
44
|
span.add_field('litmus.opts', opts)
|
45
45
|
|
@@ -83,11 +83,22 @@ module PuppetLitmus::PuppetHelpers
|
|
83
83
|
command_to_run += ' --noop' if !opts[:noop].nil? && (opts[:noop] == true)
|
84
84
|
command_to_run += ' --detailed-exitcodes' if use_detailed_exit_codes == true
|
85
85
|
|
86
|
-
span.add_field('litmus.command_to_run', command_to_run)
|
87
86
|
span.add_field('litmus.target_node_name', target_node_name)
|
88
|
-
bolt_result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
|
89
|
-
span.add_field('litmus.bolt_result', bolt_result)
|
90
87
|
|
88
|
+
if os[:family] == 'windows'
|
89
|
+
# IAC-1365 - Workaround for BOLT-1535 and bolt issue #1650
|
90
|
+
command_to_run = "try { #{command_to_run}; exit $LASTEXITCODE } catch { write-error $_ ; exit 1 }"
|
91
|
+
span.add_field('litmus.command_to_run', command_to_run)
|
92
|
+
bolt_result = Tempfile.open(['temp', '.ps1']) do |script|
|
93
|
+
script.write(command_to_run)
|
94
|
+
script.close
|
95
|
+
run_script(script.path, target_node_name, [], options: {}, config: nil, inventory: inventory_hash)
|
96
|
+
end
|
97
|
+
else
|
98
|
+
span.add_field('litmus.command_to_run', command_to_run)
|
99
|
+
bolt_result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
|
100
|
+
end
|
101
|
+
span.add_field('litmus.bolt_result', bolt_result)
|
91
102
|
result = OpenStruct.new(exit_code: bolt_result.first['value']['exit_code'],
|
92
103
|
stdout: bolt_result.first['value']['stdout'],
|
93
104
|
stderr: bolt_result.first['value']['stderr'])
|
@@ -117,7 +128,7 @@ module PuppetLitmus::PuppetHelpers
|
|
117
128
|
# @return [String] The path to the location of the manifest.
|
118
129
|
def create_manifest_file(manifest)
|
119
130
|
Honeycomb.start_span(name: 'litmus.create_manifest_file') do |span|
|
120
|
-
ENV['
|
131
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
121
132
|
span.add_field('litmus.manifest', manifest)
|
122
133
|
|
123
134
|
require 'tmpdir'
|
@@ -154,7 +165,7 @@ module PuppetLitmus::PuppetHelpers
|
|
154
165
|
# @return [Bool] Success. The file was succesfully writtne on the target.
|
155
166
|
def write_file(content, destination)
|
156
167
|
Honeycomb.start_span(name: 'litmus.write_file') do |span|
|
157
|
-
ENV['
|
168
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
158
169
|
span.add_field('litmus.destination', destination)
|
159
170
|
|
160
171
|
require 'tmpdir'
|
@@ -191,7 +202,7 @@ module PuppetLitmus::PuppetHelpers
|
|
191
202
|
# @return [Object] A result object from the command.
|
192
203
|
def run_shell(command_to_run, opts = {})
|
193
204
|
Honeycomb.start_span(name: 'litmus.run_shell') do |span|
|
194
|
-
ENV['
|
205
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
195
206
|
span.add_field('litmus.command_to_run', command_to_run)
|
196
207
|
span.add_field('litmus.opts', opts)
|
197
208
|
|
@@ -228,7 +239,7 @@ module PuppetLitmus::PuppetHelpers
|
|
228
239
|
# @return [Object] A result object from the command.
|
229
240
|
def bolt_upload_file(source, destination, opts = {}, options = {})
|
230
241
|
Honeycomb.start_span(name: 'litmus.bolt_upload_file') do |span|
|
231
|
-
ENV['
|
242
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
232
243
|
span.add_field('litmus.source', source)
|
233
244
|
span.add_field('litmus.destination', destination)
|
234
245
|
span.add_field('litmus.opts', opts)
|
@@ -280,7 +291,7 @@ module PuppetLitmus::PuppetHelpers
|
|
280
291
|
# @return [Object] A result object from the task.The values available are stdout, stderr and result.
|
281
292
|
def run_bolt_task(task_name, params = {}, opts = {})
|
282
293
|
Honeycomb.start_span(name: 'litmus.run_task') do |span|
|
283
|
-
ENV['
|
294
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
284
295
|
span.add_field('litmus.task_name', task_name)
|
285
296
|
span.add_field('litmus.params', params)
|
286
297
|
span.add_field('litmus.opts', opts)
|
@@ -348,7 +359,7 @@ module PuppetLitmus::PuppetHelpers
|
|
348
359
|
# @return [Object] A result object from the script run.
|
349
360
|
def bolt_run_script(script, opts = {}, arguments: [])
|
350
361
|
Honeycomb.start_span(name: 'litmus.bolt_run_script') do |span|
|
351
|
-
ENV['
|
362
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
352
363
|
span.add_field('litmus.script', script)
|
353
364
|
span.add_field('litmus.opts', opts)
|
354
365
|
span.add_field('litmus.arguments', arguments)
|
@@ -9,8 +9,8 @@ Honeycomb.configure do |config|
|
|
9
9
|
config.client = Libhoney::NullClient.new
|
10
10
|
end
|
11
11
|
end
|
12
|
-
process_span = Honeycomb.start_span(name: "litmus: #{([$PROGRAM_NAME] + ($ARGV || [])).join(' ')}", serialized_trace: ENV['
|
13
|
-
ENV['
|
12
|
+
process_span = Honeycomb.start_span(name: "litmus: #{([$PROGRAM_NAME] + ($ARGV || [])).join(' ')}", serialized_trace: ENV['HONEYCOMB_TRACE'])
|
13
|
+
ENV['HONEYCOMB_TRACE'] = process_span.to_trace_header
|
14
14
|
Honeycomb.add_field_to_trace('litmus.pid', Process.pid)
|
15
15
|
if defined? PuppetLitmus::VERSION
|
16
16
|
Honeycomb.add_field_to_trace('litmus.version', PuppetLitmus::VERSION)
|
@@ -41,6 +41,13 @@ elsif ENV['GITHUB_ACTIONS'] == 'true'
|
|
41
41
|
Honeycomb.add_field_to_trace('ci.sha', ENV['GITHUB_SHA'])
|
42
42
|
end
|
43
43
|
at_exit do
|
44
|
+
if $ERROR_INFO.is_a?(SystemExit)
|
45
|
+
process_span.add_field('process.exit_code', $ERROR_INFO.status)
|
46
|
+
elsif $ERROR_INFO
|
47
|
+
process_span.add_field('process.exit_code', $ERROR_INFO.class.name)
|
48
|
+
else
|
49
|
+
process_span.add_field('process.exit_code', 'unknown')
|
50
|
+
end
|
44
51
|
process_span.send
|
45
52
|
end
|
46
53
|
|
@@ -96,7 +103,7 @@ module PuppetLitmus::RakeHelper
|
|
96
103
|
# @return [Object] the standard out stream.
|
97
104
|
def run_local_command(command)
|
98
105
|
Honeycomb.start_span(name: 'litmus.run_local_command') do |span|
|
99
|
-
ENV['
|
106
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
100
107
|
span.add_field('litmus.command', command)
|
101
108
|
|
102
109
|
require 'open3'
|
@@ -119,13 +126,18 @@ module PuppetLitmus::RakeHelper
|
|
119
126
|
|
120
127
|
Honeycomb.add_field_to_trace('litmus.provisioner', provisioner)
|
121
128
|
Honeycomb.start_span(name: 'litmus.provision') do |span|
|
122
|
-
ENV['
|
129
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
123
130
|
span.add_field('litmus.platform', platform)
|
124
|
-
|
131
|
+
|
132
|
+
task_name = provisioner_task(provisioner)
|
133
|
+
span.add_field('litmus.task_name', task_name)
|
134
|
+
span.add_field('litmus.params', params)
|
125
135
|
span.add_field('litmus.config', DEFAULT_CONFIG_DATA)
|
126
136
|
|
127
|
-
bolt_result = run_task(
|
137
|
+
bolt_result = run_task(task_name, 'localhost', params, config: DEFAULT_CONFIG_DATA, inventory: nil)
|
138
|
+
span.add_field('litmus.result', bolt_result)
|
128
139
|
span.add_field('litmus.node_name', bolt_result&.first&.dig('value', 'node_name'))
|
140
|
+
|
129
141
|
raise_bolt_errors(bolt_result, "provisioning of #{platform} failed.")
|
130
142
|
|
131
143
|
bolt_result
|
@@ -148,7 +160,7 @@ module PuppetLitmus::RakeHelper
|
|
148
160
|
|
149
161
|
def tear_down_nodes(targets, inventory_hash)
|
150
162
|
Honeycomb.start_span(name: 'litmus.tear_down_nodes') do |span|
|
151
|
-
ENV['
|
163
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
152
164
|
span.add_field('litmus.targets', targets)
|
153
165
|
|
154
166
|
include ::BoltSpec::Run
|
@@ -160,6 +172,18 @@ module PuppetLitmus::RakeHelper
|
|
160
172
|
next if node_name == 'litmus_localhost'
|
161
173
|
|
162
174
|
result = tear_down(node_name, inventory_hash)
|
175
|
+
# Some provisioners tear_down targets that were created as a batch job.
|
176
|
+
# These provisioners should return the list of additional targets
|
177
|
+
# removed so that we do not attempt to process them.
|
178
|
+
if result != [] && result[0]['value'].key?('removed')
|
179
|
+
removed_targets = result[0]['value']['removed']
|
180
|
+
result[0]['value'].delete('removed')
|
181
|
+
removed_targets.each do |removed_target|
|
182
|
+
targets.delete(removed_target)
|
183
|
+
results[removed_target] = result
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
163
187
|
results[node_name] = result unless result == []
|
164
188
|
end
|
165
189
|
results
|
@@ -168,7 +192,7 @@ module PuppetLitmus::RakeHelper
|
|
168
192
|
|
169
193
|
def tear_down(node_name, inventory_hash)
|
170
194
|
Honeycomb.start_span(name: 'litmus.tear_down') do |span|
|
171
|
-
ENV['
|
195
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
172
196
|
# how do we know what provisioner to use
|
173
197
|
|
174
198
|
span.add_field('litmus.node_name', node_name)
|
@@ -184,7 +208,7 @@ module PuppetLitmus::RakeHelper
|
|
184
208
|
|
185
209
|
def install_agent(collection, targets, inventory_hash)
|
186
210
|
Honeycomb.start_span(name: 'litmus.install_agent') do |span|
|
187
|
-
ENV['
|
211
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
188
212
|
span.add_field('litmus.collection', collection)
|
189
213
|
span.add_field('litmus.targets', targets)
|
190
214
|
|
@@ -276,7 +300,7 @@ module PuppetLitmus::RakeHelper
|
|
276
300
|
# @return a bolt result
|
277
301
|
def install_module(inventory_hash, target_node_name, module_tar, module_repository = nil, ignore_dependencies = false) # rubocop:disable Style/OptionalBooleanParameter
|
278
302
|
Honeycomb.start_span(name: 'install_module') do |span|
|
279
|
-
ENV['
|
303
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
280
304
|
span.add_field('litmus.target_node_name', target_node_name)
|
281
305
|
span.add_field('litmus.module_tar', module_tar)
|
282
306
|
|
@@ -332,7 +356,7 @@ module PuppetLitmus::RakeHelper
|
|
332
356
|
|
333
357
|
def check_connectivity?(inventory_hash, target_node_name)
|
334
358
|
Honeycomb.start_span(name: 'litmus.check_connectivity') do |span|
|
335
|
-
ENV['
|
359
|
+
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
336
360
|
# if we're only checking connectivity for a single node
|
337
361
|
if target_node_name
|
338
362
|
span.add_field('litmus.target_node_name', target_node_name)
|
@@ -355,6 +379,7 @@ module PuppetLitmus::RakeHelper
|
|
355
379
|
span.add_field('litmus.connectivity_failure', results.reject { |r| r['status'] == 'success' })
|
356
380
|
raise "Connectivity has failed on: #{failed}" unless failed.length.zero?
|
357
381
|
|
382
|
+
puts 'Connectivity check PASSED.'
|
358
383
|
true
|
359
384
|
end
|
360
385
|
end
|
@@ -439,7 +464,7 @@ module PuppetLitmus::RakeHelper
|
|
439
464
|
|
440
465
|
class LitmusTimeoutError < StandardError; end
|
441
466
|
|
442
|
-
def with_retries(options: { tries: Float::INFINITY }, max_wait_minutes:
|
467
|
+
def with_retries(options: { tries: Float::INFINITY }, max_wait_minutes: 8)
|
443
468
|
stop = Time.now + (max_wait_minutes * 60)
|
444
469
|
Retryable.retryable(options.merge(not: [LitmusTimeoutError])) do
|
445
470
|
raise LitmusTimeoutError if Time.now > stop
|
@@ -33,12 +33,11 @@ namespace :litmus do
|
|
33
33
|
inventory_vars = provision_hash[args[:key]]['vars']
|
34
34
|
# Splat the params into environment variables to pass to the provision task but only in this runspace
|
35
35
|
provision_hash[args[:key]]['params']&.each { |k, value| ENV[k.upcase] = value.to_s }
|
36
|
-
results = []
|
37
36
|
failed_image_message = ''
|
38
|
-
provision_hash[args[:key]]['images'].
|
37
|
+
if provision_hash[args[:key]]['images'].instance_of?(Hash)
|
39
38
|
begin
|
40
|
-
spinner = start_spinner("Provisioning
|
41
|
-
result = provision(provisioner,
|
39
|
+
spinner = start_spinner("Provisioning multiple images using #{provisioner} provisioner.")
|
40
|
+
result = provision(provisioner, provision_hash[args[:key]]['images'], inventory_vars)
|
42
41
|
ensure
|
43
42
|
stop_spinner(spinner)
|
44
43
|
end
|
@@ -46,9 +45,23 @@ namespace :litmus do
|
|
46
45
|
if result.first['status'] != 'success'
|
47
46
|
failed_image_message += "=====\n#{result.first['target']}\n#{result.first['value']['_output']}\n#{result.inspect}"
|
48
47
|
else
|
49
|
-
$stdout.puts
|
48
|
+
$stdout.puts 'Success'
|
49
|
+
end
|
50
|
+
else
|
51
|
+
provision_hash[args[:key]]['images'].each do |image|
|
52
|
+
begin
|
53
|
+
spinner = start_spinner("Provisioning #{image} using #{provisioner} provisioner.")
|
54
|
+
result = provision(provisioner, image, inventory_vars)
|
55
|
+
ensure
|
56
|
+
stop_spinner(spinner)
|
57
|
+
end
|
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
|
62
|
+
$stdout.puts "#{result.first['value']['node_name']}, #{image}"
|
63
|
+
end
|
50
64
|
end
|
51
|
-
results << result
|
52
65
|
end
|
53
66
|
|
54
67
|
raise "Failed to provision with '#{provisioner}'\n #{failed_image_message}" unless failed_image_message.empty?
|
@@ -112,38 +125,37 @@ namespace :litmus do
|
|
112
125
|
|
113
126
|
results = install_agent(args[:collection], targets, inventory_hash)
|
114
127
|
results.each do |result|
|
115
|
-
|
116
|
-
|
117
|
-
raise "Failed on #{result['target']}\n#{result}\ntry running '#{command_to_run}'"
|
118
|
-
else
|
119
|
-
# validate successful install
|
120
|
-
puts "Successfull install result: #{result.inspect}" if ENV['DEBUG'] == true
|
121
|
-
retries = 0
|
122
|
-
begin
|
123
|
-
responses = run_command('puppet --version', targets, options: {}, config: DEFAULT_CONFIG_DATA, inventory: inventory_hash.clone)
|
124
|
-
responses.each do |response|
|
125
|
-
raise "Error checking puppet version on #{response.to_json}" if response['status'] != 'success'
|
126
|
-
end
|
127
|
-
rescue StandardError => e
|
128
|
-
puts "ERROR:#{e}"
|
129
|
-
# fix the path
|
130
|
-
path_changes = configure_path(inventory_hash)
|
131
|
-
if ENV['DEBUG'] == true
|
132
|
-
path_changes.each do |change|
|
133
|
-
puts "Configuring puppet path result: #{change.inspect}"
|
134
|
-
end
|
135
|
-
end
|
128
|
+
command_to_run = "bolt task run puppet_agent::install --targets #{result['target']} --inventoryfile inventory.yaml --modulepath #{DEFAULT_CONFIG_DATA['modulepath']}"
|
129
|
+
raise "Failed on #{result['target']}\n#{result}\ntry running '#{command_to_run}'" if result['status'] != 'success'
|
136
130
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
131
|
+
# validate successful install
|
132
|
+
puts "Successfull install result: #{result.inspect}" if ENV['DEBUG'] == 'true'
|
133
|
+
retries = 0
|
134
|
+
begin
|
135
|
+
responses = run_command('puppet --version', targets, options: {}, config: DEFAULT_CONFIG_DATA, inventory: inventory_hash.clone)
|
136
|
+
responses.each do |response|
|
137
|
+
raise "Error checking puppet version on #{response.to_json}" if response['status'] != 'success'
|
138
|
+
end
|
139
|
+
rescue StandardError => e
|
140
|
+
puts "ERROR:#{e}" if ENV['DEBUG'] == 'true'
|
141
|
+
# fix the path
|
142
|
+
path_changes = configure_path(inventory_hash)
|
143
|
+
if ENV['DEBUG'] == 'true'
|
144
|
+
path_changes.each do |change|
|
145
|
+
puts "Configuring puppet path result: #{change.inspect}"
|
146
|
+
end
|
141
147
|
end
|
142
148
|
|
143
|
-
|
144
|
-
|
149
|
+
retries += 1
|
150
|
+
sleep 3
|
151
|
+
retry if retries <= 300
|
152
|
+
raise 'Failed to detect installed puppet version after 5 minutes'
|
145
153
|
end
|
154
|
+
|
155
|
+
# add puppet-agent feature to successful nodes
|
156
|
+
inventory_hash = add_feature_to_node(inventory_hash, 'puppet-agent', result['target'])
|
146
157
|
end
|
158
|
+
|
147
159
|
# update the inventory with the puppet-agent feature set per node
|
148
160
|
write_to_inventory_file(inventory_hash, 'inventory.yaml')
|
149
161
|
end
|
@@ -375,7 +387,7 @@ namespace :litmus do
|
|
375
387
|
at_exit { exit! }
|
376
388
|
|
377
389
|
env = options[:env].nil? ? {} : options[:env]
|
378
|
-
env['
|
390
|
+
env['HONEYCOMB_TRACE'] = Honeycomb.current_span.to_trace_header
|
379
391
|
stdout, stderr, status = Open3.capture3(env, test)
|
380
392
|
["\n================\n#{title}\n", stdout, stderr, status]
|
381
393
|
end
|
@@ -393,7 +405,7 @@ namespace :litmus do
|
|
393
405
|
spinners = TTY::Spinner::Multi.new("[:spinner] Running against #{targets.size} targets.")
|
394
406
|
payloads.each do |title, test, options|
|
395
407
|
env = options[:env].nil? ? {} : options[:env]
|
396
|
-
env['
|
408
|
+
env['HONEYCOMB_TRACE'] = Honeycomb.current_span.to_trace_header
|
397
409
|
spinners.register("[:spinner] #{title}") do |sp|
|
398
410
|
stdout, stderr, status = Open3.capture3(env, test)
|
399
411
|
if status.to_i.zero?
|
File without changes
|
@@ -77,6 +77,42 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
context 'with bulk tear_down' do
|
81
|
+
let(:inventory_hash) do
|
82
|
+
{ 'groups' =>
|
83
|
+
[{ 'name' => 'ssh_nodes', 'targets' =>
|
84
|
+
[
|
85
|
+
{ 'uri' => 'one.host', 'facts' => { 'provisioner' => 'abs', 'platform' => 'ubuntu-1604-x86_64', 'job_id' => 'iac-task-pid-21648' } },
|
86
|
+
{ 'uri' => 'two.host', 'facts' => { 'provisioner' => 'abs', 'platform' => 'ubuntu-1804-x86_64', 'job_id' => 'iac-task-pid-21648' } },
|
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' } },
|
89
|
+
] }] }
|
90
|
+
end
|
91
|
+
let(:targets) { ['one.host'] }
|
92
|
+
let(:params) { { 'action' => 'tear_down', 'node_name' => 'one.host', 'inventory' => Dir.pwd } }
|
93
|
+
|
94
|
+
it 'calls function' do
|
95
|
+
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision')).and_return(true)
|
96
|
+
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('provision::abs', 'localhost', params, config: described_class::DEFAULT_CONFIG_DATA, inventory: nil).and_return(
|
97
|
+
[{ 'target' => 'localhost',
|
98
|
+
'action' => 'task',
|
99
|
+
'object' => 'provision::abs',
|
100
|
+
'status' => 'success',
|
101
|
+
'value' =>
|
102
|
+
{ 'status' => 'ok',
|
103
|
+
'removed' =>
|
104
|
+
['one.host',
|
105
|
+
'two.host',
|
106
|
+
'three.host'] } }],
|
107
|
+
)
|
108
|
+
results = tear_down_nodes(targets, inventory_hash)
|
109
|
+
expect(results.keys).to eq(['one.host', 'two.host', 'three.host'])
|
110
|
+
results.each_value do |value|
|
111
|
+
expect(value[0]['value']).to eq({ 'status' => 'ok' })
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
80
116
|
context 'with install_agent' do
|
81
117
|
let(:inventory_hash) do
|
82
118
|
{ 'groups' =>
|
@@ -68,10 +68,13 @@ describe 'litmus rake tasks' do
|
|
68
68
|
|
69
69
|
allow(File).to receive(:directory?).with(any_args).and_return(true)
|
70
70
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results)
|
71
|
-
|
71
|
+
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).with(any_args).and_return({})
|
72
72
|
allow_any_instance_of(PuppetLitmus::RakeHelper).to receive(:check_connectivity?).with(any_args).and_return(true)
|
73
|
+
|
74
|
+
expect($stdout).to receive(:puts).with('Provisioning centos:7 using docker provisioner.')
|
73
75
|
expect($stdout).to receive(:puts).with("Successfully provisioned centos:7 using docker\n")
|
74
76
|
expect($stdout).to receive(:puts).with('localhost:2222, centos:7')
|
77
|
+
|
75
78
|
Rake::Task['litmus:provision'].invoke('docker', 'centos:7')
|
76
79
|
end
|
77
80
|
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.
|
4
|
+
version: 0.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bolt
|
@@ -185,16 +185,16 @@ files:
|
|
185
185
|
- spec/data/jim.yaml
|
186
186
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
187
187
|
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
188
|
+
- spec/lib/puppet_litmus/puppet_litmus_version_spec.rb
|
188
189
|
- spec/lib/puppet_litmus/rake_helper_spec.rb
|
189
190
|
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
190
191
|
- spec/lib/puppet_litmus/util_spec.rb
|
191
|
-
- spec/lib/puppet_litmus/version_spec.rb
|
192
192
|
- spec/spec_helper.rb
|
193
193
|
homepage: https://github.com/puppetlabs/puppet_litmus
|
194
194
|
licenses:
|
195
195
|
- Apache-2.0
|
196
196
|
metadata: {}
|
197
|
-
post_install_message:
|
197
|
+
post_install_message:
|
198
198
|
rdoc_options: []
|
199
199
|
require_paths:
|
200
200
|
- lib
|
@@ -202,26 +202,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
202
|
requirements:
|
203
203
|
- - ">="
|
204
204
|
- !ruby/object:Gem::Version
|
205
|
-
version:
|
205
|
+
version: 2.5.0
|
206
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
207
|
requirements:
|
208
208
|
- - ">="
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: '0'
|
211
211
|
requirements: []
|
212
|
-
rubygems_version: 3.
|
213
|
-
signing_key:
|
212
|
+
rubygems_version: 3.0.6
|
213
|
+
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
217
|
test_files:
|
218
|
-
- spec/
|
219
|
-
- spec/
|
220
|
-
- spec/
|
218
|
+
- spec/spec_helper.rb
|
219
|
+
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
220
|
+
- spec/lib/puppet_litmus/puppet_litmus_version_spec.rb
|
221
221
|
- spec/lib/puppet_litmus/util_spec.rb
|
222
|
-
- spec/lib/puppet_litmus/version_spec.rb
|
223
222
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
224
223
|
- spec/lib/puppet_litmus/rake_helper_spec.rb
|
225
224
|
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
226
|
-
- spec/
|
227
|
-
- spec/
|
225
|
+
- spec/data/doot.tar.gz
|
226
|
+
- spec/data/jim.yaml
|
227
|
+
- spec/data/inventory.yaml
|