|
8 | 8 | __metaclass__ = type |
9 | 9 |
|
10 | 10 | import os |
| 11 | +import re |
11 | 12 |
|
12 | 13 | from ansible.module_utils.basic import AnsibleModule |
13 | 14 |
|
@@ -490,7 +491,30 @@ def create_or_update(self): |
490 | 491 | self.client, self.resource_name, self.resource_module_params |
491 | 492 | ) |
492 | 493 | if not ok: |
493 | | - self.return_failure(err) |
| 494 | + if not self.resource_name == "sslhsmkey": |
| 495 | + self.return_failure(err) |
| 496 | + else: |
| 497 | + # sslhsmkey returns errocode 1065 and message |
| 498 | + # "Internal error while adding HSM key" on successful addition |
| 499 | + status_code = None |
| 500 | + errorcode = None |
| 501 | + message = None |
| 502 | + err_str = str(err) |
| 503 | + regex_string = re.search(r'status_code:\s*(\d+)', err_str) |
| 504 | + if regex_string: |
| 505 | + status_code = int(regex_string.group(1)) |
| 506 | + regex_string = re.search(r"'errorcode':\s*(\d+)", err_str) |
| 507 | + if regex_string: |
| 508 | + regex_string = int(regex_string.group(1)) |
| 509 | + regex_string = re.search(r"'message':\s*'([^']+)'", err_str) |
| 510 | + if regex_string: |
| 511 | + message = regex_string.group(1) |
| 512 | + if not ( |
| 513 | + status_code == 599 and |
| 514 | + errorcode == 1065 and |
| 515 | + message == "Internal error while adding HSM key." |
| 516 | + ): |
| 517 | + self.return_failure(err) |
494 | 518 |
|
495 | 519 | # There can be module_params in the playbook which are not part of `add_payload_keys`, |
496 | 520 | # but part of `update_payload_keys` in the NITRO_RESOURCE_MAP |
@@ -676,7 +700,30 @@ def delete(self): |
676 | 700 | self.client, self.resource_name, self.resource_module_params |
677 | 701 | ) |
678 | 702 | if not ok: |
679 | | - self.return_failure(err) |
| 703 | + if self.resource_name == "sslhsmkey": |
| 704 | + # sslhsmkey returns errocode 1065 and message |
| 705 | + # "Internal error while adding HSM key" on successful addition |
| 706 | + status_code = None |
| 707 | + errorcode = None |
| 708 | + message = None |
| 709 | + err_str = str(err) |
| 710 | + regex_string = re.search(r'status_code:\s*(\d+)', err_str) |
| 711 | + if regex_string: |
| 712 | + status_code = int(regex_string.group(1)) |
| 713 | + regex_string = re.search(r"'errorcode':\s*(\d+)", err_str) |
| 714 | + if regex_string: |
| 715 | + errorcode = int(regex_string.group(1)) |
| 716 | + regex_string = re.search(r"'message':\s*'([^']+)'", err_str) |
| 717 | + if regex_string: |
| 718 | + message = regex_string.group(1) |
| 719 | + if not ( |
| 720 | + status_code == 599 and |
| 721 | + errorcode == 1065 and |
| 722 | + message == "Internal error while adding HSM key." |
| 723 | + ): |
| 724 | + self.return_failure(err) |
| 725 | + else: |
| 726 | + self.return_failure(err) |
680 | 727 |
|
681 | 728 | @trace |
682 | 729 | def delete_bindings( |
|
0 commit comments