Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-6268) Fix error when switching monthly trigger types #17

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/puppet/provider/scheduled_task/taskscheduler_api2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def flush
def triggers_same?(current_trigger, desired_trigger)
return false unless current_trigger['schedule'] == desired_trigger['schedule']
return false if current_trigger.has_key?('enabled') && !current_trigger['enabled']
return false if translate_hash_to_trigger(desired_trigger)['trigger_type'] != translate_hash_to_trigger(current_trigger)['trigger_type']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an unnecessary conversion for 2 reasons:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with @glennsarti, realized that in its current state, we do need to perform the conversion to compare because there are 2 different types of "monthly" schedules.

That said, we identified some room for improvement in the overall flow of trigger hash building / initial resource population and will file a new ticket for refactoring some of that, which will introduce some refactoring here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was finally cleaned up in #38 / particularly as part of refactoring triggers_same? in 2e97281 and d7d218c


desired = desired_trigger.dup
desired['start_date'] ||= current_trigger['start_date'] if current_trigger.has_key?('start_date')
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/provider/scheduled_task/win32_taskscheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def flush
def triggers_same?(current_trigger, desired_trigger)
return false unless current_trigger['schedule'] == desired_trigger['schedule']
return false if current_trigger.has_key?('enabled') && !current_trigger['enabled']
return false if translate_hash_to_trigger(desired_trigger)['trigger_type'] != translate_hash_to_trigger(current_trigger)['trigger_type']

desired = desired_trigger.dup
desired['start_date'] ||= current_trigger['start_date'] if current_trigger.has_key?('start_date')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,15 @@ def time_component
expect(provider).not_to be_triggers_same(current, desired)
end

it 'should not consider triggers with different monthly types to be the same' do
# A trigger of type Win32::TaskScheduler::MONTHLYDATE
current = {'schedule' => 'monthly', 'start_time' => '14:00', 'months' => [1,2,3,4,5,6,7,8,9,10,11,12], 'on' => [9]}
# A trigger of type Win32::TaskScheduler::MONTHLYDOW
desired = {'schedule' => 'monthly', 'start_time' => '14:00', 'which_occurrence' => 'second', 'day_of_week' => ['sat']}

expect(provider).not_to be_triggers_same(current, desired)
end

describe 'start_date' do
it "considers triggers to be equal when start_date is not specified in the 'desired' trigger" do
current = {'schedule' => 'daily', 'start_date' => '2011-09-12', 'start_time' => '15:30', 'every' => 3}
Expand Down