-
Notifications
You must be signed in to change notification settings - Fork 346
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
Added started and stopped states for rds cluster #1647
Merged
softwarefactory-project-zuul
merged 20 commits into
ansible-collections:main
from
taehopark32:stop_cluster
Aug 2, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8c00027
added start and stop cluster
taehopark32 f9369f9
added fragment
taehopark32 1429ca6
added integration test cases and added more description into fragment
taehopark32 eef40af
rename fragement and changed get_rds_method_attribute_name method
taehopark32 9ee6485
typo in the fragment
taehopark32 fa9e732
changed function get_rds_method_attribute_name
taehopark32 7f45e52
made changes to get_rds_method_attribute_name and more clarified chec…
taehopark32 ebeb157
started and stopped can only be used with Aurora DB clusters
taehopark32 e665151
changes to the defaults
taehopark32 b400509
updated aliases
taehopark32 8463d0b
only allow aurora to be stopped and started
taehopark32 c2f455f
discarded check on start rds cluster
taehopark32 5696981
add checkmode for starting db clusters
taehopark32 f46e124
remove debug statements in the integration test
taehopark32 d66e292
included unit test for stop and start rds
taehopark32 4844746
added description about stopped and started were added in version 6.3…
taehopark32 d33641c
fixed rds.py
taehopark32 2933346
Fix typo
alinabuzachis dfc2c6d
Update plugins/modules/rds_cluster.py
gravesm e1b34f8
Fix linting
gravesm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
minor_changes: | ||
- rds_cluster - add support for another ``state`` choice called ``started``. This starts the rds cluster (https://github.com/ansible-collections/amazon.aws/pull/1647/files). | ||
- rds_cluster - add support for another ``state`` choice called ``stopped``. This stops the rds cluster (https://github.com/ansible-collections/amazon.aws/pull/1647/files). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
time=30m | ||
cloud/aws | ||
rds_cluster | ||
rds_cluster_info |
11 changes: 11 additions & 0 deletions
11
tests/integration/targets/rds_cluster_states/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cluster_id: ansible-test-cluster-{{ tiny_prefix }} | ||
username: testrdsusername | ||
password: test-rds_password | ||
engine: aurora | ||
db_cluster_instance_class: db.r5.large | ||
|
||
mysql_cluster_id: ansible-test-mysql-cluster-{{ tiny_prefix }} | ||
mysql_engine: mysql | ||
mysql_allocated_storage: 100 | ||
mysql_iops: 1000 | ||
mysql_db_cluster_instance_class: db.m5d.large |
240 changes: 240 additions & 0 deletions
240
tests/integration/targets/rds_cluster_states/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
- module_defaults: | ||
group/aws: | ||
region: '{{ aws_region }}' | ||
aws_access_key: '{{ aws_access_key }}' | ||
aws_secret_key: '{{ aws_secret_key }}' | ||
security_token: '{{ security_token | default(omit) }}' | ||
block: | ||
# ------------------------------------------------------------------------------------------ | ||
# Create DB cluster | ||
- name: Ensure the resource doesn't exist | ||
rds_cluster: | ||
id: '{{ cluster_id }}' | ||
state: absent | ||
engine: '{{ engine}}' | ||
username: '{{ username }}' | ||
password: '{{ password }}' | ||
skip_final_snapshot: true | ||
register: _result_delete_db_cluster | ||
|
||
- assert: | ||
that: | ||
- not _result_delete_db_cluster.changed | ||
ignore_errors: yes | ||
|
||
- name: Create an Aurora-PostgreSQL DB cluster | ||
rds_cluster: | ||
id: '{{ cluster_id }}' | ||
state: present | ||
engine: aurora-postgresql | ||
engine_mode: provisioned | ||
username: '{{ username }}' | ||
password: '{{ password }}' | ||
register: _result_create_source_db_cluster | ||
|
||
- assert: | ||
that: | ||
- _result_create_source_db_cluster.changed | ||
- "'allocated_storage' in _result_create_source_db_cluster" | ||
- _result_create_source_db_cluster.allocated_storage == 1 | ||
- "'cluster_create_time' in _result_create_source_db_cluster" | ||
- _result_create_source_db_cluster.copy_tags_to_snapshot == false | ||
- "'db_cluster_arn' in _result_create_source_db_cluster" | ||
- _result_create_source_db_cluster.db_cluster_identifier == '{{ cluster_id }}' | ||
- "'db_cluster_parameter_group' in _result_create_source_db_cluster" | ||
- "'db_cluster_resource_id' in _result_create_source_db_cluster" | ||
- "'endpoint' in _result_create_source_db_cluster" | ||
- "'engine' in _result_create_source_db_cluster" | ||
- _result_create_source_db_cluster.engine == "aurora-postgresql" | ||
- "'engine_mode' in _result_create_source_db_cluster" | ||
- _result_create_source_db_cluster.engine_mode == "provisioned" | ||
- "'engine_version' in _result_create_source_db_cluster" | ||
- "'master_username' in _result_create_source_db_cluster" | ||
- _result_create_source_db_cluster.master_username == "{{ username }}" | ||
- "'port' in _result_create_source_db_cluster" | ||
- "'status' in _result_create_source_db_cluster" | ||
- _result_create_source_db_cluster.status == "available" | ||
- "'tags' in _result_create_source_db_cluster" | ||
- "'vpc_security_groups' in _result_create_source_db_cluster" | ||
|
||
# ------------------------------------------------------------------------------------------ | ||
# Test stopping db clusters | ||
- name: Stop db clusters - checkmode | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: stopped | ||
register: check_stopped_cluster | ||
check_mode: yes | ||
|
||
- assert: | ||
that: | ||
- check_stopped_cluster.changed | ||
|
||
- name: Stop db clusters | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: stopped | ||
register: stopped_cluster | ||
|
||
- assert: | ||
that: | ||
- stopped_cluster.changed | ||
|
||
- name: Wait until db clusters state is stopped | ||
amazon.aws.rds_cluster_info: | ||
cluster_id: '{{ cluster_id }}' | ||
register: stopped_cluster_info | ||
retries: 30 | ||
delay: 60 | ||
until: stopped_cluster_info.clusters[0].status == "stopped" | ||
|
||
- name: Stop db clusters (idempotence) - checkmode | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: stopped | ||
register: check_stopped_cluster_idem | ||
check_mode: yes | ||
|
||
- assert: | ||
that: | ||
- not check_stopped_cluster_idem.changed | ||
|
||
- name: Stop db clusters (idempotence) | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: stopped | ||
register: stopped_cluster_idem | ||
|
||
- assert: | ||
that: | ||
- not stopped_cluster_idem.changed | ||
|
||
# ------------------------------------------------------------------------------------------ | ||
# Test starting DB clusters | ||
- name: Start db clusters - checkmode | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: started | ||
register: check_started_cluster | ||
check_mode: yes | ||
|
||
- assert: | ||
that: | ||
- check_started_cluster.changed | ||
|
||
- name: Start db clusters | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: started | ||
register: started_cluster | ||
|
||
- assert: | ||
that: | ||
- started_cluster.changed | ||
|
||
- name: Start db clusters (idempotence) - checkmode | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: started | ||
register: check_started_cluster | ||
check_mode: yes | ||
|
||
- assert: | ||
that: | ||
- not check_started_cluster.changed | ||
|
||
- name: Start db clusters | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ cluster_id }}' | ||
state: started | ||
register: started_cluster | ||
|
||
- assert: | ||
that: | ||
- not started_cluster.changed | ||
|
||
# ------------------------------------------------------------------------------------------ | ||
# Give errors for MySql DB cluster | ||
- name: Ensure the resource doesn't exist | ||
rds_cluster: | ||
id: '{{ mysql_cluster_id }}' | ||
state: absent | ||
engine: '{{ mysql_engine }}' | ||
username: '{{ username }}' | ||
password: '{{ password }}' | ||
skip_final_snapshot: true | ||
register: _result_delete_mysql_db_cluster | ||
|
||
- assert: | ||
that: | ||
- not _result_delete_mysql_db_cluster.changed | ||
ignore_errors: yes | ||
|
||
- name: Create an MySql DB cluster | ||
rds_cluster: | ||
id: '{{ mysql_cluster_id }}' | ||
state: present | ||
engine: '{{ mysql_engine }}' | ||
engine_mode: provisioned | ||
allocated_storage: '{{ mysql_allocated_storage }}' | ||
iops: '{{ mysql_iops }}' | ||
db_cluster_instance_class: '{{ mysql_db_cluster_instance_class }}' | ||
username: '{{ username }}' | ||
password: '{{ password }}' | ||
ignore_errors: yes | ||
register: mysql_cluster | ||
|
||
- assert: | ||
that: | ||
- mysql_cluster.changed | ||
- "'allocated_storage' in mysql_cluster" | ||
- mysql_cluster.allocated_storage == 100 | ||
- "'cluster_create_time' in mysql_cluster" | ||
- mysql_cluster.copy_tags_to_snapshot == false | ||
- "'db_cluster_arn' in mysql_cluster" | ||
- mysql_cluster.db_cluster_identifier == "{{ mysql_cluster_id }}" | ||
- "'db_cluster_parameter_group' in mysql_cluster" | ||
- "'db_cluster_resource_id' in mysql_cluster" | ||
- "'endpoint' in mysql_cluster" | ||
- "'engine' in mysql_cluster" | ||
- mysql_cluster.engine == "{{ mysql_engine }}" | ||
- "'engine_mode' in mysql_cluster" | ||
- mysql_cluster.engine_mode == "provisioned" | ||
- "'engine_version' in mysql_cluster" | ||
- "'master_username' in mysql_cluster" | ||
- mysql_cluster.master_username == "{{ username }}" | ||
- "'port' in mysql_cluster" | ||
- "'status' in mysql_cluster" | ||
- mysql_cluster.status == "available" | ||
- "'tags' in mysql_cluster" | ||
- "'vpc_security_groups' in mysql_cluster" | ||
|
||
|
||
- name: Stop MySql DB cluster | ||
amazon.aws.rds_cluster: | ||
cluster_id: '{{ mysql_cluster_id }}' | ||
state: stopped | ||
register: mysql_cluster | ||
ignore_errors: true | ||
|
||
- assert: | ||
that: | ||
- mysql_cluster is failed | ||
- mysql_cluster.msg == "Only aurora clusters can use the state stopped" | ||
|
||
always: | ||
# ------------------------------------------------------------------------------------------ | ||
# Cleanup starts here | ||
- name: Delete MySql db cluster without creating a final snapshot | ||
rds_cluster: | ||
state: absent | ||
cluster_id: '{{ mysql_cluster_id }}' | ||
skip_final_snapshot: true | ||
ignore_errors: true | ||
|
||
- name: Delete Aurora-PostgreSql db cluster without creating a final snapshot | ||
rds_cluster: | ||
state: absent | ||
cluster_id: '{{ cluster_id }}' | ||
skip_final_snapshot: true | ||
ignore_errors: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you please cover these two with units tests? https://github.com/ansible-collections/amazon.aws/blob/main/tests/unit/module_utils/test_rds.py