Skip to content

Commit 73bc852

Browse files
authored
Merge pull request #169 from da-ar/FM-7867
(FM-7867) Always throw when transport schema validation fails
2 parents d7091b4 + 33db655 commit 73bc852

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ group :tests do
1616
# unless we're dealing with jruby...
1717
if RUBY_PLATFORM == 'java'
1818
# load any rubocop version that works on java for the Rakefile
19-
gem 'rubocop'
19+
gem 'rubocop', '0.41.2'
2020
elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')
2121
gem 'rubocop', '0.57.2'
2222
# the last version of parallel to support ruby 2.1

lib/puppet/resource_api/type_definition.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def validate(resource)
6363
error_msg = "The following mandatory attributes were not provided:\n * " + missing_attrs.join(", \n * ")
6464
raise Puppet::ResourceError, error_msg if missing_attrs.any?
6565
end
66+
67+
def notify_schema_errors(message)
68+
raise Puppet::DevError, message
69+
end
6670
end
6771

6872
# Base RSAPI schema Object
@@ -144,6 +148,10 @@ def check_schema(resource, message_prefix = nil)
144148

145149
return if rejected_keys.empty? && bad_values.empty?
146150

151+
notify_schema_errors(message)
152+
end
153+
154+
def notify_schema_errors(message)
147155
if Puppet.settings[:strict] == :off
148156
Puppet.debug(message)
149157
elsif Puppet.settings[:strict] == :warning

spec/acceptance/transport/transport_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ def is_device_apply_supported?
5757
f.write 'notify { "foo": }'
5858
f.close
5959

60-
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
60+
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
61+
expect(status.exitstatus).to eq 0
6162
expect(stdout_str).not_to match %r{Value type mismatch}
63+
expect(stdout_str).not_to match %r{Error}
6264

6365
expect(stdout_str).to match %r{transport connection_info:}
6466
expect(stdout_str).to match %r{:username=>"foo"}
@@ -88,12 +90,15 @@ def is_device_apply_supported?
8890
f.write 'notify { "foo": }'
8991
f.close
9092

91-
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
93+
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
94+
expect(stdout_str).to match %r{Error}
9295
expect(stdout_str).to match %r{Value type mismatch}
9396
expect(stdout_str).to match %r{secret_string: << redacted value >> }
9497
expect(stdout_str).not_to match %r{optional_secret}
9598
expect(stdout_str).not_to match %r{array_secret}
9699
expect(stdout_str).not_to match %r{variant_secret}
100+
101+
expect(status.exitstatus).to eq 1
97102
end
98103
end
99104
end
@@ -116,12 +121,15 @@ def is_device_apply_supported?
116121
f.write 'notify { "foo": }'
117122
f.close
118123

119-
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
124+
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
125+
expect(stdout_str).to match %r{Error}
120126
expect(stdout_str).to match %r{Value type mismatch}
121127
expect(stdout_str).not_to match %r{secret_string }
122128
expect(stdout_str).to match %r{optional_secret: << redacted value >>}
123129
expect(stdout_str).not_to match %r{array_secret}
124130
expect(stdout_str).not_to match %r{variant_secret}
131+
132+
expect(status.exitstatus).to eq 1
125133
end
126134
end
127135
end
@@ -144,12 +152,15 @@ def is_device_apply_supported?
144152
f.write 'notify { "foo": }'
145153
f.close
146154

147-
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
155+
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
156+
expect(stdout_str).to match %r{Error}
148157
expect(stdout_str).to match %r{Value type mismatch}
149158
expect(stdout_str).not_to match %r{secret_string }
150159
expect(stdout_str).not_to match %r{optional_secret}
151160
expect(stdout_str).to match %r{array_secret: << redacted value >>}
152161
expect(stdout_str).not_to match %r{variant_secret}
162+
163+
expect(status.exitstatus).to eq 1
153164
end
154165
end
155166
end
@@ -172,12 +183,15 @@ def is_device_apply_supported?
172183
f.write 'notify { "foo": }'
173184
f.close
174185

175-
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
186+
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
187+
expect(stdout_str).to match %r{Error}
176188
expect(stdout_str).to match %r{Value type mismatch}
177189
expect(stdout_str).not_to match %r{secret_string }
178190
expect(stdout_str).not_to match %r{optional_secret}
179191
expect(stdout_str).not_to match %r{array_secret}
180192
expect(stdout_str).to match %r{variant_secret: << redacted value >>}
193+
194+
expect(status.exitstatus).to eq 1
181195
end
182196
end
183197
end

spec/puppet/resource_api/transport_schema_def_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@
4242
it { expect { type.validate(resource) }.not_to raise_error }
4343
end
4444
end
45+
46+
describe '#notify_schema_errors' do
47+
context 'when a message is received ' do
48+
let(:message) { 'Missing attribute: foo' }
49+
50+
it 'raises an error with the supplied message' do
51+
expect { type.notify_schema_errors(message) }.to raise_error Puppet::DevError, message
52+
end
53+
end
54+
end
4555
end

0 commit comments

Comments
 (0)