Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcnm_vrf: UT - fix null fabric name in vrf attachments #365

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

allenrobel
Copy link
Collaborator

@allenrobel allenrobel commented Jan 18, 2025

Summary

In dcnm_vrf unit tests, multiple tests show a null fabric name in vrf attachments.

This PR provides a fix for this issue.

No changes in this PR impact dcnm_vrf functionality.

RCA

Serial number to fabric name translation was not happening because there was not a mock defined for `DcnmVrf().sn_fab.

Changes

1. module_utils/network/dcnm.py

Add two new methods which duplicate the functionality of get_ip_sn_fabric_dict()

  • get_ip_fabric_dict()
  • get_sn_fabric_dict()

get_ip_sn_fabric_dict() was not touched.

The reason for the new methods is because patch (test_dcnm_vrf.py, setUp()) doesn't seem to support patching a method that returns more than one value (at least I couldn't make that work).

Another reason is that it's cleaner for these utility methods to be as simple as possible. For example, dcnm_vrf.py does not need or use the ip_fab dict that is returned by get_ip_sn_fabric_dict(), so it's better if we don't have to define ip_fab in DcnmVrf(). Separating get_ip_sn_fabric_dict() into two methods allows DcnmVrf() to define and use only sn_fab.

2. modules/dcnm_vrf.py

In init(), use the replacement method get_sn_fabric_dict() rather than get_ip_sn_fabric_dict()

3. test_dcnm_vrf.py

  • Add the mock for sn_fab

  • Modify load_fixtures() for all test cases that required a sn_fab mock.

  • Define two new vars for fabric details (for a future commit)

    • fabric_details_mfd
    • fabric_details_vxlan

4. dcnm_vrf.json

Add the following objects

  • mock_ip_fab
  • mock_sn_fab
  • fabric_details_mfd
  • fabric_details_vxlan

Of the above, only mock_sn_fab is currently used. The others will be used in future PRs as we work through cleaning up these unit tests.

1. module_utils/network/dcnm.py

Add two new methods which are duplicate functionality to get_ip_sn_fabric_dict()

get_ip_fabric_dict()
get_sn_fabric_dict()

get_ip_sn_fabric_dict() was not touched.

The reason for the new defs is because patch (in test_dcnm_vrf.py setUp() did not like patching to a def that returns more than one value.  But another reason is that it's cleaner for these utility defs to be as simple as possible.

2. test_dcnm_vrf.py

- Add the mock for sn_fab

- Modify load_fixtures() for all test cases that required having sn_fab dict mocked.

- Define two new vars for fabric details (for a future commit)
    -  fabric_details_mfd
    - fabric_details_vxlan

3. dcnm_vrf.json

Add the following objects (fabric_details_* for a future commit)

- mock_sn_fab
- fabric_details_mfd
- fabric_details_vxlan
@allenrobel allenrobel added the Work in Progress Code not ready for review. label Jan 18, 2025
@allenrobel allenrobel self-assigned this Jan 18, 2025
1. test_dcnm_vrf.py

Fix black whitespace on blank line.

2. dcnm_vrf.py

Fix pylint unused-import

3. module_utils/network/dcnm/dcnm.py

1. Run through black
2. Fix pep8 expected 2 blank lines, found 1
Update fabric_details_*

1. tests/unit/modules/dcnm/fixtures/dcnm_vrf.json

- Remove dcnm_fabric_orig
- Update fabric_details_mfd with default MSD fabric
- Update fabric_details_vxlan with default VXLAN/EVPN fabric
@allenrobel allenrobel added ready for review PR is ready to be reviewed and removed Work in Progress Code not ready for review. labels Jan 19, 2025
@allenrobel allenrobel requested a review from mikewiebe January 19, 2025 01:30
module_utils/network/dcnm/dcnm.py

Clean up the two recently-added method's docstrings.  Fix typos and descriptions of return values.
Maybe overly paranoid, but better to fail at earliest possible point, IMHO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant