summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-05-04 19:46:35 -0700
committerGitHub <noreply@github.com>2020-05-04 19:46:35 -0700
commit8e33745aa0ab1610388f9539e51472d8181d4a08 (patch)
tree8243062f595bf369a411836913d1143c38b5f09a
parent3eef7a1befa2ef5883f047fea5d2a2c5eee36948 (diff)
parentefb1e88fb848777144709680298a0761f294ebad (diff)
downloadchef-8e33745aa0ab1610388f9539e51472d8181d4a08.tar.gz
Merge pull request #9794 from chef/cron_d
Fix failures in the cron_d resource :remove action
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_cron.rb67
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/default.rb15
-rw-r--r--lib/chef/resource/cron_d.rb12
3 files changed, 79 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..545d895869
--- /dev/null
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_cron.rb
@@ -0,0 +1,67 @@
+#
+# 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"
+ command "/bin/true"
+ action :create
+end
+
+cron_d "name_of_cron_entry" do
+ minute "0"
+ hour "20"
+ day "*"
+ month "11"
+ weekday "1-5"
+ command "/bin/true"
+ 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..a3225c8fdb 100644
--- a/lib/chef/resource/cron_d.rb
+++ b/lib/chef/resource/cron_d.rb
@@ -60,6 +60,7 @@ class Chef
hour '8'
weekday '6'
mailto 'admin@example.com'
+ command "/bin/true"
action :create
end
```
@@ -73,9 +74,18 @@ class Chef
day '*'
month '11'
weekday '1-5'
+ command "/bin/true"
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 +130,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.",