Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
feat: Add additional error handling to some upgrade assurance modules (
Browse files Browse the repository at this point in the history
  • Loading branch information
acelebanski authored May 16, 2024
1 parent 37ab39b commit c64cd79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
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

0 comments on commit c64cd79

Please sign in to comment.