puppet_litmus 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 071a673e5f77fa53f54031196856229f59a8869b
4
- data.tar.gz: d35953f4b2d720a7f185c558ff71ea21964db698
3
+ metadata.gz: 8eb95d6d8c4273f6f5a8adb391bd2733a63780a6
4
+ data.tar.gz: d0ee040ae15c4d6e3eeffa0a87e58983647545ea
5
5
  SHA512:
6
- metadata.gz: da87c6046e0eddf2873ce385a95fb772cdbc92acf62525f588d1e86f6b10b43bde52634a9a228ceb99ad3f22a48ae16c44d0f387e0c31a069e59a8e7378dc9c8
7
- data.tar.gz: ca340854e2b2f81d0205c30a9a07a13343c0f75ad67879a38c405f1d5962cc427ca783a71e301d90e1804c69e0f23105eb0b4110746f0768f41d22d68a4f3d46
6
+ metadata.gz: 37edcc9a67e468ffb8a6de584ef74c260e430f0acc4dada0004e732ddf0b472999154302d05f3eec4fee26c33e795c65895b15442ee126af4ed754f12ceb24c7
7
+ data.tar.gz: 7185b48a857a1bd10a5501f85fbe6ee311a5b45f65b1ed2e9ea265a205701bd041f1dfc0c894df13fcb54567d5971012d8fabaf72c8cbfbe7cfcb3b872568a25
@@ -6,6 +6,7 @@ require 'bolt_spec/run'
6
6
  require 'open3'
7
7
  require 'pdk'
8
8
  require 'json'
9
+ require 'parallel'
9
10
 
10
11
  def get_metadata_operating_systems(metadata)
11
12
  return unless metadata.is_a?(Hash)
@@ -102,15 +103,15 @@ namespace :litmus do
102
103
  raise "Failed to provision with '#{provisioner}'\n #{failed_image_message}" unless failed_image_message.empty?
103
104
  end
104
105
 
105
- desc "provision container/VM - abs/docker/vmpooler eg 'bundle exec rake 'litmus:provision[vmpooler, ubuntu-1604-x86_64]'"
106
+ desc "provision container/VM - abs/docker/vagrant/vmpooler eg 'bundle exec rake 'litmus:provision[vmpooler, ubuntu-1604-x86_64]'"
106
107
  task :provision, [:provisioner, :platform] do |_task, args|
107
108
  include BoltSpec::Run
108
109
  Rake::Task['spec_prep'].invoke
109
110
  config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
110
111
  raise "the provision module was not found in #{config_data['modulepath']}, please amend the .fixtures.yml file" unless File.directory?(File.join(config_data['modulepath'], 'provision'))
111
112
 
112
- unless %w[abs vmpooler docker vagrant].include?(args[:provisioner])
113
- raise "Unknown provisioner '#{args[:provisioner]}', try abs/docker/vmpooler/vagrant"
113
+ unless %w[abs docker docker_exp vagrant vmpooler].include?(args[:provisioner])
114
+ raise "Unknown provisioner '#{args[:provisioner]}', try abs/docker/vagrant/vmpooler"
114
115
  end
115
116
 
116
117
  params = { 'action' => 'provision', 'platform' => args[:platform], 'inventory' => Dir.pwd }
@@ -142,7 +143,8 @@ namespace :litmus do
142
143
  results = run_task('puppet_agent::install', targets, params, config: config_data, inventory: inventory_hash)
143
144
  results.each do |result|
144
145
  if result['status'] != 'success'
145
- puts "Failed on #{result['node']}\n#{result}"
146
+ command_to_run = "bolt task run puppet_agent::install --targets #{result['node']} --inventoryfile inventory.yaml --modulepath #{config_data['modulepath']}"
147
+ puts "Failed on #{result['node']}\n#{result}\ntry running '#{command_to_run}'"
146
148
  end
147
149
  end
148
150
 
@@ -207,7 +209,7 @@ namespace :litmus do
207
209
  targets.each do |node_name|
208
210
  # how do we know what provisioner to use
209
211
  node_facts = facts_from_node(inventory_hash, node_name)
210
- next unless %w[abs docker vmpooler vagrant].include?(node_facts['provisioner'])
212
+ next unless %w[abs docker docker_exp vagrant vmpooler].include?(node_facts['provisioner'])
211
213
 
212
214
  params = { 'action' => 'tear_down', 'node_name' => node_name, 'inventory' => Dir.pwd }
213
215
  result = run_task("provision::#{node_facts['provisioner']}", 'localhost', params, config: config_data, inventory: nil)
@@ -253,6 +255,14 @@ namespace :litmus do
253
255
  stdout, stderr, status = Open3.capture3(test)
254
256
  ["================\n#{title}\n", stdout, stderr, status]
255
257
  end
258
+ # because we cannot modify variables inside of Parallel
259
+ results.each do |result|
260
+ if result.last.to_i.zero?
261
+ success_list.push(result.first.scan(%r{.*})[2])
262
+ else
263
+ failure_list.push(result.first.scan(%r{.*})[2])
264
+ end
265
+ end
256
266
  spinner.success
257
267
  else
258
268
  spinners = TTY::Spinner::Multi.new("[:spinner] Running against #{targets.size} targets.")
@@ -42,18 +42,7 @@ module PuppetLitmus::Serverspec
42
42
  command_to_run += " --modulepath #{Dir.pwd}/spec/fixtures/modules" if target_node_name.nil? || target_node_name == 'localhost'
43
43
  command_to_run += ' --detailed-exitcodes' if !opts[:catch_changes].nil? && (opts[:catch_changes] == true)
44
44
  command_to_run += ' --debug' if !opts[:debug].nil? && (opts[:debug] == true)
45
- # BOLT-608
46
- if Gem.win_platform?
47
- stdout, stderr, status = Open3.capture3(command_to_run)
48
- status_text = if status.to_i.zero?
49
- 'success'
50
- else
51
- 'failure'
52
- end
53
- result = [{ 'node' => 'localhost', 'status' => status_text, 'result' => { 'exit_code' => status.to_i, 'stderr' => stderr, 'stdout' => stdout } }]
54
- else
55
- result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
56
- end
45
+ result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
57
46
 
58
47
  raise "apply manifest failed\n`#{command_to_run}`\n======\n#{result}" if result.first['result']['exit_code'] != 0 && opts[:expect_failures] != true
59
48
 
@@ -64,15 +53,15 @@ module PuppetLitmus::Serverspec
64
53
  result
65
54
  end
66
55
 
67
- # Creates a manifest file locally, if running against localhost create in a temp location. Or create it on the target system.
56
+ # Creates a manifest file locally in a temp location, if its a remote target copy it to there.
68
57
  #
69
58
  # @param manifest [String] puppet manifest code.
70
59
  # @return [String] The path to the location of the manifest.
71
60
  def create_manifest_file(manifest)
72
- require 'tempfile'
73
-
61
+ require 'tmpdir'
74
62
  target_node_name = ENV['TARGET_HOST']
75
- manifest_file = Tempfile.new(['manifest_', '.pp'])
63
+ tmp_filename = File.join(Dir.tmpdir, "manifest_#{Time.now.strftime('%Y%m%d')}_#{Process.pid}_#{rand(0x100000000).to_s(36)}.pp")
64
+ manifest_file = File.open(tmp_filename, 'w')
76
65
  manifest_file.write(manifest)
77
66
  manifest_file.close
78
67
  if target_node_name.nil? || target_node_name == 'localhost'
@@ -122,6 +111,10 @@ module PuppetLitmus::Serverspec
122
111
 
123
112
  raise "task failed\n`#{task_name}`\n======\n#{result}" if result.first['status'] != 'success'
124
113
 
114
+ result = OpenStruct.new(exit_code: result.first['result']['exit_code'],
115
+ stdout: result.first['result']['stdout'],
116
+ stderr: result.first['result']['stderr'])
117
+ yield result if block_given?
125
118
  result
126
119
  end
127
120
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.2.0'
5
+ VERSION ||= '0.3.0'
6
6
  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.2.0
4
+ version: 0.3.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-05-15 00:00:00.000000000 Z
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bolt