Skip to content

Commit

Permalink
pyinfra/operations: fix crontab comparison
Browse files Browse the repository at this point in the history
The Crontab fact tries to convert numerical values from 'str' to 'int',
but the crontab operation was doing a direct comparison of the values
provided (whether they were strings or ints).

Mimic what the Crontab fact does and use 'try_int' to compare. Also, add
a test to confirm this behaviour doesn't regress.

Signed-off-by: Andrew Dunham <[email protected]>
  • Loading branch information
andrew-d authored and Fizzadar committed Aug 10, 2024
1 parent da9b5ae commit ab3f20c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyinfra/operations/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ def comma_sep(value):
if any(
(
special_time != existing_crontab.get("special_time"),
minute != existing_crontab.get("minute"),
hour != existing_crontab.get("hour"),
month != existing_crontab.get("month"),
day_of_week != existing_crontab.get("day_of_week"),
day_of_month != existing_crontab.get("day_of_month"),
try_int(minute) != existing_crontab.get("minute"),
try_int(hour) != existing_crontab.get("hour"),
try_int(month) != existing_crontab.get("month"),
try_int(day_of_week) != existing_crontab.get("day_of_week"),
try_int(day_of_month) != existing_crontab.get("day_of_month"),
existing_crontab_command != command,
),
):
Expand Down
22 changes: 22 additions & 0 deletions tests/operations/server.crontab/add_existing_int.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"args": ["this_is_a_command"],
"kwargs": {
"minute": "0",
"hour": "0"
},
"facts": {
"server.Crontab": {
"user=None": {
"this_is_a_command": {
"minute": 0,
"hour": 0,
"month": "*",
"day_of_week": "*",
"day_of_month": "*"
}
}
}
},
"commands": [],
"noop_description": "crontab this_is_a_command exists"
}

0 comments on commit ab3f20c

Please sign in to comment.