Skip to content

(MODULES-3529) add deprecation function #617

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 1 commit into from
Jul 18, 2016

Conversation

tphoney
Copy link
Contributor

@tphoney tphoney commented Jul 5, 2016

No description provided.

@tphoney tphoney force-pushed the add_deprecate_function branch 3 times, most recently from 3523142 to ff30448 Compare July 5, 2016 12:44
@tphoney tphoney changed the title {WIP} add deprecation function add deprecation function Jul 5, 2016
@tphoney tphoney force-pushed the add_deprecate_function branch from ff30448 to 294d7f8 Compare July 5, 2016 12:53
@@ -289,6 +289,10 @@ Deletes all instances of a given value from a hash. For example, `delete_values(

Deletes all instances of the undef value from an array or hash. For example, `$hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})` returns {a => 'A', b => '', d => false}. *Type*: rvalue.

#### `deprecation`

Function to print deprecation warnings, it will display a provided message as well as the caller. The deprecation message will only be displayed once per caller. It is affected by the puppet setting 'strict', which can be set to :error, :off and :warning (default) *Type*: String.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't tell reader how strict affects the function.

@tphoney tphoney force-pushed the add_deprecate_function branch from 294d7f8 to a73e6ff Compare July 5, 2016 13:39
module Stdlib
class DeprecationState
# This is so we display one message per caller
@@deprecation_warning_said = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good - no @@vars please - they hold on to the data forever.

@hlindberg
Copy link
Contributor

There is yet another possibility - there is a migration support class that can be used to report issues during runtime in a more structured way. That API is then used by the catalog preview tool to collect and present issues. That makes it a lot easier to do migration of old code. In 3.8, that API has a fairly rich set of methods. They are mostly removed in 4.x. It is possible to introduce new methods akin to the 3.8.x -> 4.x migration checks. The result of using the migration checking issues makes it possible to offer a better user experience than just "stuff logged with messages".

@tphoney
Copy link
Contributor Author

tphoney commented Jul 5, 2016

@hlindberg @DavidS I think that your last recommendation about using catalog_preview may be outside of our requirements.

I have a question: if Puppet.settings[:strict] = :error, what logging / error method would you recommend i use. http://www.rubydoc.info/gems/puppet/4.4.1/Puppet/Util/Logging
We still only want to display the message once

@tphoney tphoney force-pushed the add_deprecate_function branch from a73e6ff to 290aa49 Compare July 7, 2016 15:00
@tphoney
Copy link
Contributor Author

tphoney commented Jul 7, 2016

@hlindberg @DavidS i have made the suggested changes, what do you think of the README, i pulled in your comments @hlindberg .

@hlindberg
Copy link
Contributor

there is an :err (or is it :error - I mix them up all the time) log level. This level does not cause puppet to fail. The spirit of {{--strict=error}} is that you want the evaluation to actually stop as you would use that level to be pedantic and enforce that all deprecations have been dealt with. I suggest failing in that case rather than just logging an error.

#### `deprecation`

Function to print deprecation warnings, Logs a (non deprecation) warning once for a given key. A key, that can be used to denote this particular type of deprecation (for instance also adding it to disabled_warnings). The second is the uniqueness key - in the example, the deprecation can appear once per module name. The msg is the message text including any positional information that is formatted by the user/caller of the method It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message), :off (no message / error is displayed) and :warning (default, outputs a warning) *Type*: String, String, String.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding to disabled_warnings requires an update to puppet as it lists all keys that can be disabled - so that part will not work without a change to that setting in puppet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is very unfortunate, as we hoped to expose this functionality to the user. Specifically, allowing them(us) to specify finegrained deprecations, at least at the module level.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually what I said is misleading, the first parameter kind to warn once, is the key to disabled_warnings. So, kind can be set to 'deprecation' which means it can be disabled. Here is an example from puppet source: Puppet.warn_once('deprecation', 'symbol_comparison', 'Comparing Symbols to non-Symbol values is deprecated'). If a new kind is wanted and that it is also wanted to be able to disable that kind then puppet must be updated. (It would not be unreasonable to support any kind in the disable_warnings (with the only downside that typos will not be caught)).

@tphoney tphoney force-pushed the add_deprecate_function branch from 290aa49 to 80a7374 Compare July 8, 2016 11:18
@DavidS
Copy link
Contributor

DavidS commented Jul 8, 2016

Given the vague descriptions of the core infrastructure we're using here, a few integration tests exercising the whole stack would be great.

Also, please put the ticket number in the Commit and PR title for automatic linking to JIRA.

@tphoney tphoney force-pushed the add_deprecate_function branch from 80a7374 to d222e4c Compare July 8, 2016 12:33
@tphoney
Copy link
Contributor Author

tphoney commented Jul 8, 2016

@hlindberg @DavidS changes made.

@tphoney tphoney force-pushed the add_deprecate_function branch from d222e4c to 737b39f Compare July 13, 2016 15:22
@tphoney tphoney changed the title add deprecation function (MODULES-3529) add deprecation function Jul 13, 2016
@tphoney
Copy link
Contributor Author

tphoney commented Jul 13, 2016

@DavidS i didnt know you were pointing that comment at me. What you mean by full stack testing ?

@DavidS
Copy link
Contributor

DavidS commented Jul 14, 2016

@tphoney tphoney force-pushed the add_deprecate_function branch from 737b39f to 6cdd86c Compare July 14, 2016 17:33
@tphoney
Copy link
Contributor Author

tphoney commented Jul 15, 2016

@DavidS i changed the check for puppet4 in the acceptance test to

if: get_puppet_version =~ /^4/ do
following other acceptance tests.

@DavidS
Copy link
Contributor

DavidS commented Jul 15, 2016

@tphoney please apply shellquoting and then fix the fialing tests:

diff --git a/spec/acceptance/deprecation_spec.rb b/spec/acceptance/deprecation_spec.rb
index 54cdfdb..4215e6c 100644
--- a/spec/acceptance/deprecation_spec.rb
+++ b/spec/acceptance/deprecation_spec.rb
@@ -1,5 +1,6 @@
 #! /usr/bin/env ruby -S rspec
 require 'spec_helper_acceptance'
+require 'shellwords'

 describe 'deprecation function' do
   before :each do
@@ -12,7 +13,7 @@ describe 'deprecation function' do
       deprecation('key', 'message')
       file { '/tmp/deprecation': ensure => present }
       EOS
-      @result = on(default, puppet('apply', '--strict=error', '-e', pp), acceptable_exit_codes: (0...256))
+      @result = on(default, puppet('apply', '--strict=error', '-e', Shellwords.shellescape(pp)), acceptable_exit_codes: (0...256))
     end

     it "should return an error" do
@@ -34,7 +35,7 @@ describe 'deprecation function' do
       deprecation('key', 'message')
       file { '/tmp/deprecation': ensure => present }
       EOS
-      @result = on(default, puppet('apply', '--strict=warning', '-e', pp), acceptable_exit_codes: (0...256))
+      @result = on(default, puppet('apply', '--strict=warning', '-e', Shellwords.shellescape(pp)), acceptable_exit_codes: (0...256))
     end

     it "should not return an error" do
@@ -56,7 +57,7 @@ describe 'deprecation function' do
       deprecation('key', 'message')
       file { '/tmp/deprecation': ensure => present }
       EOS
-      @result = on(default, puppet('apply', '--strict=off', '-e', pp), acceptable_exit_codes: (0...256))
+      @result = on(default, puppet('apply', '--strict=off', '-e', Shellwords.shellescape(pp)), acceptable_exit_codes: (0...256))
     end

     it "should not return an error" do

@tphoney tphoney force-pushed the add_deprecate_function branch from 6cdd86c to 8d83b43 Compare July 15, 2016 15:10
@tphoney
Copy link
Contributor Author

tphoney commented Jul 15, 2016

@DavidS boom !

@DavidS
Copy link
Contributor

DavidS commented Jul 15, 2016

retriggered jenkins to pickup the new beaker version

@tphoney tphoney force-pushed the add_deprecate_function branch from 8d83b43 to 72d2365 Compare July 18, 2016 10:58
@tphoney
Copy link
Contributor Author

tphoney commented Jul 18, 2016

@DavidS tests are now passing

@DavidS DavidS merged commit 01bc41e into puppetlabs:master Jul 18, 2016
@DavidS
Copy link
Contributor

DavidS commented Jul 18, 2016

Wohoo!! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants