summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneha-p6 <neha.pansare@progress.com>2023-01-25 02:19:30 +0530
committerGitHub <noreply@github.com>2023-01-24 15:49:30 -0500
commit18b757c76b270c8a719341d00cda4927a6983a6c (patch)
tree3ddc0b7c7762d836f79fe2fc58357d2d10da5dba
parent23c39c14d305d217431721701bcb83ca43369ea8 (diff)
downloadchef-18b757c76b270c8a719341d00cda4927a6983a6c.tar.gz
Backport https://github.com/chef/chef/pull/13147: Fix false updates on cron resource when using integers (#13523)
Signed-off-by: Neha Pansare <neha.pansare@progress.com>
-rw-r--r--lib/chef/provider/cron.rb6
-rw-r--r--spec/unit/provider/cron_spec.rb34
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb
index 7d37f34b1a..ec8df36998 100644
--- a/lib/chef/provider/cron.rb
+++ b/lib/chef/provider/cron.rb
@@ -88,7 +88,11 @@ class Chef
def cron_different?
CRON_ATTRIBUTES.any? do |cron_var|
- new_resource.send(cron_var) != current_resource.send(cron_var)
+ if new_resource.send(cron_var).class == current_resource.send(cron_var).class
+ new_resource.send(cron_var) != current_resource.send(cron_var)
+ else
+ new_resource.send(cron_var).to_s != current_resource.send(cron_var).to_s
+ end
end
end
diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb
index 76f170312e..3455e3de4f 100644
--- a/spec/unit/provider/cron_spec.rb
+++ b/spec/unit/provider/cron_spec.rb
@@ -724,6 +724,40 @@ describe Chef::Provider::Cron do
end
end
+ context "when integers are provided to the resource to express time values" do
+ it "should not report any difference" do
+ @new_resource.minute(1)
+ @new_resource.hour(1)
+ @new_resource.day(1)
+ @new_resource.month(1)
+ @new_resource.weekday(1)
+ allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB)
+ # Chef Name: cronhole some stuff
+ 1 1 1 1 1 /bin/true
+ CRONTAB
+
+ @provider.run_action(:create)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+ end
+
+ context "when strings are provided to the resource to express time values" do
+ it "should not report any difference" do
+ @new_resource.minute("1")
+ @new_resource.hour("1")
+ @new_resource.day("1")
+ @new_resource.month("1")
+ @new_resource.weekday("1")
+ allow(@provider).to receive(:read_crontab).and_return(<<~CRONTAB)
+ # Chef Name: cronhole some stuff
+ 1 1 1 1 1 /bin/true
+ CRONTAB
+
+ @provider.run_action(:create)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+ end
+
context "when environment variable is used" do
before :each do
@provider.cron_exists = true