diff options
author | Vasu1105 <vasundhara.jagdale@msystechnologies.com> | 2017-12-18 11:57:04 +0000 |
---|---|---|
committer | Vasu1105 <vasundhara.jagdale@msystechnologies.com> | 2018-01-05 06:38:55 +0000 |
commit | 7fd821058fb94d708e8f2fdc95b26823c1ef92b2 (patch) | |
tree | 92391c4d76d546a7ee456b196f06230e1f6ec02d /lib | |
parent | c6433605bae0a9f52c843ca8cb97e64b2bcf5f0a (diff) | |
download | chef-7fd821058fb94d708e8f2fdc95b26823c1ef92b2.tar.gz |
chef#6638 fixed random_delay and execution_time_limit property not idempotent for windows_task resource
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/windows_task.rb | 18 | ||||
-rw-r--r-- | lib/chef/resource/windows_task.rb | 29 |
2 files changed, 17 insertions, 30 deletions
diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index 02e45cb9e0..dca0156d9c 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -229,8 +229,8 @@ class Chef current_resource.frequency_modifier != new_resource.frequency_modifier || current_resource.frequency != new_resource.frequency || current_resource.idle_time != new_resource.idle_time || - current_resource.random_delay != new_resource.random_delay || - !new_resource.execution_time_limit.include?(current_resource.execution_time_limit) || + random_delay_updated? || + execution_time_limit_updated? || (new_resource.start_day && new_resource.start_day != "N/A" && start_day_updated?) || (new_resource.start_time && new_resource.start_time != "N/A" && start_time_updated?) begin @@ -243,6 +243,20 @@ class Chef false end + def random_delay_updated? + return false if current_resource.random_delay.nil? && new_resource.random_delay.nil? + return true if new_resource.random_delay.nil? + current_resource.random_delay = 0 if current_resource.random_delay.nil? + ISO8601::Duration.new(current_resource.random_delay) != ISO8601::Duration.new(new_resource.random_delay) + end + + def execution_time_limit_updated? + return false if current_resource.execution_time_limit.nil? && new_resource.execution_time_limit.nil? + return true if new_resource.execution_time_limit.nil? + current_resource.execution_time_limit = 0 if current_resource.execution_time_limit.nil? + ISO8601::Duration.new(current_resource.execution_time_limit) != ISO8601::Duration.new(new_resource.execution_time_limit) + end + def start_day_updated? current_day = DateTime.strptime(current_resource.start_day, convert_system_date_format_to_ruby_date_format) new_day = parse_day(new_resource.start_day) diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index f61a119b5a..5ab5715ccf 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -209,34 +209,7 @@ class Chef # @see http://tools.ietf.org/html/rfc2445#section-4.3.6 # @param [Integer] seconds The amount of seconds for this duration def sec_to_dur(seconds) - seconds = seconds.to_i - iso_str = "P" - if seconds > 604_800 # more than a week - weeks = seconds / 604_800 - seconds -= (604_800 * weeks) - iso_str << "#{weeks}W" - end - if seconds > 86_400 # more than a day - days = seconds / 86_400 - seconds -= (86_400 * days) - iso_str << "#{days}D" - end - if seconds >= 0 - iso_str << "T" - if seconds > 3600 # more than an hour - hours = seconds / 3600 - seconds -= (3600 * hours) - iso_str << "#{hours}H" - end - if seconds > 60 # more than a minute - minutes = seconds / 60 - seconds -= (60 * minutes) - iso_str << "#{minutes}M" - end - iso_str << "#{seconds}S" - end - - iso_str + dur = seconds.to_i == 0 ? nil : ISO8601::Duration.new(seconds.to_i).to_s end end |