puppet_litmus 0.27.0 → 0.31.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 +28 -5
- data/lib/puppet_litmus/inventory_manipulation.rb +121 -23
- data/lib/puppet_litmus/puppet_helpers.rb +63 -27
- 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/inventory_manipulation_spec.rb +69 -87
- data/spec/lib/puppet_litmus/puppet_helpers_spec.rb +39 -22
- data/spec/spec_helper.rb +13 -0
- data/spec/support/inventory.rb +130 -0
- data/spec/support/inventorytesting.yaml +41 -0
- metadata +14 -6
@@ -1,96 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
require 'support/inventory'
|
4
5
|
|
5
6
|
RSpec.describe PuppetLitmus::InventoryManipulation do
|
6
|
-
|
7
|
-
let(:no_config_hash) do
|
8
|
-
{ 'groups' =>
|
9
|
-
[{ 'name' => 'ssh_nodes',
|
10
|
-
'targets' =>
|
11
|
-
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
12
|
-
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
|
13
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:no_docker_hash) do
|
17
|
-
{ 'groups' =>
|
18
|
-
[{ 'name' => 'ssh_nodes', 'targets' => [] },
|
19
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:config_hash) do
|
23
|
-
{ 'groups' =>
|
24
|
-
[{ 'name' => 'ssh_nodes',
|
25
|
-
'targets' =>
|
26
|
-
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
27
|
-
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
28
|
-
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
29
|
-
'vars' => { 'role' => 'agent' } }] },
|
30
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:inventory_full_path) { 'spec/data/inventory.yaml' }
|
34
|
-
|
35
|
-
let(:no_feature_hash) do
|
36
|
-
{ 'groups' =>
|
37
|
-
[{ 'name' => 'ssh_nodes',
|
38
|
-
'targets' =>
|
39
|
-
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
40
|
-
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
41
|
-
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
|
42
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
43
|
-
end
|
44
|
-
|
45
|
-
let(:feature_hash_group) do
|
46
|
-
{ 'groups' =>
|
47
|
-
[{ 'name' => 'ssh_nodes',
|
48
|
-
'targets' =>
|
49
|
-
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
50
|
-
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
51
|
-
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }],
|
52
|
-
'features' => ['puppet-agent'] },
|
53
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
54
|
-
end
|
55
|
-
|
56
|
-
let(:empty_feature_hash_group) do
|
57
|
-
{ 'groups' =>
|
58
|
-
[{ 'name' => 'ssh_nodes',
|
59
|
-
'targets' =>
|
60
|
-
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
61
|
-
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
62
|
-
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }],
|
63
|
-
'features' => [] },
|
64
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
65
|
-
end
|
66
|
-
|
67
|
-
let(:feature_hash_node) do
|
68
|
-
{ 'groups' =>
|
69
|
-
[{ 'name' => 'ssh_nodes',
|
70
|
-
'targets' =>
|
71
|
-
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
72
|
-
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
73
|
-
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
74
|
-
'features' => ['puppet-agent'] }] },
|
75
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
76
|
-
end
|
77
|
-
|
78
|
-
let(:empty_feature_hash_node) do
|
79
|
-
{ 'groups' =>
|
80
|
-
[{ 'name' => 'ssh_nodes',
|
81
|
-
'targets' =>
|
82
|
-
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
83
|
-
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
84
|
-
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
85
|
-
'features' => [] }] },
|
86
|
-
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
87
|
-
end
|
88
|
-
|
89
|
-
let(:foo_node) do
|
90
|
-
{ 'uri' => 'foo',
|
91
|
-
'facts' => { 'provisioner' => 'bar', 'platform' => 'ubuntu' } }
|
92
|
-
end
|
7
|
+
let(:inventory_full_path) { 'spec/data/inventory.yaml' }
|
93
8
|
|
9
|
+
context 'with config_from_node' do
|
94
10
|
it 'no matching node, raises' do
|
95
11
|
expect { config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
|
96
12
|
end
|
@@ -159,4 +75,70 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
|
|
159
75
|
[{ 'name' => 'ssh_nodes', 'targets' => [foo_node] }, { 'name' => 'winrm_nodes', 'targets' => [] }])
|
160
76
|
end
|
161
77
|
end
|
78
|
+
|
79
|
+
context 'with target searching' do
|
80
|
+
it 'gets correct groups names from an inventory' do
|
81
|
+
expect(groups_in_inventory(complex_inventory)).to eql(%w[ssh_nodes frontend winrm_nodes])
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'applies a code block to groups' do
|
85
|
+
counts = groups_in_inventory(complex_inventory) do |group|
|
86
|
+
if group.key? 'targets'
|
87
|
+
group['targets'].count
|
88
|
+
end
|
89
|
+
end
|
90
|
+
expect(counts.sum).to be 4
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'gets names of targets' do
|
94
|
+
target_list = ['test.delivery.puppetlabs.net', 'test2.delivery.puppetlabs.net', 'test3.delivery.puppetlabs.net', 'test4.delivery.puppetlabs.net']
|
95
|
+
expect(targets_in_inventory(complex_inventory)).to eql target_list
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'applies a code block to targets' do
|
99
|
+
target_list = targets_in_inventory(complex_inventory) do |target|
|
100
|
+
next unless target['config']['transport'] == 'winrm'
|
101
|
+
|
102
|
+
target['uri']
|
103
|
+
end
|
104
|
+
|
105
|
+
expect(target_list).to eql ['test4.delivery.puppetlabs.net']
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'returns agent nodes' do
|
109
|
+
node_list = nodes_with_role('agent', complex_inventory)
|
110
|
+
expected_node_list = ['test.delivery.puppetlabs.net', 'test3.delivery.puppetlabs.net', 'test4.delivery.puppetlabs.net']
|
111
|
+
expect(node_list).to eql expected_node_list
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns agent nodes with different capitolization' do
|
115
|
+
node_list = nodes_with_role('Agent', complex_inventory)
|
116
|
+
expected_node_list = ['test.delivery.puppetlabs.net', 'test3.delivery.puppetlabs.net', 'test4.delivery.puppetlabs.net']
|
117
|
+
expect(node_list).to eql expected_node_list
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'searches for a group' do
|
121
|
+
expect(search_for_target('winrm_nodes', complex_inventory)).to eql ['winrm_nodes']
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'seaches for an array of groups' do
|
125
|
+
expect(search_for_target(%w[winrm_nodes ssh_nodes], complex_inventory)).to eql %w[winrm_nodes ssh_nodes]
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'searches for a specific target' do
|
129
|
+
expect(search_for_target('test.delivery.puppetlabs.net', complex_inventory)).to eql ['test.delivery.puppetlabs.net']
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'searches for an array of roles' do
|
133
|
+
expect(search_for_target(%w[iis nginx], complex_inventory)).to eql ['test4.delivery.puppetlabs.net', 'test3.delivery.puppetlabs.net']
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'searches for roles as symbols' do
|
137
|
+
expect(search_for_target([:iis, :nginx], complex_inventory)).to eql ['test4.delivery.puppetlabs.net', 'test3.delivery.puppetlabs.net']
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'raises an error if target not found' do
|
141
|
+
expect { search_for_target(:blah, complex_inventory) }.to raise_error 'targets not found in inventory'
|
142
|
+
end
|
143
|
+
end
|
162
144
|
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|
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def no_config_hash
|
4
|
+
{ 'groups' =>
|
5
|
+
[
|
6
|
+
{ 'name' => 'ssh_nodes',
|
7
|
+
'targets' =>
|
8
|
+
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
9
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
|
10
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] },
|
11
|
+
] }
|
12
|
+
end
|
13
|
+
|
14
|
+
def no_docker_hash
|
15
|
+
{ 'groups' =>
|
16
|
+
[{ 'name' => 'ssh_nodes', 'targets' => [] },
|
17
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
18
|
+
end
|
19
|
+
|
20
|
+
def config_hash
|
21
|
+
{ 'groups' =>
|
22
|
+
[{ 'name' => 'ssh_nodes',
|
23
|
+
'targets' =>
|
24
|
+
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
25
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
26
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
27
|
+
'vars' => { 'role' => 'agent' } }] },
|
28
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
29
|
+
end
|
30
|
+
|
31
|
+
def no_feature_hash
|
32
|
+
{ 'groups' =>
|
33
|
+
[{ 'name' => 'ssh_nodes',
|
34
|
+
'targets' =>
|
35
|
+
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
36
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
37
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }] },
|
38
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
39
|
+
end
|
40
|
+
|
41
|
+
def feature_hash_group
|
42
|
+
{ 'groups' =>
|
43
|
+
[{ 'name' => 'ssh_nodes',
|
44
|
+
'targets' =>
|
45
|
+
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
46
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
47
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }],
|
48
|
+
'features' => ['puppet-agent'] },
|
49
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
50
|
+
end
|
51
|
+
|
52
|
+
def empty_feature_hash_group
|
53
|
+
{ 'groups' =>
|
54
|
+
[{ 'name' => 'ssh_nodes',
|
55
|
+
'targets' =>
|
56
|
+
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
57
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
58
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' } }],
|
59
|
+
'features' => [] },
|
60
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
61
|
+
end
|
62
|
+
|
63
|
+
def feature_hash_node
|
64
|
+
{ 'groups' =>
|
65
|
+
[{ 'name' => 'ssh_nodes',
|
66
|
+
'targets' =>
|
67
|
+
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
68
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
69
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
70
|
+
'features' => ['puppet-agent'] }] },
|
71
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
72
|
+
end
|
73
|
+
|
74
|
+
def empty_feature_hash_node
|
75
|
+
{ 'groups' =>
|
76
|
+
[{ 'name' => 'ssh_nodes',
|
77
|
+
'targets' =>
|
78
|
+
[{ 'uri' => 'test.delivery.puppetlabs.net',
|
79
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
80
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
81
|
+
'features' => [] }] },
|
82
|
+
{ 'name' => 'winrm_nodes', 'targets' => [] }] }
|
83
|
+
end
|
84
|
+
|
85
|
+
def foo_node
|
86
|
+
{ 'uri' => 'foo',
|
87
|
+
'facts' => { 'provisioner' => 'bar', 'platform' => 'ubuntu' } }
|
88
|
+
end
|
89
|
+
|
90
|
+
def complex_inventory
|
91
|
+
{ 'groups' =>
|
92
|
+
[
|
93
|
+
{
|
94
|
+
'name' => 'ssh_nodes',
|
95
|
+
'groups' => [
|
96
|
+
{ 'name' => 'frontend',
|
97
|
+
'targets' => [
|
98
|
+
{
|
99
|
+
'uri' => 'test.delivery.puppetlabs.net',
|
100
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
101
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
102
|
+
'vars' => { 'role' => 'agent' },
|
103
|
+
},
|
104
|
+
{
|
105
|
+
'uri' => 'test2.delivery.puppetlabs.net',
|
106
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
107
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
108
|
+
'vars' => { 'role' => 'server' },
|
109
|
+
},
|
110
|
+
{
|
111
|
+
'uri' => 'test3.delivery.puppetlabs.net',
|
112
|
+
'config' => { 'transport' => 'ssh', 'ssh' => { 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false } },
|
113
|
+
'vars' => { 'roles' => %w[agent nginx webserver] },
|
114
|
+
},
|
115
|
+
] },
|
116
|
+
],
|
117
|
+
},
|
118
|
+
{
|
119
|
+
'name' => 'winrm_nodes',
|
120
|
+
'targets' => [
|
121
|
+
{
|
122
|
+
'uri' => 'test4.delivery.puppetlabs.net',
|
123
|
+
'config' => { 'transport' => 'winrm', 'winrm' => { 'user' => 'admin', 'password' => 'Qu@lity!' } },
|
124
|
+
'facts' => { 'provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64' },
|
125
|
+
'vars' => { 'roles' => %w[agent iis webserver] },
|
126
|
+
},
|
127
|
+
],
|
128
|
+
},
|
129
|
+
] }
|
130
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
groups:
|
2
|
+
- name: ssh_nodes
|
3
|
+
groups:
|
4
|
+
- name: webservers
|
5
|
+
targets:
|
6
|
+
- 192.168.100.179
|
7
|
+
- 192.168.100.180
|
8
|
+
- 192.168.100.181
|
9
|
+
- name: memcached
|
10
|
+
targets:
|
11
|
+
- 192.168.101.50
|
12
|
+
- 192.168.101.60
|
13
|
+
config:
|
14
|
+
ssh:
|
15
|
+
user: root
|
16
|
+
config:
|
17
|
+
transport: ssh
|
18
|
+
ssh:
|
19
|
+
user: centos
|
20
|
+
private-key: ~/.ssh/id_rsa
|
21
|
+
host-key-check: false
|
22
|
+
- name: win_nodes
|
23
|
+
groups:
|
24
|
+
- name: domaincontrollers
|
25
|
+
targets:
|
26
|
+
- 192.168.110.10
|
27
|
+
- 192.168.110.20
|
28
|
+
- name: testservers
|
29
|
+
targets:
|
30
|
+
- 172.16.219.20
|
31
|
+
- 172.16.219.30
|
32
|
+
config:
|
33
|
+
winrm:
|
34
|
+
realm: MYDOMAIN
|
35
|
+
ssl: false
|
36
|
+
config:
|
37
|
+
transport: winrm
|
38
|
+
winrm:
|
39
|
+
user: DOMAIN\opsaccount
|
40
|
+
password: S3cretP@ssword
|
41
|
+
ssl: true
|
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.31.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:
|
11
|
+
date: 2022-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bolt
|
@@ -185,6 +185,8 @@ files:
|
|
185
185
|
- spec/data/doot.tar.gz
|
186
186
|
- spec/data/inventory.yaml
|
187
187
|
- spec/data/jim.yaml
|
188
|
+
- spec/exe/fake_metadata.json
|
189
|
+
- spec/exe/matrix_from_metadata_v2_spec.rb
|
188
190
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
189
191
|
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
190
192
|
- spec/lib/puppet_litmus/puppet_litmus_version_spec.rb
|
@@ -192,11 +194,13 @@ files:
|
|
192
194
|
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
193
195
|
- spec/lib/puppet_litmus/util_spec.rb
|
194
196
|
- spec/spec_helper.rb
|
197
|
+
- spec/support/inventory.rb
|
198
|
+
- spec/support/inventorytesting.yaml
|
195
199
|
homepage: https://github.com/puppetlabs/puppet_litmus
|
196
200
|
licenses:
|
197
201
|
- Apache-2.0
|
198
202
|
metadata: {}
|
199
|
-
post_install_message:
|
203
|
+
post_install_message:
|
200
204
|
rdoc_options: []
|
201
205
|
require_paths:
|
202
206
|
- lib
|
@@ -211,19 +215,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
215
|
- !ruby/object:Gem::Version
|
212
216
|
version: '0'
|
213
217
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
215
|
-
signing_key:
|
218
|
+
rubygems_version: 3.0.3
|
219
|
+
signing_key:
|
216
220
|
specification_version: 4
|
217
221
|
summary: Providing a simple command line tool for puppet content creators, to enable
|
218
222
|
simple and complex test deployments.
|
219
223
|
test_files:
|
220
224
|
- spec/spec_helper.rb
|
225
|
+
- spec/support/inventory.rb
|
226
|
+
- spec/support/inventorytesting.yaml
|
221
227
|
- spec/lib/puppet_litmus/rake_tasks_spec.rb
|
222
228
|
- spec/lib/puppet_litmus/puppet_litmus_version_spec.rb
|
223
229
|
- spec/lib/puppet_litmus/util_spec.rb
|
224
230
|
- spec/lib/puppet_litmus/inventory_manipulation_spec.rb
|
225
231
|
- spec/lib/puppet_litmus/rake_helper_spec.rb
|
226
232
|
- spec/lib/puppet_litmus/puppet_helpers_spec.rb
|
233
|
+
- spec/exe/fake_metadata.json
|
234
|
+
- spec/exe/matrix_from_metadata_v2_spec.rb
|
227
235
|
- spec/data/doot.tar.gz
|
228
236
|
- spec/data/jim.yaml
|
229
237
|
- spec/data/inventory.yaml
|