puppet_litmus 0.24.0 → 0.26.2

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: 8484d287566c6611244f1048285e745ef1ec33c8e06ff6ebea0e517c2bf82647
4
- data.tar.gz: 56e1065ea8aabd7851266745f4ccf2ca95c21548b32f7b246835397dc60b28a3
3
+ metadata.gz: b54d56fe9cd63b49874f5dad0646bb656ad791f45b751315770d09e9f69f7c9d
4
+ data.tar.gz: 5098a3a890f18ce448f3060323ee663834eb348b9b2000dd399e3e3678cea91f
5
5
  SHA512:
6
- metadata.gz: 4d0a8be65d7c13e095479366ba95b7b22bbbeb5518f1fc2da7ede5e248e3e9ae3e3e3a82a388134cb29ab3641ce71b5d189b733cc459f1f7dcb91522e5ad9f49
7
- data.tar.gz: d55c84b38566630694ac2605aff7ecd769a2d8e218a70ec26c70dc6c855ab128420757fbd19bc87d69cfdb01dbada14b65cd34c7ffe4da8eb066d336f8df11e8
6
+ metadata.gz: acb0fc34a9fd73f2639daada9f05a6e9d7cd47727b4b652b0da90d0249d05364f9a67dd4cfb2e3f10840b26b23aec3a867b9630d13f263ce37765d774a12c187
7
+ data.tar.gz: 5ca486321dc9c226042316645cb091b35ebeb9e5ea5c6859c5a605986dae4a3552b7e88405153e3ce2238c0b1a01078c22f817763b38a2b22ee661ba5a6f41c6
data/README.md CHANGED
@@ -22,6 +22,8 @@ Litmus also facilitates parallel test runs and running tests in isolation. Each
22
22
 
23
23
  Install Litmus as a gem by running ```gem install puppet_litmus```.
24
24
 
25
+ * Note if you choose to override the `litmus_inventory.yaml` location, please ensure that the directory strutcture you define exists.
26
+
25
27
  ## Documentation
26
28
 
27
29
  For documentation, see our [Litmus Docs Site](https://puppetlabs.github.io/litmus/).
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # this script creates a build matrix for github actions from the claimed supported platforms and puppet versions in metadata.json
5
+
6
+ require 'json'
7
+
8
+ IMAGE_TABLE = {
9
+ 'RedHat-7' => 'rhel-7',
10
+ 'RedHat-8' => 'rhel-8',
11
+ 'SLES-12' => 'sles-12',
12
+ 'SLES-15' => 'sles-15',
13
+ 'Windows-2012 R2' => 'windows-2012-r2-core',
14
+ 'Windows-2016' => 'windows-2016',
15
+ 'Windows-2019' => 'windows-2019-core',
16
+ }.freeze
17
+
18
+ DOCKER_PLATFORMS = {
19
+ 'CentOS-6' => 'litmusimage/centos:6',
20
+ 'CentOS-7' => 'litmusimage/centos:7',
21
+ 'CentOS-8' => 'litmusimage/centos:8',
22
+ 'Debian-10' => 'litmusimage/debian:10',
23
+ # 'Debian-8' => 'litmusimage/debian:8', Removing from testing: https://puppet.com/docs/pe/2021.0/supported_operating_systems.html
24
+ 'Debian-9' => 'litmusimage/debian:9',
25
+ 'OracleLinux-6' => 'litmusimage/oraclelinux:6',
26
+ 'OracleLinux-7' => 'litmusimage/oraclelinux:7',
27
+ 'Scientific-6' => 'litmusimage/scientificlinux:6',
28
+ 'Scientific-7' => 'litmusimage/scientificlinux:7',
29
+ # 'Ubuntu-14.04' => 'litmusimage/ubuntu:14.04', Removing from testing: https://puppet.com/docs/pe/2021.0/supported_operating_systems.html
30
+ 'Ubuntu-16.04' => 'litmusimage/ubuntu:16.04',
31
+ 'Ubuntu-18.04' => 'litmusimage/ubuntu:18.04',
32
+ 'Ubuntu-20.04' => 'litmusimage/ubuntu:20.04',
33
+ }.freeze
34
+
35
+ # This table uses the latest version in each collection for accurate
36
+ # comparison when evaluating puppet requirements from the metadata
37
+ COLLECTION_TABLE = [
38
+ {
39
+ puppet_maj_version: 6,
40
+ ruby_version: 2.5,
41
+ },
42
+ {
43
+ puppet_maj_version: 7,
44
+ ruby_version: 2.7,
45
+ },
46
+ ].freeze
47
+
48
+ matrix = {
49
+ platforms: [],
50
+ collection: [],
51
+ }
52
+
53
+ spec_matrix = {
54
+ include: [],
55
+ }
56
+
57
+ metadata = JSON.parse(File.read('metadata.json'))
58
+ # Set platforms based on declared operating system support
59
+ metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
60
+ os = sup['operatingsystem']
61
+ sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
62
+ image_key = "#{os}-#{ver}"
63
+ if IMAGE_TABLE.key? image_key
64
+ matrix[:platforms] << {
65
+ label: image_key,
66
+ provider: 'provision::provision_service',
67
+ image: IMAGE_TABLE[image_key],
68
+ }
69
+ elsif DOCKER_PLATFORMS.key? image_key
70
+ matrix[:platforms] << {
71
+ label: image_key,
72
+ provider: 'provision::docker',
73
+ image: DOCKER_PLATFORMS[image_key],
74
+ }
75
+ else
76
+ puts "::warning::Cannot find image for #{image_key}"
77
+ end
78
+ end
79
+ end
80
+
81
+ # Set collections based on puppet version requirements
82
+ if metadata.key?('requirements') && metadata['requirements'].length.positive?
83
+ metadata['requirements'].each do |req|
84
+ next unless req.key?('name') && req.key?('version_requirement') && req['name'] == 'puppet'
85
+
86
+ ver_regexp = %r{^([>=<]{1,2})\s*([\d.]+)\s+([>=<]{1,2})\s*([\d.]+)$}
87
+ match = ver_regexp.match(req['version_requirement'])
88
+ if match.nil?
89
+ puts "::warning::Didn't recognize version_requirement '#{req['version_requirement']}'"
90
+ break
91
+ end
92
+
93
+ cmp_one, ver_one, cmp_two, ver_two = match.captures
94
+ reqs = ["#{cmp_one} #{ver_one}", "#{cmp_two} #{ver_two}"]
95
+
96
+ COLLECTION_TABLE.each do |collection|
97
+ # Test against the "largest" puppet version in a collection, e.g. `7.9999` to allow puppet requirements with a non-zero lower bound on minor/patch versions.
98
+ # This assumes that such a boundary will always allow the latest actually existing puppet version of a release stream, trading off simplicity vs accuracy here.
99
+ next unless Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new("#{collection[:puppet_maj_version]}.9999"))
100
+
101
+ matrix[:collection] << "puppet#{collection[:puppet_maj_version]}-nightly"
102
+ spec_matrix[:include] << { puppet_version: "~> #{collection[:puppet_maj_version]}.0", ruby_version: collection[:ruby_version] }
103
+ end
104
+ end
105
+ end
106
+
107
+ # Set to defaults (all collections) if no matches are found
108
+ if matrix[:collection].empty?
109
+ matrix[:collection] = COLLECTION_TABLE.map { |collection| "puppet#{collection[:puppet_maj_version]}-nightly" }
110
+ end
111
+
112
+ # Just to make sure there aren't any duplicates
113
+ matrix[:platforms] = matrix[:platforms].uniq.sort { |a, b| a[:label] <=> b[:label] }
114
+ matrix[:collection] = matrix[:collection].uniq.sort
115
+
116
+ puts "::set-output name=matrix::#{JSON.generate(matrix)}"
117
+ puts "::set-output name=spec_matrix::#{JSON.generate(spec_matrix)}"
118
+
119
+ acceptance_test_cell_count = matrix[:platforms].length * matrix[:collection].length
120
+ spec_test_cell_count = spec_matrix[:include].length
121
+
122
+ puts "Created matrix with #{acceptance_test_cell_count + spec_test_cell_count} cells:"
123
+ puts " - Acceptance Test Cells: #{acceptance_test_cell_count}"
124
+ puts " - Spec Test Cells: #{spec_test_cell_count}"
@@ -11,7 +11,7 @@ module PuppetLitmus::InventoryManipulation
11
11
  def inventory_hash_from_inventory_file(inventory_full_path = nil)
12
12
  require 'yaml'
13
13
  inventory_full_path = if inventory_full_path.nil?
14
- 'inventory.yaml'
14
+ "#{Dir.pwd}/spec/fixtures/litmus_inventory.yaml"
15
15
  else
16
16
  inventory_full_path
17
17
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # helper functions for running puppet commands. They execute a target system specified by ENV['TARGET_HOST']
4
- # heavily uses functions from here https://github.com/puppetlabs/bolt/blob/master/developer-docs/bolt_spec-run.md
4
+ # heavily uses functions from here https://github.com/puppetlabs/bolt/blob/main/developer-docs/bolt_spec-run.md
5
5
  module PuppetLitmus::PuppetHelpers
6
6
  # Applies a manifest twice. First checking for errors. Secondly to make sure no changes occur.
7
7
  #
@@ -69,13 +69,19 @@ module PuppetLitmus::PuppetHelpers
69
69
  end
70
70
 
71
71
  manifest_file_location = opts[:manifest_file_location] || create_manifest_file(manifest)
72
- inventory_hash = File.exist?('inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
73
- raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
72
+ inventory_hash = File.exist?('spec/fixtures/litmus_inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
73
+ raise "Target '#{target_node_name}' not found in spec/fixtures/litmus_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
76
  add_platform_field(inventory_hash, target_node_name)
77
77
 
78
- command_to_run = "#{opts[:prefix_command]} puppet apply #{manifest_file_location}"
78
+ # Forcibly set the locale of the command
79
+ locale = if os[:family] != 'windows'
80
+ 'LC_ALL=en_US.UTF-8 '
81
+ else
82
+ ''
83
+ end
84
+ command_to_run = "#{locale}#{opts[:prefix_command]} puppet apply #{manifest_file_location}"
79
85
  command_to_run += ' --trace' if !opts[:trace].nil? && (opts[:trace] == true)
80
86
  command_to_run += " --modulepath #{Dir.pwd}/spec/fixtures/modules" if target_node_name == 'litmus_localhost'
81
87
  command_to_run += " --hiera_config='#{opts[:hiera_config]}'" unless opts[:hiera_config].nil?
@@ -207,8 +213,8 @@ module PuppetLitmus::PuppetHelpers
207
213
  span.add_field('litmus.opts', opts)
208
214
 
209
215
  target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
210
- inventory_hash = File.exist?('inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
211
- raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
216
+ inventory_hash = File.exist?('spec/fixtures/litmus_inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
217
+ raise "Target '#{target_node_name}' not found in spec/fixtures/litmus_inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
212
218
 
213
219
  span.add_field('litmus.node_name', target_node_name)
214
220
  add_platform_field(inventory_hash, target_node_name)
@@ -246,8 +252,8 @@ module PuppetLitmus::PuppetHelpers
246
252
  span.add_field('litmus.options', options)
247
253
 
248
254
  target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
249
- inventory_hash = File.exist?('inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
250
- raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
255
+ inventory_hash = File.exist?('spec/fixtures/litmus_inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
256
+ raise "Target '#{target_node_name}' not found in spec/fixtures/litmus_inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
251
257
 
252
258
  span.add_field('litmus.node_name', target_node_name)
253
259
  add_platform_field(inventory_hash, target_node_name)
@@ -300,12 +306,12 @@ module PuppetLitmus::PuppetHelpers
300
306
  target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
301
307
  inventory_hash = if !opts[:inventory_file].nil? && File.exist?(opts[:inventory_file])
302
308
  inventory_hash_from_inventory_file(opts[:inventory_file])
303
- elsif File.exist?('inventory.yaml')
304
- inventory_hash_from_inventory_file('inventory.yaml')
309
+ elsif File.exist?('spec/fixtures/litmus_inventory.yaml')
310
+ inventory_hash_from_inventory_file('spec/fixtures/litmus_inventory.yaml')
305
311
  else
306
312
  localhost_inventory_hash
307
313
  end
308
- raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
314
+ raise "Target '#{target_node_name}' not found in spec/fixtures/litmus_inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
309
315
 
310
316
  span.add_field('litmus.node_name', target_node_name)
311
317
  add_platform_field(inventory_hash, target_node_name)
@@ -365,8 +371,8 @@ module PuppetLitmus::PuppetHelpers
365
371
  span.add_field('litmus.arguments', arguments)
366
372
 
367
373
  target_node_name = targeting_localhost? ? 'litmus_localhost' : ENV['TARGET_HOST']
368
- inventory_hash = File.exist?('inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
369
- raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
374
+ inventory_hash = File.exist?('spec/fixtures/litmus_inventory.yaml') ? inventory_hash_from_inventory_file : localhost_inventory_hash
375
+ raise "Target '#{target_node_name}' not found in spec/fixtures/litmus_inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)
370
376
 
371
377
  span.add_field('litmus.node_name', target_node_name)
372
378
  add_platform_field(inventory_hash, target_node_name)
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.24.0'
5
+ VERSION ||= '0.26.2'
6
6
  end
@@ -16,7 +16,7 @@ describe 'litmus rake tasks' do
16
16
  'operatingsystem_support' =>
17
17
  [{ 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => ['5'] },
18
18
  { 'operatingsystem' => 'Ubuntu', 'operatingsystemrelease' => ['14.04', '18.04'] }],
19
- 'template-ref' => 'heads/master-0-g7827fc2' }
19
+ 'template-ref' => 'heads/main-0-g7827fc2' }
20
20
  expect(File).to receive(:read).with(any_args).once
21
21
  expect(JSON).to receive(:parse).with(any_args).and_return(metadata)
22
22
  expect($stdout).to receive(:puts).with('redhat-5-x86_64')
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.24.0
4
+ version: 0.26.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-15 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bolt
@@ -166,12 +166,14 @@ email:
166
166
  - info@puppet.com
167
167
  executables:
168
168
  - matrix_from_metadata
169
+ - matrix_from_metadata_v2
169
170
  extensions: []
170
171
  extra_rdoc_files: []
171
172
  files:
172
173
  - LICENSE
173
174
  - README.md
174
175
  - exe/matrix_from_metadata
176
+ - exe/matrix_from_metadata_v2
175
177
  - lib/puppet_litmus.rb
176
178
  - lib/puppet_litmus/inventory_manipulation.rb
177
179
  - lib/puppet_litmus/puppet_helpers.rb
@@ -209,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
211
  - !ruby/object:Gem::Version
210
212
  version: '0'
211
213
  requirements: []
212
- rubygems_version: 3.0.6
214
+ rubygems_version: 3.1.4
213
215
  signing_key:
214
216
  specification_version: 4
215
217
  summary: Providing a simple command line tool for puppet content creators, to enable