puppet_litmus 0.13.1 → 0.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 010e8b1b5a215086d880ace04e48f7beeb259d27d565e0d187f6509412aaf42e
4
- data.tar.gz: 48cabdd685b1fb4ec5772ae64bea6f3ccdef822f7237029f19279b62c6bdc5a6
3
+ metadata.gz: 815ccaf832ee6fa876fa73222f64246bf39d1510488cd5c655ea880976e94c32
4
+ data.tar.gz: 40c94ee82672dd7a48d100d54cdf1091fea06b8b706e69c0382e4dbf5edfdb86
5
5
  SHA512:
6
- metadata.gz: eba91d7ef1dbd290daf9e50cccb85548cd0ae8975de31ef3761ea6794bb339f9a8efc3911ffe02a6308d525d76c3dd21ad00d353f18f2ac9f276faff581c4e7b
7
- data.tar.gz: 5d4dc9f8ea6b08663e527737bb5974e5dcd5cd691a88994d5c0271f0c6df4e205dcff8766995ee74a693c118ed621cca8d221e7b83120433d6eafdc4c044711d
6
+ metadata.gz: 6aa9e819c9d11d3d2f149e29792ee373c715cac86d4f6b2f6620efba1111b27b2fb9756470bed981e3fcf0d9b1897e398390a6dd8215e9d3cced0842311f58bb
7
+ data.tar.gz: 14fa50906d8122c789d13a380dc245e41da0106c9ee9b1c7993b62b40de2661aa3a700303dcb2f7194756cbb34d3f143b94fb987d620a21cfd31a73bdf243382
@@ -207,4 +207,18 @@ module PuppetLitmus::RakeHelper
207
207
  install_module_command = "puppet module uninstall #{module_name}"
208
208
  run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash)
209
209
  end
210
+
211
+ def check_connectivity?(inventory_hash, target_node_name)
212
+ require 'bolt_spec/run'
213
+ include BoltSpec::Run
214
+ target_nodes = find_targets(inventory_hash, target_node_name)
215
+ results = run_command('cd .', target_nodes, config: nil, inventory: inventory_hash)
216
+ failed = []
217
+ results.each do |result|
218
+ failed.push(result['target']) if result['status'] == 'failure'
219
+ end
220
+ raise "Connectivity has failed on: #{failed}" unless failed.length.zero?
221
+
222
+ true
223
+ end
210
224
  end
@@ -53,7 +53,7 @@ namespace :litmus do
53
53
  end
54
54
 
55
55
  if result.first['status'] != 'success'
56
- failed_image_message += "=====\n#{result.first['node']}\n#{result.first['result']['_output']}\n"
56
+ failed_image_message += "=====\n#{result.first['node']}\n#{result.first['result']['_output']}\n#{result.inspect}"
57
57
  else
58
58
  STDOUT.puts "#{result.first['result']['node_name']}, #{image}"
59
59
  end
@@ -175,6 +175,20 @@ namespace :litmus do
175
175
  end
176
176
  end
177
177
 
178
+ # Check that the nodes in the inventory are still contactable
179
+ #
180
+ # @param :target_node_name [Array] nodes on which to check connnectivity
181
+ desc 'check_connectivity - build and install module'
182
+ task :check_connectivity, [:target_node_name] do |_task, args|
183
+ inventory_hash = inventory_hash_from_inventory_file
184
+ target_nodes = find_targets(inventory_hash, args[:target_node_name])
185
+ if target_nodes.empty?
186
+ puts 'No targets found'
187
+ exit 0
188
+ end
189
+ check_connectivity?(inventory_hash, args[:target_node_name])
190
+ end
191
+
178
192
  # Install the puppet module under test on a collection of nodes
179
193
  #
180
194
  # @param :target_node_name [Array] nodes on which to install a puppet module for testing.
@@ -366,23 +380,10 @@ namespace :litmus do
366
380
  # output test summary
367
381
  puts "Successful on #{success_list.size} nodes: #{success_list}" if success_list.any?
368
382
  puts "Failed on #{failure_list.size} nodes: #{failure_list}" if failure_list.any?
383
+ Rake::Task['litmus:check_connectivity'].invoke
369
384
  exit 1 if failure_list.any?
370
385
  end
371
386
 
372
- # Run acceptance tests against all machines in the inventory file in serial.
373
- desc 'Run tests in serial against all machines in the inventory file'
374
- task :serial do
375
- # Iterate over all of the acceptance test tasks and invoke them;
376
- # We can rely on them always being in the format `litmus:acceptance:host_name:port`
377
- # The host_name might be localhost or an IP or a DNS-resolvable node.
378
- prefix = 'litmus:acceptance:'
379
- tasks = Rake::Task.tasks.select { |task| task.name =~ %r{^#{prefix}.+:\d+$} }
380
- tasks.each do |task|
381
- puts "Running acceptance tests against #{task.name[prefix.length..-1]}"
382
- task.invoke
383
- end
384
- end
385
-
386
387
  targets.each do |target|
387
388
  desc "Run serverspec against #{target}"
388
389
  next if target == 'litmus_localhost'
@@ -9,6 +9,7 @@ module PuppetLitmus
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.include PuppetLitmus
12
+ config.extend PuppetLitmus
12
13
  end
13
14
 
14
15
  if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
@@ -73,7 +74,9 @@ module PuppetLitmus
73
74
  set :os, family: 'windows'
74
75
  user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
75
76
  pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
76
- endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"
77
+ endpoint = URI("http://#{ENV['TARGET_HOST']}")
78
+ endpoint.port = 5985 if endpoint.port == 80
79
+ endpoint.path = '/wsman'
77
80
 
78
81
  opts = {
79
82
  user: user,
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.13.1'
5
+ VERSION ||= '0.14.0'
6
6
  end
@@ -122,10 +122,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
122
122
  let(:local) { '/tmp' }
123
123
  let(:remote) { '/remote_tmp' }
124
124
  # Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
125
- # rubocop:disable SpaceInsideHashLiteralBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
125
+ # rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Metrics/LineLength, Layout/SpaceAfterComma
126
126
  let(:result_success) {[{'node'=>'some.host','target'=>'some.host','action'=>'upload','object'=>'C:\foo\bar.ps1','status'=>'success','result'=>{'_output'=>'Uploaded \'C:\foo\bar.ps1\' to \'some.host:C:\bar\''}}]}
127
127
  let(:result_failure) {[{'node'=>'some.host','target'=>'some.host','action'=>nil,'object'=>nil,'status'=>'failure','result'=>{'_error'=>{'kind'=>'puppetlabs.tasks/task_file_error','msg'=>'No such file or directory @ rb_sysopen - /nonexistant/file/path','details'=>{},'issue_code'=>'WRITE_ERROR'}}}]}
128
- # rubocop:enable SpaceInsideHashLiteralBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
128
+ # rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Metrics/LineLength, Layout/SpaceAfterComma
129
129
  let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
130
130
  let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
131
131
 
@@ -228,11 +228,11 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
228
228
  let(:params) { { 'action' => 'install', 'name' => 'foo' } }
229
229
  let(:config_data) { { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } }
230
230
  # Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
231
- # rubocop:disable SpaceInsideHashLiteralBraces, SpaceBeforeBlockBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
231
+ # rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Metrics/LineLength, Layout/SpaceAfterComma
232
232
  let(:result_unstructured_task_success){ [{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'success','result'=>{'_output'=>'SUCCESS!'}}]}
233
233
  let(:result_structured_task_success){ [{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::structured','status'=>'success','result'=>{'key1'=>'foo','key2'=>'bar'}}]}
234
234
  let(:result_failure) {[{'node'=>'some.host','target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'failure','result'=>{'_error'=>{'msg'=>'FAILURE!','kind'=>'puppetlabs.tasks/task-error','details'=>{'exitcode'=>123}}}}]}
235
- # rubocop:enable SpaceInsideHashLiteralBraces, SpaceBeforeBlockBraces, SpaceInsideBlockBraces, SpaceAroundOperators, LineLength, SpaceAfterComma
235
+ # rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Metrics/LineLength, Layout/SpaceAfterComma
236
236
  let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
237
237
 
238
238
  it 'responds to bolt_run_task' do
@@ -78,6 +78,27 @@ RSpec.describe PuppetLitmus::RakeHelper do
78
78
  end
79
79
  end
80
80
 
81
+ context 'with check_connectivity' do
82
+ let(:inventory_hash) do
83
+ { 'groups' =>
84
+ [{ 'name' => 'ssh_nodes', 'nodes' =>
85
+ [{ 'name' => 'some.host', 'facts' => { 'provisioner' => 'docker', 'container_name' => 'foo', 'platform' => 'some.host' } }] }] }
86
+ end
87
+ let(:targets) { ['some.host'] }
88
+ let(:command) { 'cd .' }
89
+
90
+ it 'node available' do
91
+ allow(Open3).to receive(:capture3).with('cd .').and_return(['success', '', 0])
92
+ allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(command, targets, config: nil, inventory: inventory_hash).and_return([{ 'target' => 'some.host', 'status' => 'success' }])
93
+ described_class.check_connectivity?(inventory_hash, nil)
94
+ end
95
+
96
+ it 'node unavailable' do
97
+ 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' }])
98
+ expect { described_class.check_connectivity?(inventory_hash, nil) }.to raise_error(RuntimeError, %r{Connectivity has failed on:})
99
+ end
100
+ end
101
+
81
102
  context 'with uninstall module' do
82
103
  let(:inventory_hash) do
83
104
  { 'groups' =>
@@ -81,4 +81,15 @@ describe 'litmus rake tasks' do
81
81
  expect { Rake::Task['litmus:provision_list'].invoke('deet') }.to raise_error(%r{deet})
82
82
  end
83
83
  end
84
+
85
+ context 'with litmus:check_connectivity task' do
86
+ let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'name' => 'some.host' }] }] } }
87
+
88
+ it 'happy path' do
89
+ stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
90
+ expect_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
91
+ expect_any_instance_of(PuppetLitmus::RakeHelper).to receive(:check_connectivity?).with(inventory_hash, nil).and_return(true)
92
+ Rake::Task['litmus:check_connectivity'].invoke
93
+ end
94
+ end
84
95
  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.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2020-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bolt
@@ -163,18 +163,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubygems_version: 3.0.4
166
+ rubyforge_project:
167
+ rubygems_version: 2.7.6.2
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: Providing a simple command line tool for puppet content creators, to enable
170
171
  simple and complex test deployments.
171
172
  test_files:
172
- - spec/data/doot.tar.gz
173
- - spec/data/inventory.yaml
174
- - spec/data/jim.yaml
175
- - spec/lib/puppet_litmus/inventory_manipulation_spec.rb
176
- - spec/lib/puppet_litmus/puppet_helpers_spec.rb
177
- - spec/lib/puppet_litmus/rake_helper_spec.rb
173
+ - spec/spec_helper.rb
178
174
  - spec/lib/puppet_litmus/rake_tasks_spec.rb
179
175
  - spec/lib/puppet_litmus/version_spec.rb
180
- - spec/spec_helper.rb
176
+ - spec/lib/puppet_litmus/inventory_manipulation_spec.rb
177
+ - spec/lib/puppet_litmus/rake_helper_spec.rb
178
+ - spec/lib/puppet_litmus/puppet_helpers_spec.rb
179
+ - spec/data/doot.tar.gz
180
+ - spec/data/jim.yaml
181
+ - spec/data/inventory.yaml