|
34 | 34 | except ImportError: |
35 | 35 | HAS_REQUESTS = False |
36 | 36 |
|
| 37 | +FEDERATION_MANAGER_NOT_FOUND_ERRORS = [ |
| 38 | + 'Invalid JSON response: this API is allowed only for remote user', |
| 39 | + 'A federation manager does not exist', |
| 40 | + 'Invalid JSON response: cannot serve APIs as federation state is secondary. Use primary cluster for APIs' |
| 41 | +] |
| 42 | + |
37 | 43 | dcnm_paths = { |
38 | 44 | 11: {"TEMPLATE_WITH_NAME": "/rest/config/templates/{}"}, |
39 | 45 | 12: { |
@@ -1409,20 +1415,36 @@ def obtain_federated_fabric_associations(action_module, task_vars, tmp): |
1409 | 1415 | # * Federation manager does not exist (standalone or MSD fabrics in a non-clustered environment) |
1410 | 1416 | # * ND3.2 returns an invalid JSON response for remote users |
1411 | 1417 | if federated_fabric_associations.get('failed') and federated_fabric_associations.get('msg'): |
1412 | | - error_msg = federated_fabric_associations.get('msg').get('DATA') |
| 1418 | + message = federated_fabric_associations.get('msg') |
| 1419 | + error_msg = message.get('DATA') |
| 1420 | + error_code = message.get('RETURN_CODE') |
| 1421 | + |
1413 | 1422 | # For ND3.2 error_msg will be a string |
1414 | 1423 | # For ND4.X error_msg will be a dict |
1415 | 1424 | if isinstance(error_msg, dict): |
1416 | 1425 | error_msg = error_msg.get('error') |
1417 | 1426 |
|
1418 | 1427 | if not isinstance(error_msg, str): |
1419 | | - raise Exception("Unexpected error message format received from federated fabric associations API.") |
| 1428 | + error_details = { |
| 1429 | + "error_msg_type": type(error_msg).__name__, |
| 1430 | + "error_msg_value": str(error_msg), |
| 1431 | + "response": federated_fabric_associations |
| 1432 | + } |
| 1433 | + return action_module.error_handler.handle_failure( |
| 1434 | + "Unexpected error message format from federated fabric associations API", |
| 1435 | + details=error_details |
| 1436 | + ) |
1420 | 1437 |
|
1421 | | - error_messages = ['Invalid JSON response: this API is allowed only for remote user', 'A federation manager does not exist'] |
1422 | | - if error_msg in error_messages: |
| 1438 | + if error_msg in FEDERATION_MANAGER_NOT_FOUND_ERRORS: |
1423 | 1439 | # Return the same error message for both ND3.2 and ND4.X for consistency |
1424 | 1440 | return 'A federation manager does not exist' |
1425 | 1441 |
|
| 1442 | + # ND3.1 Returns a very cryptic error message using RC 404 |
| 1443 | + # 'Invalid JSON response: <html>\r\n<head><title>404 Not Found<...<snip>...n' |
| 1444 | + if action_module.ndfc_version < 12.4 and error_code == 404 and \ |
| 1445 | + error_msg.startswith("Invalid JSON response: <html>"): |
| 1446 | + return 'A federation manager does not exist' |
| 1447 | + |
1426 | 1448 | # Validate API response structure and extract data |
1427 | 1449 | response_data = action_module.error_handler.validate_api_response( |
1428 | 1450 | federated_fabric_associations, |
|
0 commit comments