puppet_litmus 0.18.0 → 0.18.1

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: b57432738dbfa9e3c83c891565286c43703437df4d4b8f3a1c09431012dd869d
4
- data.tar.gz: 7d4213842c29f689b943dea1a89fc1ea5c4cda272a67fad70c2d55a9b74114a8
3
+ metadata.gz: 6b3fcb695b5204b13b091211f12201ade70cd34af04ad8aefd81856f5b212116
4
+ data.tar.gz: 4f941ab55af8dbed7848e39fbdbeba76586aabce36a1a52194d76cee6680ecf3
5
5
  SHA512:
6
- metadata.gz: 01344ef395005540dc7ae2d109b19e6bf94064f0a27031e886c2f114cdaec8c33c6cbcd71c57a0c164b4724cc5014fb17b7b8ddf12220189f2e10bb22ead26b7
7
- data.tar.gz: 4f6a4144f1785e618d40560463de94e874d03208c1a35ba2ca3d031752e9791b133466105f45b50e4ef59f0f12a3e0736e606d2140d0e517b63c633a0dd7aae6
6
+ metadata.gz: 8254a6ec0ffe6a9d398730de3a4c5878330ece15912ebc39d560bb3e811616e05319f4577434d457088e44f48391e043579f808ec5d4628e2ed0bd49843bbf70
7
+ data.tar.gz: cb009e0328b4373a3fccb987a02c143f0b61bd5ae6c3718ee9adb6553242b057a0674dc84cb13f6aa0f31821a130aeec1db8498a8957dbe5ba8eb2a2263332b5
@@ -4,7 +4,6 @@
4
4
  module PuppetLitmus; end
5
5
 
6
6
  require 'bolt_spec/run'
7
- require 'puppet_litmus/honeycomb_utils'
8
7
  require 'puppet_litmus/inventory_manipulation'
9
8
  require 'puppet_litmus/puppet_helpers'
10
9
  require 'puppet_litmus/rake_helper'
@@ -235,7 +235,7 @@ module PuppetLitmus::InventoryManipulation
235
235
  #
236
236
  # @param inventory_hash [Hash] hash of the inventory.yaml file
237
237
  # @param feature_name [String] feature to locate in the node
238
- # node_name [String] node of nodes to limit the search for the node_name in
238
+ # @param node_name [String] node of nodes to limit the search for the node_name in
239
239
  # @return inventory.yaml file with feature removed from the node.
240
240
  # @return [Hash] inventory_hash with feature added to node if node_name exists in inventory hash.
241
241
  def remove_feature_from_node(inventory_hash, feature_name, node_name)
@@ -257,4 +257,13 @@ module PuppetLitmus::InventoryManipulation
257
257
  def write_to_inventory_file(inventory_hash, inventory_full_path)
258
258
  File.open(inventory_full_path, 'wb+') { |f| f.write(inventory_hash.to_yaml) }
259
259
  end
260
+
261
+ # Add the `litmus.platform` with platform information for the target
262
+ #
263
+ # @param inventory_hash [Hash] hash of the inventory.yaml file
264
+ # @param node_name [String] node of nodes to limit the search for the node_name in
265
+ def add_platform_field(inventory_hash, node_name)
266
+ facts = facts_from_node(inventory_hash, node_name)
267
+ Honeycomb.current_span.add_field('litmus.platform', facts&.dig('platform'))
268
+ end
260
269
  end
@@ -73,7 +73,7 @@ module PuppetLitmus::PuppetHelpers
73
73
  raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
74
74
 
75
75
  span.add_field('litmus.node_name', target_node_name)
76
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
76
+ add_platform_field(inventory_hash, target_node_name)
77
77
 
78
78
  command_to_run = "#{opts[:prefix_command]} puppet apply #{manifest_file_location}"
79
79
  command_to_run += ' --trace' if !opts[:trace].nil? && (opts[:trace] == true)
@@ -133,7 +133,7 @@ module PuppetLitmus::PuppetHelpers
133
133
  # transfer to TARGET_HOST
134
134
  inventory_hash = inventory_hash_from_inventory_file
135
135
  span.add_field('litmus.node_name', target_node_name)
136
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
136
+ add_platform_field(inventory_hash, target_node_name)
137
137
 
138
138
  manifest_file_location = "/tmp/#{File.basename(manifest_file)}"
139
139
  bolt_result = upload_file(manifest_file.path, manifest_file_location, target_node_name, options: {}, config: nil, inventory: inventory_hash)
@@ -164,7 +164,7 @@ module PuppetLitmus::PuppetHelpers
164
164
  raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
165
165
 
166
166
  span.add_field('litmus.node_name', target_node_name)
167
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
167
+ add_platform_field(inventory_hash, target_node_name)
168
168
 
169
169
  bolt_result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
170
170
  span.add_field('litmus.bolt_result', bolt_result)
@@ -203,7 +203,7 @@ module PuppetLitmus::PuppetHelpers
203
203
  raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
204
204
 
205
205
  span.add_field('litmus.node_name', target_node_name)
206
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
206
+ add_platform_field(inventory_hash, target_node_name)
207
207
 
208
208
  bolt_result = upload_file(source, destination, target_node_name, options: options, config: nil, inventory: inventory_hash)
209
209
  span.add_field('litmus.bolt_result', bolt_result)
@@ -261,7 +261,7 @@ module PuppetLitmus::PuppetHelpers
261
261
  raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
262
262
 
263
263
  span.add_field('litmus.node_name', target_node_name)
264
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
264
+ add_platform_field(inventory_hash, target_node_name)
265
265
 
266
266
  bolt_result = run_task(task_name, target_node_name, params, config: config_data, inventory: inventory_hash)
267
267
  result_obj = {
@@ -322,7 +322,7 @@ module PuppetLitmus::PuppetHelpers
322
322
  raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
323
323
 
324
324
  span.add_field('litmus.node_name', target_node_name)
325
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
325
+ add_platform_field(inventory_hash, target_node_name)
326
326
 
327
327
  bolt_result = run_script(script, target_node_name, arguments, options: opts, config: nil, inventory: inventory_hash)
328
328
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'bolt_spec/run'
4
4
  require 'honeycomb-beeline'
5
- require 'puppet_litmus/honeycomb_utils'
6
5
  Honeycomb.configure do |config|
7
6
  # override client if no configuration is provided, so that the pesky libhoney warning about lack of configuration is not shown
8
7
  unless ENV['HONEYCOMB_WRITEKEY'] && ENV['HONEYCOMB_DATASET']
@@ -167,7 +166,7 @@ module PuppetLitmus::RakeHelper
167
166
  # how do we know what provisioner to use
168
167
 
169
168
  span.add_field('litmus.node_name', node_name)
170
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, node_name)
169
+ add_platform_field(inventory_hash, node_name)
171
170
 
172
171
  params = { 'action' => 'tear_down', 'node_name' => node_name, 'inventory' => Dir.pwd }
173
172
  node_facts = facts_from_node(inventory_hash, node_name)
@@ -301,7 +300,7 @@ module PuppetLitmus::RakeHelper
301
300
  # if we're only checking connectivity for a single node
302
301
  if target_node_name
303
302
  span.add_field('litmus.node_name', target_node_name)
304
- PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
303
+ add_platform_field(inventory_hash, target_node_name)
305
304
  end
306
305
 
307
306
  include ::BoltSpec::Run
@@ -354,8 +354,12 @@ namespace :litmus do
354
354
 
355
355
  require 'parallel'
356
356
  results = Parallel.map(payloads) do |title, test, options|
357
+ # avoid sending the parent process' main span in the sub-processes
358
+ # https://www.ruby-forum.com/t/at-exit-inherited-across-fork/122473/2
359
+ at_exit { exit! }
360
+
357
361
  env = options[:env].nil? ? {} : options[:env]
358
- ENV['HTTP_X_HONEYCOMB_TRACE'] = Honecomb.current_span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
362
+ env['HTTP_X_HONEYCOMB_TRACE'] = Honeycomb.current_span.to_trace_header
359
363
  stdout, stderr, status = Open3.capture3(env, test)
360
364
  ["\n================\n#{title}\n", stdout, stderr, status]
361
365
  end
@@ -373,8 +377,8 @@ namespace :litmus do
373
377
  spinners = TTY::Spinner::Multi.new("[:spinner] Running against #{targets.size} targets.")
374
378
  payloads.each do |title, test, options|
375
379
  env = options[:env].nil? ? {} : options[:env]
380
+ env['HTTP_X_HONEYCOMB_TRACE'] = Honeycomb.current_span.to_trace_header
376
381
  spinners.register("[:spinner] #{title}") do |sp|
377
- ENV['HTTP_X_HONEYCOMB_TRACE'] = Honecomb.current_span.to_trace_header unless ENV['HTTP_X_HONEYCOMB_TRACE']
378
382
  stdout, stderr, status = Open3.capture3(env, test)
379
383
  if status.to_i.zero?
380
384
  sp.success
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.18.0'
5
+ VERSION ||= '0.18.1'
6
6
  end
@@ -92,70 +92,70 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
92
92
  end
93
93
 
94
94
  it 'no matching node, raises' do
95
- expect { described_class.config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
95
+ expect { config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
96
96
  end
97
97
 
98
98
  it 'no config section, returns nil' do
99
- expect(described_class.config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
99
+ expect(config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
100
100
  end
101
101
 
102
102
  it 'config exists, and returns' do
103
- expect(described_class.config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
103
+ expect(config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
104
104
  { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false })
105
105
  end
106
106
 
107
107
  it 'facts exists, and returns' do
108
- expect(described_class.facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
108
+ expect(facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
109
109
  end
110
110
 
111
111
  it 'vars exists, and returns' do
112
- expect(described_class.vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
112
+ expect(vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
113
113
  end
114
114
 
115
115
  it 'no feature exists for the group, and returns hash with feature added' do
116
- expect(described_class.add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
116
+ expect(add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
117
117
  end
118
118
 
119
119
  it 'feature exists for the group, and returns hash with feature removed' do
120
- expect(described_class.remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
120
+ expect(remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
121
121
  end
122
122
 
123
123
  it 'write from inventory_hash to inventory_yaml file feature_hash_group' do
124
- expect { described_class.write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
124
+ expect { write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
125
125
  end
126
126
 
127
127
  it 'empty feature exists for the group, and returns hash with feature added' do
128
- expect(described_class.add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
128
+ expect(add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
129
129
  end
130
130
 
131
131
  it 'no feature exists for the node, and returns hash with feature added' do
132
- expect(described_class.add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
132
+ expect(add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
133
133
  end
134
134
 
135
135
  it 'feature exists for the node, and returns hash with feature removed' do
136
- expect(described_class.remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
136
+ expect(remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
137
137
  end
138
138
 
139
139
  it 'write from inventory_hash to inventory_yaml file feature_hash_node' do
140
- expect { described_class.write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
140
+ expect { write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
141
141
  end
142
142
 
143
143
  it 'empty feature exists for the node, and returns hash with feature added' do
144
- expect(described_class.add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
144
+ expect(add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
145
145
  end
146
146
 
147
147
  it 'write from inventory_hash to inventory_yaml file no feature_hash' do
148
148
  expect(File).to exist(inventory_full_path)
149
- expect { described_class.write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
149
+ expect { write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
150
150
  end
151
151
 
152
152
  it 'group does not exist in inventory, and returns hash with group added' do
153
- expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
153
+ expect(add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
154
154
  [{ 'name' => 'ssh_nodes', 'targets' => [] }, { 'name' => 'winrm_nodes', 'targets' => [] }, { 'name' => 'docker_nodes', 'targets' => [foo_node] }])
155
155
  end
156
156
 
157
157
  it 'group exists in inventory, and returns hash with node added' do
158
- expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
158
+ expect(add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
159
159
  [{ 'name' => 'ssh_nodes', 'targets' => [foo_node] }, { 'name' => 'winrm_nodes', 'targets' => [] }])
160
160
  end
161
161
  end
@@ -13,10 +13,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
13
13
  end
14
14
 
15
15
  it 'calls all functions' do
16
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
17
- expect(described_class).to receive(:apply_manifest).with(nil, expect_failures: false, manifest_file_location: '/bla.pp')
18
- expect(described_class).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
19
- described_class.idempotent_apply(manifest)
16
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
17
+ expect(self).to receive(:apply_manifest).with(nil, expect_failures: false, manifest_file_location: '/bla.pp')
18
+ expect(self).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
19
+ idempotent_apply(manifest)
20
20
  end
21
21
  end
22
22
 
@@ -28,11 +28,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
28
28
 
29
29
  it 'passes the --hiera_config flag if the :hiera_config opt is specified' do
30
30
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
31
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
32
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
33
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
34
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
35
- described_class.apply_manifest(manifest, hiera_config: '/hiera.yaml')
31
+ expect(self).to receive(:target_in_inventory?).and_return(true)
32
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
33
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
34
+ apply_manifest(manifest, hiera_config: '/hiera.yaml')
36
35
  end
37
36
  end
38
37
 
@@ -43,42 +42,38 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
43
42
 
44
43
  it 'uses detailed-exitcodes with expect_failures' do
45
44
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
46
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
47
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
48
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
49
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
50
- expect { described_class.apply_manifest(manifest, expect_failures: true) }.to raise_error(RuntimeError)
45
+ expect(self).to receive(:target_in_inventory?).and_return(true)
46
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
47
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
48
+ expect { apply_manifest(manifest, expect_failures: true) }.to raise_error(RuntimeError)
51
49
  end
52
50
 
53
51
  it 'uses detailed-exitcodes with catch_failures' do
54
52
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
55
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
56
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
57
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
58
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
59
- described_class.apply_manifest(manifest, catch_failures: true)
53
+ expect(self).to receive(:target_in_inventory?).and_return(true)
54
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
55
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
56
+ apply_manifest(manifest, catch_failures: true)
60
57
  end
61
58
 
62
59
  it 'uses detailed-exitcodes with expect_changes' do
63
60
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
64
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
65
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
66
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
67
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
68
- expect { described_class.apply_manifest(manifest, expect_changes: true) }.to raise_error(RuntimeError)
61
+ expect(self).to receive(:target_in_inventory?).and_return(true)
62
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
63
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
64
+ expect { apply_manifest(manifest, expect_changes: true) }.to raise_error(RuntimeError)
69
65
  end
70
66
 
71
67
  it 'uses detailed-exitcodes with catch_changes' do
72
68
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
73
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
74
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
75
- expect(described_class).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
76
- expect(described_class).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
77
- described_class.apply_manifest(manifest, catch_changes: true)
69
+ expect(self).to receive(:target_in_inventory?).and_return(true)
70
+ expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
71
+ expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
72
+ apply_manifest(manifest, catch_changes: true)
78
73
  end
79
74
 
80
75
  it 'uses raises exception for multiple options' do
81
- expect { described_class.apply_manifest(manifest, catch_changes: true, expect_failures: true) }
76
+ expect { apply_manifest(manifest, catch_changes: true, expect_failures: true) }
82
77
  .to raise_error(RuntimeError, 'please specify only one of `catch_changes`, `expect_changes`, `catch_failures` or `expect_failures`')
83
78
  end
84
79
  end
@@ -89,17 +84,16 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
89
84
  let(:result) { ['value' => { 'exit_code' => 0, 'exit_status' => 0, 'stdout' => nil, 'stderr' => nil }] }
90
85
 
91
86
  it 'responds to run_shell' do
92
- expect(described_class).to respond_to(:run_shell).with(1..2).arguments
87
+ expect(self).to respond_to(:run_shell).with(1..2).arguments
93
88
  end
94
89
 
95
90
  context 'when running against localhost and no inventory.yaml file' do
96
91
  it 'does run_shell against localhost without error' do
97
92
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
98
93
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
99
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
100
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
101
- expect(described_class).to receive(:run_command).with(command_to_run, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
102
- expect { described_class.run_shell(command_to_run) }.not_to raise_error
94
+ expect(self).to receive(:target_in_inventory?).and_return(true)
95
+ expect(self).to receive(:run_command).with(command_to_run, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
96
+ expect { run_shell(command_to_run) }.not_to raise_error
103
97
  end
104
98
  end
105
99
 
@@ -107,10 +101,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
107
101
  it 'does run_shell against remote host without error' do
108
102
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
109
103
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
110
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
111
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
112
- expect(described_class).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
113
- expect { described_class.run_shell(command_to_run) }.not_to raise_error
104
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
105
+ expect(self).to receive(:target_in_inventory?).and_return(true)
106
+ expect(self).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
107
+ expect { run_shell(command_to_run) }.not_to raise_error
114
108
  end
115
109
  end
116
110
  end
@@ -125,27 +119,26 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
125
119
  # rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
126
120
 
127
121
  it 'responds to run_shell' do
128
- expect(described_class).to respond_to(:bolt_upload_file).with(2..3).arguments
122
+ expect(self).to respond_to(:bolt_upload_file).with(2..3).arguments
129
123
  end
130
124
 
131
125
  context 'when upload returns success' do
132
126
  it 'does upload_file against remote host without error' do
133
127
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
134
128
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
135
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
136
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
137
- expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
138
- expect { described_class.bolt_upload_file(local, remote) }.not_to raise_error
129
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
130
+ expect(self).to receive(:target_in_inventory?).and_return(true)
131
+ expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
132
+ expect { bolt_upload_file(local, remote) }.not_to raise_error
139
133
  end
140
134
 
141
135
  it 'does upload_file against localhost without error' do
142
136
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
143
137
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
144
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
145
- expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
146
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
147
- expect(described_class).to receive(:upload_file).with(local, remote, 'litmus_localhost', options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result_success)
148
- expect { described_class.bolt_upload_file(local, remote) }.not_to raise_error
138
+ expect(self).not_to receive(:inventory_hash_from_inventory_file)
139
+ expect(self).to receive(:target_in_inventory?).and_return(true)
140
+ expect(self).to receive(:upload_file).with(local, remote, 'litmus_localhost', options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result_success)
141
+ expect { bolt_upload_file(local, remote) }.not_to raise_error
149
142
  end
150
143
  end
151
144
 
@@ -153,19 +146,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
153
146
  it 'does upload_file gives runtime error for failure' do
154
147
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
155
148
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
156
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
157
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
158
- expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
159
- expect { described_class.bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
149
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
150
+ expect(self).to receive(:target_in_inventory?).and_return(true)
151
+ expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
152
+ expect { bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
160
153
  end
161
154
 
162
155
  it 'returns the exit code and error message when expecting failure' do
163
156
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
164
157
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
165
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
166
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
167
- expect(described_class).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
168
- method_result = described_class.bolt_upload_file(local, remote, expect_failures: true)
158
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
159
+ expect(self).to receive(:target_in_inventory?).and_return(true)
160
+ expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
161
+ method_result = bolt_upload_file(local, remote, expect_failures: true)
169
162
  expect(method_result.exit_code).to be(255)
170
163
  expect(method_result.stderr).to be('No such file or directory @ rb_sysopen - /nonexistant/file/path')
171
164
  end
@@ -177,18 +170,17 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
177
170
  let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
178
171
 
179
172
  it 'responds to bolt_run_script' do
180
- expect(described_class).to respond_to(:bolt_run_script).with(1..2).arguments
173
+ expect(self).to respond_to(:bolt_run_script).with(1..2).arguments
181
174
  end
182
175
 
183
176
  context 'when running against localhost and no inventory.yaml file' do
184
177
  it 'does bolt_run_script against localhost without error' do
185
178
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
186
179
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
187
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
188
- expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
189
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
190
- expect(described_class).to receive(:run_script).with(script, 'litmus_localhost', [], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
191
- expect { described_class.bolt_run_script(script) }.not_to raise_error
180
+ expect(self).not_to receive(:inventory_hash_from_inventory_file)
181
+ expect(self).to receive(:target_in_inventory?).and_return(true)
182
+ expect(self).to receive(:run_script).with(script, 'litmus_localhost', [], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
183
+ expect { bolt_run_script(script) }.not_to raise_error
192
184
  end
193
185
  end
194
186
 
@@ -196,10 +188,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
196
188
  it 'does bolt_run_script against remote host without error' do
197
189
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
198
190
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
199
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
200
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
201
- expect(described_class).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: inventory_hash).and_return(result)
202
- expect { described_class.bolt_run_script(script) }.not_to raise_error
191
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
192
+ expect(self).to receive(:target_in_inventory?).and_return(true)
193
+ expect(self).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: inventory_hash).and_return(result)
194
+ expect { bolt_run_script(script) }.not_to raise_error
203
195
  end
204
196
  end
205
197
 
@@ -207,11 +199,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
207
199
  it 'does bolt_run_script with arguments without error' do
208
200
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
209
201
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
210
- expect(described_class).to receive(:localhost_inventory_hash).and_return(localhost_inventory_hash)
211
- expect(described_class).not_to receive(:inventory_hash_from_inventory_file)
212
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
213
- expect(described_class).to receive(:run_script).with(script, 'litmus_localhost', ['doot'], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
214
- expect { described_class.bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
202
+ expect(self).not_to receive(:inventory_hash_from_inventory_file)
203
+ expect(self).to receive(:target_in_inventory?).and_return(true)
204
+ expect(self).to receive(:run_script).with(script, 'litmus_localhost', ['doot'], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
205
+ expect { bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
215
206
  end
216
207
  end
217
208
  end
@@ -228,45 +219,45 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
228
219
  # rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
229
220
 
230
221
  it 'responds to bolt_run_task' do
231
- expect(described_class).to respond_to(:run_bolt_task).with(2..3).arguments
222
+ expect(self).to respond_to(:run_bolt_task).with(2..3).arguments
232
223
  end
233
224
 
234
225
  context 'when bolt returns success' do
235
226
  it 'does bolt_task_run gives no runtime error for success' do
236
227
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
237
228
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
238
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
239
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
240
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
241
- expect { described_class.run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
229
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
230
+ expect(self).to receive(:target_in_inventory?).and_return(true)
231
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
232
+ expect { run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
242
233
  end
243
234
 
244
235
  it 'does bolt_task_run gives no runtime error for success, for a named inventory file' do
245
236
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
246
237
  expect(File).to receive(:exist?).with('jim.yaml').and_return(true)
247
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
248
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
249
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
250
- expect { described_class.run_bolt_task(task_name, params, inventory_file: 'jim.yaml') }.not_to raise_error
238
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
239
+ expect(self).to receive(:target_in_inventory?).and_return(true)
240
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
241
+ expect { run_bolt_task(task_name, params, inventory_file: 'jim.yaml') }.not_to raise_error
251
242
  end
252
243
 
253
244
  it 'returns stdout for unstructured-data tasks' do
254
245
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
255
246
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
256
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
257
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
258
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
259
- method_result = described_class.run_bolt_task(task_name, params, opts: {})
247
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
248
+ expect(self).to receive(:target_in_inventory?).and_return(true)
249
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
250
+ method_result = run_bolt_task(task_name, params, opts: {})
260
251
  expect(method_result.stdout).to eq('SUCCESS!')
261
252
  end
262
253
 
263
254
  it 'returns structured output for structured-data tasks' do
264
255
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
265
256
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
266
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
267
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
268
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
269
- method_result = described_class.run_bolt_task(task_name, params, opts: {})
257
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
258
+ expect(self).to receive(:target_in_inventory?).and_return(true)
259
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
260
+ method_result = run_bolt_task(task_name, params, opts: {})
270
261
  expect(method_result.stdout).to eq('{"key1"=>"foo", "key2"=>"bar"}')
271
262
  expect(method_result.result['key1']).to eq('foo')
272
263
  expect(method_result.result['key2']).to eq('bar')
@@ -277,19 +268,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
277
268
  it 'does bolt_task_run gives runtime error for failure' do
278
269
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
279
270
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
280
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
281
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
282
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
283
- expect { described_class.run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
271
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
272
+ expect(self).to receive(:target_in_inventory?).and_return(true)
273
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
274
+ expect { run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
284
275
  end
285
276
 
286
277
  it 'returns the exit code and error message when expecting failure' do
287
278
  stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
288
279
  expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
289
- expect(described_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
290
- expect(described_class).to receive(:target_in_inventory?).and_return(true)
291
- expect(described_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
292
- method_result = described_class.run_bolt_task(task_name, params, expect_failures: true)
280
+ expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
281
+ expect(self).to receive(:target_in_inventory?).and_return(true)
282
+ expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
283
+ method_result = run_bolt_task(task_name, params, expect_failures: true)
293
284
  expect(method_result.exit_code).to be(123)
294
285
  expect(method_result.stderr).to be('FAILURE!')
295
286
  end
@@ -13,12 +13,12 @@ RSpec.shared_examples 'supported provisioner' do |args|
13
13
  it 'calls function' do
14
14
  allow(File).to receive(:directory?).and_call_original
15
15
  allow(File).to receive(:directory?)
16
- .with(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'provision'))
16
+ .with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision'))
17
17
  .and_return(true)
18
18
  allow_any_instance_of(BoltSpec::Run).to receive(:run_task)
19
- .with("provision::#{provisioner}", 'localhost', params, config: DEFAULT_CONFIG_DATA, inventory: nil)
19
+ .with("provision::#{provisioner}", 'localhost', params, config: described_class::DEFAULT_CONFIG_DATA, inventory: nil)
20
20
  .and_return(results)
21
- result = described_class.provision(provisioner, platform, inventory_vars)
21
+ result = provision(provisioner, platform, inventory_vars)
22
22
  expect(result).to eq(results)
23
23
  end
24
24
  end
@@ -29,8 +29,8 @@ RSpec.describe PuppetLitmus::RakeHelper do
29
29
  let(:results) { [] }
30
30
 
31
31
  it 'calls function' do
32
- expect(described_class).to receive(:provision).with('docker', 'waffleimage/centos7', nil).and_return(results)
33
- described_class.provision_list(provision_hash, 'default')
32
+ expect(self).to receive(:provision).with('docker', 'waffleimage/centos7', nil).and_return(results)
33
+ provision_list(provision_hash, 'default')
34
34
  end
35
35
  end
36
36
 
@@ -71,9 +71,9 @@ RSpec.describe PuppetLitmus::RakeHelper do
71
71
  let(:params) { { 'action' => 'tear_down', 'node_name' => 'some.host', 'inventory' => Dir.pwd } }
72
72
 
73
73
  it 'calls function' do
74
- allow(File).to receive(:directory?).with(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'provision')).and_return(true)
75
- allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('provision::docker', 'localhost', params, config: DEFAULT_CONFIG_DATA, inventory: nil).and_return([])
76
- described_class.tear_down_nodes(targets, inventory_hash)
74
+ allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision')).and_return(true)
75
+ allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('provision::docker', 'localhost', params, config: described_class::DEFAULT_CONFIG_DATA, inventory: nil).and_return([])
76
+ tear_down_nodes(targets, inventory_hash)
77
77
  end
78
78
  end
79
79
 
@@ -87,9 +87,9 @@ RSpec.describe PuppetLitmus::RakeHelper do
87
87
  let(:params) { { 'collection' => 'puppet6' } }
88
88
 
89
89
  it 'calls function' do
90
- allow(File).to receive(:directory?).with(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
91
- allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
92
- described_class.install_agent('puppet6', targets, inventory_hash)
90
+ allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
91
+ allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
92
+ install_agent('puppet6', targets, inventory_hash)
93
93
  end
94
94
  end
95
95
 
@@ -113,7 +113,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
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
- described_class.install_module(inventory_hash, nil, module_tar)
116
+ install_module(inventory_hash, nil, module_tar)
117
117
  end
118
118
  end
119
119
 
@@ -129,12 +129,12 @@ RSpec.describe PuppetLitmus::RakeHelper do
129
129
  it 'node available' do
130
130
  allow(Open3).to receive(:capture3).with('cd .').and_return(['success', '', 0])
131
131
  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' }])
132
- described_class.check_connectivity?(inventory_hash, 'some.host')
132
+ check_connectivity?(inventory_hash, 'some.host')
133
133
  end
134
134
 
135
135
  it 'node unavailable' do
136
136
  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' }])
137
- expect { described_class.check_connectivity?(inventory_hash, 'some.host') }.to raise_error(RuntimeError, %r{Connectivity has failed on:})
137
+ expect { check_connectivity?(inventory_hash, 'some.host') }.to raise_error(RuntimeError, %r{Connectivity has failed on:})
138
138
  end
139
139
  end
140
140
 
@@ -149,13 +149,13 @@ RSpec.describe PuppetLitmus::RakeHelper do
149
149
 
150
150
  it 'uninstalls module' do
151
151
  allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
152
- expect(described_class).to receive(:metadata_module_name).and_return('foo-bar')
153
- described_class.uninstall_module(inventory_hash, nil)
152
+ expect(self).to receive(:metadata_module_name).and_return('foo-bar')
153
+ uninstall_module(inventory_hash, nil)
154
154
  end
155
155
 
156
156
  it 'and custom name' do
157
157
  allow_any_instance_of(BoltSpec::Run).to receive(:run_command).with(uninstall_module_command, targets, config: nil, inventory: inventory_hash).and_return([])
158
- described_class.uninstall_module(inventory_hash, nil, 'foo-bar')
158
+ uninstall_module(inventory_hash, nil, 'foo-bar')
159
159
  end
160
160
  end
161
161
 
@@ -165,7 +165,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
165
165
  it 'reads module name' do
166
166
  allow(File).to receive(:exist?).with(File.join(Dir.pwd, 'metadata.json')).and_return(true)
167
167
  allow(File).to receive(:read).with(File.join(Dir.pwd, 'metadata.json')).and_return(metadata)
168
- name = described_class.metadata_module_name
168
+ name = metadata_module_name
169
169
  expect(name).to eq('foo-bar')
170
170
  end
171
171
  end
@@ -173,12 +173,12 @@ RSpec.describe PuppetLitmus::RakeHelper do
173
173
  context 'with provisioner_task' do
174
174
  described_class::SUPPORTED_PROVISIONERS.each do |supported_provisioner|
175
175
  it "returns supported provisioner task name for #{supported_provisioner}" do
176
- expect(described_class.provisioner_task(supported_provisioner)).to eq("provision::#{supported_provisioner}")
176
+ expect(provisioner_task(supported_provisioner)).to eq("provision::#{supported_provisioner}")
177
177
  end
178
178
  end
179
179
 
180
180
  it 'returns an unsupported provisioner name' do
181
- expect(described_class.provisioner_task('my_org::custom_provisioner')).to eql('my_org::custom_provisioner')
181
+ expect(provisioner_task('my_org::custom_provisioner')).to eql('my_org::custom_provisioner')
182
182
  end
183
183
  end
184
184
  end
@@ -1,12 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rspec'
4
- require 'puppet_litmus'
5
-
6
- # Unfortunately this needs to be included as this is
7
- # how Litmus functions. We only include once here instead
8
- # of including for every single spec file.
9
- include PuppetLitmus # rubocop:disable Style/MixinUsage
10
4
 
11
5
  if ENV['COVERAGE'] == 'yes'
12
6
  require 'simplecov'
@@ -37,3 +31,10 @@ if ENV['COVERAGE'] == 'yes'
37
31
  end
38
32
  end
39
33
  end
34
+
35
+ # This is basically how `configure!` sets up RSpec in tests.
36
+ require 'puppet_litmus'
37
+ RSpec.configure do |config|
38
+ config.include PuppetLitmus
39
+ config.extend PuppetLitmus
40
+ 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.0
4
+ version: 0.18.1
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-03-31 00:00:00.000000000 Z
11
+ date: 2020-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bolt
@@ -151,7 +151,6 @@ files:
151
151
  - LICENSE
152
152
  - README.md
153
153
  - lib/puppet_litmus.rb
154
- - lib/puppet_litmus/honeycomb_utils.rb
155
154
  - lib/puppet_litmus/inventory_manipulation.rb
156
155
  - lib/puppet_litmus/puppet_helpers.rb
157
156
  - lib/puppet_litmus/rake_helper.rb
@@ -201,7 +200,7 @@ test_files:
201
200
  - spec/lib/puppet_litmus/util_spec.rb
202
201
  - spec/lib/puppet_litmus/version_spec.rb
203
202
  - spec/lib/puppet_litmus/inventory_manipulation_spec.rb
204
- - spec/lib/puppet_litmus/rake_helper_spec.rb
205
203
  - spec/lib/puppet_litmus/puppet_helpers_spec.rb
206
204
  - spec/lib/puppet_litmus/rake_tasks_spec.rb
205
+ - spec/lib/puppet_litmus/rake_helper_spec.rb
207
206
  - spec/spec_helper.rb
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PuppetLitmus; end # rubocop:disable Style/Documentation
4
-
5
- # a set of semi-private utility functions that should not contaminate the global namespace
6
- module PuppetLitmus::HoneycombUtils
7
- module_function
8
-
9
- def add_platform_field(inventory_hash, target_node_name)
10
- facts = facts_from_node(inventory_hash, target_node_name)
11
- Honeycomb.current_span.add_field('litmus.platform', facts&.dig('platform'))
12
- end
13
- end