Skip to content

Commit 5d13efa

Browse files
authored
Enable Fabric Associations Lookup on Secondary Cluster (#630)
* Fix for fed api lookup on secondary cluster * ND3.1 Version Fix * Actions fix
1 parent 42df0bd commit 5d13efa

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

  • plugins/module_utils/network/dcnm

plugins/module_utils/network/dcnm/dcnm.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
except ImportError:
3535
HAS_REQUESTS = False
3636

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+
3743
dcnm_paths = {
3844
11: {"TEMPLATE_WITH_NAME": "/rest/config/templates/{}"},
3945
12: {
@@ -1409,20 +1415,36 @@ def obtain_federated_fabric_associations(action_module, task_vars, tmp):
14091415
# * Federation manager does not exist (standalone or MSD fabrics in a non-clustered environment)
14101416
# * ND3.2 returns an invalid JSON response for remote users
14111417
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+
14131422
# For ND3.2 error_msg will be a string
14141423
# For ND4.X error_msg will be a dict
14151424
if isinstance(error_msg, dict):
14161425
error_msg = error_msg.get('error')
14171426

14181427
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+
)
14201437

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:
14231439
# Return the same error message for both ND3.2 and ND4.X for consistency
14241440
return 'A federation manager does not exist'
14251441

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+
14261448
# Validate API response structure and extract data
14271449
response_data = action_module.error_handler.validate_api_response(
14281450
federated_fabric_associations,

0 commit comments

Comments
 (0)