Skip to content

Commit

Permalink
Exception handling when restore plugin not supported (#630)
Browse files Browse the repository at this point in the history
* Exception handling when restore plugin not supported

Signed-off-by: rohitthakur2590 <[email protected]>

* update changeog details

Signed-off-by: rohitthakur2590 <[email protected]>

* narrow_down_the_exception

Signed-off-by: rohitthakur2590 <[email protected]>

* check_for_method_not_found

Signed-off-by: rohitthakur2590 <[email protected]>

* check_based_on_err_code

Signed-off-by: rohitthakur2590 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update plugins/modules/cli_restore.py

Co-authored-by: Nilashish Chakraborty <[email protected]>

---------

Signed-off-by: rohitthakur2590 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Nilashish Chakraborty <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent 30eb278 commit 3904237
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/update_not_supported_exception.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- Improved module execution to gracefully handle cases where plugin support is required, providing a clear error message to the user.
- Added guidance for users to open an issue for the respective platform if plugin support is needed.
19 changes: 13 additions & 6 deletions plugins/modules/cli_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@
RETURN = """
"""

from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import Connection
from ansible.module_utils.connection import Connection, ConnectionError


def validate_args(module, device_operations):
Expand Down Expand Up @@ -108,12 +109,18 @@ def main():

result = {"changed": False}
connection = Connection(module._socket_path)
running = connection.restore(
filename=module.params["filename"],
path=module.params["path"],
)
try:
running = connection.restore(
filename=module.params["filename"],
path=module.params["path"],
)
except ConnectionError as exc:
if exc.code == -32601: # Method not found
msg = "This platform is not supported with cli_restore. Please report an issue against this platform's cliconf plugin."
module.fail_json(msg, code=exc.code)
else:
module.fail_json(msg=to_text(exc, errors="surrogate_then_replace").strip())
result["__restore__"] = running

module.exit_json(**result)


Expand Down

0 comments on commit 3904237

Please sign in to comment.