puppet_litmus 0.26.3 → 0.30.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 +27 -5
- data/lib/puppet_litmus/inventory_manipulation.rb +2 -2
- data/lib/puppet_litmus/puppet_helpers.rb +14 -3
- data/lib/puppet_litmus/rake_helper.rb +1 -1
- 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 +39 -22
- data/spec/spec_helper.rb +13 -0
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 325cdb47d0f7db0541938b78bf14879da2db05ba40d9a946ce99fd506d0f9c1d
|
4
|
+
data.tar.gz: d157bb8ff3192444f9eb974a12428e2b24dc4a3340a40a0bfaed2e5a33c3dd99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8384b785f1b183bf5554f51113171af51d3c2ebe5ec5c5695222be7cac2cfd30716c0b28d47aa277c2b7bacbd9a2715af780d93479817cfb2ac0f2d1b964c1a
|
7
|
+
data.tar.gz: d387235b43cae7895acc007cd9bb314136488d29b9196fc5b51a2b7ab45357befb0c2e4a1c63f11a6b3cb24232ce6e5230b300fb7c5658bca1bdb5a6abe5ac64
|
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
@@ -19,9 +19,12 @@ DOCKER_PLATFORMS = {
|
|
19
19
|
'CentOS-6' => 'litmusimage/centos:6',
|
20
20
|
'CentOS-7' => 'litmusimage/centos:7',
|
21
21
|
'CentOS-8' => 'litmusimage/centos:8',
|
22
|
-
'
|
22
|
+
'Rocky-8' => 'litmusimage/rockylinux:8',
|
23
|
+
'AlmaLinux-8' => 'litmusimage/almalinux:8',
|
23
24
|
# 'Debian-8' => 'litmusimage/debian:8', Removing from testing: https://puppet.com/docs/pe/2021.0/supported_operating_systems.html
|
24
25
|
'Debian-9' => 'litmusimage/debian:9',
|
26
|
+
'Debian-10' => 'litmusimage/debian:10',
|
27
|
+
'Debian-11' => 'litmusimage/debian:11',
|
25
28
|
'OracleLinux-6' => 'litmusimage/oraclelinux:6',
|
26
29
|
'OracleLinux-7' => 'litmusimage/oraclelinux:7',
|
27
30
|
'Scientific-6' => 'litmusimage/scientificlinux:6',
|
@@ -54,26 +57,45 @@ spec_matrix = {
|
|
54
57
|
include: [],
|
55
58
|
}
|
56
59
|
|
57
|
-
|
60
|
+
if ARGV.include?('--exclude-platforms')
|
61
|
+
exclude_platforms_occurencies = ARGV.select { |arg| arg == '--exclude-platforms' }.length
|
62
|
+
raise '--exclude-platforms argument should be present just one time in the command' unless exclude_platforms_occurencies <= 1
|
63
|
+
|
64
|
+
exclude_platforms_list = ARGV[ARGV.find_index('--exclude-platforms') + 1]
|
65
|
+
raise 'you need to provide a list of platforms in JSON format' if exclude_platforms_list.nil?
|
66
|
+
|
67
|
+
begin
|
68
|
+
exclude_list = JSON.parse(exclude_platforms_list).map { |platform| platform.downcase }
|
69
|
+
rescue JSON::ParserError
|
70
|
+
raise 'the exclude platforms list must valid JSON'
|
71
|
+
end
|
72
|
+
else
|
73
|
+
exclude_list = []
|
74
|
+
end
|
75
|
+
|
76
|
+
metadata_path = ENV['TEST_MATRIX_FROM_METADATA'] || 'metadata.json'
|
77
|
+
metadata = JSON.parse(File.read(metadata_path))
|
58
78
|
# Set platforms based on declared operating system support
|
59
79
|
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
|
60
80
|
os = sup['operatingsystem']
|
61
81
|
sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
|
62
82
|
image_key = "#{os}-#{ver}"
|
63
|
-
|
83
|
+
|
84
|
+
if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase)
|
64
85
|
matrix[:platforms] << {
|
65
86
|
label: image_key,
|
66
87
|
provider: 'provision::provision_service',
|
67
88
|
image: IMAGE_TABLE[image_key],
|
68
89
|
}
|
69
|
-
elsif DOCKER_PLATFORMS.key? image_key
|
90
|
+
elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase)
|
70
91
|
matrix[:platforms] << {
|
71
92
|
label: image_key,
|
72
93
|
provider: 'provision::docker',
|
73
94
|
image: DOCKER_PLATFORMS[image_key],
|
74
95
|
}
|
75
96
|
else
|
76
|
-
puts "::warning
|
97
|
+
puts "::warning::#{image_key} was excluded from testing" if exclude_list.include?(image_key.downcase)
|
98
|
+
puts "::warning::Cannot find image for #{image_key}" unless exclude_list.include?(image_key.downcase)
|
77
99
|
end
|
78
100
|
end
|
79
101
|
end
|
@@ -6,8 +6,8 @@ module PuppetLitmus; end # rubocop:disable Style/Documentation
|
|
6
6
|
module PuppetLitmus::InventoryManipulation
|
7
7
|
# Creates an inventory hash from the inventory.yaml.
|
8
8
|
#
|
9
|
-
# @param inventory_full_path [String] path to the
|
10
|
-
# @return [Hash] hash of the
|
9
|
+
# @param inventory_full_path [String] path to the litmus_inventory.yaml file
|
10
|
+
# @return [Hash] hash of the litmus_inventory.yaml file.
|
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?
|
@@ -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
|
|
@@ -464,7 +464,7 @@ module PuppetLitmus::RakeHelper
|
|
464
464
|
|
465
465
|
class LitmusTimeoutError < StandardError; end
|
466
466
|
|
467
|
-
def with_retries(options: { tries: Float::INFINITY }, max_wait_minutes:
|
467
|
+
def with_retries(options: { tries: Float::INFINITY }, max_wait_minutes: 15)
|
468
468
|
stop = Time.now + (max_wait_minutes * 60)
|
469
469
|
Retryable.retryable(options.merge(not: [LitmusTimeoutError])) do
|
470
470
|
raise LitmusTimeoutError if Time.now > stop
|
@@ -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
|
@@ -14,20 +14,32 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
14
14
|
|
15
15
|
it 'calls all functions' do
|
16
16
|
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
17
|
-
expect(self).to receive(:apply_manifest).with(nil,
|
17
|
+
expect(self).to receive(:apply_manifest).with(nil, catch_failures: true, manifest_file_location: '/bla.pp')
|
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
|
24
31
|
context 'when specifying a hiera config' do
|
25
32
|
let(:manifest) { "include '::doot'" }
|
26
33
|
let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
27
|
-
let
|
34
|
+
let :os do
|
35
|
+
{
|
36
|
+
family: 'redhat',
|
37
|
+
}
|
38
|
+
end
|
39
|
+
let(:command) { "LC_ALL=en_US.UTF-8 puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --hiera_config='/hiera.yaml'" }
|
28
40
|
|
29
41
|
it 'passes the --hiera_config flag if the :hiera_config opt is specified' do
|
30
|
-
expect(File).to receive(:exist?).with('
|
42
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
31
43
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
32
44
|
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
33
45
|
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
@@ -38,10 +50,15 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
38
50
|
context 'when using detailed-exitcodes' do
|
39
51
|
let(:manifest) { "include '::doot'" }
|
40
52
|
let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
41
|
-
let(:command) { "
|
53
|
+
let(:command) { "LC_ALL=en_US.UTF-8 puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --detailed-exitcodes" }
|
54
|
+
let :os do
|
55
|
+
{
|
56
|
+
family: 'redhat',
|
57
|
+
}
|
58
|
+
end
|
42
59
|
|
43
60
|
it 'uses detailed-exitcodes with expect_failures' do
|
44
|
-
expect(File).to receive(:exist?).with('
|
61
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
45
62
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
46
63
|
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
47
64
|
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
@@ -49,7 +66,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
49
66
|
end
|
50
67
|
|
51
68
|
it 'uses detailed-exitcodes with catch_failures' do
|
52
|
-
expect(File).to receive(:exist?).with('
|
69
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
53
70
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
54
71
|
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
55
72
|
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
@@ -57,7 +74,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
57
74
|
end
|
58
75
|
|
59
76
|
it 'uses detailed-exitcodes with expect_changes' do
|
60
|
-
expect(File).to receive(:exist?).with('
|
77
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
61
78
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
62
79
|
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
63
80
|
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
@@ -65,7 +82,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
65
82
|
end
|
66
83
|
|
67
84
|
it 'uses detailed-exitcodes with catch_changes' do
|
68
|
-
expect(File).to receive(:exist?).with('
|
85
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
69
86
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
70
87
|
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
71
88
|
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
@@ -90,7 +107,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
90
107
|
context 'when running against localhost and no inventory.yaml file' do
|
91
108
|
it 'does run_shell against localhost without error' do
|
92
109
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
93
|
-
expect(File).to receive(:exist?).with('
|
110
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
94
111
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
95
112
|
expect(self).to receive(:run_command).with(command_to_run, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
96
113
|
expect { run_shell(command_to_run) }.not_to raise_error
|
@@ -100,7 +117,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
100
117
|
context 'when running against remote host' do
|
101
118
|
it 'does run_shell against remote host without error' do
|
102
119
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
103
|
-
expect(File).to receive(:exist?).with('
|
120
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
104
121
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
105
122
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
106
123
|
expect(self).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
|
@@ -125,7 +142,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
125
142
|
context 'when upload returns success' do
|
126
143
|
it 'does upload_file against remote host without error' do
|
127
144
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
128
|
-
expect(File).to receive(:exist?).with('
|
145
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
129
146
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
130
147
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
131
148
|
expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
|
@@ -134,7 +151,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
134
151
|
|
135
152
|
it 'does upload_file against localhost without error' do
|
136
153
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
137
|
-
expect(File).to receive(:exist?).with('
|
154
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
138
155
|
expect(self).not_to receive(:inventory_hash_from_inventory_file)
|
139
156
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
140
157
|
expect(self).to receive(:upload_file).with(local, remote, 'litmus_localhost', options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result_success)
|
@@ -145,7 +162,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
145
162
|
context 'when upload returns failure' do
|
146
163
|
it 'does upload_file gives runtime error for failure' do
|
147
164
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
148
|
-
expect(File).to receive(:exist?).with('
|
165
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
149
166
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
150
167
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
151
168
|
expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
@@ -154,7 +171,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
154
171
|
|
155
172
|
it 'returns the exit code and error message when expecting failure' do
|
156
173
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
157
|
-
expect(File).to receive(:exist?).with('
|
174
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
158
175
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
159
176
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
160
177
|
expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
@@ -176,7 +193,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
176
193
|
context 'when running against localhost and no inventory.yaml file' do
|
177
194
|
it 'does bolt_run_script against localhost without error' do
|
178
195
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
179
|
-
expect(File).to receive(:exist?).with('
|
196
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
180
197
|
expect(self).not_to receive(:inventory_hash_from_inventory_file)
|
181
198
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
182
199
|
expect(self).to receive(:run_script).with(script, 'litmus_localhost', [], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
|
@@ -187,7 +204,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
187
204
|
context 'when running against remote host' do
|
188
205
|
it 'does bolt_run_script against remote host without error' do
|
189
206
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
190
|
-
expect(File).to receive(:exist?).with('
|
207
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
191
208
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
192
209
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
193
210
|
expect(self).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: inventory_hash).and_return(result)
|
@@ -198,7 +215,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
198
215
|
context 'when running with arguments' do
|
199
216
|
it 'does bolt_run_script with arguments without error' do
|
200
217
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
201
|
-
expect(File).to receive(:exist?).with('
|
218
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(false)
|
202
219
|
expect(self).not_to receive(:inventory_hash_from_inventory_file)
|
203
220
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
204
221
|
expect(self).to receive(:run_script).with(script, 'litmus_localhost', ['doot'], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
|
@@ -225,7 +242,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
225
242
|
context 'when bolt returns success' do
|
226
243
|
it 'does bolt_task_run gives no runtime error for success' do
|
227
244
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
228
|
-
expect(File).to receive(:exist?).with('
|
245
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
229
246
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
230
247
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
231
248
|
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
@@ -243,7 +260,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
243
260
|
|
244
261
|
it 'returns stdout for unstructured-data tasks' do
|
245
262
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
246
|
-
expect(File).to receive(:exist?).with('
|
263
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
247
264
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
248
265
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
249
266
|
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
@@ -253,7 +270,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
253
270
|
|
254
271
|
it 'returns structured output for structured-data tasks' do
|
255
272
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
256
|
-
expect(File).to receive(:exist?).with('
|
273
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
257
274
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
258
275
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
259
276
|
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
|
@@ -267,7 +284,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
267
284
|
context 'when bolt returns failure' do
|
268
285
|
it 'does bolt_task_run gives runtime error for failure' do
|
269
286
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
270
|
-
expect(File).to receive(:exist?).with('
|
287
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
271
288
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
272
289
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
273
290
|
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
@@ -276,7 +293,7 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
276
293
|
|
277
294
|
it 'returns the exit code and error message when expecting failure' do
|
278
295
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
279
|
-
expect(File).to receive(:exist?).with('
|
296
|
+
expect(File).to receive(:exist?).with('spec/fixtures/litmus_inventory.yaml').and_return(true)
|
280
297
|
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
281
298
|
expect(self).to receive(:target_in_inventory?).and_return(true)
|
282
299
|
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
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.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bolt
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 2.0.1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 4.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 2.0.1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 4.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: puppet-modulebuilder
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|
@@ -196,7 +198,7 @@ homepage: https://github.com/puppetlabs/puppet_litmus
|
|
196
198
|
licenses:
|
197
199
|
- Apache-2.0
|
198
200
|
metadata: {}
|
199
|
-
post_install_message:
|
201
|
+
post_install_message:
|
200
202
|
rdoc_options: []
|
201
203
|
require_paths:
|
202
204
|
- lib
|
@@ -211,8 +213,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
213
|
- !ruby/object:Gem::Version
|
212
214
|
version: '0'
|
213
215
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
215
|
-
signing_key:
|
216
|
+
rubygems_version: 3.0.3
|
217
|
+
signing_key:
|
216
218
|
specification_version: 4
|
217
219
|
summary: Providing a simple command line tool for puppet content creators, to enable
|
218
220
|
simple and complex test deployments.
|
@@ -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
|