-
Notifications
You must be signed in to change notification settings - Fork 50
FabricSummary (v2): address tech debt #564
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
Conversation
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
No functional changes in this commit
There was a problem hiding this 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._conversioninstead ofself.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.
…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
…oDevNet/ansible-dcnm into tech-debt-fabric-summary-v2
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>
* 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>
Summary
This PR addresses tech debt in the following file:
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)
2. FabricSummary (v2)