puppet_litmus 0.18.2 → 0.18.3

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: c9148f5cf259702d6b12f875555b4cbef8fdbc4ff78081e495ca1b9b8948d082
4
- data.tar.gz: 3b002919bfff6ce6cb794ed9bd3d8b6b5712ba76d1cceceba1c8d205488f9057
3
+ metadata.gz: 7ace2d5a5ae33d1e795535b4704d84a54b9d97e48bd5a77b39866887c077e300
4
+ data.tar.gz: 611dbd8bd462331462506280920ac3355a732c18ca2a6edc2ce15e4da5071214
5
5
  SHA512:
6
- metadata.gz: 458f9935cf9148d839f0a2ac3cb3851a85ef18df7a7e99a0b216adafb9d33999a1d672da95f5450c1b371794cd6ecf7d92131778d79cdb47ea0cd0788e1901c4
7
- data.tar.gz: 4c1c40a1b40865ff788af2f52c6766a5f5d159674ce3f62173da91713dd96f5e1e78f1fb41234e5a7d82aa89c1cb1b2f35a29c841bf2e3307719506c4a130793
6
+ metadata.gz: 3f2024d6a7afed0976cdc5ab48ab1fe1e42ff17f75a39637feed9cf102d0a8defc8fd2c8bf54dac45512f9849fd9ec1a1862691455c6246e79afc55008376d23
7
+ data.tar.gz: 8a91349dc69667bdb7e701fa64a60fe71b0f8e311c017d5bda53b4fd0d1fa17c0276db50982076abdbf2d56408ea88cd6d9de8fac151ba609f41c75282c7125b
data/README.md CHANGED
@@ -24,7 +24,7 @@ Install Litmus as a gem by running ```gem install puppet_litmus```.
24
24
 
25
25
  ## Documentation
26
26
 
27
- For documentation, see our [Litmus Wiki](https://github.com/puppetlabs/puppet_litmus/wiki).
27
+ For documentation, see our [Litmus Docs Site](https://puppetlabs.github.io/litmus/).
28
28
 
29
29
  ## Other Resources
30
30
 
@@ -9,7 +9,7 @@ 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['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
12
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
13
13
  manifest_file_location = create_manifest_file(manifest)
14
14
  apply_manifest(nil, expect_failures: false, manifest_file_location: manifest_file_location)
15
15
  apply_manifest(nil, catch_changes: true, manifest_file_location: manifest_file_location)
@@ -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['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
42
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
43
43
  span.add_field('litmus.manifest', manifest)
44
44
  span.add_field('litmus.opts', opts)
45
45
 
@@ -117,7 +117,7 @@ module PuppetLitmus::PuppetHelpers
117
117
  # @return [String] The path to the location of the manifest.
118
118
  def create_manifest_file(manifest)
119
119
  Honeycomb.start_span(name: 'litmus.create_manifest_file') do |span|
120
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
120
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
121
121
  span.add_field('litmus.manifest', manifest)
122
122
 
123
123
  require 'tmpdir'
@@ -155,7 +155,7 @@ module PuppetLitmus::PuppetHelpers
155
155
  # @return [Object] A result object from the command.
156
156
  def run_shell(command_to_run, opts = {})
157
157
  Honeycomb.start_span(name: 'litmus.run_shell') do |span|
158
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
158
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
159
159
  span.add_field('litmus.command_to_run', command_to_run)
160
160
  span.add_field('litmus.opts', opts)
161
161
 
@@ -192,7 +192,7 @@ module PuppetLitmus::PuppetHelpers
192
192
  # @return [Object] A result object from the command.
193
193
  def bolt_upload_file(source, destination, opts = {}, options = {})
194
194
  Honeycomb.start_span(name: 'litmus.bolt_upload_file') do |span|
195
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
195
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
196
196
  span.add_field('litmus.source', source)
197
197
  span.add_field('litmus.destination', destination)
198
198
  span.add_field('litmus.opts', opts)
@@ -244,7 +244,7 @@ module PuppetLitmus::PuppetHelpers
244
244
  # @return [Object] A result object from the task.The values available are stdout, stderr and result.
245
245
  def run_bolt_task(task_name, params = {}, opts = {})
246
246
  Honeycomb.start_span(name: 'litmus.run_task') do |span|
247
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
247
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
248
248
  span.add_field('litmus.task_name', task_name)
249
249
  span.add_field('litmus.params', params)
250
250
  span.add_field('litmus.opts', opts)
@@ -312,7 +312,7 @@ module PuppetLitmus::PuppetHelpers
312
312
  # @return [Object] A result object from the script run.
313
313
  def bolt_run_script(script, opts = {}, arguments: [])
314
314
  Honeycomb.start_span(name: 'litmus.bolt_run_script') do |span|
315
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
315
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
316
316
  span.add_field('litmus.script', script)
317
317
  span.add_field('litmus.opts', opts)
318
318
  span.add_field('litmus.arguments', arguments)
@@ -2,15 +2,17 @@
2
2
 
3
3
  require 'bolt_spec/run'
4
4
  require 'honeycomb-beeline'
5
+ require 'puppet_litmus/version'
5
6
  Honeycomb.configure do |config|
6
7
  # override client if no configuration is provided, so that the pesky libhoney warning about lack of configuration is not shown
7
8
  unless ENV['HONEYCOMB_WRITEKEY'] && ENV['HONEYCOMB_DATASET']
8
9
  config.client = Libhoney::NullClient.new
9
10
  end
10
11
  end
11
- process_span = Honeycomb.start_span(name: 'Litmus Testing', serialized_trace: ENV['HTTP_X_HONEYCOMB_TRACE'])
12
- ENV['HTTP_X_HONEYCOMB_TRACE'] = process_span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
12
+ process_span = Honeycomb.start_span(name: "litmus: #{([$PROGRAM_NAME] + ($ARGV || [])).join(' ')}", serialized_trace: ENV['HTTP_X_HONEYCOMB_TRACE'])
13
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = process_span.to_trace_header
13
14
  Honeycomb.add_field_to_trace('litmus.pid', Process.pid)
15
+ Honeycomb.add_field_to_trace('litmus.version', PuppetLitmus::VERSION)
14
16
  if ENV['CI'] == 'true' && ENV['TRAVIS'] == 'true'
15
17
  Honeycomb.add_field_to_trace('module_name', ENV['TRAVIS_REPO_SLUG'])
16
18
  Honeycomb.add_field_to_trace('ci.provider', 'travis')
@@ -90,7 +92,7 @@ module PuppetLitmus::RakeHelper
90
92
  # @return [Object] the standard out stream.
91
93
  def run_local_command(command)
92
94
  Honeycomb.start_span(name: 'litmus.run_local_command') do |span|
93
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
95
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
94
96
  span.add_field('litmus.command', command)
95
97
 
96
98
  require 'open3'
@@ -113,7 +115,7 @@ module PuppetLitmus::RakeHelper
113
115
 
114
116
  Honeycomb.add_field_to_trace('litmus.provisioner', provisioner)
115
117
  Honeycomb.start_span(name: 'litmus.provision') do |span|
116
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
118
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
117
119
  span.add_field('litmus.platform', platform)
118
120
  span.add_field('litmus.inventory', params['inventory'])
119
121
  span.add_field('litmus.config', DEFAULT_CONFIG_DATA)
@@ -142,7 +144,7 @@ module PuppetLitmus::RakeHelper
142
144
 
143
145
  def tear_down_nodes(targets, inventory_hash)
144
146
  Honeycomb.start_span(name: 'litmus.tear_down_nodes') do |span|
145
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
147
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
146
148
  span.add_field('litmus.targets', targets)
147
149
 
148
150
  include ::BoltSpec::Run
@@ -162,7 +164,7 @@ module PuppetLitmus::RakeHelper
162
164
 
163
165
  def tear_down(node_name, inventory_hash)
164
166
  Honeycomb.start_span(name: 'litmus.tear_down') do |span|
165
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
167
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
166
168
  # how do we know what provisioner to use
167
169
 
168
170
  span.add_field('litmus.node_name', node_name)
@@ -178,7 +180,7 @@ module PuppetLitmus::RakeHelper
178
180
 
179
181
  def install_agent(collection, targets, inventory_hash)
180
182
  Honeycomb.start_span(name: 'litmus.install_agent') do |span|
181
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
183
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
182
184
  span.add_field('litmus.collection', collection)
183
185
  span.add_field('litmus.targets', targets)
184
186
 
@@ -209,32 +211,71 @@ module PuppetLitmus::RakeHelper
209
211
  results
210
212
  end
211
213
 
214
+ # Build the module in `module_dir` and put the resulting compressed tarball into `target_dir`.
215
+ #
212
216
  # @param opts Hash of options to build the module
213
217
  # @param module_dir [String] The path of the module to build. If missing defaults to Dir.pwd
214
- # @param target_dir [String] The path the module will be built into. The default is <source_dir>/pkg
218
+ # @param target_dir [String] The path the module will be built into. The default is <module_dir>/pkg
215
219
  # @return [String] The path to the built module
216
220
  def build_module(module_dir = nil, target_dir = nil)
217
221
  require 'puppet/modulebuilder'
218
222
 
219
- source_dir = module_dir || Dir.pwd
220
- dest_dir = target_dir || File.join(source_dir, 'pkg')
223
+ module_dir ||= Dir.pwd
224
+ target_dir ||= File.join(source_dir, 'pkg')
225
+
226
+ puts "Building '#{module_dir}' into '#{target_dir}''"
227
+ builder = Puppet::Modulebuilder::Builder.new(module_dir, target_dir, nil)
221
228
 
222
- builder = Puppet::Modulebuilder::Builder.new(source_dir, dest_dir, nil)
223
229
  # Force the metadata to be read. Raises if metadata could not be found
224
230
  _metadata = builder.metadata
225
231
 
226
232
  builder.build
227
233
  end
228
234
 
229
- def install_module(inventory_hash, target_node_name, module_tar, module_repository = 'https://forgeapi.puppetlabs.com')
235
+ # Builds all the modules in a specified directory
236
+ #
237
+ # @param source_dir [String] the directory to get the modules from
238
+ # @param target_dir [String] temporary location to store tarballs before uploading. This directory will be cleaned before use. The default is <source_dir>/pkg
239
+ # @return [Array] an array of module tars' filenames
240
+ def build_modules_in_dir(source_dir, target_dir = nil)
241
+ target_dir ||= File.join(Dir.pwd, 'pkg')
242
+ # remove old build dir if exists, before we build afresh
243
+ FileUtils.rm_rf(target_dir) if File.directory?(target_dir)
244
+
245
+ module_tars = Dir.entries(source_dir).map do |entry|
246
+ next if ['.', '..'].include? entry
247
+
248
+ module_dir = File.join(source_dir, entry)
249
+ next unless File.directory? module_dir
250
+
251
+ build_module(module_dir, target_dir)
252
+ end
253
+ module_tars.compact
254
+ end
255
+
256
+ # @deprecated Use `build_modules_in_dir` instead
257
+ def build_modules_in_folder(source_folder)
258
+ build_modules_in_dir(source_folder)
259
+ end
260
+
261
+ # Install a specific module tarball to the specified target.
262
+ # This method installs dependencies using a forge repository.
263
+ #
264
+ # @param inventory_hash [Hash] the pre-loaded inventory
265
+ # @param target_node_name [String] the name of the target where the module should be installed
266
+ # @param module_tar [String] the filename of the module tarball to upload
267
+ # @param module_repository [String] the URL for the forge to use for downloading modules. Defaults to the public Forge API.
268
+ # @return a bolt result
269
+ def install_module(inventory_hash, target_node_name, module_tar, module_repository = nil)
230
270
  Honeycomb.start_span(name: 'install_module') do |span|
231
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
271
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
232
272
  span.add_field('litmus.target_node_name', target_node_name)
233
273
  span.add_field('litmus.module_tar', module_tar)
234
274
 
235
- # make sure the target module is not installed
275
+ # make sure the module to install is not installed
236
276
  # otherwise `puppet module install` might silently skip it
237
- uninstall_module(inventory_hash.clone, target_node_name, force: true)
277
+ module_name = File.basename(module_tar, '.tar.gz').split('-', 3)[0..1].join('-')
278
+ uninstall_module(inventory_hash.clone, target_node_name, module_name, force: true)
238
279
 
239
280
  include ::BoltSpec::Run
240
281
 
@@ -243,7 +284,8 @@ module PuppetLitmus::RakeHelper
243
284
  bolt_result = upload_file(module_tar, File.basename(module_tar), target_nodes, options: {}, config: nil, inventory: inventory_hash.clone)
244
285
  raise_bolt_errors(bolt_result, 'Failed to upload module.')
245
286
 
246
- install_module_command = "puppet module install --module_repository '#{module_repository}' #{File.basename(module_tar)}"
287
+ module_repository_opts = "--module_repository '#{module_repository}'" unless module_repository.nil?
288
+ install_module_command = "puppet module install #{module_repository_opts} #{File.basename(module_tar)}"
247
289
  span.add_field('litmus.install_module_command', install_module_command)
248
290
 
249
291
  bolt_result = run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash.clone)
@@ -252,31 +294,6 @@ module PuppetLitmus::RakeHelper
252
294
  end
253
295
  end
254
296
 
255
- # Builds all the modules in a specified module
256
- #
257
- # @param source_folder [String] the folder to get the modules from
258
- # @return [Array] an array of module tar's
259
- def build_modules_in_folder(source_folder)
260
- folder_list = Dir.entries(source_folder).reject { |f| File.directory? f }
261
- module_tars = []
262
-
263
- target_dir = File.join(Dir.pwd, 'pkg')
264
- # remove old build folder if exists, before we build afresh
265
- FileUtils.rm_rf(target_dir) if File.directory?(target_dir)
266
-
267
- folder_list.each do |folder|
268
- folder_handle = Dir.open(File.join(source_folder, folder))
269
- next if File.symlink?(folder_handle)
270
-
271
- module_dir = folder_handle.path
272
-
273
- # build_module
274
- module_tar = build_module(module_dir, target_dir)
275
- module_tars.push(File.new(module_tar))
276
- end
277
- module_tars
278
- end
279
-
280
297
  def metadata_module_name
281
298
  require 'json'
282
299
  raise 'Could not find metadata.json' unless File.exist?(File.join(Dir.pwd, 'metadata.json'))
@@ -287,6 +304,11 @@ module PuppetLitmus::RakeHelper
287
304
  metadata['name']
288
305
  end
289
306
 
307
+ # Uninstall a module from a specified target
308
+ # @param inventory_hash [Hash] the pre-loaded inventory
309
+ # @param target_node_name [String] the name of the target where the module should be uninstalled
310
+ # @param module_to_remove [String] the name of the module to remove. Defaults to the module under test.
311
+ # @param opts [Hash] additional options to pass on to `puppet module uninstall`
290
312
  def uninstall_module(inventory_hash, target_node_name, module_to_remove = nil, **opts)
291
313
  include ::BoltSpec::Run
292
314
  module_name = module_to_remove || metadata_module_name
@@ -301,7 +323,7 @@ module PuppetLitmus::RakeHelper
301
323
 
302
324
  def check_connectivity?(inventory_hash, target_node_name)
303
325
  Honeycomb.start_span(name: 'litmus.check_connectivity') do |span|
304
- ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
326
+ ENV['HTTP_X_HONEYCOMB_TRACE'] = span.to_trace_header
305
327
  # if we're only checking connectivity for a single node
306
328
  if target_node_name
307
329
  span.add_field('litmus.node_name', target_node_name)
@@ -346,7 +368,7 @@ module PuppetLitmus::RakeHelper
346
368
 
347
369
  target = target_result['target']
348
370
  # get some info from error
349
- errors[target] = target_result['value']['_error']
371
+ errors[target] = target_result['value']
350
372
  end
351
373
  errors
352
374
  end
@@ -359,7 +381,8 @@ module PuppetLitmus::RakeHelper
359
381
  errors = check_bolt_errors(result_set)
360
382
 
361
383
  unless errors.empty?
362
- raise "#{error_msg}\nErrors: #{errors}"
384
+ formatted_results = errors.map { |k, v| " #{k}: #{v.inspect}" }.join("\n")
385
+ raise "#{error_msg}\nResults:\n#{formatted_results}}"
363
386
  end
364
387
 
365
388
  nil
@@ -17,15 +17,15 @@ namespace :litmus do
17
17
  end
18
18
 
19
19
  # Provisions a list of OSes from provision.yaml file e.g. 'bundle exec rake litmus:provision_list[default]'.
20
- # @See https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus#provisioning-via-yaml
20
+ # @See https://puppetlabs.github.io/litmus/Litmus-core-commands.html#provisioning-via-yaml
21
21
  #
22
22
  # @param :key [String] key that maps to a value for a provisioner and an image to be used for each OS provisioned.
23
- desc "provision list of machines from provision.yaml file. 'bundle exec rake 'litmus:provision_list[default]'"
23
+ desc 'provision list of machines from provision.yaml file'
24
24
  task :provision_list, [:key] do |_task, args|
25
25
  raise 'Cannot find provision.yaml file' unless File.file?('./provision.yaml')
26
26
 
27
27
  provision_hash = YAML.load_file('./provision.yaml')
28
- raise "No key #{args[:key]} in ./provision.yaml, see https://github.com/puppetlabs/puppet_litmus/wiki/Overview-of-Litmus#provisioning-via-yaml for examples" if provision_hash[args[:key]].nil?
28
+ raise "No key #{args[:key]} in ./provision.yaml, see https://puppetlabs.github.io/litmus/Litmus-core-commands.html#provisioning-via-yaml for examples" if provision_hash[args[:key]].nil?
29
29
 
30
30
  Rake::Task['spec_prep'].invoke
31
31
 
@@ -71,7 +71,7 @@ namespace :litmus do
71
71
  #
72
72
  # @param :provisioner [String] provisioner to use in provisioning given platform.
73
73
  # @param :platform [String] OS platform for container or VM to use.
74
- desc "provision container/VM - abs/docker/vagrant/vmpooler eg 'bundle exec rake 'litmus:provision[vmpooler, ubuntu-1604-x86_64]'"
74
+ desc 'provision a test system using the given provisioner and platform name. See the puppetlabs-provision module tasks for more documentation'
75
75
  task :provision, [:provisioner, :platform, :inventory_vars] do |_task, args|
76
76
  Rake::Task['spec_prep'].invoke
77
77
  if (ENV['CI'] == 'true') || !ENV['DISTELLI_BUILDNUM'].nil?
@@ -103,7 +103,7 @@ namespace :litmus do
103
103
  #
104
104
  # @param :collection [String] parameters to pass to the puppet agent install command.
105
105
  # @param :target_node_name [Array] nodes on which to install puppet agent.
106
- desc 'install puppet agent, [:collection, :target_node_name]'
106
+ desc 'install a puppet agent to all or a specified set of targets'
107
107
  task :install_agent, [:collection, :target_node_name] do |_task, args|
108
108
  inventory_hash = inventory_hash_from_inventory_file
109
109
  targets = find_targets(inventory_hash, args[:target_node_name])
@@ -143,7 +143,7 @@ namespace :litmus do
143
143
  #
144
144
  # @param :target_node_name [Array] nodes on which to add the feature.
145
145
  # @param :added_feature [String] the feature which you wish to add.
146
- desc 'add_feature, [:added_feature, :target_node_name]'
146
+ desc 'add a feature tag to a node'
147
147
  task :add_feature, [:added_feature, :target_node_name] do |_task, args|
148
148
  inventory_hash = inventory_hash_from_inventory_file
149
149
  targets = find_targets(inventory_hash, args[:target_node_name])
@@ -166,83 +166,118 @@ namespace :litmus do
166
166
  puts 'Feature added'
167
167
  end
168
168
 
169
+ # Install the puppet module under test on a collection of nodes
170
+ #
171
+ # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
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
+ inventory_hash = inventory_hash_from_inventory_file
176
+ target_nodes = find_targets(inventory_hash, args[:target_node_name])
177
+ if target_nodes.empty?
178
+ puts 'No targets found'
179
+ exit 0
180
+ 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]}"
191
+ end
192
+
169
193
  # Install the puppet modules from a source directory to nodes. It does not install dependencies.
170
194
  #
171
195
  # @param :source [String] source directory to look in (ignores symlinks) defaults do './spec/fixtures/modules'.
172
196
  # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
173
- desc 'install_module - build and install module'
197
+ desc 'build and install all modules from a directory'
174
198
  task :install_modules_from_directory, [:source, :target_node_name, :module_repository] do |_task, args|
175
- args.with_defaults(source: nil, target_node_name: nil, module_repository: 'https://forgeapi.puppetlabs.com')
199
+ args.with_defaults(source: nil, target_node_name: nil, module_repository: nil)
176
200
  inventory_hash = inventory_hash_from_inventory_file
177
201
  target_nodes = find_targets(inventory_hash, args[:target_node_name])
178
202
  if target_nodes.empty?
179
203
  puts 'No targets found'
180
204
  exit 0
181
205
  end
182
- source_folder = if args[:source].nil?
183
- './spec/fixtures/modules'
184
- else
185
- File.expand_path(args[:source])
186
- end
187
- raise "Source folder doesnt exist #{source_folder}" unless File.directory?(source_folder)
188
-
189
- puts 'Building'
190
- module_tars = build_modules_in_folder(source_folder)
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)
191
215
  require 'bolt_spec/run'
192
216
  include BoltSpec::Run
193
- puts "\nInstalling"
194
217
  module_tars.each do |module_tar|
218
+ puts "Installing '#{module_tar}'"
195
219
  target_nodes.each do |target_node_name|
196
220
  install_module(inventory_hash, target_node_name, module_tar, args[:module_repository])
221
+ puts "Installed '#{module_tar}' on #{target_node_name}"
197
222
  end
198
223
  end
199
224
  end
200
225
 
201
- # Check that the nodes in the inventory are still contactable
226
+ # Uninstall the puppet module under test on a collection of nodes
202
227
  #
203
- # @param :target_node_name [Array] nodes on which to check connnectivity
204
- desc 'check_connectivity - build and install module'
205
- task :check_connectivity, [:target_node_name] do |_task, args|
228
+ # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
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|
206
232
  inventory_hash = inventory_hash_from_inventory_file
207
233
  target_nodes = find_targets(inventory_hash, args[:target_node_name])
208
234
  if target_nodes.empty?
209
235
  puts 'No targets found'
210
236
  exit 0
211
237
  end
212
- check_connectivity?(inventory_hash, args[:target_node_name])
238
+
239
+ result = uninstall_module(inventory_hash, args[:target_node_name], args[:module_name])
240
+
241
+ raise "Failed trying to run 'puppet module uninstall #{module_name}' against inventory." unless result.is_a?(Array)
242
+
243
+ result.each do |node|
244
+ puts "#{node['target']} failed #{node['value']}" if node['status'] != 'success'
245
+ end
246
+
247
+ puts 'Uninstalled'
213
248
  end
214
249
 
215
- # Install the puppet module under test on a collection of nodes
250
+ # Reinstall the puppet module under test on a collection of nodes
216
251
  #
217
252
  # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
218
- desc 'install_module - build and install module'
219
- task :install_module, [:target_node_name, :module_repository] do |_task, args|
220
- args.with_defaults(target_node_name: nil, module_repository: 'https://forgeapi.puppetlabs.com')
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|
221
265
  inventory_hash = inventory_hash_from_inventory_file
222
266
  target_nodes = find_targets(inventory_hash, args[:target_node_name])
223
267
  if target_nodes.empty?
224
268
  puts 'No targets found'
225
269
  exit 0
226
270
  end
227
-
228
- module_tar = build_module
229
- puts 'Built'
230
-
231
- # module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
232
- raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?
233
-
234
- install_module(inventory_hash, args[:target_node_name], module_tar, args[:module_repository])
235
-
236
- puts 'Installed'
271
+ check_connectivity?(inventory_hash, args[:target_node_name])
237
272
  end
238
273
 
239
274
  # Provision a list of machines, install a puppet agent, and install the puppet module under test on a collection of nodes
240
275
  #
241
276
  # @param :key [String] key that maps to a value for a provisioner and an image to be used for each OS provisioned.
242
277
  # @param :collection [String] parameters to pass to the puppet agent install command.
243
- desc 'provision_install - provision a list of machines, install an agent, and the module.'
278
+ desc 'provision a list of machines, install an agent, and the module.'
244
279
  task :provision_install, [:key, :collection, :module_repository] do |_task, args|
245
- args.with_defaults(module_repository: 'https://forgeapi.puppetlabs.com')
280
+ args.with_defaults(module_repository: nil)
246
281
  Rake::Task['spec_prep'].invoke
247
282
  Rake::Task['litmus:provision_list'].invoke(args[:key])
248
283
  Rake::Task['litmus:install_agent'].invoke(args[:collection])
@@ -252,7 +287,7 @@ namespace :litmus do
252
287
  # Decommissions test machines.
253
288
  #
254
289
  # @param :target [Array] nodes to remove from test environemnt and decommission.
255
- desc 'tear-down - decommission machines'
290
+ desc 'destroy provisioned targets'
256
291
  task :tear_down, [:target] do |_task, args|
257
292
  inventory_hash = inventory_hash_from_inventory_file
258
293
  targets = find_targets(inventory_hash, args[:target])
@@ -278,40 +313,6 @@ namespace :litmus do
278
313
  end
279
314
  end
280
315
 
281
- # Uninstall the puppet module under test on a collection of nodes
282
- #
283
- # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
284
- # @param :module_name [String] module name to be uninstalled
285
- desc 'uninstall_module - uninstall module'
286
- task :uninstall_module, [:target_node_name, :module_name] do |_task, args|
287
- inventory_hash = inventory_hash_from_inventory_file
288
- target_nodes = find_targets(inventory_hash, args[:target_node_name])
289
- if target_nodes.empty?
290
- puts 'No targets found'
291
- exit 0
292
- end
293
-
294
- result = uninstall_module(inventory_hash, args[:target_node_name], args[:module_name])
295
-
296
- raise "Failed trying to run 'puppet module uninstall #{module_name}' against inventory." unless result.is_a?(Array)
297
-
298
- result.each do |node|
299
- puts "#{node['target']} failed #{node['value']}" if node['status'] != 'success'
300
- end
301
-
302
- puts 'Uninstalled'
303
- end
304
-
305
- # Reinstall the puppet module under test on a collection of nodes
306
- #
307
- # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
308
- desc 'reinstall_module - reinstall module'
309
- task :reinstall_module, [:target_node_name, :module_repository] do |_task, args|
310
- args.with_defaults(target_node_name: nil, module_repository: 'https://forgeapi.puppetlabs.com')
311
- Rake::Task['litmus:uninstall_module'].invoke(args[:target_node_name])
312
- Rake::Task['litmus:install_module'].invoke(args[:target_node_name], args[:module_repository])
313
- end
314
-
315
316
  namespace :acceptance do
316
317
  require 'rspec/core/rake_task'
317
318
  if File.file?('inventory.yaml')
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.18.2'
5
+ VERSION ||= '0.18.3'
6
6
  end
@@ -100,20 +100,20 @@ RSpec.describe PuppetLitmus::RakeHelper do
100
100
  [{ 'name' => 'ssh_nodes', 'targets' =>
101
101
  [{ 'uri' => 'some.host', 'facts' => { 'provisioner' => 'docker', 'container_name' => 'foo', 'platform' => 'some.host' } }] }] }
102
102
  end
103
- let(:module_tar) { '/tmp/foo.tar.gz' }
103
+ let(:module_tar) { 'foo.tar.gz' }
104
104
  let(:targets) { ['some.host'] }
105
105
  let(:uninstall_module_command) { 'puppet module uninstall foo --force' }
106
- let(:install_module_command) { "puppet module install --module_repository 'https://forgeapi.puppetlabs.com' #{module_tar}" }
106
+ let(:install_module_command) { "puppet module install --module_repository 'https://forgeapi.example.com' #{module_tar}" }
107
107
 
108
108
  it 'calls function' do
109
109
  allow_any_instance_of(BoltSpec::Run).to receive(:upload_file).with(module_tar, module_tar, targets, options: {}, config: nil, inventory: inventory_hash).and_return([])
110
110
  allow(File).to receive(:exist?).with(File.join(Dir.pwd, 'metadata.json')).and_return(true)
111
111
  allow(File).to receive(:read).with(File.join(Dir.pwd, 'metadata.json')).and_return(JSON.dump({ name: 'foo' }))
112
- allow(Open3).to receive(:capture3).with("bundle exec bolt file upload \"#{module_tar}\" /tmp/#{File.basename(module_tar)} --targets all --inventoryfile inventory.yaml")
112
+ allow(Open3).to receive(:capture3).with("bundle exec bolt file upload \"#{module_tar}\" #{File.basename(module_tar)} --targets all --inventoryfile inventory.yaml")
113
113
  .and_return(['success', '', 0])
114
114
  allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
115
115
  allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(install_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
116
- install_module(inventory_hash, nil, module_tar)
116
+ install_module(inventory_hash, nil, module_tar, 'https://forgeapi.example.com')
117
117
  end
118
118
  end
119
119
 
@@ -28,8 +28,8 @@ describe 'litmus rake tasks' do
28
28
 
29
29
  context 'with litmus:install_modules_from_directory' do
30
30
  let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }] }] } }
31
- let(:target_folder) { File.join(Dir.pwd, 'spec/fixtures/modules') }
32
- let(:dummy_tar) { File.new('spec/data/doot.tar.gz') }
31
+ let(:target_dir) { File.join(Dir.pwd, 'spec/fixtures/modules') }
32
+ let(:dummy_tar) { 'spec/data/doot.tar.gz' }
33
33
 
34
34
  it 'happy path' do
35
35
  allow(File).to receive(:exist?).with(File.join(Dir.pwd, 'metadata.json')).and_return(true)
@@ -37,12 +37,13 @@ describe 'litmus rake tasks' do
37
37
 
38
38
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
39
39
  expect_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
40
- expect(File).to receive(:directory?).with(target_folder).and_return(true)
41
- expect_any_instance_of(Object).to receive(:build_modules_in_folder).with(target_folder).and_return([dummy_tar])
42
- expect(STDOUT).to receive(:puts).with('Building')
40
+ expect(File).to receive(:directory?).with(target_dir).and_return(true)
41
+ expect_any_instance_of(Object).to receive(:build_modules_in_dir).with(target_dir).and_return([dummy_tar])
42
+ expect(STDOUT).to receive(:puts).with(start_with('Building all modules in'))
43
43
  expect_any_instance_of(Object).to receive(:upload_file).once.and_return([])
44
- expect(STDOUT).to receive(:puts).with("\nInstalling")
44
+ expect(STDOUT).to receive(:puts).with(start_with('Installing \'spec/data/doot.tar.gz\''))
45
45
  expect_any_instance_of(Object).to receive(:run_command).twice.and_return([])
46
+ expect(STDOUT).to receive(:puts).with(start_with('Installed \'spec/data/doot.tar.gz\''))
46
47
  Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/modules')
47
48
  end
48
49
  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.18.2
4
+ version: 0.18.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-28 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bolt
@@ -34,16 +34,22 @@ dependencies:
34
34
  name: puppet-modulebuilder
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.2.1
40
+ - - "<"
38
41
  - !ruby/object:Gem::Version
39
- version: '0.1'
42
+ version: 1.0.0
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
45
48
  - !ruby/object:Gem::Version
46
- version: '0.1'
49
+ version: 0.2.1
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.0
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: tty-spinner
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -233,13 +239,13 @@ specification_version: 4
233
239
  summary: Providing a simple command line tool for puppet content creators, to enable
234
240
  simple and complex test deployments.
235
241
  test_files:
236
- - spec/spec_helper.rb
237
- - spec/lib/puppet_litmus/rake_tasks_spec.rb
238
- - spec/lib/puppet_litmus/version_spec.rb
242
+ - spec/data/doot.tar.gz
243
+ - spec/data/inventory.yaml
244
+ - spec/data/jim.yaml
239
245
  - spec/lib/puppet_litmus/util_spec.rb
246
+ - spec/lib/puppet_litmus/version_spec.rb
240
247
  - spec/lib/puppet_litmus/inventory_manipulation_spec.rb
241
- - spec/lib/puppet_litmus/rake_helper_spec.rb
242
248
  - spec/lib/puppet_litmus/puppet_helpers_spec.rb
243
- - spec/data/doot.tar.gz
244
- - spec/data/jim.yaml
245
- - spec/data/inventory.yaml
249
+ - spec/lib/puppet_litmus/rake_helper_spec.rb
250
+ - spec/lib/puppet_litmus/rake_tasks_spec.rb
251
+ - spec/spec_helper.rb