Skip to content

(MODULES-3393) Deprecation - Use puppet stacktrace if available #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2016
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
6 changes: 6 additions & 0 deletions lib/puppet/functions/deprecation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
end

def deprecation(key, message)
if defined? Puppet::Pops::PuppetStack.stacktrace()
stacktrace = Puppet::Pops::PuppetStack.stacktrace()
file = stacktrace[0]
line = stacktrace[1]
message = "#{message} at #{file}:#{line}"
end
# depending on configuration setting of strict
case Puppet.settings[:strict]
when :off
Expand Down
17 changes: 17 additions & 0 deletions spec/acceptance/deprecation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,21 @@
it { is_expected.to be_file }
end
end

context 'puppet 3 test', if: get_puppet_version =~ /^3/ do
before :all do
@result = on(default, puppet('apply', '--parser=future', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
end
after :all do
apply_manifest(remove_file_manifest)
end

it "should return a deprecation error" do
expect(@result.stderr).to match(/Warning: message/)
end
it "should pass without error" do
expect(@result.exit_code).to eq(0)
end
end

end
5 changes: 4 additions & 1 deletion spec/functions/deprecation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
}
end
else
# Puppet version < 4 will use these tests.
describe 'deprecation' do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
before(:all) do
ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
end
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }

Expand Down