Skip to content

Enhance user-friendly error messaging for UDI limit (50) in playbook#445

Merged
madhansansel merged 5 commits intocisco-en-programmability:mainfrom
Kandarimegha:cg_issue_settings
Apr 29, 2026
Merged

Enhance user-friendly error messaging for UDI limit (50) in playbook#445
madhansansel merged 5 commits intocisco-en-programmability:mainfrom
Kandarimegha:cg_issue_settings

Conversation

@Kandarimegha
Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Description

This PR includes the bug fix of [Assurance][iac3.0]: Playbook throws unclear error when user-defined issue creation exceeds limit of 50.

Summary:
The earlier unclear error ('list' object has no attribute 'get') is no longer observed, indicating improvement in error handling. Currently, the playbook returns the API error message, which correctly reflects that the maximum limit of 50 UDIs has been reached. However, the message is still not user-friendly. The submitter requests further enhancement to format the error into a clearer, more actionable message for better user experience.

Testing Done:

  • [] Manual testing
  • [] Unit tests
  • [] Integration tests

Test cases covered: [Mention test case IDs or brief points]

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • All the sanity checks have been completed and the sanity test cases have been executed

Ansible Best Practices

  • Tasks are idempotent (can be run multiple times without changing state)
  • Variables and secrets are handled securely (e.g., using ansible-vault or environment variables)
  • Playbooks are modular and reusable
  • Handlers are used for actions that need to run on change

Documentation

  • All options and parameters are documented clearly.
  • Examples are provided and tested.
  • Notes and limitations are clearly stated.

Screenshots (if applicable)

Notes to Reviewers

if "9003" in error_str or "max supported number" in error_str or "UDIs have hit max" in error_str:
self.msg = (
"Failed to create the user-defined issue '{name}'. "
"The system has reached the maximum limit of 50 custom issues. "
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define the value 50 in the class itself?

    MAX_CUSTOM_ISSUES = 50
    UDI_LIMIT_ERROR_PATTERNS = ("9003", "max supported number", "UDIs have hit max")
            except Exception as msg:
                error_str = str(msg)
                if any(pattern in error_str for pattern in self.UDI_LIMIT_ERROR_PATTERNS):
                    self.msg = (
                        "Failed to create the user-defined issue '{name}' in Cisco Catalyst Center. "
                        "The system has reached the maximum limit of {limit} custom issues. "
                        "Please delete one or more existing issues before creating new ones."
                    ).format(name=issue.get("name"), limit=self.MAX_CUSTOM_ISSUES)
                    self.log(self.msg, "WARNING")
                else:
                    self.msg = (
                        "Exception occurred while creating the user-defined issue "
                        "in Cisco Catalyst Center: {msg}"
                    ).format(msg=msg)
                self.log(error_str, "ERROR")

requirements:
- dnacentersdk >= 2.8.6
- python >= 3.9
notes:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- The maximum number of user-defined (custom) issue definitions
  supported by Cisco Catalyst Center is 50. Attempting to create
  more will result in an error.

@@ -1 +1 @@
#!/usr/bin/python
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update the Unit test cases?

import pytest
from unittest.mock import MagicMock, patch

def test_create_issue_udi_limit_error_returns_friendly_message():
    """Verify user-friendly message when UDI limit is reached."""
    # Setup module mock
    module = MagicMock()
    instance = create_assurance_settings_instance(module)
    instance.dnac._exec = MagicMock(
        side_effect=Exception("Error 9003: UDIs have hit max supported number")
    )
    instance.set_operation_result = MagicMock()

    issue = {"name": "Test Issue", "rules": [], "is_enabled": True,
             "priority": "P1", "is_notification_enabled": False,
             "description": "desc"}
    # Call create with one issue that will hit the limit
    # Assert self.msg contains "maximum limit of 50"
    assert "maximum limit of 50" in instance.msg


def test_create_issue_generic_error_preserves_original_message():
    """Verify generic errors are not swallowed by the UDI limit handler."""
    module = MagicMock()
    instance = create_assurance_settings_instance(module)
    instance.dnac._exec = MagicMock(
        side_effect=Exception("Connection timeout")
    )
    instance.set_operation_result = MagicMock()

    # Assert self.msg contains "Connection timeout"
    assert "Connection timeout" in instance.msg

@madhansansel madhansansel merged commit 82f115a into cisco-en-programmability:main Apr 29, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants