summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-05-04 19:08:00 -0700
committerTim Smith <tsmith84@gmail.com>2020-05-04 19:18:29 -0700
commitef16c85f47cb1fc5684cc7731c32c161626fee6d (patch)
tree5ed757da9ced6238b2611208f32e011873a23424
parent3eef7a1befa2ef5883f047fea5d2a2c5eee36948 (diff)
downloadchef-ef16c85f47cb1fc5684cc7731c32c161626fee6d.tar.gz
Fix failurs in the cron_d resource :remove action
Add kitchen testing for the cron resources Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_cron.rb65
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/default.rb15
-rw-r--r--lib/chef/resource/cron_d.rb10
3 files changed, 75 insertions, 15 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_cron.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_cron.rb
new file mode 100644
index 0000000000..af55c15090
--- /dev/null
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_cron.rb
@@ -0,0 +1,65 @@
+#
+# Cookbook:: end_to_end
+# Recipe:: cron
+#
+
+#
+# cron_d resource
+#
+
+cron_d "noop" do
+ hour "5"
+ minute "0"
+ command "/bin/true"
+end
+
+cron_d "name_of_cron_entry" do
+ minute "0"
+ hour "8"
+ weekday "6"
+ mailto "admin@example.com"
+ action :create
+end
+
+cron_d "name_of_cron_entry" do
+ minute "0"
+ hour "20"
+ day "*"
+ month "11"
+ weekday "1-5"
+ action :create
+end
+
+cron_d "job_to_remove" do
+ action :delete
+end
+
+#
+# cron_access resource
+#
+
+cron_access "alice" do
+ action :allow
+end
+
+cron_access "bob"
+
+# legacy resource name
+cron_manage "Bill breaks things. Take away cron" do
+ user "bill"
+ action :deny
+end
+
+#
+# cron resource
+#
+
+cron "some random cron job" do
+ minute 0
+ hour 23
+ command "/usr/bin/true"
+end
+
+cron "remove_a_job" do
+ action :delete
+end \ No newline at end of file
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/default.rb b/kitchen-tests/cookbooks/end_to_end/recipes/default.rb
index 494d48ec06..8f7d068df5 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/default.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/default.rb
@@ -76,20 +76,6 @@ include_recipe "git"
directory "/etc/ssl"
-cron_access "bob"
-
-cron "some random cron job" do
- minute 0
- hour 23
- command "/usr/bin/true"
-end
-
-cron_d "another random cron job" do
- minute 0
- hour 23
- command "/usr/bin/true"
-end
-
# Generate new key and certificate
openssl_dhparam "/etc/ssl/dhparam.pem" do
key_length 1024
@@ -160,4 +146,5 @@ include_recipe "::_chef-vault" unless includes_recipe?("end_to_end::chef-vault")
include_recipe "::_sysctl"
include_recipe "::_apt_preference"
include_recipe "::_alternatives"
+include_recipe "::_cron"
include_recipe "::_tests"
diff --git a/lib/chef/resource/cron_d.rb b/lib/chef/resource/cron_d.rb
index d06d479cc9..34820820d9 100644
--- a/lib/chef/resource/cron_d.rb
+++ b/lib/chef/resource/cron_d.rb
@@ -76,6 +76,14 @@ class Chef
action :create
end
```
+
+ **Remove a cron job by name**:
+
+ ```ruby
+ cron_d 'job_to_remove' do
+ action :delete
+ end
+ ```
DOC
property :cron_name, String,
@@ -120,7 +128,7 @@ class Chef
property :command, String,
description: "The command to run.",
- required: true
+ required: [:create]
property :user, String,
description: "The name of the user that runs the command.",