Please review pull request #582: (#3452) Autorequire user for cron opened by (pcarlisle)
Description:
If you specify a “user” on a cron entry, it ought to be automatically
required.
- Opened: Thu Mar 15 19:58:22 UTC 2012
- Based on: puppetlabs:master (0a96a8ec5cb74ab661b690988fb72c9aae725499)
- Requested merge: pcarlisle:tickets/master/3452 (50ac0dff189bbb66cb9c5fda41c6be78667fe14c)
Diff follows:
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index 40f9fe8..a742a17 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -358,6 +358,11 @@ def should_to_s(newvalue = @should)
}
end
+ # Autorequire the owner of the crontab entry.
+ autorequire(:user) do
+ self[:user]
+ end
+
newproperty(:target) do
desc "Where the cron job should be stored. For crontab-style
entries this is the same as the user and defaults that way.
diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb
index 8216a5b..7adafff 100755
--- a/spec/unit/type/cron_spec.rb
+++ b/spec/unit/type/cron_spec.rb
@@ -34,7 +34,8 @@
end
- describe "when validating attribute" do
+ describe "when validating values" do
+
describe "ensure" do
it "should support present as a value for ensure" do
proc { described_class.new(:name => 'foo', :ensure => :present) }.should_not raise_error
@@ -459,6 +460,25 @@
end
end
+ describe "when autorequiring resources" do
+
+ before :each do
+ @user_bob = Puppet::Type.type(:user).new(:name => 'bob', :ensure => :present)
+ @user_alice = Puppet::Type.type(:user).new(:name => 'alice', :ensure => :present)
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.add_resource @user_bob, @user_alice
+ end
+
+ it "should autorequire the user" do
+ @resource = described_class.new(:name => 'dummy', :command => '/usr/bin/uptime', :user => 'alice')
+ @catalog.add_resource @resource
+ req = @resource.autorequire
+ req.size.should == 1
+ req[0].target.must == @resource
+ req[0].source.must == @user_alice
+ end
+ end
+
it "should require a command when adding an entry" do
entry = described_class.new(:name => "test_entry", :ensure => :present)
expect { entry.value(:command) }.should raise_error(Puppet::Error, /No command/)
-- 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.
