puppet_litmus 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/puppet_litmus/serverspec.rb +32 -4
- data/lib/puppet_litmus/version.rb +1 -1
- data/spec/lib/puppet_litmus/serverspec_spec.rb +68 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe018c648a86597b46e5cdb5840468cb790e3471b49c25d5fd4003c57f140ca6
|
4
|
+
data.tar.gz: 180250778c72cb783085036e6ee1908f7d99533f2b26dd92b7fa963711942a03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a7f75b8b6a1bd870e6df72d784f1bfa433b0a663b3e3cc505a6feb6d404998591f6bb62e183a385de44412bc45a0ca0986f15e969a7adfde8f89522de36deac
|
7
|
+
data.tar.gz: 5d571a1f5fba0acad3425fab872bcd1abe404137be45b0aec2cb433f7b89e6f3c3d1eca9ce27173c160cce76d50ef84f420b20399110c3bf744910bfbefe2ccc
|
@@ -137,15 +137,16 @@ module PuppetLitmus::Serverspec
|
|
137
137
|
#
|
138
138
|
# @param task_name [String] The name of the task to run.
|
139
139
|
# @param params [Hash] key : value pairs to be passed to the task.
|
140
|
-
# @
|
141
|
-
|
140
|
+
# @param opts [Hash] Alters the behaviour of the command. Valid options are :expect_failures [Boolean] doesnt return an exit code of non-zero if the command failed.
|
141
|
+
# @return [Object] A result object from the task.The values available are stdout, stderr and result.
|
142
|
+
def run_bolt_task(task_name, params = {}, opts = {})
|
142
143
|
config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
|
143
144
|
inventory_hash = inventory_hash_from_inventory_file
|
144
145
|
target_node_name = ENV['TARGET_HOST'] if target_node_name.nil?
|
145
146
|
|
146
147
|
result = run_task(task_name, target_node_name, params, config: config_data, inventory: inventory_hash)
|
147
148
|
|
148
|
-
raise "task failed\n`#{task_name}`\n======\n#{result}" if result.first['status'] != 'success'
|
149
|
+
raise "task failed\n`#{task_name}`\n======\n#{result}" if result.first['status'] != 'success' && opts[:expect_failures] != true
|
149
150
|
|
150
151
|
exit_code = if result.first['status'] == 'success'
|
151
152
|
0
|
@@ -154,7 +155,34 @@ module PuppetLitmus::Serverspec
|
|
154
155
|
end
|
155
156
|
result = OpenStruct.new(exit_code: exit_code,
|
156
157
|
stdout: result.first['result']['status'],
|
157
|
-
stderr: result.first['result']['
|
158
|
+
stderr: result.first['result']['stderr'],
|
159
|
+
result: result.first['result'])
|
160
|
+
yield result if block_given?
|
161
|
+
result
|
162
|
+
end
|
163
|
+
|
164
|
+
# Runs a script against the target system.
|
165
|
+
#
|
166
|
+
# @param script [String] The path to the script on the source machine
|
167
|
+
# @param opts [Hash] Alters the behaviour of the command. Valid options are :expect_failures [Boolean] doesnt return an exit code of non-zero if the command failed.
|
168
|
+
# @param arguments [Array] Array of arguments to pass to script on runtime
|
169
|
+
# @yieldreturn [Block] this method will yield to a block of code passed by the caller; this can be used for additional validation, etc.
|
170
|
+
# @return [Object] A result object from the script run.
|
171
|
+
def bolt_run_script(script, opts = {}, arguments: [])
|
172
|
+
target_node_name = ENV['TARGET_HOST'] if target_node_name.nil?
|
173
|
+
inventory_hash = if target_node_name.nil? || target_node_name == 'localhost'
|
174
|
+
nil
|
175
|
+
else
|
176
|
+
inventory_hash_from_inventory_file
|
177
|
+
end
|
178
|
+
|
179
|
+
result = run_script(script, target_node_name, arguments, options: opts, config: nil, inventory: inventory_hash)
|
180
|
+
|
181
|
+
raise "script run failed\n`#{script}`\n======\n#{result}" if result.first['result']['exit_code'] != 0 && opts[:expect_failures] != true
|
182
|
+
|
183
|
+
result = OpenStruct.new(exit_code: result.first['result']['exit_code'],
|
184
|
+
stdout: result.first['result']['stdout'],
|
185
|
+
stderr: result.first['result']['stderr'])
|
158
186
|
yield result if block_given?
|
159
187
|
result
|
160
188
|
end
|
@@ -79,4 +79,72 @@ RSpec.describe PuppetLitmus::Serverspec do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
82
|
+
|
83
|
+
describe '.bolt_run_script' do
|
84
|
+
let(:script) { '/tmp/script.sh' }
|
85
|
+
let(:result) { ['result' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil }] }
|
86
|
+
let(:inventory_hash) { Hash.new(0) }
|
87
|
+
|
88
|
+
it 'responds to bolt_run_script' do
|
89
|
+
expect(dummy_class).to respond_to(:bolt_run_script).with(1..2).arguments
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when running against localhost and no inventory.yaml file' do
|
93
|
+
it 'does bolt_run_script against localhost without error' do
|
94
|
+
allow(ENV).to receive(:[]).with('TARGET_HOST').and_return('localhost')
|
95
|
+
expect(dummy_class).not_to receive(:inventory_hash_from_inventory_file)
|
96
|
+
expect(dummy_class).to receive(:run_script).with(script, 'localhost', [], options: {}, config: nil, inventory: nil).and_return(result)
|
97
|
+
expect { dummy_class.bolt_run_script(script) }.not_to raise_error
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when running against remote host' do
|
102
|
+
it 'does bolt_run_script against remote host without error' do
|
103
|
+
allow(ENV).to receive(:[]).with('TARGET_HOST').and_return('some.host')
|
104
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file)
|
105
|
+
expect(dummy_class).to receive(:run_script).with(script, 'some.host', [], options: {}, config: nil, inventory: nil).and_return(result)
|
106
|
+
expect { dummy_class.bolt_run_script(script) }.not_to raise_error
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when running with arguments' do
|
111
|
+
it 'does bolt_run_script with arguments without error' do
|
112
|
+
allow(ENV).to receive(:[]).with('TARGET_HOST').and_return('localhost')
|
113
|
+
expect(dummy_class).not_to receive(:inventory_hash_from_inventory_file)
|
114
|
+
expect(dummy_class).to receive(:run_script).with(script, 'localhost', ['doot'], options: {}, config: nil, inventory: nil).and_return(result)
|
115
|
+
expect { dummy_class.bolt_run_script(script, arguments: ['doot']) }.not_to raise_error
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '.run_bolt_task' do
|
121
|
+
let(:task_name) { 'testtask' }
|
122
|
+
let(:params) { { 'action' => 'install', 'name' => 'foo' } }
|
123
|
+
let(:config_data) { { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } }
|
124
|
+
let(:result_success) { ['status' => 'success', 'result' => { 'exit_code' => 0, 'stdout' => nil, 'stderr' => nil, 'result' => nil }] }
|
125
|
+
let(:result_failure) { ['status' => 'failure', 'result' => { 'exit_code' => 255, 'stdout' => 'failure', 'stderr' => 'failure', 'result' => nil }] }
|
126
|
+
let(:inventory_hash) { Hash.new(0) }
|
127
|
+
|
128
|
+
it 'responds to bolt_run_task' do
|
129
|
+
expect(dummy_class).to respond_to(:run_bolt_task).with(2..3).arguments
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when bolt returns success' do
|
133
|
+
it 'does bolt_task_run gives no runtime error for success' do
|
134
|
+
allow(ENV).to receive(:[]).with('TARGET_HOST').and_return('some.host')
|
135
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
136
|
+
expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_success)
|
137
|
+
expect { dummy_class.run_bolt_task(task_name, params, opts: {}) }.not_to raise_error
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when bolt returns failure' do
|
142
|
+
it 'does bolt_task_run gives runtime error for failure' do
|
143
|
+
allow(ENV).to receive(:[]).with('TARGET_HOST').and_return('some.host')
|
144
|
+
expect(dummy_class).to receive(:inventory_hash_from_inventory_file).and_return(inventory_hash)
|
145
|
+
expect(dummy_class).to receive(:run_task).with(task_name, 'some.host', params, config: config_data, inventory: inventory_hash).and_return(result_failure)
|
146
|
+
expect { dummy_class.run_bolt_task(task_name, params, opts: {}) }.to raise_error(RuntimeError, %r{task failed})
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
82
150
|
end
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bolt
|
@@ -110,7 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.7.7
|
114
115
|
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: Providing a simple command line tool for puppet content creators, to enable
|