puppet_litmus 0.28.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -8
- data/exe/matrix_from_metadata_v2 +23 -4
- data/lib/puppet_litmus/puppet_helpers.rb +14 -3
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/exe/fake_metadata.json +46 -0
- data/spec/exe/matrix_from_metadata_v2_spec.rb +95 -0
- data/spec/lib/puppet_litmus/puppet_helpers_spec.rb +7 -0
- data/spec/spec_helper.rb +13 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 484ed9be18bf1f3555b2075641bb34bfa60203bd78548564b268a3831c1b9ec4
|
4
|
+
data.tar.gz: a3e9ce241dec2ce34b93a2cc8cab3febf0067282b218efed62d036f12cfe6b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d6f9f8df5025e677cdcdf99196b09531d7069d4002aab0b033edf57e37201c7362002b520d4c798728494f421cd35415a72e5dab91b6952dbfab42cc03cca31
|
7
|
+
data.tar.gz: b66435bfb8fbd219caabca73b2c594354f5e8db4415ec736122f0350d1fedbc1f35a5f3806fa334e5c2559a59fe51493281a2095e89d2eff8dc985e1028bd410
|
data/README.md
CHANGED
@@ -12,17 +12,39 @@
|
|
12
12
|
Litmus is a command line tool that allows you to run acceptance tests against Puppet modules.
|
13
13
|
|
14
14
|
Litmus allows you to:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
|
16
|
+
- Provision targets to test against
|
17
|
+
|
18
|
+
- Install a Puppet agent
|
19
|
+
|
20
|
+
- Install a module
|
21
|
+
|
22
|
+
- Run tests
|
23
|
+
|
24
|
+
- Tear down the infrastructure
|
20
25
|
|
21
26
|
Litmus also facilitates parallel test runs and running tests in isolation. Each step is standalone, allowing other operations between test runs, such as debugging or configuration updates on the test targets.
|
22
27
|
|
23
|
-
Install Litmus as a gem by running
|
28
|
+
Install Litmus as a gem by running `gem install puppet_litmus`.
|
29
|
+
|
30
|
+
- Note if you choose to override the `litmus_inventory.yaml` location, please ensure that the directory strutcture you define exists.
|
31
|
+
|
32
|
+
## matrix_from_metadata_v2
|
33
|
+
|
34
|
+
matrix_from_metadata_v2 tool generates github actions matrix from metadata.json
|
35
|
+
|
36
|
+
How to use it: in the project module root directory run `bundle exec matrix_from_metadata_v2`
|
37
|
+
|
38
|
+
### --exclude-platforms parameter
|
39
|
+
|
40
|
+
matrix_from_metadata_v2 accepts `--exclude-platforms <JSON array>` option in order to exclude some platforms from GA matrixes.
|
41
|
+
|
42
|
+
In order to use this new functionality just simply run:
|
43
|
+
|
44
|
+
`$: bundle exec matrix_from_metadata_v2 --exclude-platforms '["debian-11","centos-8"]'`
|
24
45
|
|
25
|
-
|
46
|
+
> Note: The option value should be JSON string otherwise it will throw an error.
|
47
|
+
> The values provided in the json array are case-insensitive `["debian-11","centos-8"]'` or `["Debian-11","CentOS-8"]'` are treated as being the same.
|
26
48
|
|
27
49
|
## Documentation
|
28
50
|
|
@@ -30,4 +52,4 @@ For documentation, see our [Litmus Docs Site](https://puppetlabs.github.io/litmu
|
|
30
52
|
|
31
53
|
## Other Resources
|
32
54
|
|
33
|
-
|
55
|
+
- [Is it Worth the Time?](https://xkcd.com/1205/)
|
data/exe/matrix_from_metadata_v2
CHANGED
@@ -55,26 +55,45 @@ spec_matrix = {
|
|
55
55
|
include: [],
|
56
56
|
}
|
57
57
|
|
58
|
-
|
58
|
+
if ARGV.include?('--exclude-platforms')
|
59
|
+
exclude_platforms_occurencies = ARGV.select { |arg| arg == '--exclude-platforms' }.length
|
60
|
+
raise '--exclude-platforms argument should be present just one time in the command' unless exclude_platforms_occurencies <= 1
|
61
|
+
|
62
|
+
exclude_platforms_list = ARGV[ARGV.find_index('--exclude-platforms') + 1]
|
63
|
+
raise 'you need to provide a list of platforms in JSON format' if exclude_platforms_list.nil?
|
64
|
+
|
65
|
+
begin
|
66
|
+
exclude_list = JSON.parse(exclude_platforms_list).map { |platform| platform.downcase }
|
67
|
+
rescue JSON::ParserError
|
68
|
+
raise 'the exclude platforms list must valid JSON'
|
69
|
+
end
|
70
|
+
else
|
71
|
+
exclude_list = []
|
72
|
+
end
|
73
|
+
|
74
|
+
metadata_path = ENV['TEST_MATRIX_FROM_METADATA'] || 'metadata.json'
|
75
|
+
metadata = JSON.parse(File.read(metadata_path))
|
59
76
|
# Set platforms based on declared operating system support
|
60
77
|
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
|
61
78
|
os = sup['operatingsystem']
|
62
79
|
sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
|
63
80
|
image_key = "#{os}-#{ver}"
|
64
|
-
|
81
|
+
|
82
|
+
if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase)
|
65
83
|
matrix[:platforms] << {
|
66
84
|
label: image_key,
|
67
85
|
provider: 'provision::provision_service',
|
68
86
|
image: IMAGE_TABLE[image_key],
|
69
87
|
}
|
70
|
-
elsif DOCKER_PLATFORMS.key? image_key
|
88
|
+
elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase)
|
71
89
|
matrix[:platforms] << {
|
72
90
|
label: image_key,
|
73
91
|
provider: 'provision::docker',
|
74
92
|
image: DOCKER_PLATFORMS[image_key],
|
75
93
|
}
|
76
94
|
else
|
77
|
-
puts "::warning
|
95
|
+
puts "::warning::#{image_key} was excluded from testing" if exclude_list.include?(image_key.downcase)
|
96
|
+
puts "::warning::Cannot find image for #{image_key}" unless exclude_list.include?(image_key.downcase)
|
78
97
|
end
|
79
98
|
end
|
80
99
|
end
|
@@ -6,13 +6,24 @@ module PuppetLitmus::PuppetHelpers
|
|
6
6
|
# Applies a manifest twice. First checking for errors. Secondly to make sure no changes occur.
|
7
7
|
#
|
8
8
|
# @param manifest [String] puppet manifest code to be applied.
|
9
|
+
# @param opts [Hash] Alters the behaviour of the command. Valid options are:
|
10
|
+
# :catch_changes [Boolean] (false) We're after idempotency so allow exit code 0 only.
|
11
|
+
# :expect_changes [Boolean] (false) We're after changes specifically so allow exit code 2 only.
|
12
|
+
# :catch_failures [Boolean] (false) We're after only complete success so allow exit codes 0 and 2 only.
|
13
|
+
# :expect_failures [Boolean] (false) We're after failures specifically so allow exit codes 1, 4, and 6 only.
|
14
|
+
# :manifest_file_location [Path] The place on the target system.
|
15
|
+
# :hiera_config [Path] The path to the hiera.yaml configuration on the target.
|
16
|
+
# :prefix_command [String] prefixes the puppet apply command; eg "export LANGUAGE='ja'".
|
17
|
+
# :trace [Boolean] run puppet apply with the trace flag (defaults to `true`).
|
18
|
+
# :debug [Boolean] run puppet apply with the debug flag.
|
19
|
+
# :noop [Boolean] run puppet apply with the noop flag.
|
9
20
|
# @return [Boolean] The result of the 2 apply manifests.
|
10
|
-
def idempotent_apply(manifest)
|
21
|
+
def idempotent_apply(manifest, opts = {})
|
11
22
|
Honeycomb.start_span(name: 'litmus.idempotent_apply') do |span|
|
12
23
|
ENV['HONEYCOMB_TRACE'] = span.to_trace_header
|
13
24
|
manifest_file_location = create_manifest_file(manifest)
|
14
|
-
apply_manifest(nil, catch_failures: true, manifest_file_location: manifest_file_location)
|
15
|
-
apply_manifest(nil, catch_changes: true, manifest_file_location: manifest_file_location)
|
25
|
+
apply_manifest(nil, **opts, catch_failures: true, manifest_file_location: manifest_file_location)
|
26
|
+
apply_manifest(nil, **opts, catch_changes: true, manifest_file_location: manifest_file_location)
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
{
|
2
|
+
"name": "puppetlabs-fake_module",
|
3
|
+
"version": "3.1.0",
|
4
|
+
"author": "puppetlabs",
|
5
|
+
"summary": "fake_module is a test",
|
6
|
+
"license": "Apache-2.0",
|
7
|
+
"source": "it has no source",
|
8
|
+
"project_page": "it has no project page",
|
9
|
+
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
|
10
|
+
"dependencies": [
|
11
|
+
{
|
12
|
+
"name": "puppetlabs/stdlib",
|
13
|
+
"version_requirement": ">= 4.0.0 < 9.0.0"
|
14
|
+
}
|
15
|
+
],
|
16
|
+
"operatingsystem_support": [
|
17
|
+
{
|
18
|
+
"operatingsystem": "CentOS",
|
19
|
+
"operatingsystemrelease": [
|
20
|
+
"6"
|
21
|
+
]
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"operatingsystem": "RedHat",
|
25
|
+
"operatingsystemrelease": [
|
26
|
+
"8"
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"operatingsystem": "Ubuntu",
|
31
|
+
"operatingsystemrelease": [
|
32
|
+
"14.04",
|
33
|
+
"18.04"
|
34
|
+
]
|
35
|
+
}
|
36
|
+
],
|
37
|
+
"requirements": [
|
38
|
+
{
|
39
|
+
"name": "puppet",
|
40
|
+
"version_requirement": ">= 6.0.0 < 8.0.0"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"template-url": "https://github.com/puppetlabs/pdk-templates.git#main",
|
44
|
+
"template-ref": "heads/main-0-g2381db6",
|
45
|
+
"pdk-version": "2.1.1"
|
46
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'matrix_from_metadata_v2' do
|
6
|
+
context 'without arguments' do
|
7
|
+
let(:result) { run_matrix_from_metadata_v2 }
|
8
|
+
|
9
|
+
it 'run successfully' do
|
10
|
+
expect(result.status_code).to eq 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'generates the matrix' do
|
14
|
+
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
|
15
|
+
expect(result.stdout).to include(
|
16
|
+
[
|
17
|
+
'::set-output name=matrix::{',
|
18
|
+
'"platforms":[',
|
19
|
+
'{"label":"CentOS-6","provider":"provision::docker","image":"litmusimage/centos:6"},',
|
20
|
+
'{"label":"RedHat-8","provider":"provision::provision_service","image":"rhel-8"},',
|
21
|
+
'{"label":"Ubuntu-18.04","provider":"provision::docker","image":"litmusimage/ubuntu:18.04"}',
|
22
|
+
'],',
|
23
|
+
'"collection":[',
|
24
|
+
'"puppet6-nightly","puppet7-nightly"',
|
25
|
+
']',
|
26
|
+
'}',
|
27
|
+
].join,
|
28
|
+
)
|
29
|
+
expect(result.stdout).to include(
|
30
|
+
'::set-output name=spec_matrix::{"include":[{"puppet_version":"~> 6.0","ruby_version":2.5},{"puppet_version":"~> 7.0","ruby_version":2.7}]}',
|
31
|
+
)
|
32
|
+
expect(result.stdout).to include("Created matrix with 8 cells:\n - Acceptance Test Cells: 6\n - Spec Test Cells: 2")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with --exclude-platforms ["ubuntu-18.04"]' do
|
37
|
+
let(:result) { run_matrix_from_metadata_v2({ '--exclude-platforms' => ['ubuntu-18.04'] }) }
|
38
|
+
|
39
|
+
it 'run successfully' do
|
40
|
+
expect(result.status_code).to eq 0
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'generates the matrix without excluded platforms' do
|
44
|
+
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
|
45
|
+
expect(result.stdout).to include('::warning::Ubuntu-18.04 was excluded from testing')
|
46
|
+
expect(result.stdout).to include(
|
47
|
+
[
|
48
|
+
'::set-output name=matrix::{',
|
49
|
+
'"platforms":[',
|
50
|
+
'{"label":"CentOS-6","provider":"provision::docker","image":"litmusimage/centos:6"},',
|
51
|
+
'{"label":"RedHat-8","provider":"provision::provision_service","image":"rhel-8"}',
|
52
|
+
'],',
|
53
|
+
'"collection":[',
|
54
|
+
'"puppet6-nightly","puppet7-nightly"',
|
55
|
+
']',
|
56
|
+
'}',
|
57
|
+
].join,
|
58
|
+
)
|
59
|
+
expect(result.stdout).to include(
|
60
|
+
'::set-output name=spec_matrix::{"include":[{"puppet_version":"~> 6.0","ruby_version":2.5},{"puppet_version":"~> 7.0","ruby_version":2.7}]}',
|
61
|
+
)
|
62
|
+
expect(result.stdout).to include("Created matrix with 6 cells:\n - Acceptance Test Cells: 4\n - Spec Test Cells: 2")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with --exclude-platforms \'["ubuntu-18.04","redhat-8"]\'' do
|
67
|
+
let(:result) { run_matrix_from_metadata_v2({ '--exclude-platforms' => ['ubuntu-18.04', 'redhat-8'] }) }
|
68
|
+
|
69
|
+
it 'run successfully' do
|
70
|
+
expect(result.status_code).to eq 0
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'generates the matrix without excluded platforms' do
|
74
|
+
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
|
75
|
+
expect(result.stdout).to include('::warning::Ubuntu-18.04 was excluded from testing')
|
76
|
+
expect(result.stdout).to include('::warning::RedHat-8 was excluded from testing')
|
77
|
+
expect(result.stdout).to include(
|
78
|
+
[
|
79
|
+
'::set-output name=matrix::{',
|
80
|
+
'"platforms":[',
|
81
|
+
'{"label":"CentOS-6","provider":"provision::docker","image":"litmusimage/centos:6"}',
|
82
|
+
'],',
|
83
|
+
'"collection":[',
|
84
|
+
'"puppet6-nightly","puppet7-nightly"',
|
85
|
+
']',
|
86
|
+
'}',
|
87
|
+
].join,
|
88
|
+
)
|
89
|
+
expect(result.stdout).to include(
|
90
|
+
'::set-output name=spec_matrix::{"include":[{"puppet_version":"~> 6.0","ruby_version":2.5},{"puppet_version":"~> 7.0","ruby_version":2.7}]}',
|
91
|
+
)
|
92
|
+
expect(result.stdout).to include("Created matrix with 4 cells:\n - Acceptance Test Cells: 2\n - Spec Test Cells: 2")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -18,6 +18,13 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
18
18
|
expect(self).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
|
19
19
|
idempotent_apply(manifest)
|
20
20
|
end
|
21
|
+
|
22
|
+
it 'passes options to apply_manifest' do
|
23
|
+
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
24
|
+
expect(self).to receive(:apply_manifest).with(nil, catch_failures: true, manifest_file_location: '/bla.pp', option: 'value')
|
25
|
+
expect(self).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp', option: 'value')
|
26
|
+
idempotent_apply(manifest, option: 'value')
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
describe '.apply_manifest' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rspec'
|
4
|
+
require 'open3'
|
5
|
+
require 'ostruct'
|
4
6
|
|
5
7
|
if ENV['COVERAGE'] == 'yes'
|
6
8
|
require 'simplecov'
|
@@ -32,6 +34,17 @@ if ENV['COVERAGE'] == 'yes'
|
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
37
|
+
def run_matrix_from_metadata_v2(options = {})
|
38
|
+
command = 'bundle exec ./exe/matrix_from_metadata_v2'
|
39
|
+
command += " --exclude-platforms '#{options['--exclude-platforms']}'" unless options['--exclude-platforms'].nil?
|
40
|
+
result = Open3.capture3({ 'TEST_MATRIX_FROM_METADATA' => 'spec/exe/fake_metadata.json' }, command)
|
41
|
+
OpenStruct.new(
|
42
|
+
stdout: result[0],
|
43
|
+
stderr: result[1],
|
44
|
+
status_code: result[2],
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
35
48
|
# This is basically how `configure!` sets up RSpec in tests.
|
36
49
|
require 'puppet_litmus'
|
37
50
|
RSpec.configure do |config|
|
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.
|
4
|
+
version: 0.29.0
|
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-
|
11
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bolt
|
@@ -185,6 +185,8 @@ files:
|
|
185
185
|
- spec/data/doot.tar.gz
|
186
186
|
- spec/data/inventory.yaml
|
187
187
|
- spec/data/jim.yaml
|
188
|
+
- spec/exe/fake_metadata.json
|
189
|
+
- spec/exe/matrix_from_metadata_v2_spec.rb
|
188
190
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
189
191
|
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
190
192
|
- spec/lib/puppet_litmus/puppet_litmus_version_spec.rb
|
@@ -211,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
213
|
- !ruby/object:Gem::Version
|
212
214
|
version: '0'
|
213
215
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
216
|
+
rubygems_version: 3.1.2
|
215
217
|
signing_key:
|
216
218
|
specification_version: 4
|
217
219
|
summary: Providing a simple command line tool for puppet content creators, to enable
|
@@ -224,6 +226,8 @@ test_files:
|
|
224
226
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
225
227
|
- spec/lib/puppet_litmus/rake_helper_spec.rb
|
226
228
|
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
229
|
+
- spec/exe/fake_metadata.json
|
230
|
+
- spec/exe/matrix_from_metadata_v2_spec.rb
|
227
231
|
- spec/data/doot.tar.gz
|
228
232
|
- spec/data/jim.yaml
|
229
233
|
- spec/data/inventory.yaml
|