Please review pull request #537: (#12357) Fix cron type default name error on windows opened by (jeffmccune)
Description:
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)returnsnil. This patch fixes
the problem by binding the object returned byEtc.getpwuid(Process.uid)to a variable. We then check if the
variable responds to thenamemethod, 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
- Opened: Tue Feb 28 23:03:11 UTC 2012
- Based on: puppetlabs:master (04c6a22e02e9fe02aec30cd8749b08aeca328488)
- Requested merge: jeffmccune:ticket/2.7.x/12357_make_pe_modules_safe_on_windows (2189dc15c7ae4cbf06f893c68cd924e1329e3c72)
Diff follows:
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index adf502b..40f9fe8 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -352,7 +352,10 @@ def should_to_s(newvalue = @should)
The user defaults to whomever Puppet is running as."
- defaultto { Etc.getpwuid(Process.uid).name || "root" }
+ defaultto {
+ struct = Etc.getpwuid(Process.uid)
+ struct.respond_to?(:name) && struct.name or 'root'
+ }
end
newproperty(:target) do
diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb
index 0a82e30..8216a5b 100755
--- a/spec/unit/type/cron_spec.rb
+++ b/spec/unit/type/cron_spec.rb
@@ -468,4 +468,10 @@
entry = described_class.new(:name => "test_entry", :ensure => :absent)
entry.value(:command).should == nil
end
+
+ it "should default to user => root if Etc.getpwuid(Process.uid) returns nil (#12357)" do
+ Etc.expects(:getpwuid).returns(nil)
+ entry = described_class.new(:name => "test_entry", :ensure => :present)
+ entry.value(:user).should eql "root"
+ end
end
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
