puppet_litmus 0.16.0 → 0.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -16
- data/lib/puppet_litmus.rb +0 -30
- data/lib/puppet_litmus/inventory_manipulation.rb +10 -1
- data/lib/puppet_litmus/puppet_helpers.rb +200 -137
- data/lib/puppet_litmus/rake_helper.rb +258 -96
- data/lib/puppet_litmus/rake_tasks.rb +96 -100
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/lib/puppet_litmus/inventory_manipulation_spec.rb +16 -16
- data/spec/lib/puppet_litmus/puppet_helpers_spec.rb +103 -117
- data/spec/lib/puppet_litmus/rake_helper_spec.rb +79 -27
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +14 -12
- data/spec/spec_helper.rb +7 -6
- metadata +77 -17
@@ -92,70 +92,70 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'no matching node, raises' do
|
95
|
-
expect {
|
95
|
+
expect { config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'no config section, returns nil' do
|
99
|
-
expect(
|
99
|
+
expect(config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'config exists, and returns' do
|
103
|
-
expect(
|
103
|
+
expect(config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
|
104
104
|
{ 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false })
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'facts exists, and returns' do
|
108
|
-
expect(
|
108
|
+
expect(facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'vars exists, and returns' do
|
112
|
-
expect(
|
112
|
+
expect(vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'no feature exists for the group, and returns hash with feature added' do
|
116
|
-
expect(
|
116
|
+
expect(add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'feature exists for the group, and returns hash with feature removed' do
|
120
|
-
expect(
|
120
|
+
expect(remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'write from inventory_hash to inventory_yaml file feature_hash_group' do
|
124
|
-
expect {
|
124
|
+
expect { write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'empty feature exists for the group, and returns hash with feature added' do
|
128
|
-
expect(
|
128
|
+
expect(add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'no feature exists for the node, and returns hash with feature added' do
|
132
|
-
expect(
|
132
|
+
expect(add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'feature exists for the node, and returns hash with feature removed' do
|
136
|
-
expect(
|
136
|
+
expect(remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'write from inventory_hash to inventory_yaml file feature_hash_node' do
|
140
|
-
expect {
|
140
|
+
expect { write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'empty feature exists for the node, and returns hash with feature added' do
|
144
|
-
expect(
|
144
|
+
expect(add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'write from inventory_hash to inventory_yaml file no feature_hash' do
|
148
148
|
expect(File).to exist(inventory_full_path)
|
149
|
-
expect {
|
149
|
+
expect { write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'group does not exist in inventory, and returns hash with group added' do
|
153
|
-
expect(
|
153
|
+
expect(add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
|
154
154
|
[{ 'name' => 'ssh_nodes', 'targets' => [] }, { 'name' => 'winrm_nodes', 'targets' => [] }, { 'name' => 'docker_nodes', 'targets' => [foo_node] }])
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'group exists in inventory, and returns hash with node added' do
|
158
|
-
expect(
|
158
|
+
expect(add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
|
159
159
|
[{ 'name' => 'ssh_nodes', 'targets' => [foo_node] }, { 'name' => 'winrm_nodes', 'targets' => [] }])
|
160
160
|
end
|
161
161
|
end
|
@@ -3,80 +3,77 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe PuppetLitmus::PuppetHelpers do
|
6
|
+
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'targets' => [{ 'uri' => 'some.host', 'config' => { 'transport' => 'local' }, 'facts' => facts_hash }] }] } }
|
7
|
+
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'targets' => [{ 'uri' => 'litmus_localhost', 'config' => { 'transport' => 'local' }, 'facts' => facts_hash }] }] } }
|
8
|
+
let(:facts_hash) { { 'provisioner' => 'docker', 'container_name' => 'litmusimage_debian_10-2222', 'platform' => 'litmusimage/debian:10' } }
|
9
|
+
|
6
10
|
context 'with idempotent_apply' do
|
7
11
|
let(:manifest) do
|
8
12
|
"include '::doot'"
|
9
13
|
end
|
10
14
|
|
11
15
|
it 'calls all functions' do
|
12
|
-
expect(
|
13
|
-
expect(
|
14
|
-
expect(
|
15
|
-
|
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')
|
18
|
+
expect(self).to receive(:apply_manifest).with(nil, catch_changes: true, manifest_file_location: '/bla.pp')
|
19
|
+
idempotent_apply(manifest)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
23
|
describe '.apply_manifest' do
|
20
24
|
context 'when specifying a hiera config' do
|
21
25
|
let(:manifest) { "include '::doot'" }
|
22
|
-
let(:
|
23
|
-
let(:
|
24
|
-
let(:command) { " puppet apply /bla.pp --modulepath #{Dir.pwd}/spec/fixtures/modules --hiera_config='/hiera.yaml'" }
|
26
|
+
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'" }
|
25
28
|
|
26
29
|
it 'passes the --hiera_config flag if the :hiera_config opt is specified' do
|
27
30
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
28
|
-
expect(
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
|
32
|
-
described_class.apply_manifest(manifest, hiera_config: '/hiera.yaml')
|
31
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
32
|
+
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
33
|
+
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
34
|
+
apply_manifest(manifest, hiera_config: '/hiera.yaml')
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
context 'when using detailed-exitcodes' do
|
37
39
|
let(:manifest) { "include '::doot'" }
|
38
|
-
let(:
|
39
|
-
let(:
|
40
|
-
let(:command) { " puppet apply /bla.pp --modulepath #{Dir.pwd}/spec/fixtures/modules --detailed-exitcodes" }
|
40
|
+
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" }
|
41
42
|
|
42
43
|
it 'uses detailed-exitcodes with expect_failures' do
|
43
44
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
44
|
-
expect(
|
45
|
-
expect(
|
46
|
-
expect(
|
47
|
-
expect
|
48
|
-
expect { described_class.apply_manifest(manifest, expect_failures: true) }.to raise_error(RuntimeError)
|
45
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
46
|
+
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
47
|
+
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
48
|
+
expect { apply_manifest(manifest, expect_failures: true) }.to raise_error(RuntimeError)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'uses detailed-exitcodes with catch_failures' do
|
52
52
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
53
|
-
expect(
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
|
57
|
-
described_class.apply_manifest(manifest, catch_failures: true)
|
53
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
54
|
+
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
55
|
+
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
56
|
+
apply_manifest(manifest, catch_failures: true)
|
58
57
|
end
|
59
58
|
|
60
59
|
it 'uses detailed-exitcodes with expect_changes' do
|
61
60
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
62
|
-
expect(
|
63
|
-
expect(
|
64
|
-
expect(
|
65
|
-
expect
|
66
|
-
expect { described_class.apply_manifest(manifest, expect_changes: true) }.to raise_error(RuntimeError)
|
61
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
62
|
+
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
63
|
+
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
64
|
+
expect { apply_manifest(manifest, expect_changes: true) }.to raise_error(RuntimeError)
|
67
65
|
end
|
68
66
|
|
69
67
|
it 'uses detailed-exitcodes with catch_changes' do
|
70
68
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
71
|
-
expect(
|
72
|
-
expect(
|
73
|
-
expect(
|
74
|
-
|
75
|
-
described_class.apply_manifest(manifest, catch_changes: true)
|
69
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
70
|
+
expect(self).to receive(:create_manifest_file).with(manifest).and_return('/bla.pp')
|
71
|
+
expect(self).to receive(:run_command).with(command, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
72
|
+
apply_manifest(manifest, catch_changes: true)
|
76
73
|
end
|
77
74
|
|
78
75
|
it 'uses raises exception for multiple options' do
|
79
|
-
expect {
|
76
|
+
expect { apply_manifest(manifest, catch_changes: true, expect_failures: true) }
|
80
77
|
.to raise_error(RuntimeError, 'please specify only one of `catch_changes`, `expect_changes`, `catch_failures` or `expect_failures`')
|
81
78
|
end
|
82
79
|
end
|
@@ -84,22 +81,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
84
81
|
|
85
82
|
describe '.run_shell' do
|
86
83
|
let(:command_to_run) { "puts 'doot'" }
|
87
|
-
let(:result) { ['
|
88
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'name' => 'some.host' }] }] } }
|
89
|
-
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
|
84
|
+
let(:result) { ['value' => { 'exit_code' => 0, 'exit_status' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
90
85
|
|
91
86
|
it 'responds to run_shell' do
|
92
|
-
expect(
|
87
|
+
expect(self).to respond_to(:run_shell).with(1..2).arguments
|
93
88
|
end
|
94
89
|
|
95
90
|
context 'when running against localhost and no inventory.yaml file' do
|
96
91
|
it 'does run_shell against localhost without error' do
|
97
92
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
98
93
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
99
|
-
expect(
|
100
|
-
expect(
|
101
|
-
expect(
|
102
|
-
expect { described_class.run_shell(command_to_run) }.not_to raise_error
|
94
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
95
|
+
expect(self).to receive(:run_command).with(command_to_run, 'litmus_localhost', config: nil, inventory: localhost_inventory_hash).and_return(result)
|
96
|
+
expect { run_shell(command_to_run) }.not_to raise_error
|
103
97
|
end
|
104
98
|
end
|
105
99
|
|
@@ -107,10 +101,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
107
101
|
it 'does run_shell against remote host without error' do
|
108
102
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
109
103
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
110
|
-
expect(
|
111
|
-
expect(
|
112
|
-
expect(
|
113
|
-
expect {
|
104
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
105
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
106
|
+
expect(self).to receive(:run_command).with(command_to_run, 'some.host', config: nil, inventory: inventory_hash).and_return(result)
|
107
|
+
expect { run_shell(command_to_run) }.not_to raise_error
|
114
108
|
end
|
115
109
|
end
|
116
110
|
end
|
@@ -120,34 +114,31 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
120
114
|
let(:remote) { '/remote_tmp' }
|
121
115
|
# Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
|
122
116
|
# rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
123
|
-
let(:result_success) {[{'
|
124
|
-
let(:result_failure) {[{'
|
117
|
+
let(:result_success) {[{'target'=>'some.host','action'=>'upload','object'=>'C:\foo\bar.ps1','status'=>'success','value'=>{'_output'=>'Uploaded \'C:\foo\bar.ps1\' to \'some.host:C:\bar\''}}]}
|
118
|
+
let(:result_failure) {[{'target'=>'some.host','action'=>nil,'object'=>nil,'status'=>'failure','value'=>{'_error'=>{'kind'=>'puppetlabs.tasks/task_file_error','msg'=>'No such file or directory @ rb_sysopen - /nonexistant/file/path','details'=>{},'issue_code'=>'WRITE_ERROR'}}}]}
|
125
119
|
# rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
126
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
|
127
|
-
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
|
128
120
|
|
129
121
|
it 'responds to run_shell' do
|
130
|
-
expect(
|
122
|
+
expect(self).to respond_to(:bolt_upload_file).with(2..3).arguments
|
131
123
|
end
|
132
124
|
|
133
125
|
context 'when upload returns success' do
|
134
126
|
it 'does upload_file against remote host without error' do
|
135
127
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
136
128
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
137
|
-
expect(
|
138
|
-
expect(
|
139
|
-
expect(
|
140
|
-
expect {
|
129
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
130
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
131
|
+
expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_success)
|
132
|
+
expect { bolt_upload_file(local, remote) }.not_to raise_error
|
141
133
|
end
|
142
134
|
|
143
135
|
it 'does upload_file against localhost without error' do
|
144
136
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
145
137
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
146
|
-
expect(
|
147
|
-
expect(
|
148
|
-
expect(
|
149
|
-
expect
|
150
|
-
expect { described_class.bolt_upload_file(local, remote) }.not_to raise_error
|
138
|
+
expect(self).not_to receive(:inventory_hash_from_inventory_file)
|
139
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
140
|
+
expect(self).to receive(:upload_file).with(local, remote, 'litmus_localhost', options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result_success)
|
141
|
+
expect { bolt_upload_file(local, remote) }.not_to raise_error
|
151
142
|
end
|
152
143
|
end
|
153
144
|
|
@@ -155,19 +146,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
155
146
|
it 'does upload_file gives runtime error for failure' do
|
156
147
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
157
148
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
158
|
-
expect(
|
159
|
-
expect(
|
160
|
-
expect(
|
161
|
-
expect {
|
149
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
150
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
151
|
+
expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
152
|
+
expect { bolt_upload_file(local, remote) }.to raise_error(RuntimeError, %r{upload file failed})
|
162
153
|
end
|
163
154
|
|
164
155
|
it 'returns the exit code and error message when expecting failure' do
|
165
156
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
166
157
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
167
|
-
expect(
|
168
|
-
expect(
|
169
|
-
expect(
|
170
|
-
method_result =
|
158
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
159
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
160
|
+
expect(self).to receive(:upload_file).with(local, remote, 'some.host', options: {}, config: nil, inventory: inventory_hash).and_return(result_failure)
|
161
|
+
method_result = bolt_upload_file(local, remote, expect_failures: true)
|
171
162
|
expect(method_result.exit_code).to be(255)
|
172
163
|
expect(method_result.stderr).to be('No such file or directory @ rb_sysopen - /nonexistant/file/path')
|
173
164
|
end
|
@@ -176,23 +167,20 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
176
167
|
|
177
168
|
describe '.bolt_run_script' do
|
178
169
|
let(:script) { '/tmp/script.sh' }
|
179
|
-
let(:result) { ['
|
180
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
|
181
|
-
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
|
170
|
+
let(:result) { ['value' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
182
171
|
|
183
172
|
it 'responds to bolt_run_script' do
|
184
|
-
expect(
|
173
|
+
expect(self).to respond_to(:bolt_run_script).with(1..2).arguments
|
185
174
|
end
|
186
175
|
|
187
176
|
context 'when running against localhost and no inventory.yaml file' do
|
188
177
|
it 'does bolt_run_script against localhost without error' do
|
189
178
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
190
179
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
191
|
-
expect(
|
192
|
-
expect(
|
193
|
-
expect(
|
194
|
-
expect
|
195
|
-
expect { described_class.bolt_run_script(script) }.not_to raise_error
|
180
|
+
expect(self).not_to receive(:inventory_hash_from_inventory_file)
|
181
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
182
|
+
expect(self).to receive(:run_script).with(script, 'litmus_localhost', [], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
|
183
|
+
expect { bolt_run_script(script) }.not_to raise_error
|
196
184
|
end
|
197
185
|
end
|
198
186
|
|
@@ -200,10 +188,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
200
188
|
it 'does bolt_run_script against remote host without error' do
|
201
189
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
202
190
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
203
|
-
expect(
|
204
|
-
expect(
|
205
|
-
expect(
|
206
|
-
expect {
|
191
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
192
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
193
|
+
expect(self).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: inventory_hash).and_return(result)
|
194
|
+
expect { bolt_run_script(script) }.not_to raise_error
|
207
195
|
end
|
208
196
|
end
|
209
197
|
|
@@ -211,11 +199,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
211
199
|
it 'does bolt_run_script with arguments without error' do
|
212
200
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
213
201
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
214
|
-
expect(
|
215
|
-
expect(
|
216
|
-
expect(
|
217
|
-
expect
|
218
|
-
expect { described_class.bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
|
202
|
+
expect(self).not_to receive(:inventory_hash_from_inventory_file)
|
203
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
204
|
+
expect(self).to receive(:run_script).with(script, 'litmus_localhost', ['doot'], options: {}, config: nil, inventory: localhost_inventory_hash).and_return(result)
|
205
|
+
expect { bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
|
219
206
|
end
|
220
207
|
end
|
221
208
|
end
|
@@ -226,52 +213,51 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
226
213
|
let(:config_data) { { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } }
|
227
214
|
# Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
|
228
215
|
# rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
229
|
-
let(:result_unstructured_task_success){ [{'
|
230
|
-
let(:result_structured_task_success){ [{'
|
231
|
-
let(:result_failure) {[{'
|
216
|
+
let(:result_unstructured_task_success){ [{'target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'success','value'=>{'_output'=>'SUCCESS!'}}]}
|
217
|
+
let(:result_structured_task_success){ [{'target'=>'some.host','action'=>'task','object'=>'testtask::structured','status'=>'success','value'=>{'key1'=>'foo','key2'=>'bar'}}]}
|
218
|
+
let(:result_failure) {[{'target'=>'some.host','action'=>'task','object'=>'testtask::unstructured','status'=>'failure','value'=>{'_error'=>{'msg'=>'FAILURE!','kind'=>'puppetlabs.tasks/task-error','details'=>{'exitcode'=>123}}}}]}
|
232
219
|
# rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
233
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
|
234
220
|
|
235
221
|
it 'responds to bolt_run_task' do
|
236
|
-
expect(
|
222
|
+
expect(self).to respond_to(:run_bolt_task).with(2..3).arguments
|
237
223
|
end
|
238
224
|
|
239
225
|
context 'when bolt returns success' do
|
240
226
|
it 'does bolt_task_run gives no runtime error for success' do
|
241
227
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
242
228
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
243
|
-
expect(
|
244
|
-
expect(
|
245
|
-
expect(
|
246
|
-
expect {
|
229
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
230
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
231
|
+
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
232
|
+
expect { run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
|
247
233
|
end
|
248
234
|
|
249
235
|
it 'does bolt_task_run gives no runtime error for success, for a named inventory file' do
|
250
236
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
251
237
|
expect(File).to receive(:exist?).with('jim.yaml').and_return(true)
|
252
|
-
expect(
|
253
|
-
expect(
|
254
|
-
expect(
|
255
|
-
expect {
|
238
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
239
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
240
|
+
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
241
|
+
expect { run_bolt_task(task_name, params, inventory_file: 'jim.yaml') }.not_to raise_error
|
256
242
|
end
|
257
243
|
|
258
244
|
it 'returns stdout for unstructured-data tasks' do
|
259
245
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
260
246
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
261
|
-
expect(
|
262
|
-
expect(
|
263
|
-
expect(
|
264
|
-
method_result =
|
247
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
248
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
249
|
+
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_unstructured_task_success)
|
250
|
+
method_result = run_bolt_task(task_name, params, opts: {})
|
265
251
|
expect(method_result.stdout).to eq('SUCCESS!')
|
266
252
|
end
|
267
253
|
|
268
254
|
it 'returns structured output for structured-data tasks' do
|
269
255
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
270
256
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
271
|
-
expect(
|
272
|
-
expect(
|
273
|
-
expect(
|
274
|
-
method_result =
|
257
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
258
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
259
|
+
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_structured_task_success)
|
260
|
+
method_result = run_bolt_task(task_name, params, opts: {})
|
275
261
|
expect(method_result.stdout).to eq('{"key1"=>"foo", "key2"=>"bar"}')
|
276
262
|
expect(method_result.result['key1']).to eq('foo')
|
277
263
|
expect(method_result.result['key2']).to eq('bar')
|
@@ -282,19 +268,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
282
268
|
it 'does bolt_task_run gives runtime error for failure' do
|
283
269
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
284
270
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
285
|
-
expect(
|
286
|
-
expect(
|
287
|
-
expect(
|
288
|
-
expect {
|
271
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
272
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
273
|
+
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
274
|
+
expect { run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
|
289
275
|
end
|
290
276
|
|
291
277
|
it 'returns the exit code and error message when expecting failure' do
|
292
278
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
293
279
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
294
|
-
expect(
|
295
|
-
expect(
|
296
|
-
expect(
|
297
|
-
method_result =
|
280
|
+
expect(self).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
281
|
+
expect(self).to receive(:target_in_inventory?).and_return(true)
|
282
|
+
expect(self).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
283
|
+
method_result = run_bolt_task(task_name, params, expect_failures: true)
|
298
284
|
expect(method_result.exit_code).to be(123)
|
299
285
|
expect(method_result.stderr).to be('FAILURE!')
|
300
286
|
end
|