Skip to content

check_mode advertised but not supported #83

Description

@acbk2b

Issue

Background: --check allows users to run a playbook and see the proposed changes without actually executing them - this is essentially for guarding against accidental destructive configuration updates on critical network infrastructure.

All of the cp_gaia_* modules advertise support for Check Mode (i.e. supports_check_mode=True), however the main checkpoint.py module does not incorporate logic for check_mode and runs the associated /set-* or /add-* API regardless of whether the playbook is run with --check.

Fix

checkpoint.py contains the main API functions utilized by all upstream modules, specifically chkp_api_call and chkp_api_operation.
These functions handle several logical trees for different request types, as well as idempotency flows:

  • Value exists and must be removed (i.e. state=absent)
  • Value matches -> no change
  • Value does not match -> run update
  • Maestro special cases

To support check_mode, the logic in these functions needs to be updated to return early, with a diff, rather than running the /set-* or /add-* command.

# EXAMPLE: object exists and needs to be updated
# object exists and would be modified
if module.check_mode:
    after_preview = dict(before)
    after_preview.update(params_for_idempotency)
    return {
        api_call_object.replace('-', '_'): before,
        'diff': {'before': before, 'after': after_preview},
        "changed": True,
    }

Adding diff to the response allows the --diff flag to display the results for the user to view and confirm - this is a very important feature for reviewing changes

I am happy to help contribute a fix for this issue via pull-request.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions