puppet_litmus 1.3.0 → 1.5.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 +40 -28
- data/exe/matrix.json +94 -0
- data/exe/matrix_from_metadata +0 -1
- data/exe/matrix_from_metadata_v2 +18 -7
- data/exe/matrix_from_metadata_v3 +314 -0
- data/lib/puppet_litmus/inventory_manipulation.rb +2 -6
- data/lib/puppet_litmus/rake_helper.rb +7 -10
- data/lib/puppet_litmus/rake_tasks.rb +4 -6
- data/lib/puppet_litmus/spec_helper_acceptance.rb +7 -1
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/exe/fake_metadata.json +7 -0
- data/spec/exe/matrix_from_metadata_v2_spec.rb +50 -7
- data/spec/exe/matrix_from_metadata_v3_spec.rb +205 -0
- data/spec/lib/puppet_litmus/rake_helper_spec.rb +15 -4
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +56 -1
- data/spec/lib/puppet_litmus/util_spec.rb +5 -4
- data/spec/spec_helper.rb +29 -21
- metadata +7 -2
@@ -210,9 +210,9 @@ namespace :litmus do
|
|
210
210
|
# module_tar = Dir.glob('pkg/*.tar.gz').max_by { |f| File.mtime(f) }
|
211
211
|
raise "Unable to find package in 'pkg/*.tar.gz'" if module_tar.nil?
|
212
212
|
|
213
|
-
install_module(inventory_hash,
|
213
|
+
install_module(inventory_hash, target_nodes, module_tar, args[:module_repository])
|
214
214
|
|
215
|
-
puts "Installed '#{module_tar}' on #{
|
215
|
+
puts "Installed '#{module_tar}' on #{target_nodes.join(', ')}"
|
216
216
|
end
|
217
217
|
|
218
218
|
# Install the puppet modules from a source directory to nodes. It does not install dependencies.
|
@@ -241,10 +241,8 @@ namespace :litmus do
|
|
241
241
|
include BoltSpec::Run
|
242
242
|
module_tars.each do |module_tar|
|
243
243
|
puts "Installing '#{module_tar}'"
|
244
|
-
target_nodes
|
245
|
-
|
246
|
-
puts "Installed '#{module_tar}' on #{target_node_name}"
|
247
|
-
end
|
244
|
+
install_module(inventory_hash, target_nodes, module_tar, args[:module_repository], args[:ignore_dependencies])
|
245
|
+
puts "Installed '#{module_tar}' on #{target_nodes.join(', ')}"
|
248
246
|
end
|
249
247
|
end
|
250
248
|
|
@@ -26,8 +26,14 @@ module PuppetLitmus
|
|
26
26
|
|
27
27
|
if target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'docker_nodes')
|
28
28
|
host = ENV.fetch('TARGET_HOST', nil)
|
29
|
-
set :backend, :
|
29
|
+
set :backend, :dockercli
|
30
30
|
set :docker_container, host
|
31
|
+
elsif target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'lxd_nodes')
|
32
|
+
host = ENV.fetch('TARGET_HOST', nil)
|
33
|
+
set :backend, :lxd
|
34
|
+
set :login_shell, true
|
35
|
+
set :lxd_remote, node_config.dig('lxd', 'remote') unless node_config.dig('lxd', 'remote').nil?
|
36
|
+
set :lxd_instance, host
|
31
37
|
elsif target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'ssh_nodes')
|
32
38
|
set :backend, :ssh
|
33
39
|
options = Net::SSH::Config.for(host)
|
data/spec/exe/fake_metadata.json
CHANGED
@@ -17,12 +17,14 @@ RSpec.describe 'matrix_from_metadata_v2' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'generates the matrix' do # rubocop:disable RSpec/ExampleLength
|
20
|
+
expect(result.stdout).to include('::warning::Cannot find image for CentOS-6')
|
20
21
|
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
|
21
22
|
expect(github_output_content).to include(
|
22
23
|
[
|
23
24
|
'matrix={',
|
24
25
|
'"platforms":[',
|
25
|
-
'{"label":"
|
26
|
+
'{"label":"AmazonLinux-2","provider":"docker","image":"litmusimage/amazonlinux:2"},',
|
27
|
+
'{"label":"AmazonLinux-2023","provider":"docker","image":"litmusimage/amazonlinux:2023"},',
|
26
28
|
'{"label":"RedHat-8","provider":"provision_service","image":"rhel-8"},',
|
27
29
|
'{"label":"RedHat-9","provider":"provision_service","image":"rhel-9"},',
|
28
30
|
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64"},',
|
@@ -39,7 +41,7 @@ RSpec.describe 'matrix_from_metadata_v2' do
|
|
39
41
|
expect(github_output_content).to include(
|
40
42
|
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
41
43
|
)
|
42
|
-
expect(result.stdout).to include("Created matrix with
|
44
|
+
expect(result.stdout).to include("Created matrix with 18 cells:\n - Acceptance Test Cells: 16\n - Spec Test Cells: 2")
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -57,13 +59,15 @@ RSpec.describe 'matrix_from_metadata_v2' do
|
|
57
59
|
end
|
58
60
|
|
59
61
|
it 'generates the matrix without excluded platforms' do # rubocop:disable RSpec/ExampleLength
|
62
|
+
expect(result.stdout).to include('::warning::Cannot find image for CentOS-6')
|
60
63
|
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
|
61
64
|
expect(result.stdout).to include('::warning::Ubuntu-18.04 was excluded from testing')
|
62
65
|
expect(github_output_content).to include(
|
63
66
|
[
|
64
67
|
'matrix={',
|
65
68
|
'"platforms":[',
|
66
|
-
'{"label":"
|
69
|
+
'{"label":"AmazonLinux-2","provider":"docker","image":"litmusimage/amazonlinux:2"},',
|
70
|
+
'{"label":"AmazonLinux-2023","provider":"docker","image":"litmusimage/amazonlinux:2023"},',
|
67
71
|
'{"label":"RedHat-8","provider":"provision_service","image":"rhel-8"},',
|
68
72
|
'{"label":"RedHat-9","provider":"provision_service","image":"rhel-9"},',
|
69
73
|
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64"},',
|
@@ -79,14 +83,14 @@ RSpec.describe 'matrix_from_metadata_v2' do
|
|
79
83
|
expect(github_output_content).to include(
|
80
84
|
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
81
85
|
)
|
82
|
-
expect(result.stdout).to include("Created matrix with
|
86
|
+
expect(result.stdout).to include("Created matrix with 16 cells:\n - Acceptance Test Cells: 14\n - Spec Test Cells: 2")
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
86
90
|
context 'with --exclude-platforms \'["ubuntu-18.04","redhat-8"]\'' do
|
87
91
|
let(:github_output) { Tempfile.new('github_output') }
|
88
92
|
let(:github_output_content) { github_output.read }
|
89
|
-
let(:result) { run_matrix_from_metadata_v2({ '--exclude-platforms' => ['ubuntu-18.04', 'ubuntu-22.04', 'redhat-8', 'redhat-9'] }) }
|
93
|
+
let(:result) { run_matrix_from_metadata_v2({ '--exclude-platforms' => ['amazonlinux-2', 'amazonlinux-2023', 'ubuntu-18.04', 'ubuntu-22.04', 'redhat-8', 'redhat-9'] }) }
|
90
94
|
|
91
95
|
before do
|
92
96
|
ENV['GITHUB_OUTPUT'] = github_output.path
|
@@ -98,6 +102,7 @@ RSpec.describe 'matrix_from_metadata_v2' do
|
|
98
102
|
|
99
103
|
it 'generates the matrix without excluded platforms' do
|
100
104
|
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
|
105
|
+
expect(result.stdout).to include('::warning::Cannot find image for CentOS-6')
|
101
106
|
expect(result.stdout).to include('::warning::Ubuntu-18.04 was excluded from testing')
|
102
107
|
expect(result.stdout).to include('::warning::Ubuntu-22.04 was excluded from testing')
|
103
108
|
expect(result.stdout).to include('::warning::RedHat-8 was excluded from testing')
|
@@ -105,7 +110,6 @@ RSpec.describe 'matrix_from_metadata_v2' do
|
|
105
110
|
[
|
106
111
|
'matrix={',
|
107
112
|
'"platforms":[',
|
108
|
-
'{"label":"CentOS-6","provider":"docker","image":"litmusimage/centos:6"},',
|
109
113
|
'{"label":"RedHat-9-arm","provider":"provision_service","image":"rhel-9-arm64"},',
|
110
114
|
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","image":"ubuntu-2204-lts-arm64"}',
|
111
115
|
'],',
|
@@ -118,7 +122,46 @@ RSpec.describe 'matrix_from_metadata_v2' do
|
|
118
122
|
expect(github_output_content).to include(
|
119
123
|
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
120
124
|
)
|
121
|
-
expect(result.stdout).to include("Created matrix with
|
125
|
+
expect(result.stdout).to include("Created matrix with 6 cells:\n - Acceptance Test Cells: 4\n - Spec Test Cells: 2")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'without arguments and GITHUB_REPOSITORY_OWNER is not puppetlabs' do
|
130
|
+
let(:github_output) { Tempfile.new('github_output') }
|
131
|
+
let(:github_output_content) { github_output.read }
|
132
|
+
let(:result) { run_matrix_from_metadata_v2 }
|
133
|
+
|
134
|
+
before do
|
135
|
+
ENV['GITHUB_OUTPUT'] = github_output.path
|
136
|
+
ENV['GITHUB_REPOSITORY_OWNER'] = 'aforkuser'
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'run successfully' do
|
140
|
+
expect(result.status_code).to eq 0
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'generates the matrix' do
|
144
|
+
expect(result.stdout).to include('::warning::Cannot find image for CentOS-6')
|
145
|
+
expect(result.stdout).to include('::warning::Cannot find image for Ubuntu-14.04')
|
146
|
+
expect(github_output_content).to include(
|
147
|
+
[
|
148
|
+
'matrix={',
|
149
|
+
'"platforms":[',
|
150
|
+
'{"label":"AmazonLinux-2","provider":"docker","image":"litmusimage/amazonlinux:2"},',
|
151
|
+
'{"label":"AmazonLinux-2023","provider":"docker","image":"litmusimage/amazonlinux:2023"},',
|
152
|
+
'{"label":"Ubuntu-18.04","provider":"docker","image":"litmusimage/ubuntu:18.04"},',
|
153
|
+
'{"label":"Ubuntu-22.04","provider":"docker","image":"litmusimage/ubuntu:22.04"}',
|
154
|
+
'],',
|
155
|
+
'"collection":[',
|
156
|
+
'"puppet7-nightly","puppet8-nightly"',
|
157
|
+
']',
|
158
|
+
'}'
|
159
|
+
].join
|
160
|
+
)
|
161
|
+
expect(github_output_content).to include(
|
162
|
+
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
163
|
+
)
|
164
|
+
expect(result.stdout).to include("Created matrix with 10 cells:\n - Acceptance Test Cells: 8\n - Spec Test Cells: 2")
|
122
165
|
end
|
123
166
|
end
|
124
167
|
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'matrix_from_metadata_v3' do
|
6
|
+
let(:github_output) { Tempfile.new('github_output') }
|
7
|
+
let(:github_output_content) { github_output.read }
|
8
|
+
let(:github_repository_owner) { nil }
|
9
|
+
|
10
|
+
before do
|
11
|
+
ENV['GITHUB_ACTIONS'] = '1'
|
12
|
+
ENV['GITHUB_OUTPUT'] = github_output.path
|
13
|
+
ENV['GITHUB_REPOSITORY_OWNER'] = github_repository_owner
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'without arguments' do
|
17
|
+
let(:result) { run_matrix_from_metadata_v3 }
|
18
|
+
|
19
|
+
it 'run successfully' do
|
20
|
+
expect(result.status_code).to eq 0
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'generates the matrix' do
|
24
|
+
matrix = [
|
25
|
+
'matrix={',
|
26
|
+
'"platforms":[',
|
27
|
+
'{"label":"AmazonLinux-2","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2","runner":"ubuntu-20.04"},',
|
28
|
+
'{"label":"AmazonLinux-2023","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2023","runner":"ubuntu-20.04"},',
|
29
|
+
'{"label":"Ubuntu-18.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:18.04","runner":"ubuntu-20.04"},',
|
30
|
+
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"}',
|
31
|
+
'],',
|
32
|
+
'"collection":[',
|
33
|
+
'"puppet7-nightly","puppet8-nightly"',
|
34
|
+
']',
|
35
|
+
'}'
|
36
|
+
].join
|
37
|
+
expect(result.stdout).to include(
|
38
|
+
'::warning::CentOS-6 no provisioner found',
|
39
|
+
'::warning::Ubuntu-14.04 no provisioner found',
|
40
|
+
'::group::matrix',
|
41
|
+
'::group::spec_matrix'
|
42
|
+
)
|
43
|
+
expect(github_output_content).to include(matrix)
|
44
|
+
expect(github_output_content).to include('spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with puppetlabs GITHUB_REPOSITORY_OWNER' do
|
49
|
+
let(:result) { run_matrix_from_metadata_v3 }
|
50
|
+
let(:github_repository_owner) { 'puppetlabs' }
|
51
|
+
|
52
|
+
let(:matrix) do
|
53
|
+
[
|
54
|
+
'matrix={',
|
55
|
+
'"platforms":[',
|
56
|
+
'{"label":"AmazonLinux-2","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2","runner":"ubuntu-20.04"},',
|
57
|
+
'{"label":"AmazonLinux-2023","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2023","runner":"ubuntu-20.04"},',
|
58
|
+
'{"label":"RedHat-8","provider":"provision_service","arch":"x86_64","image":"rhel-8","runner":"ubuntu-latest"},',
|
59
|
+
'{"label":"RedHat-9","provider":"provision_service","arch":"x86_64","image":"rhel-9","runner":"ubuntu-latest"},',
|
60
|
+
'{"label":"RedHat-9-arm","provider":"provision_service","arch":"arm","image":"rhel-9-arm64","runner":"ubuntu-latest"},',
|
61
|
+
'{"label":"Ubuntu-18.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:18.04","runner":"ubuntu-20.04"},',
|
62
|
+
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"},',
|
63
|
+
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","arch":"arm","image":"ubuntu-2204-lts-arm64","runner":"ubuntu-latest"}',
|
64
|
+
'],',
|
65
|
+
'"collection":[',
|
66
|
+
'"puppet7-nightly","puppet8-nightly"',
|
67
|
+
']',
|
68
|
+
'}'
|
69
|
+
].join
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'run successfully' do
|
73
|
+
expect(result.status_code).to eq 0
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'generates the matrix' do
|
77
|
+
expect(result.stdout).to include(
|
78
|
+
'::warning::CentOS-6 no provisioner found',
|
79
|
+
'::warning::Ubuntu-14.04 no provisioner found',
|
80
|
+
'::group::matrix',
|
81
|
+
'::group::spec_matrix'
|
82
|
+
)
|
83
|
+
expect(github_output_content).to include(matrix)
|
84
|
+
expect(github_output_content).to include(
|
85
|
+
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with argument --puppetlabs' do
|
91
|
+
let(:result) { run_matrix_from_metadata_v3(['--puppetlabs']) }
|
92
|
+
let(:matrix) do
|
93
|
+
[
|
94
|
+
'matrix={',
|
95
|
+
'"platforms":[',
|
96
|
+
'{"label":"AmazonLinux-2","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2","runner":"ubuntu-20.04"},',
|
97
|
+
'{"label":"AmazonLinux-2023","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2023","runner":"ubuntu-20.04"},',
|
98
|
+
'{"label":"RedHat-8","provider":"provision_service","arch":"x86_64","image":"rhel-8","runner":"ubuntu-latest"},',
|
99
|
+
'{"label":"RedHat-9","provider":"provision_service","arch":"x86_64","image":"rhel-9","runner":"ubuntu-latest"},',
|
100
|
+
'{"label":"RedHat-9-arm","provider":"provision_service","arch":"arm","image":"rhel-9-arm64","runner":"ubuntu-latest"},',
|
101
|
+
'{"label":"Ubuntu-18.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:18.04","runner":"ubuntu-20.04"},',
|
102
|
+
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"},',
|
103
|
+
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","arch":"arm","image":"ubuntu-2204-lts-arm64","runner":"ubuntu-latest"}',
|
104
|
+
'],',
|
105
|
+
'"collection":[',
|
106
|
+
'"puppet7-nightly","puppet8-nightly"',
|
107
|
+
']',
|
108
|
+
'}'
|
109
|
+
].join
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'run successfully' do
|
113
|
+
expect(result.status_code).to eq 0
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'generates the matrix' do
|
117
|
+
expect(result.stdout).to include(
|
118
|
+
'::warning::CentOS-6 no provisioner found',
|
119
|
+
'::warning::Ubuntu-14.04 no provisioner found',
|
120
|
+
'::group::matrix',
|
121
|
+
'::group::spec_matrix'
|
122
|
+
)
|
123
|
+
expect(github_output_content).to include(matrix)
|
124
|
+
expect(github_output_content).to include(
|
125
|
+
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
126
|
+
)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'with --exclude-platforms "ubuntu-18.04"' do
|
131
|
+
let(:result) { run_matrix_from_metadata_v3(['--puppetlabs', '--platform-exclude', 'ubuntu-18.04']) }
|
132
|
+
let(:matrix) do
|
133
|
+
[
|
134
|
+
'matrix={',
|
135
|
+
'"platforms":[',
|
136
|
+
'{"label":"AmazonLinux-2","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2","runner":"ubuntu-20.04"},',
|
137
|
+
'{"label":"AmazonLinux-2023","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2023","runner":"ubuntu-20.04"},',
|
138
|
+
'{"label":"RedHat-8","provider":"provision_service","arch":"x86_64","image":"rhel-8","runner":"ubuntu-latest"},',
|
139
|
+
'{"label":"RedHat-9","provider":"provision_service","arch":"x86_64","image":"rhel-9","runner":"ubuntu-latest"},',
|
140
|
+
'{"label":"RedHat-9-arm","provider":"provision_service","arch":"arm","image":"rhel-9-arm64","runner":"ubuntu-latest"},',
|
141
|
+
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"},',
|
142
|
+
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","arch":"arm","image":"ubuntu-2204-lts-arm64","runner":"ubuntu-latest"}',
|
143
|
+
'],',
|
144
|
+
'"collection":[',
|
145
|
+
'"puppet7-nightly","puppet8-nightly"',
|
146
|
+
']',
|
147
|
+
'}'
|
148
|
+
].join
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'run successfully' do
|
152
|
+
expect(result.status_code).to eq 0
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'generates the matrix without excluded platforms' do
|
156
|
+
expect(result.stdout).to include(
|
157
|
+
'::warning::CentOS-6 no provisioner found',
|
158
|
+
'::warning::Ubuntu-14.04 no provisioner found',
|
159
|
+
'::notice::platform-exclude filtered Ubuntu-18.04',
|
160
|
+
'::group::matrix',
|
161
|
+
'::group::spec_matrix'
|
162
|
+
)
|
163
|
+
expect(github_output_content).to include(matrix)
|
164
|
+
expect(github_output_content).to include(
|
165
|
+
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
166
|
+
)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'with --platform-exclude "ubuntu-(18.04|22.04)" --platform-exclude "redhat-[89]"' do
|
171
|
+
let(:result) { run_matrix_from_metadata_v3(['--puppetlabs', '--platform-exclude', '(amazonlinux|ubuntu)-(2|18.04|22.04|2023)', '--platform-exclude', 'redhat-[89]']) }
|
172
|
+
let(:matrix) do
|
173
|
+
[
|
174
|
+
'matrix={',
|
175
|
+
'"platforms":[',
|
176
|
+
'],',
|
177
|
+
'"collection":[',
|
178
|
+
'"puppet7-nightly","puppet8-nightly"',
|
179
|
+
']',
|
180
|
+
'}'
|
181
|
+
].join
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'run successfully' do
|
185
|
+
expect(result.status_code).to eq 0
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'generates the matrix without excluded platforms' do
|
189
|
+
expect(result.stdout).to include(
|
190
|
+
'::warning::CentOS-6 no provisioner found',
|
191
|
+
'::warning::Ubuntu-14.04 no provisioner found',
|
192
|
+
'::notice::platform-exclude filtered RedHat-8',
|
193
|
+
'::notice::platform-exclude filtered RedHat-9',
|
194
|
+
'::notice::platform-exclude filtered Ubuntu-18.04',
|
195
|
+
'::notice::platform-exclude filtered Ubuntu-22.04',
|
196
|
+
'::group::matrix',
|
197
|
+
'::group::spec_matrix'
|
198
|
+
)
|
199
|
+
expect(github_output_content).to include(matrix)
|
200
|
+
expect(github_output_content).to include(
|
201
|
+
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
|
202
|
+
)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -24,6 +24,9 @@ RSpec.shared_examples 'supported provisioner' do |args|
|
|
24
24
|
end
|
25
25
|
|
26
26
|
RSpec.describe PuppetLitmus::RakeHelper do
|
27
|
+
inventory_file = File.join(Dir.pwd, 'spec', 'fixtures', 'litmus_inventory.yaml')
|
28
|
+
let(:inventory_file) { inventory_file }
|
29
|
+
|
27
30
|
context 'with provision_list' do
|
28
31
|
let(:provision_hash) { { 'default' => { 'provisioner' => 'docker', 'images' => ['waffleimage/centos7'] } } }
|
29
32
|
let(:results) { [] }
|
@@ -42,7 +45,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
42
45
|
inventory_vars: nil,
|
43
46
|
provision_hash: { 'default' => { 'provisioner' => 'docker', 'images' => ['waffleimage/centos7'] } },
|
44
47
|
results: [],
|
45
|
-
params: { 'action' => 'provision', 'platform' => 'waffleimage/centos7', 'inventory' =>
|
48
|
+
params: { 'action' => 'provision', 'platform' => 'waffleimage/centos7', 'inventory' => inventory_file }
|
46
49
|
},
|
47
50
|
{
|
48
51
|
provisioner: 'vagrant',
|
@@ -50,7 +53,15 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
50
53
|
inventory_vars: nil,
|
51
54
|
provision_hash: { 'default' => { 'provisioner' => 'vagrant', 'images' => ['centos7'] } },
|
52
55
|
results: [],
|
53
|
-
params: { 'action' => 'provision', 'platform' => 'centos7', 'inventory' =>
|
56
|
+
params: { 'action' => 'provision', 'platform' => 'centos7', 'inventory' => inventory_file }
|
57
|
+
},
|
58
|
+
{
|
59
|
+
provisioner: 'lxd',
|
60
|
+
platform: 'images:centos/7',
|
61
|
+
inventory_vars: nil,
|
62
|
+
provision_hash: { 'default' => { 'provisioner' => 'lxd', 'images' => ['images:centos/7'] } },
|
63
|
+
results: [],
|
64
|
+
params: { 'action' => 'provision', 'platform' => 'images:centos/7', 'inventory' => inventory_file }
|
54
65
|
}
|
55
66
|
].freeze
|
56
67
|
|
@@ -68,7 +79,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
68
79
|
[{ 'uri' => 'some.host', 'facts' => { 'provisioner' => 'docker', 'container_name' => 'foo', 'platform' => 'some.host' } }] }] }
|
69
80
|
end
|
70
81
|
let(:targets) { ['some.host'] }
|
71
|
-
let(:params) { { 'action' => 'tear_down', 'node_name' => 'some.host', 'inventory' =>
|
82
|
+
let(:params) { { 'action' => 'tear_down', 'node_name' => 'some.host', 'inventory' => inventory_file } }
|
72
83
|
|
73
84
|
it 'calls function' do
|
74
85
|
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision')).and_return(true)
|
@@ -89,7 +100,7 @@ RSpec.describe PuppetLitmus::RakeHelper do
|
|
89
100
|
] }] }
|
90
101
|
end
|
91
102
|
let(:targets) { ['one.host'] }
|
92
|
-
let(:params) { { 'action' => 'tear_down', 'node_name' => 'one.host', 'inventory' =>
|
103
|
+
let(:params) { { 'action' => 'tear_down', 'node_name' => 'one.host', 'inventory' => inventory_file } }
|
93
104
|
|
94
105
|
it 'calls function' do
|
95
106
|
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'provision')).and_return(true)
|
@@ -22,10 +22,60 @@ describe 'litmus rake tasks' do
|
|
22
22
|
expect($stdout).to receive(:puts).with('redhat-5-x86_64')
|
23
23
|
expect($stdout).to receive(:puts).with('ubuntu-1404-x86_64')
|
24
24
|
expect($stdout).to receive(:puts).with('ubuntu-1804-x86_64')
|
25
|
+
allow_any_instance_of(Object).to receive(:exit)
|
25
26
|
Rake::Task['litmus:metadata'].invoke
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
30
|
+
context 'with litmus:install_module' do
|
31
|
+
let(:args) { { target_node_name: nil, module_repository: nil } }
|
32
|
+
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }, { 'uri' => 'some.otherhost' }] }] } }
|
33
|
+
let(:target_nodes) { ['some.host', 'some.otherhost'] }
|
34
|
+
let(:dummy_tar) { 'spec/data/doot.tar.gz' }
|
35
|
+
|
36
|
+
before do
|
37
|
+
Rake::Task['litmus:install_module'].reenable
|
38
|
+
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
39
|
+
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:find_targets).with(inventory_hash, args[:target_node_name]).and_return(target_nodes)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'installs module' do
|
43
|
+
expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar)
|
44
|
+
expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'")
|
45
|
+
|
46
|
+
expect_any_instance_of(Object).to receive(:install_module).with(inventory_hash, target_nodes, dummy_tar, args[:module_repository])
|
47
|
+
expect($stdout).to receive(:puts).with("Installed '#{dummy_tar}' on #{target_nodes.join(', ')}")
|
48
|
+
allow_any_instance_of(Object).to receive(:exit)
|
49
|
+
Rake::Task['litmus:install_module'].invoke(*args.values)
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with unknown target' do
|
53
|
+
let(:args) { { target_node_name: 'un.known', module_repository: nil } }
|
54
|
+
let(:target_nodes) { [] }
|
55
|
+
|
56
|
+
it 'exits with No targets found' do
|
57
|
+
expect do
|
58
|
+
expect($stdout).to receive(:puts).with('No targets found')
|
59
|
+
Rake::Task['litmus:install_module'].invoke(*args.values)
|
60
|
+
end.to raise_error(SystemExit) { |error|
|
61
|
+
expect(error.status).to eq(0)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when build_module returns nil' do
|
67
|
+
let(:dummy_tar) { nil }
|
68
|
+
|
69
|
+
it 'raises error if build fails' do
|
70
|
+
expect_any_instance_of(Object).to receive(:build_module).and_return(dummy_tar)
|
71
|
+
expect($stdout).to receive(:puts).with("Built '#{dummy_tar}'")
|
72
|
+
|
73
|
+
expect { Rake::Task['litmus:install_module'].invoke(*args.values) }
|
74
|
+
.to raise_error(RuntimeError, "Unable to find package in 'pkg/*.tar.gz'")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
29
79
|
context 'with litmus:install_modules_from_directory' do
|
30
80
|
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'uri' => 'some.host' }] }] } }
|
31
81
|
let(:target_dir) { File.join(Dir.pwd, 'spec/fixtures/modules') }
|
@@ -44,6 +94,7 @@ describe 'litmus rake tasks' do
|
|
44
94
|
expect($stdout).to receive(:puts).with(start_with('Installing \'spec/data/doot.tar.gz\''))
|
45
95
|
expect_any_instance_of(Object).to receive(:run_command).twice.and_return([])
|
46
96
|
expect($stdout).to receive(:puts).with(start_with('Installed \'spec/data/doot.tar.gz\''))
|
97
|
+
allow_any_instance_of(Object).to receive(:exit)
|
47
98
|
Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/modules')
|
48
99
|
end
|
49
100
|
end
|
@@ -54,6 +105,7 @@ describe 'litmus rake tasks' do
|
|
54
105
|
expect(Rake::Task['litmus:provision_list']).to receive(:invoke).with('default')
|
55
106
|
expect(Rake::Task['litmus:install_agent']).to receive(:invoke).with('puppet6')
|
56
107
|
expect(Rake::Task['litmus:install_module']).to receive(:invoke)
|
108
|
+
allow_any_instance_of(Object).to receive(:exit)
|
57
109
|
Rake::Task['litmus:provision_install'].invoke('default', 'puppet6')
|
58
110
|
end
|
59
111
|
end
|
@@ -77,7 +129,7 @@ describe 'litmus rake tasks' do
|
|
77
129
|
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with(any_args).and_return(results)
|
78
130
|
allow_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).with(any_args).and_return({})
|
79
131
|
allow_any_instance_of(PuppetLitmus::RakeHelper).to receive(:check_connectivity?).with(any_args).and_return(true)
|
80
|
-
|
132
|
+
allow_any_instance_of(Object).to receive(:exit)
|
81
133
|
expect { Rake::Task['litmus:provision'].invoke('docker', 'centos:7') }.to output(/#{expected_output}/).to_stdout
|
82
134
|
end
|
83
135
|
end
|
@@ -89,6 +141,7 @@ describe 'litmus rake tasks' do
|
|
89
141
|
it 'no key in provision file' do
|
90
142
|
allow(File).to receive(:file?).with(any_args).and_return(true)
|
91
143
|
expect(YAML).to receive(:load_file).with(provision_file).and_return(provision_hash)
|
144
|
+
allow_any_instance_of(Object).to receive(:exit)
|
92
145
|
expect { Rake::Task['litmus:provision_list'].invoke('deet') }.to raise_error(/deet/)
|
93
146
|
end
|
94
147
|
end
|
@@ -100,6 +153,7 @@ describe 'litmus rake tasks' do
|
|
100
153
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
101
154
|
expect_any_instance_of(PuppetLitmus::InventoryManipulation).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
102
155
|
expect_any_instance_of(PuppetLitmus::RakeHelper).to receive(:check_connectivity?).with(inventory_hash, nil).and_return(true)
|
156
|
+
allow_any_instance_of(Object).to receive(:exit)
|
103
157
|
Rake::Task['litmus:check_connectivity'].invoke
|
104
158
|
end
|
105
159
|
end
|
@@ -108,6 +162,7 @@ describe 'litmus rake tasks' do
|
|
108
162
|
it 'calls spec_prep' do
|
109
163
|
expect(Rake::Task['spec_prep']).to receive(:invoke).and_return('')
|
110
164
|
expect_any_instance_of(RSpec::Core::RakeTask).to receive(:run_task)
|
165
|
+
allow_any_instance_of(Object).to receive(:exit)
|
111
166
|
Rake::Task['litmus:acceptance:localhost'].invoke
|
112
167
|
end
|
113
168
|
end
|
@@ -5,11 +5,12 @@ load File.expand_path('../../../lib/puppet_litmus/util.rb', __dir__)
|
|
5
5
|
|
6
6
|
RSpec.describe PuppetLitmus::Util do
|
7
7
|
context 'when using interpolate_powershell' do
|
8
|
+
let(:command) { 'foo' }
|
9
|
+
let(:encoded) { Base64.strict_encode64(command.encode('UTF-16LE')) }
|
10
|
+
|
8
11
|
it 'interpolates the command' do
|
9
|
-
expect(described_class.interpolate_powershell(
|
10
|
-
expect(described_class.interpolate_powershell(
|
11
|
-
expect(described_class.interpolate_powershell('foo')).to match(/EncodedCommand/)
|
12
|
-
expect(described_class.interpolate_powershell('foo')).not_to match(/foo/)
|
12
|
+
expect(described_class.interpolate_powershell(command)).to eql("powershell.exe -NoProfile -EncodedCommand #{encoded}")
|
13
|
+
expect(described_class.interpolate_powershell(command)).not_to match(/#{command}/)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,32 +5,25 @@ require 'open3'
|
|
5
5
|
require 'ostruct'
|
6
6
|
|
7
7
|
if ENV['COVERAGE'] == 'yes'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require 'codecov'
|
12
|
-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
13
|
-
else
|
8
|
+
begin
|
9
|
+
require 'simplecov'
|
10
|
+
require 'simplecov-console'
|
14
11
|
SimpleCov.formatters = [
|
15
|
-
SimpleCov::Formatter::HTMLFormatter
|
12
|
+
SimpleCov::Formatter::HTMLFormatter,
|
13
|
+
SimpleCov::Formatter::Console
|
16
14
|
]
|
17
|
-
end
|
18
|
-
SimpleCov.start do
|
19
|
-
track_files 'lib/**/*.rb'
|
20
|
-
|
21
|
-
add_filter '/spec'
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
add_filter '/.vendor'
|
16
|
+
SimpleCov.start do
|
17
|
+
track_files 'lib/**/*.rb'
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
system("git check-ignore --quiet #{f.filename}")
|
19
|
+
add_filter '/spec'
|
20
|
+
add_filter 'lib/puppet_litmus/version.rb'
|
21
|
+
# do not track vendored files
|
22
|
+
add_filter '/vendor'
|
23
|
+
add_filter '/.vendor'
|
33
24
|
end
|
25
|
+
rescue LoadError
|
26
|
+
raise 'Add the simplecov & simplecov-console gems to Gemfile to enable this task'
|
34
27
|
end
|
35
28
|
end
|
36
29
|
|
@@ -45,6 +38,21 @@ def run_matrix_from_metadata_v2(options = {})
|
|
45
38
|
)
|
46
39
|
end
|
47
40
|
|
41
|
+
def run_matrix_from_metadata_v3(options = [])
|
42
|
+
command = %w[bundle exec ./exe/matrix_from_metadata_v3]
|
43
|
+
unless options.include? '--metadata'
|
44
|
+
options << '--metadata'
|
45
|
+
options << File.join(File.dirname(__FILE__), 'exe', 'fake_metadata.json')
|
46
|
+
end
|
47
|
+
command += options
|
48
|
+
result = Open3.capture3(*command)
|
49
|
+
OpenStruct.new(
|
50
|
+
stdout: result[0],
|
51
|
+
stderr: result[1],
|
52
|
+
status_code: result[2]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
48
56
|
# This is basically how `configure!` sets up RSpec in tests.
|
49
57
|
require 'puppet_litmus'
|
50
58
|
RSpec.configure do |config|
|