puppet_litmus 0.15.0 → 0.18.2
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 -20
- data/lib/puppet_litmus/inventory_manipulation.rb +12 -1
- data/lib/puppet_litmus/puppet_helpers.rb +200 -137
- data/lib/puppet_litmus/rake_helper.rb +243 -101
- data/lib/puppet_litmus/rake_tasks.rb +36 -41
- data/lib/puppet_litmus/util.rb +17 -0
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/lib/puppet_litmus/inventory_manipulation_spec.rb +16 -18
- data/spec/lib/puppet_litmus/puppet_helpers_spec.rb +107 -124
- data/spec/lib/puppet_litmus/rake_helper_spec.rb +77 -27
- data/spec/lib/puppet_litmus/rake_tasks_spec.rb +8 -9
- data/spec/lib/puppet_litmus/util_spec.rb +15 -0
- data/spec/lib/puppet_litmus/version_spec.rb +0 -3
- data/spec/spec_helper.rb +7 -1
- metadata +76 -25
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Helper methods for testing puppet content
|
4
|
+
module PuppetLitmus::Util
|
5
|
+
# Ensure that a passed command is base 64 encoded and passed to PowerShell; this obviates the need to
|
6
|
+
# carefully interpolate strings for passing to ruby which will then be passed to PowerShell/CMD which will
|
7
|
+
# then be executed. This also ensures that a single PowerShell command may be specified for Windows targets
|
8
|
+
# leveraging PowerShell as bolt run_shell will use PowerShell against a remote target but CMD against a
|
9
|
+
# localhost target.
|
10
|
+
#
|
11
|
+
# @param :command [String] A PowerShell script block to be converted to base64
|
12
|
+
# @return [String] An invocation for PowerShell with the encoded command which may be passed to run_shell
|
13
|
+
def self.interpolate_powershell(command)
|
14
|
+
encoded_command = Base64.strict_encode64(command.encode('UTF-16LE'))
|
15
|
+
"powershell.exe -NoProfile -EncodedCommand #{encoded_command}"
|
16
|
+
end
|
17
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
load File.expand_path('../../../lib/puppet_litmus/inventory_manipulation.rb', __dir__)
|
5
|
-
include PuppetLitmus::InventoryManipulation # rubocop:disable Style/MixinUsage
|
6
4
|
|
7
5
|
RSpec.describe PuppetLitmus::InventoryManipulation do
|
8
6
|
context 'with config_from_node' do
|
@@ -94,70 +92,70 @@ RSpec.describe PuppetLitmus::InventoryManipulation do
|
|
94
92
|
end
|
95
93
|
|
96
94
|
it 'no matching node, raises' do
|
97
|
-
expect {
|
95
|
+
expect { config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
|
98
96
|
end
|
99
97
|
|
100
98
|
it 'no config section, returns nil' do
|
101
|
-
expect(
|
99
|
+
expect(config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
|
102
100
|
end
|
103
101
|
|
104
102
|
it 'config exists, and returns' do
|
105
|
-
expect(
|
103
|
+
expect(config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
|
106
104
|
{ 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false })
|
107
105
|
end
|
108
106
|
|
109
107
|
it 'facts exists, and returns' do
|
110
|
-
expect(
|
108
|
+
expect(facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
|
111
109
|
end
|
112
110
|
|
113
111
|
it 'vars exists, and returns' do
|
114
|
-
expect(
|
112
|
+
expect(vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
|
115
113
|
end
|
116
114
|
|
117
115
|
it 'no feature exists for the group, and returns hash with feature added' do
|
118
|
-
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
|
119
117
|
end
|
120
118
|
|
121
119
|
it 'feature exists for the group, and returns hash with feature removed' do
|
122
|
-
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
|
123
121
|
end
|
124
122
|
|
125
123
|
it 'write from inventory_hash to inventory_yaml file feature_hash_group' do
|
126
|
-
expect {
|
124
|
+
expect { write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
|
127
125
|
end
|
128
126
|
|
129
127
|
it 'empty feature exists for the group, and returns hash with feature added' do
|
130
|
-
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
|
131
129
|
end
|
132
130
|
|
133
131
|
it 'no feature exists for the node, and returns hash with feature added' do
|
134
|
-
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
|
135
133
|
end
|
136
134
|
|
137
135
|
it 'feature exists for the node, and returns hash with feature removed' do
|
138
|
-
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
|
139
137
|
end
|
140
138
|
|
141
139
|
it 'write from inventory_hash to inventory_yaml file feature_hash_node' do
|
142
|
-
expect {
|
140
|
+
expect { write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
|
143
141
|
end
|
144
142
|
|
145
143
|
it 'empty feature exists for the node, and returns hash with feature added' do
|
146
|
-
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
|
147
145
|
end
|
148
146
|
|
149
147
|
it 'write from inventory_hash to inventory_yaml file no feature_hash' do
|
150
148
|
expect(File).to exist(inventory_full_path)
|
151
|
-
expect {
|
149
|
+
expect { write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
|
152
150
|
end
|
153
151
|
|
154
152
|
it 'group does not exist in inventory, and returns hash with group added' do
|
155
|
-
expect(
|
153
|
+
expect(add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
|
156
154
|
[{ 'name' => 'ssh_nodes', 'targets' => [] }, { 'name' => 'winrm_nodes', 'targets' => [] }, { 'name' => 'docker_nodes', 'targets' => [foo_node] }])
|
157
155
|
end
|
158
156
|
|
159
157
|
it 'group exists in inventory, and returns hash with node added' do
|
160
|
-
expect(
|
158
|
+
expect(add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
|
161
159
|
[{ 'name' => 'ssh_nodes', 'targets' => [foo_node] }, { 'name' => 'winrm_nodes', 'targets' => [] }])
|
162
160
|
end
|
163
161
|
end
|
@@ -1,85 +1,79 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
load File.expand_path('../../../lib/puppet_litmus/puppet_helpers.rb', __dir__)
|
5
|
-
|
6
|
-
include PuppetLitmus::PuppetHelpers # rubocop:disable Style/MixinUsage
|
7
4
|
|
8
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
|
+
|
9
10
|
context 'with idempotent_apply' do
|
10
11
|
let(:manifest) do
|
11
12
|
"include '::doot'"
|
12
13
|
end
|
13
14
|
|
14
15
|
it 'calls all functions' do
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
|
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)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
describe '.apply_manifest' do
|
23
24
|
context 'when specifying a hiera config' do
|
24
25
|
let(:manifest) { "include '::doot'" }
|
25
|
-
let(:
|
26
|
-
let(:
|
27
|
-
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'" }
|
28
28
|
|
29
29
|
it 'passes the --hiera_config flag if the :hiera_config opt is specified' do
|
30
30
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
31
|
-
expect(
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
|
35
|
-
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')
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
context 'when using detailed-exitcodes' do
|
40
39
|
let(:manifest) { "include '::doot'" }
|
41
|
-
let(:
|
42
|
-
let(:
|
43
|
-
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" }
|
44
42
|
|
45
43
|
it 'uses detailed-exitcodes with expect_failures' do
|
46
44
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
47
|
-
expect(
|
48
|
-
expect(
|
49
|
-
expect(
|
50
|
-
expect
|
51
|
-
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)
|
52
49
|
end
|
53
50
|
|
54
51
|
it 'uses detailed-exitcodes with catch_failures' do
|
55
52
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
56
|
-
expect(
|
57
|
-
expect(
|
58
|
-
expect(
|
59
|
-
|
60
|
-
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)
|
61
57
|
end
|
62
58
|
|
63
59
|
it 'uses detailed-exitcodes with expect_changes' do
|
64
60
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
65
|
-
expect(
|
66
|
-
expect(
|
67
|
-
expect(
|
68
|
-
expect
|
69
|
-
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)
|
70
65
|
end
|
71
66
|
|
72
67
|
it 'uses detailed-exitcodes with catch_changes' do
|
73
68
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
74
|
-
expect(
|
75
|
-
expect(
|
76
|
-
expect(
|
77
|
-
|
78
|
-
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)
|
79
73
|
end
|
80
74
|
|
81
75
|
it 'uses raises exception for multiple options' do
|
82
|
-
expect {
|
76
|
+
expect { apply_manifest(manifest, catch_changes: true, expect_failures: true) }
|
83
77
|
.to raise_error(RuntimeError, 'please specify only one of `catch_changes`, `expect_changes`, `catch_failures` or `expect_failures`')
|
84
78
|
end
|
85
79
|
end
|
@@ -87,22 +81,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
87
81
|
|
88
82
|
describe '.run_shell' do
|
89
83
|
let(:command_to_run) { "puts 'doot'" }
|
90
|
-
let(:result) { ['
|
91
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'ssh_nodes', 'nodes' => [{ 'name' => 'some.host' }] }] } }
|
92
|
-
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 }] }
|
93
85
|
|
94
86
|
it 'responds to run_shell' do
|
95
|
-
expect(
|
87
|
+
expect(self).to respond_to(:run_shell).with(1..2).arguments
|
96
88
|
end
|
97
89
|
|
98
90
|
context 'when running against localhost and no inventory.yaml file' do
|
99
91
|
it 'does run_shell against localhost without error' do
|
100
92
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
101
93
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
102
|
-
expect(
|
103
|
-
expect(
|
104
|
-
expect(
|
105
|
-
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
|
106
97
|
end
|
107
98
|
end
|
108
99
|
|
@@ -110,10 +101,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
110
101
|
it 'does run_shell against remote host without error' do
|
111
102
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
112
103
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
113
|
-
expect(
|
114
|
-
expect(
|
115
|
-
expect(
|
116
|
-
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
|
117
108
|
end
|
118
109
|
end
|
119
110
|
end
|
@@ -122,35 +113,32 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
122
113
|
let(:local) { '/tmp' }
|
123
114
|
let(:remote) { '/remote_tmp' }
|
124
115
|
# Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
|
125
|
-
# rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators,
|
126
|
-
let(:result_success) {[{'
|
127
|
-
let(:result_failure) {[{'
|
128
|
-
# rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators,
|
129
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
|
130
|
-
let(:localhost_inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'litmus_localhost', 'config' => { 'transport' => 'local' } }] }] } }
|
116
|
+
# rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
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'}}}]}
|
119
|
+
# rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
131
120
|
|
132
121
|
it 'responds to run_shell' do
|
133
|
-
expect(
|
122
|
+
expect(self).to respond_to(:bolt_upload_file).with(2..3).arguments
|
134
123
|
end
|
135
124
|
|
136
125
|
context 'when upload returns success' do
|
137
126
|
it 'does upload_file against remote host without error' do
|
138
127
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
139
128
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
140
|
-
expect(
|
141
|
-
expect(
|
142
|
-
expect(
|
143
|
-
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
|
144
133
|
end
|
145
134
|
|
146
135
|
it 'does upload_file against localhost without error' do
|
147
136
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
148
137
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
149
|
-
expect(
|
150
|
-
expect(
|
151
|
-
expect(
|
152
|
-
expect
|
153
|
-
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
|
154
142
|
end
|
155
143
|
end
|
156
144
|
|
@@ -158,19 +146,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
158
146
|
it 'does upload_file gives runtime error for failure' do
|
159
147
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
160
148
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
161
|
-
expect(
|
162
|
-
expect(
|
163
|
-
expect(
|
164
|
-
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})
|
165
153
|
end
|
166
154
|
|
167
155
|
it 'returns the exit code and error message when expecting failure' do
|
168
156
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
169
157
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
170
|
-
expect(
|
171
|
-
expect(
|
172
|
-
expect(
|
173
|
-
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)
|
174
162
|
expect(method_result.exit_code).to be(255)
|
175
163
|
expect(method_result.stderr).to be('No such file or directory @ rb_sysopen - /nonexistant/file/path')
|
176
164
|
end
|
@@ -179,23 +167,20 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
179
167
|
|
180
168
|
describe '.bolt_run_script' do
|
181
169
|
let(:script) { '/tmp/script.sh' }
|
182
|
-
let(:result) { ['
|
183
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
|
184
|
-
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 }] }
|
185
171
|
|
186
172
|
it 'responds to bolt_run_script' do
|
187
|
-
expect(
|
173
|
+
expect(self).to respond_to(:bolt_run_script).with(1..2).arguments
|
188
174
|
end
|
189
175
|
|
190
176
|
context 'when running against localhost and no inventory.yaml file' do
|
191
177
|
it 'does bolt_run_script against localhost without error' do
|
192
178
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
193
179
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
194
|
-
expect(
|
195
|
-
expect(
|
196
|
-
expect(
|
197
|
-
expect
|
198
|
-
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
|
199
184
|
end
|
200
185
|
end
|
201
186
|
|
@@ -203,10 +188,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
203
188
|
it 'does bolt_run_script against remote host without error' do
|
204
189
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
205
190
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
206
|
-
expect(
|
207
|
-
expect(
|
208
|
-
expect(
|
209
|
-
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
|
210
195
|
end
|
211
196
|
end
|
212
197
|
|
@@ -214,11 +199,10 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
214
199
|
it 'does bolt_run_script with arguments without error' do
|
215
200
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'localhost'))
|
216
201
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(false)
|
217
|
-
expect(
|
218
|
-
expect(
|
219
|
-
expect(
|
220
|
-
expect
|
221
|
-
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
|
222
206
|
end
|
223
207
|
end
|
224
208
|
end
|
@@ -228,53 +212,52 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
228
212
|
let(:params) { { 'action' => 'install', 'name' => 'foo' } }
|
229
213
|
let(:config_data) { { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } }
|
230
214
|
# Ignore rubocop because these hashes are representative of output from an external method and editing them leads to test failures.
|
231
|
-
# rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators,
|
232
|
-
let(:result_unstructured_task_success){ [{'
|
233
|
-
let(:result_structured_task_success){ [{'
|
234
|
-
let(:result_failure) {[{'
|
235
|
-
# rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators,
|
236
|
-
let(:inventory_hash) { { 'groups' => [{ 'name' => 'local', 'nodes' => [{ 'name' => 'some.host', 'config' => { 'transport' => 'local' } }] }] } }
|
215
|
+
# rubocop:disable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
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}}}}]}
|
219
|
+
# rubocop:enable Layout/SpaceInsideHashLiteralBraces, Layout/SpaceBeforeBlockBraces, Layout/SpaceInsideBlockBraces, Layout/SpaceAroundOperators, Layout/LineLength, Layout/SpaceAfterComma
|
237
220
|
|
238
221
|
it 'responds to bolt_run_task' do
|
239
|
-
expect(
|
222
|
+
expect(self).to respond_to(:run_bolt_task).with(2..3).arguments
|
240
223
|
end
|
241
224
|
|
242
225
|
context 'when bolt returns success' do
|
243
226
|
it 'does bolt_task_run gives no runtime error for success' do
|
244
227
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
245
228
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
246
|
-
expect(
|
247
|
-
expect(
|
248
|
-
expect(
|
249
|
-
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
|
250
233
|
end
|
251
234
|
|
252
235
|
it 'does bolt_task_run gives no runtime error for success, for a named inventory file' do
|
253
236
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
254
237
|
expect(File).to receive(:exist?).with('jim.yaml').and_return(true)
|
255
|
-
expect(
|
256
|
-
expect(
|
257
|
-
expect(
|
258
|
-
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
|
259
242
|
end
|
260
243
|
|
261
244
|
it 'returns stdout for unstructured-data tasks' do
|
262
245
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
263
246
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
264
|
-
expect(
|
265
|
-
expect(
|
266
|
-
expect(
|
267
|
-
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: {})
|
268
251
|
expect(method_result.stdout).to eq('SUCCESS!')
|
269
252
|
end
|
270
253
|
|
271
254
|
it 'returns structured output for structured-data tasks' do
|
272
255
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
273
256
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
274
|
-
expect(
|
275
|
-
expect(
|
276
|
-
expect(
|
277
|
-
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: {})
|
278
261
|
expect(method_result.stdout).to eq('{"key1"=>"foo", "key2"=>"bar"}')
|
279
262
|
expect(method_result.result['key1']).to eq('foo')
|
280
263
|
expect(method_result.result['key2']).to eq('bar')
|
@@ -285,19 +268,19 @@ RSpec.describe PuppetLitmus::PuppetHelpers do
|
|
285
268
|
it 'does bolt_task_run gives runtime error for failure' do
|
286
269
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
287
270
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
288
|
-
expect(
|
289
|
-
expect(
|
290
|
-
expect(
|
291
|
-
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})
|
292
275
|
end
|
293
276
|
|
294
277
|
it 'returns the exit code and error message when expecting failure' do
|
295
278
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'some.host'))
|
296
279
|
expect(File).to receive(:exist?).with('inventory.yaml').and_return(true)
|
297
|
-
expect(
|
298
|
-
expect(
|
299
|
-
expect(
|
300
|
-
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)
|
301
284
|
expect(method_result.exit_code).to be(123)
|
302
285
|
expect(method_result.stderr).to be('FAILURE!')
|
303
286
|
end
|