Pyinfra: sed replace quoting (server.crontab fails to update crontab entry sometimes)

Created on 20 Feb 2021  ยท  7Comments  ยท  Source: Fizzadar/pyinfra

Describe the bug
I have a feeling this is caused by the cron_name param. Basically, if I modify the command param for server.crontab but leave cron_name as is, when the deploy is run, it will consider the task to already be present resulting in a no-op.

To Reproduce

  • Run on host: crontab -r
  • Run the below deploy once and verify the crontab updated.
  • Change the command, and run the below deploy again.
  • The crontab will not have been updated.
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""Deploy to illustrate crontab bug.
"""


###############################################################################
# Imports
###############################################################################


# ==Site-Packages==
from pyinfra.operations import server


###############################################################################
# Main
###############################################################################


server.crontab(
    name="Install test cron task.",
    command="echo 'banana'",
    #  command="echo 'yummy'",
    cron_name="My special task",
    minute="*/10",
)

Expected behavior
The crontab should be updated to reflect the changes to the command.

Meta

โฏ pyinfra --support
--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Darwin
      Platform: macOS-10.14.6-x86_64-i386-64bit
      Release: 18.7.0
      Machine: x86_64
    pyinfra: v1.3.6
    Executable: /Users/----/.virtualenvs/05-hz-pyinfra-d0Faa_8y-py3.9/bin/pyinfra
    Python: 3.9.1 (CPython, Clang 10.0.1 (clang-1001.0.46.4))
Bug Operations

All 7 comments

Nice spot @taranlu-houzz, little bug in checking the command when using cron_name, fixed in https://github.com/Fizzadar/pyinfra/commit/228460d004175ebd539bba641d27773eb955bc40 for release in 1.3.7 shortly!

I'm still seeing this issue on 1.3.7. Did the fix not make it into that release?

It did! Will reopen this to investigate :grimacing:

So it looks like this happens due to a error handling the quotes in the command, for example the following file does change the command correctly:

server.crontab(
    name="Install test cron task.",
    command="echo banana",
    #command="echo yummy",
    cron_name="My special task",
    minute="*/10",
)

Still looking into fixing this; certainly looks like it boils down to the sed_replace function but have no solution yet!

Awesome! Thank you for looking into that! I'll take a look at the next release.

Have now released those fixes in 1.3.9!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harold-b picture harold-b  ยท  3Comments

relaxdiego picture relaxdiego  ยท  3Comments

grybakov picture grybakov  ยท  3Comments

mkinney picture mkinney  ยท  5Comments

MartinThoma picture MartinThoma  ยท  3Comments