puppet_litmus 0.26.2 → 0.29.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
  SHA256:
3
- metadata.gz: b54d56fe9cd63b49874f5dad0646bb656ad791f45b751315770d09e9f69f7c9d
4
- data.tar.gz: 5098a3a890f18ce448f3060323ee663834eb348b9b2000dd399e3e3678cea91f
3
+ metadata.gz: 484ed9be18bf1f3555b2075641bb34bfa60203bd78548564b268a3831c1b9ec4
4
+ data.tar.gz: a3e9ce241dec2ce34b93a2cc8cab3febf0067282b218efed62d036f12cfe6b3e
5
5
  SHA512:
6
- metadata.gz: acb0fc34a9fd73f2639daada9f05a6e9d7cd47727b4b652b0da90d0249d05364f9a67dd4cfb2e3f10840b26b23aec3a867b9630d13f263ce37765d774a12c187
7
- data.tar.gz: 5ca486321dc9c226042316645cb091b35ebeb9e5ea5c6859c5a605986dae4a3552b7e88405153e3ce2238c0b1a01078c22f817763b38a2b22ee661ba5a6f41c6
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
- * Provision targets to test against
16
- * Install a Puppet agent
17
- * Install a module
18
- * Run tests
19
- * Tear down the infrastructure
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 ```gem install puppet_litmus```.
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
- * Note if you choose to override the `litmus_inventory.yaml` location, please ensure that the directory strutcture you define exists.
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
- * [Is it Worth the Time?](https://xkcd.com/1205/)
55
+ - [Is it Worth the Time?](https://xkcd.com/1205/)
@@ -19,9 +19,10 @@ DOCKER_PLATFORMS = {
19
19
  'CentOS-6' => 'litmusimage/centos:6',
20
20
  'CentOS-7' => 'litmusimage/centos:7',
21
21
  'CentOS-8' => 'litmusimage/centos:8',
22
- 'Debian-10' => 'litmusimage/debian:10',
23
22
  # 'Debian-8' => 'litmusimage/debian:8', Removing from testing: https://puppet.com/docs/pe/2021.0/supported_operating_systems.html
24
23
  'Debian-9' => 'litmusimage/debian:9',
24
+ 'Debian-10' => 'litmusimage/debian:10',
25
+ 'Debian-11' => 'litmusimage/debian:11',
25
26
  'OracleLinux-6' => 'litmusimage/oraclelinux:6',
26
27
  'OracleLinux-7' => 'litmusimage/oraclelinux:7',
27
28
  'Scientific-6' => 'litmusimage/scientificlinux:6',
@@ -54,26 +55,45 @@ spec_matrix = {
54
55
  include: [],
55
56
  }
56
57
 
57
- metadata = JSON.parse(File.read('metadata.json'))
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))
58
76
  # Set platforms based on declared operating system support
59
77
  metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
60
78
  os = sup['operatingsystem']
61
79
  sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
62
80
  image_key = "#{os}-#{ver}"
63
- if IMAGE_TABLE.key? image_key
81
+
82
+ if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase)
64
83
  matrix[:platforms] << {
65
84
  label: image_key,
66
85
  provider: 'provision::provision_service',
67
86
  image: IMAGE_TABLE[image_key],
68
87
  }
69
- elsif DOCKER_PLATFORMS.key? image_key
88
+ elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase)
70
89
  matrix[:platforms] << {
71
90
  label: image_key,
72
91
  provider: 'provision::docker',
73
92
  image: DOCKER_PLATFORMS[image_key],
74
93
  }
75
94
  else
76
- puts "::warning::Cannot find image for #{image_key}"
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)
77
97
  end
78
98
  end
79
99
  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 inventory.yaml file
10
- # @return [Hash] hash of the inventory.yaml file.
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: 8)
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
@@ -125,7 +125,7 @@ namespace :litmus do
125
125
 
126
126
  results = install_agent(args[:collection], targets, inventory_hash)
127
127
  results.each do |result|
128
- command_to_run = "bolt task run puppet_agent::install --targets #{result['target']} --inventoryfile inventory.yaml --modulepath #{DEFAULT_CONFIG_DATA['modulepath']}"
128
+ command_to_run = "bolt task run puppet_agent::install --targets #{result['target']} --inventoryfile spec/fixtures/litmus_inventory.yaml --modulepath #{DEFAULT_CONFIG_DATA['modulepath']}"
129
129
  raise "Failed on #{result['target']}\n#{result}\ntry running '#{command_to_run}'" if result['status'] != 'success'
130
130
 
131
131
  # validate successful install
@@ -157,7 +157,7 @@ namespace :litmus do
157
157
  end
158
158
 
159
159
  # update the inventory with the puppet-agent feature set per node
160
- write_to_inventory_file(inventory_hash, 'inventory.yaml')
160
+ write_to_inventory_file(inventory_hash, 'spec/fixtures/litmus_inventory.yaml')
161
161
  end
162
162
 
163
163
  # Add a given feature to a selection of nodes
@@ -182,7 +182,7 @@ namespace :litmus do
182
182
  inventory_hash = add_feature_to_node(inventory_hash, args[:added_feature], target)
183
183
  end
184
184
 
185
- write_to_inventory_file(inventory_hash, 'inventory.yaml')
185
+ write_to_inventory_file(inventory_hash, 'spec/fixtures/litmus_inventory.yaml')
186
186
 
187
187
  puts 'Feature added'
188
188
  end
@@ -336,7 +336,7 @@ namespace :litmus do
336
336
 
337
337
  namespace :acceptance do
338
338
  require 'rspec/core/rake_task'
339
- if File.file?('inventory.yaml')
339
+ if File.file?('spec/fixtures/litmus_inventory.yaml')
340
340
  inventory_hash = inventory_hash_from_inventory_file
341
341
  targets = find_targets(inventory_hash, nil)
342
342
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version of this gem
4
4
  module PuppetLitmus
5
- VERSION ||= '0.26.2'
5
+ VERSION ||= '0.29.0'
6
6
  end
@@ -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, expect_failures: false, manifest_file_location: '/bla.pp')
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(:command) { " puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --hiera_config='/hiera.yaml'" }
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('inventory.yaml').and_return(false)
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) { " puppet apply /bla.pp --trace --modulepath #{Dir.pwd}/spec/fixtures/modules --detailed-exitcodes" }
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(false)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(true)
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('inventory.yaml').and_return(true)
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.26.2
4
+ version: 0.29.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-04-12 00:00:00.000000000 Z
11
+ date: 2021-09-06 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: 3.0.0
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: 3.0.0
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.1.4
215
- signing_key:
216
+ rubygems_version: 3.1.2
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