Skip to content

Conversation

@allenrobel
Copy link
Collaborator

@allenrobel allenrobel commented Nov 24, 2025

Summary

This PR addresses tech debt in the following file:

  • plugins/module_utils/fabric/fabric_summary_v2.py

This is in preparation for removing FabricSummary (v1)

Note for reviewers

Copilot has already reviewed this PR and I've addressed its comments.

1. Unit tests for FabricSummary (v2)

  • This class did not have unit tests, added unit tests and fixtures
  • Updated dcnm_fabric/utils.py with FabricSummary (v2) support

2. FabricSummary (v2)

  • Added type hints throughout
  • Updated docstrings to use Markdown throughout
  • Made several public instances private (e.g. self.conversion -> self._conversion)
  • Updated rest_send and results properties with enhanced versions we use in other classes

1. Unit tests for FabricSummary (v2)

- This class did not have unit tests, added unit tests and fixtures
- Updated dcnm_fabric/utils.py with FabricSummary (v2) support

2. FabricSummary (v2)

- Added type hints throughout
- Updated docstrings to use Markdown throughout
- Made several public instances private (e.g. self.conversion -> self._conversion)
- Updated rest_send and results properties with enhanced versions we use in other classes
@allenrobel allenrobel self-assigned this Nov 24, 2025
No functional changes in this commit
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses technical debt in the FabricSummary (v2) module by adding comprehensive unit tests, implementing type hints, converting docstrings to Markdown format, and refactoring public instances to private where appropriate.

  • Added 811 lines of unit tests for FabricSummary (v2) with comprehensive coverage of success and failure scenarios
  • Updated fabric_summary_v2.py with type hints for all methods and attributes, improving code clarity
  • Refactored instance variables to use private naming convention (e.g., self._conversion instead of self.conversion)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
tests/unit/modules/dcnm/dcnm_fabric/utils.py Added FabricSummaryV2 fixture and response helper function; reformatted imports to single-line format
tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary_v2.py Added comprehensive unit tests covering initialization, refresh operations, error handling, and property access validation
tests/unit/modules/dcnm/dcnm_fabric/fixtures/responses_FabricSummary_V2.json Added mock controller responses for various test scenarios including populated/empty fabrics and error cases
plugins/module_utils/fabric/fabric_summary_v2.py Added type hints throughout; converted docstrings to Markdown format; made several instances private; enhanced property getters/setters with type validation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

allenrobel and others added 5 commits November 24, 2025 10:26
…evice count.


Use private attributes instead of property getters when calculating device count. The current code calls property getters (self.leaf_count, self.spine_count, self.border_gateway_count) which invoke verify_refresh_has_been_called(), adding unnecessary overhead.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No functional changes in this commit.

Addressing a Copilot comment regarding commented lines in fabric_summary_v2.py
Address below Copilot review comment.

[nitpick] Remove redundant empty data check in all_data property. After a successful call to refresh(), self.data cannot be empty ({}) because _verify_controller_response() at line 212 would have raised a ControllerResponseError. The verify_refresh_has_been_called() call at line 318 already ensures refresh() completed successfully. This additional check is unnecessary and inconsistent with other properties like border_gateway_count, device_count, etc.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Addressing the below Copilot review comment.

[nitpick] The rest_send property getter validation prevents accessing the property before calling the setter, which is overly restrictive. Internal methods like _set_fabric_summary_endpoint() (line 176) use self.rest_send.path, which would fail this check. While refresh() validates params at line 245 before calling _set_fabric_summary_endpoint(), this getter-level validation adds unnecessary coupling and prevents legitimate use cases like inspecting the rest_send object. Consider removing lines 457-460 from the getter, as the setter and refresh() method already provide adequate validation.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@allenrobel allenrobel added the ready for review PR is ready to be reviewed label Nov 24, 2025
@mikewiebe mikewiebe merged commit 7890ccc into develop Dec 17, 2025
16 checks passed
mikewiebe pushed a commit that referenced this pull request Dec 17, 2025
* Address FabricSummary (v2) tech debt

1. Unit tests for FabricSummary (v2)

- This class did not have unit tests, added unit tests and fixtures
- Updated dcnm_fabric/utils.py with FabricSummary (v2) support

2. FabricSummary (v2)

- Added type hints throughout
- Updated docstrings to use Markdown throughout
- Made several public instances private (e.g. self.conversion -> self._conversion)
- Updated rest_send and results properties with enhanced versions we use in other classes

* Appease linters

No functional changes in this commit

* Use private attributes instead of property getters when calculating device count.

Use private attributes instead of property getters when calculating device count. The current code calls property getters (self.leaf_count, self.spine_count, self.border_gateway_count) which invoke verify_refresh_has_been_called(), adding unnecessary overhead.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* FabricSummary (v2): Explain why lines are commented

No functional changes in this commit.

Addressing a Copilot comment regarding commented lines in fabric_summary_v2.py

* Remove redundant empty data check in all_data property.

Address below Copilot review comment.

[nitpick] Remove redundant empty data check in all_data property. After a successful call to refresh(), self.data cannot be empty ({}) because _verify_controller_response() at line 212 would have raised a ControllerResponseError. The verify_refresh_has_been_called() call at line 318 already ensures refresh() completed successfully. This additional check is unnecessary and inconsistent with other properties like border_gateway_count, device_count, etc.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove rest_send getter validation

Addressing the below Copilot review comment.

[nitpick] The rest_send property getter validation prevents accessing the property before calling the setter, which is overly restrictive. Internal methods like _set_fabric_summary_endpoint() (line 176) use self.rest_send.path, which would fail this check. While refresh() validates params at line 245 before calling _set_fabric_summary_endpoint(), this getter-level validation adds unnecessary coupling and prevents legitimate use cases like inspecting the rest_send object. Consider removing lines 457-460 from the getter, as the setter and refresh() method already provide adequate validation.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Address Ansible Sanity issue

Fix the below sanity issue.  from __future__ needs to be the first non-docstring line in the file.

ERROR: Found 1 compile issue(s) on python 3.11 which need to be resolved:
ERROR: tests/unit/modules/dcnm/dcnm_fabric/utils.py:20:1: SyntaxError: from __future__ import absolute_import, division, print_function

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants