Skip to content

Allow cron.present to change a timespec from non-special to special #60998

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

Merged
merged 3 commits into from
Jul 19, 2022

Conversation

asomers
Copy link
Contributor

@asomers asomers commented Oct 4, 2021

What does this PR do?

Previously when changing a cron.present job from using a normal time
specification to special or vice-versa, it would duplicate the entry in
the crontab.

What issues does this PR fix or reference?

Fixes: #60997

Previous Behavior

cron.present would duplicate cron jobs when changing timespec from non-special to special

New Behavior

cron.present will delete the old non-special cronjob when creating a special one with the same identifier

Merge requirements satisfied?

Commits signed with GPG?

Yes

@asomers asomers requested a review from a team as a code owner October 4, 2021 18:35
@asomers asomers requested review from twangboy and removed request for a team October 4, 2021 18:35
@asomers asomers force-pushed the cron-antispecial branch 2 times, most recently from 369c7e1 to e52d0f0 Compare October 4, 2021 18:49
@asomers
Copy link
Contributor Author

asomers commented Oct 5, 2021

The test failure looks unrelated to this PR.

@asomers
Copy link
Contributor Author

asomers commented Nov 9, 2021

ping @twangboy would you be able to review this PR sometime?

@asomers
Copy link
Contributor Author

asomers commented Dec 7, 2021

rebased @twangboy

@garethgreenaway
Copy link
Contributor

@asomers Looks good. Can you please add a changelog to this PR? Thanks!

@garethgreenaway garethgreenaway added the Sulfur v3006.0 release code name and version label Mar 29, 2022
twangboy
twangboy previously approved these changes Mar 29, 2022
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

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

Needs a changelog

@asomers
Copy link
Contributor Author

asomers commented Mar 29, 2022

Rebased and changelog added, @twangboy @garethgreenaway

@garethgreenaway
Copy link
Contributor

re-run all

@@ -355,6 +355,9 @@ def present(
return ret

if special is None:
antidata = __salt__["cron.rm_special"](
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer the logic be in the set_job and set_special functions. Those functions do some logic to see what is currently set in the crontab and see if there is a difference. We should be able to add the logic in those functions to determine if there needs to be an update instead of removing it first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can change it. However, I just discovered that all of the mock expectations in tests/unit/modules/test_cron.py are broken, so I'll have to fix that entire file first. Sigh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ch3LL I made your requested change. And it turned out that only one of the existing modules/cron tests needed fixing.

asomers added 2 commits July 15, 2022 15:36
Previously when changing a cron.present job from using a normal time
specification to special or vice-versa, it would duplicate the entry in
the crontab.
The original assertion used "mock_method.call_args.assert_called_with",
which does nothing at all.  Correct usage is either
"mock_method.call_args == ..." or "mock_method.assert_called_with(...)"
@asomers asomers force-pushed the cron-antispecial branch from d84dd96 to 051af4e Compare July 15, 2022 21:40
This allows the cron.set_job and cron.set_special commands to change
cron entries from special to non-special or vise-versa.  It also removes
all changes to states/cron from this PR's original commit, while
retaining the behavioral changes to the cron.present state
@asomers asomers force-pushed the cron-antispecial branch from 051af4e to 54ac70f Compare July 15, 2022 21:49
@Ch3LL Ch3LL merged commit c6ddf5d into saltstack:master Jul 19, 2022
@asomers asomers deleted the cron-antispecial branch July 19, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-changelog-file Sulfur v3006.0 release code name and version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] cron.present duplicates entries when changing timespec to special
4 participants