Skip to content
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

FIX: dry run issues with config mode check #17

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

ZLLentz
Copy link
Member

@ZLLentz ZLLentz commented Mar 15, 2024

Description

  • Skip the "CONFIG" mode check when running in dry run mode
  • Add a checkbox to the pre-merge checklist for verifying the script still works in dry_run mode

Motivation and Context

  • dry_run runs no code on the target plc
  • therefore, dry_run skips running the config mode check
  • therefore, the assert always fails and you cannot run in dry_mode at all
  • so, we use the built-in ansible_check_mode variable to bypass the assert for use in dry_run mode
  • also add a checklist item so next time I remember to test using dry_run

How Has This Been Tested?

Interactively.
Before PR, dry_run script:

PLAY [plc-tst-bsd2] **************************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Verify connectivity with ping] *********************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Run PLC mode command] ******************************************************************************************************************************************************************************************************************************************************************
skipping: [plc-tst-bsd2]

TASK [Assert that PLC is in CONFIG mode] *****************************************************************************************************************************************************************************************************************************************************
fatal: [plc-tst-bsd2]: FAILED! => {"assertion": false, "changed": false, "evaluated_to": false, "msg": "PLC is in RUN mode! Abort!"}

After PR, dry_run script:

PLAY [plc-tst-bsd2] **************************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Verify connectivity with ping] *********************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Run PLC mode command] ******************************************************************************************************************************************************************************************************************************************************************
skipping: [plc-tst-bsd2]

TASK [Assert that PLC is in CONFIG mode] *****************************************************************************************************************************************************************************************************************************************************
skipping: [plc-tst-bsd2]

After PR, provision script (plc is in config):

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Verify connectivity with ping] *********************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Run PLC mode command] ******************************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Assert that PLC is in CONFIG mode] *****************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

After PR, provision script (plc is in run):

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Verify connectivity with ping] *********************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Run PLC mode command] ******************************************************************************************************************************************************************************************************************************************************************
ok: [plc-tst-bsd2]

TASK [Assert that PLC is in CONFIG mode] *****************************************************************************************************************************************************************************************************************************************************
fatal: [plc-tst-bsd2]: FAILED! => {"assertion": false, "changed": false, "evaluated_to": false, "msg": "PLC is in RUN mode! Abort!"}

Where Has This Been Documented?

Added notes about implementing tasks for dry run mode at the bottom of https://confluence.slac.stanford.edu/display/PCDS/TcBSD+Ansible+Workflows

Pre-merge checklist

@ZLLentz
Copy link
Member Author

ZLLentz commented Mar 15, 2024

One more thing to decide before review: I just remembered that you can also force a task to run even in check/dry_run mode. Maybe it's prudent to just always run the config mode check, and even skip the dry run if we're in run mode? Or maybe it's helpful to be able to run dry_run on a running PLC?

@ZLLentz
Copy link
Member Author

ZLLentz commented Mar 15, 2024

After lunchtime pondering I think being able to dry_run on a prod PLC is a good thing, so I think as-implemented is correct.

@ZLLentz ZLLentz marked this pull request as ready for review March 15, 2024 20:20
@ZLLentz ZLLentz requested review from ghalym and nrwslac March 15, 2024 20:21
@ZLLentz ZLLentz changed the title FIX: dry run issues with mode check FIX: dry run issues with config mode check Mar 15, 2024
Copy link

@nrwslac nrwslac left a comment

Choose a reason for hiding this comment

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

Looks like ansible_check_mode is set internally by Ansible. The task then will only run when this flag is false. lgtm

@ZLLentz ZLLentz merged commit 6d1f0e0 into pcdshub:master Mar 18, 2024
1 check passed
@ZLLentz ZLLentz deleted the fix_dry_run branch March 18, 2024 16:38
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.

2 participants