Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ group :tests do
# unless we're dealing with jruby...
if RUBY_PLATFORM == 'java'
# load any rubocop version that works on java for the Rakefile
gem 'rubocop'
gem 'rubocop', '0.41.2'
elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')
gem 'rubocop', '0.57.2'
# the last version of parallel to support ruby 2.1
Expand Down
8 changes: 8 additions & 0 deletions lib/puppet/resource_api/type_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def validate(resource)
error_msg = "The following mandatory attributes were not provided:\n * " + missing_attrs.join(", \n * ")
raise Puppet::ResourceError, error_msg if missing_attrs.any?
end

def notify_schema_errors(message)
raise Puppet::DevError, message
end
end

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

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

notify_schema_errors(message)
end

def notify_schema_errors(message)
if Puppet.settings[:strict] == :off
Puppet.debug(message)
elsif Puppet.settings[:strict] == :warning
Expand Down
24 changes: 19 additions & 5 deletions spec/acceptance/transport/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def is_device_apply_supported?
f.write 'notify { "foo": }'
f.close

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

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

stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
expect(stdout_str).to match %r{Error}
expect(stdout_str).to match %r{Value type mismatch}
expect(stdout_str).to match %r{secret_string: << redacted value >> }
expect(stdout_str).not_to match %r{optional_secret}
expect(stdout_str).not_to match %r{array_secret}
expect(stdout_str).not_to match %r{variant_secret}

expect(status.exitstatus).to eq 1
end
end
end
Expand All @@ -116,12 +121,15 @@ def is_device_apply_supported?
f.write 'notify { "foo": }'
f.close

stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
expect(stdout_str).to match %r{Error}
expect(stdout_str).to match %r{Value type mismatch}
expect(stdout_str).not_to match %r{secret_string }
expect(stdout_str).to match %r{optional_secret: << redacted value >>}
expect(stdout_str).not_to match %r{array_secret}
expect(stdout_str).not_to match %r{variant_secret}

expect(status.exitstatus).to eq 1
end
end
end
Expand All @@ -144,12 +152,15 @@ def is_device_apply_supported?
f.write 'notify { "foo": }'
f.close

stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
expect(stdout_str).to match %r{Error}
expect(stdout_str).to match %r{Value type mismatch}
expect(stdout_str).not_to match %r{secret_string }
expect(stdout_str).not_to match %r{optional_secret}
expect(stdout_str).to match %r{array_secret: << redacted value >>}
expect(stdout_str).not_to match %r{variant_secret}

expect(status.exitstatus).to eq 1
end
end
end
Expand All @@ -172,12 +183,15 @@ def is_device_apply_supported?
f.write 'notify { "foo": }'
f.close

stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
expect(stdout_str).to match %r{Error}
expect(stdout_str).to match %r{Value type mismatch}
expect(stdout_str).not_to match %r{secret_string }
expect(stdout_str).not_to match %r{optional_secret}
expect(stdout_str).not_to match %r{array_secret}
expect(stdout_str).to match %r{variant_secret: << redacted value >>}

expect(status.exitstatus).to eq 1
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/puppet/resource_api/transport_schema_def_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@
it { expect { type.validate(resource) }.not_to raise_error }
end
end

describe '#notify_schema_errors' do
context 'when a message is received ' do
let(:message) { 'Missing attribute: foo' }

it 'raises an error with the supplied message' do
expect { type.notify_schema_errors(message) }.to raise_error Puppet::DevError, message
end
end
end
end