Skip to content

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

Merged
Ch3LL merged 3 commits into
saltstack:masterfrom
asomers:cron-antispecial
Jul 19, 2022
Merged

Allow cron.present to change a timespec from non-special to special#60998
Ch3LL merged 3 commits into
saltstack:masterfrom
asomers:cron-antispecial

Conversation

@asomers

@asomers asomers commented Oct 4, 2021

Copy link
Copy Markdown
Contributor

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

asomers commented Oct 5, 2021

Copy link
Copy Markdown
Contributor Author

The test failure looks unrelated to this PR.

@asomers

asomers commented Nov 9, 2021

Copy link
Copy Markdown
Contributor Author

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

@asomers

asomers commented Dec 7, 2021

Copy link
Copy Markdown
Contributor Author

rebased @twangboy

@garethgreenaway

Copy link
Copy Markdown
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

@twangboy twangboy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needs a changelog

@asomers

asomers commented Mar 29, 2022

Copy link
Copy Markdown
Contributor Author

Rebased and changelog added, @twangboy @garethgreenaway

@garethgreenaway

Copy link
Copy Markdown
Contributor

re-run all

Comment thread salt/states/cron.py Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 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