Skip to content

Fix bug for crontab feature when user's cron table is empty#690

Merged
gsketefian merged 2 commits into
ufs-community:developfrom
gsketefian:bugfix/empty_crontab
Mar 4, 2022
Merged

Fix bug for crontab feature when user's cron table is empty#690
gsketefian merged 2 commits into
ufs-community:developfrom
gsketefian:bugfix/empty_crontab

Conversation

@gsketefian
Copy link
Copy Markdown
Collaborator

@gsketefian gsketefian commented Mar 4, 2022

DESCRIPTION OF CHANGES:

When a user's cron table is empty, the get_crontab_contents function does not set the return variable properly due to a bug in the way printf -v ... is called towards the end of that function. This PR fixes that bug as well as some others found after testing with an initially empty user cron table.

TESTS CONDUCTED:

On Hera, Jet, and Cheyenne, ran the WE2E test deactivate_tasks, starting with both an empty cron table and a non-empty one. All tests passed with the cron table being modified properly at the start and end of the test.

CONTRIBUTORS (optional):

@chan-hoo pointed out this error on Hera.

1) Fix calls to "printf" command by including the "%s" formatting string.  Otherwise, if the user's cron table is empty, the crontab_contents variable is undefined and causes scripts to crash.
2) Use "printf" instead of "echo" in manipulating crontab contents because "echo" adds a newline at the end of its output even if the variable to be printed out is empty.
…e; otherwise, the crontab command will fail on Cheyenne. Also, indent comments for consistency.
#
printf -v ${outvarname_crontab_cmd} "${__crontab_cmd__}"
printf -v ${outvarname_crontab_contents} "${__crontab_contents__}"
printf -v ${outvarname_crontab_cmd} "%s" "${__crontab_cmd__}"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These printf -v commands contain the original bug found by @chan-hoo.

@gsketefian
Copy link
Copy Markdown
Collaborator Author

@chan-hoo Can you test again on Hera as well as on WCOSS_DELL_P3? Thanks.

@chan-hoo
Copy link
Copy Markdown
Collaborator

chan-hoo commented Mar 4, 2022

@gsketefian, it worked well on Hera as well as on the wcoss dell.

Copy link
Copy Markdown
Contributor

@christinaholtNOAA christinaholtNOAA left a comment

Choose a reason for hiding this comment

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

This looks pretty straightforward.

@gsketefian
Copy link
Copy Markdown
Collaborator Author

@chan-hoo @christinaholtNOAA Thanks for reviewing. Merging now.

@gsketefian gsketefian merged commit d75a058 into ufs-community:develop Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants