Skip to content
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

(#12881) Fix cron type default name error on windows #542

Conversation

jeffmccune
Copy link
Contributor

On windows I ran into this error with the cron type:

err: Failed to apply catalog: undefined method 'name' for nil:NilClass

Without this patch, the problem appears to be that the cron type name
parameter defaults to the following block:

defaultto { Etc.getpwuid(Process.uid).name || "root" }

On windows Etc.getpwuid(Process.uid) returns nil. This patch fixes
the problem by binding the object returned by
Etc.getpwuid(Process.uid) to a variable. We then check if the
variable responds to the name method, and only send a message to name
if so. Otherwise, we return "root"

The included spec test will fail if there is a regression in the desired
behavior. The expected failure looks like:

Failures:

  1) Puppet::Type::Cron should default to user => root if Etc.getpwuid(Process.uid) returns nil (#12357)
     Failure/Error: entry = described_class.new(:name => "test_entry", :ensure => :present)
     NoMethodError:
       undefined method `name' for nil:NilClass
     # ./lib/puppet/type/cron.rb:359:in `default'
     # ./lib/puppet/type.rb:540:in `set_default'
     # ./lib/puppet/type.rb:1834:in `set_parameters'
     # ./lib/puppet/type.rb:1833:in `each'
     # ./lib/puppet/type.rb:1833:in `set_parameters'
     # ./lib/puppet/type.rb:1797:in `initialize'
     # ./spec/unit/type/cron_spec.rb:474:in `new'
     # ./spec/unit/type/cron_spec.rb:474

On windows I ran into this error with the cron type:

    err: Failed to apply catalog: undefined method 'name' for nil:NilClass

Without this patch, the problem appears to be that the cron type name
parameter defaults to the following block:

    defaultto { Etc.getpwuid(Process.uid).name || "root" }

On windows `Etc.getpwuid(Process.uid)` returns `nil`.  This patch fixes
the problem by binding the object returned by
`Etc.getpwuid(Process.uid)` to a variable.  We then check if the
variable responds to the `name` method, and only send a message to name
if so.  Otherwise, we return "root"

The included spec test will fail if there is a regression in the desired
behavior.  The expected failure looks like:

    Failures:

      1) Puppet::Type::Cron should default to user => root if Etc.getpwuid(Process.uid) returns nil (#12357)
         Failure/Error: entry = described_class.new(:name => "test_entry", :ensure => :present)
         NoMethodError:
           undefined method `name' for nil:NilClass
         # ./lib/puppet/type/cron.rb:359:in `default'
         # ./lib/puppet/type.rb:540:in `set_default'
         # ./lib/puppet/type.rb:1834:in `set_parameters'
         # ./lib/puppet/type.rb:1833:in `each'
         # ./lib/puppet/type.rb:1833:in `set_parameters'
         # ./lib/puppet/type.rb:1797:in `initialize'
         # ./spec/unit/type/cron_spec.rb:474:in `new'
         # ./spec/unit/type/cron_spec.rb:474
@jeffmccune
Copy link
Contributor Author

Just to be clear on this pull request. The change is intended to replace the painful error message of:

err: Failed to apply catalog: undefined method 'name' for nil:NilClass

With the less painful error message of:

err: Could not find a suitable provider for cron

@joshcooper
Copy link
Contributor

@daniel-pittman I'm okay with this, you?

slippycheeze added a commit that referenced this pull request Mar 2, 2012
…issing_provider_error_message

(#12881) Fix cron type default name error on windows
@slippycheeze slippycheeze merged commit 51a3090 into puppetlabs:2.7rc Mar 2, 2012
melissa pushed a commit to melissa/puppet that referenced this pull request Mar 30, 2018
(PCP-690) Switch to new Solaris LDOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants