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

Refactoring: RDS: Move common code in rds modules to module_utils #2003

Open
1 task done
GomathiselviS opened this issue Feb 27, 2024 · 0 comments
Open
1 task done
Assignees

Comments

@GomathiselviS
Copy link
Collaborator

Summary

Reference: https://github.com/ansible-collections/amazon.aws/pull/1998/files

camel_dict_to_snake_dict conversions and other shared portions of code present in the RDS modules can be relocated to module_utils/rds.py.

This proposal aims to refactor our codebase, making the module files more maintainable and comprehensible.

Issue Type

Feature Idea

Component Name

rds_*.py

Additional Information

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@hakbailey hakbailey self-assigned this Apr 11, 2024
softwarefactory-project-zuul bot pushed a commit that referenced this issue Jun 17, 2024
SUMMARY
This is an initial refactor PR for rds modules, focusing on documentation and shared boto3 client functionality in rds module_utils, rds_instance_info, and rds_instance. First PR for #2003 / https://issues.redhat.com/browse/ACA-1343.
COMPONENT NAME
rds_instance_info
rds_instance
module_utils/rds.py
ADDITIONAL INFORMATION
Detailed summary of all the changes:
module_utils/rds.py:

Add RDS error class and handler
Add describe_db_instances(), describe_db_snapshots(), and list_tags_for_resource() functions to handle boto3 client call
Refactor get_tags() to use new list_tags_for_resource() function
Add type hinting and function docstrings

rds_instance_info module:

Replace internal error handler and _describe_db_instances() functions with calls to new functions from module_utils/rds.py
Remove extra boto3 call to retrieve tags for resource and just reformat instance TagList attribute since it is always returned by describe_db_instances
Update instance_info() function return value for clarity
Add type hinting and function docstrings
Remove unit tests for functions no longer in module
Refactor remaining unit tests to match updated instance_info() function

rds_instance module:

Refactor internal get_instance() function to use describe_db_instances() from module_utils/rds.py, remove extra boto3 call to get resource tags, and remove manual retry logic
Refactor internal get_final_snapshot() function to use describe_db_snapshots() from module_utils/rds.py
Add type hinting and function docstrings, and in some cases inline comments to explain complex logic
Add unit tests for refactored functions

Reviewed-by: Alina Buzachis
Reviewed-by: Helen Bailey <[email protected]>
Reviewed-by: Mandar Kulkarni <[email protected]>
Reviewed-by: Mike Graves <[email protected]>
Reviewed-by: Bikouo Aubin
Reviewed-by: Mark Chappell
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this issue Jun 26, 2024
SUMMARY
This is an initial refactor PR for rds modules, focusing on documentation and shared boto3 client functionality in rds module_utils, rds_instance_info, and rds_instance. First PR for ansible-collections#2003 / https://issues.redhat.com/browse/ACA-1343.
COMPONENT NAME
rds_instance_info
rds_instance
module_utils/rds.py
ADDITIONAL INFORMATION
Detailed summary of all the changes:
module_utils/rds.py:

Add RDS error class and handler
Add describe_db_instances(), describe_db_snapshots(), and list_tags_for_resource() functions to handle boto3 client call
Refactor get_tags() to use new list_tags_for_resource() function
Add type hinting and function docstrings

rds_instance_info module:

Replace internal error handler and _describe_db_instances() functions with calls to new functions from module_utils/rds.py
Remove extra boto3 call to retrieve tags for resource and just reformat instance TagList attribute since it is always returned by describe_db_instances
Update instance_info() function return value for clarity
Add type hinting and function docstrings
Remove unit tests for functions no longer in module
Refactor remaining unit tests to match updated instance_info() function

rds_instance module:

Refactor internal get_instance() function to use describe_db_instances() from module_utils/rds.py, remove extra boto3 call to get resource tags, and remove manual retry logic
Refactor internal get_final_snapshot() function to use describe_db_snapshots() from module_utils/rds.py
Add type hinting and function docstrings, and in some cases inline comments to explain complex logic
Add unit tests for refactored functions

Reviewed-by: Alina Buzachis
Reviewed-by: Helen Bailey <[email protected]>
Reviewed-by: Mandar Kulkarni <[email protected]>
Reviewed-by: Mike Graves <[email protected]>
Reviewed-by: Bikouo Aubin
Reviewed-by: Mark Chappell
softwarefactory-project-zuul bot pushed a commit that referenced this issue Jul 23, 2024
SUMMARY
Move shared functionality from rds snapshot modules into rds module_utils. Second PR for #2003 / https://issues.redhat.com/browse/ACA-1343.
COMPONENT NAME
rds_cluster_snapshot
rds_instance_snapshot
rds_instance
rds_snapshot_info
module_utils/rds.py
ADDITIONAL INFORMATION
Detailed summary of all the changes:
module_utils/rds.py:

Add describe_db_cluster_snapshots() function
Add get_snapshot() function to retrieve a single db instance or cluster snapshot using internal describe_db_snapshots() and describe_db_cluster_snapshots()
Add format_rds_client_method_parameters() to validate and format parameters for boto3 rds client methods
Update internal collection imports to use full collection path
Add unit tests for new functions

rds_instance module:

Replace get_final_snapshot() function with calls to get_snapshot() from module_utils/rds.py
Replace parameter formatting logic in get_parameters() with call to format_rds_client_method_parameters() from module_utils/rds.py
Remove unit tests for deleted get_final_snapshot() function

rds_instance_snapshot module:

Replace get_snapshot() function with calls to get_snapshot() from module_utils/rds.py
Replace get_parameters() function with call to format_rds_client_method_parameters() from module_utils/rds.py
Remove global variables
Add type hinting to all functions

rds_cluster_snapshot module:

Replace get_parameters() function with call to format_rds_client_method_parameters() from module_utils/rds.py
Remove global variables
Add type hinting to all functions

rds_snapshot_info module:

Refactor internal common_snapshot_info() function to use describe_db_snapshots() and describe_db_cluster_snapshots() functions from module_utils/rds.py
Rename some variables to ensure consistent variable naming
Add type hinting to all functions

Reviewed-by: Alina Buzachis
Reviewed-by: Mark Chappell
Reviewed-by: Helen Bailey <[email protected]>
Reviewed-by: Bikouo Aubin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants