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

feat: Add additional error handling to some upgrade assurance modules #561

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions plugins/modules/panos_readiness_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@

try:
from panos_upgrade_assurance.check_firewall import CheckFirewall
from panos_upgrade_assurance.exceptions import UpdateServerConnectivityException
from panos_upgrade_assurance.firewall_proxy import FirewallProxy
except ImportError:
pass
Expand Down Expand Up @@ -180,14 +181,24 @@ def main():
checks = CheckFirewall(
node=firewall, skip_force_locale=module.params["skip_force_locale"]
)
results = checks.run_readiness_checks(checks_configuration=module.params["checks"])

if module.params["force_fail"]:
for check in list(results.keys()):
if results[check]["state"]:
del results[check]
else:
module_failed = True

try:
results = checks.run_readiness_checks(
checks_configuration=module.params["checks"]
)
except UpdateServerConnectivityException as exc:
results["active_support"] = {
"state": False,
"reason": getattr(exc, "message", repr(exc)),
}
module_failed = True
else:
if module.params["force_fail"]:
for check in list(results.keys()):
if results[check]["state"]:
del results[check]
else:
module_failed = True

module.exit_json(changed=False, response=results, failed=module_failed)

Expand Down
12 changes: 8 additions & 4 deletions plugins/modules/panos_snapshot_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
try:
import panos_upgrade_assurance
from panos_upgrade_assurance.snapshot_compare import SnapshotCompare
from panos_upgrade_assurance.exceptions import SnapshotSchemeMismatchException
except ImportError:
PUA_AVAILABLE = False
pass
Expand Down Expand Up @@ -198,10 +199,13 @@ def main():
)
)

results = SnapshotCompare(
left_snapshot=module.params["left_snapshot"],
right_snapshot=module.params["right_snapshot"],
).compare_snapshots(reports=module.params["reports"])
try:
results = SnapshotCompare(
left_snapshot=module.params["left_snapshot"],
right_snapshot=module.params["right_snapshot"],
).compare_snapshots(reports=module.params["reports"])
except SnapshotSchemeMismatchException as exc:
module.fail_json(msg=getattr(exc, "message", repr(exc)))

module.exit_json(changed=False, response=results)

Expand Down
Loading