Previously, if a cron entry had "ensure => absent" with no command specified
and the crontab contained unmanaged entries, the entry would fail to be removed
and every other cron entry in the catalog after it would be duplicated.

Paired-With: Jesse Wolfe

Signed-off-by: Nick Lewis <n...@puppetlabs.com>
---
Local-branch: ticket/next/775
 lib/puppet/provider/cron/crontab.rb |    8 +-------
 lib/puppet/type/cron.rb             |    2 +-
 spec/unit/type/cron_spec.rb         |   10 ++++++++++
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/lib/puppet/provider/cron/crontab.rb 
b/lib/puppet/provider/cron/crontab.rb
index 8a347b3..a554363 100755
--- a/lib/puppet/provider/cron/crontab.rb
+++ b/lib/puppet/provider/cron/crontab.rb
@@ -11,13 +11,7 @@ tab = case Facter.value(:operatingsystem)
 
 
 
-      Puppet::Type.type(:cron).provide(
-        :crontab,
-  :parent => Puppet::Provider::ParsedFile,
-  :default_target => ENV["USER"] || "root",
-        
-  :filetype => tab
-) do
+Puppet::Type.type(:cron).provide(:crontab, :parent => 
Puppet::Provider::ParsedFile, :default_target => ENV["USER"] || "root", 
:filetype => tab) do
   commands :crontab => "crontab"
 
   text_line :comment, :match => %r{^#}, :post_parse => proc { |record|
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index 4f6ea73..5083ca5 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -395,7 +395,7 @@ Puppet::Type.newtype(:cron) do
     unless ret
       case name
       when :command
-        devfail "No command, somehow"
+        devfail "No command, somehow" unless @parameters[:ensure].value == 
:absent
       when :special
         # nothing
       else
diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb
index 75cc0d4..e98529c 100755
--- a/spec/unit/type/cron_spec.rb
+++ b/spec/unit/type/cron_spec.rb
@@ -478,4 +478,14 @@ describe Puppet::Type.type(:cron) do
     end
 
   end
+
+  it "should require a command when adding an entry" do
+    entry = @class.new(:name => "test_entry", :ensure => :present)
+    expect { entry.value(:command) }.should raise_error(/No command/)
+  end
+
+  it "should not require a command when removing an entry" do
+    entry = @class.new(:name => "test_entry", :ensure => :absent)
+    entry.value(:command).should == nil
+  end
 end
-- 
1.7.4.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to