Skip to content

Commit

Permalink
Fix IOPs update and tests also
Browse files Browse the repository at this point in the history
  • Loading branch information
marknet15 committed Jan 20, 2022
1 parent c0b3e1b commit 0a9f930
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 19 deletions.
14 changes: 13 additions & 1 deletion plugins/modules/rds_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,18 @@ def get_options_with_changing_values(client, module, parameters):
updated_parameters.update(get_changing_options_with_consistent_keys(parameters, instance))
parameters = updated_parameters

if module.params['storage_type'] == 'io1':
# Bundle Iops and AllocatedStorage together while updating RDS Instance
if module.params.get('iops') and module.params.get('allocated_storage'):
parameters['Iops'] = module.params['iops']
parameters['AllocatedStorage'] = module.params['allocated_storage']
elif module.params.get('iops'):
parameters['Iops'] = module.params['iops']
parameters['AllocatedStorage'] = instance.get('AllocatedStorage')
elif module.params.get('allocated_storage'):
parameters['Iops'] = instance.get('Iops')
parameters['AllocatedStorage'] = module.params['allocated_storage']

if parameters.get('NewDBInstanceIdentifier') and instance.get('PendingModifiedValues', {}).get('DBInstanceIdentifier'):
if parameters['NewDBInstanceIdentifier'] == instance['PendingModifiedValues']['DBInstanceIdentifier'] and not apply_immediately:
parameters.pop('NewDBInstanceIdentifier')
Expand All @@ -913,7 +925,7 @@ def get_current_attributes_with_inconsistent_keys(instance):
if instance.get('PendingModifiedValues', {}).get('Port'):
options['DBPortNumber'] = instance['PendingModifiedValues']['Port']
else:
options['DBPortNumber'] = instance['Endpoint']['Port']
options['DBPortNumber'] = instance.get('Endpoint', {}).get('Port', None)
if instance.get('PendingModifiedValues', {}).get('DBSubnetGroupName'):
options['DBSubnetGroupName'] = instance['PendingModifiedValues']['DBSubnetGroupName']
else:
Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/rds_instance/aliases
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
disabled # something is broken
slow

cloud/aws
16 changes: 11 additions & 5 deletions tests/integration/targets/rds_instance/inventory
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# inventory names shortened down to fit resource name length limits
[tests]
# processor feature tests
processor
# restore instance tests
restore
# security groups db tests
sgroups
# modify complex tests
complex
# other tests
states
modify
modify_complex
processor_features
read_replica
vpc_security_groups
restore_instance
tagging
replica

# TODO: uncomment after adding rds_cluster module
# aurora
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
instance_id: "ansible-test-{{ tiny_prefix }}"
instance_id: "ansible-test-{{ inventory_hostname | replace('_','-') }}{{ tiny_prefix }}"
modified_instance_id: "{{ instance_id }}-updated"
username: test
password: test12345678
Expand All @@ -8,8 +8,12 @@ storage_encrypted_db_instance_class: db.t3.small
modified_db_instance_class: db.t3.medium
allocated_storage: 20
modified_allocated_storage: 30
io1_allocated_storage: 100
io1_modified_allocated_storage: 110
monitoring_interval: 60
preferred_maintenance_window: "mon:06:20-mon:06:50"
storage_type: io1
iops: 1000

# For aurora tests
cluster_id: "{{ instance_id }}-cluster"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
username: "{{ username }}"
password: "{{ password }}"
db_instance_class: "{{ db_instance_class }}"
allocated_storage: "{{ allocated_storage }}"
allocated_storage: "{{ io1_allocated_storage }}"
storage_type: "{{ storage_type }}"
iops: "{{ iops }}"
register: result

- assert:
Expand All @@ -48,7 +50,7 @@
rds_instance:
id: "{{ instance_id }}"
state: present
allocated_storage: 30
allocated_storage: "{{ io1_modified_allocated_storage }}"
db_instance_class: "{{ modified_db_instance_class }}"
backup_retention_period: 2
preferred_backup_window: "05:00-06:00"
Expand All @@ -59,15 +61,15 @@
monitoring_interval: "{{ monitoring_interval }}"
monitoring_role_arn: "{{ enhanced_monitoring_role.arn }}"
port: 1150
max_allocated_storage: 100
max_allocated_storage: 150
apply_immediately: True
register: result

- assert:
that:
- result.changed
- '"allocated_storage" in result.pending_modified_values or result.allocated_storage == 30'
- '"max_allocated_storage" in result.pending_modified_values or result.max_allocated_storage == 100'
- '"allocated_storage" in result.pending_modified_values or result.allocated_storage == io1_allocated_storage'
- '"max_allocated_storage" in result.pending_modified_values or result.max_allocated_storage == 150'
- '"port" in result.pending_modified_values or result.endpoint.port == 1150'
- '"db_instance_class" in result.pending_modified_values or result.db_instance_class == modified_db_instance_class'
- '"engine_version" in result.pending_modified_values or result.engine_version == mariadb_engine_version_2'
Expand All @@ -77,7 +79,7 @@
rds_instance:
id: "{{ instance_id }}"
state: present
allocated_storage: 30
allocated_storage: "{{ io1_modified_allocated_storage }}"
db_instance_class: "{{ modified_db_instance_class }}"
backup_retention_period: 2
preferred_backup_window: "05:00-06:00"
Expand All @@ -88,7 +90,8 @@
monitoring_interval: "{{ monitoring_interval }}"
monitoring_role_arn: "{{ enhanced_monitoring_role.arn }}"
port: 1150
max_allocated_storage: 100
max_allocated_storage: 150
apply_immediately: True
register: result
retries: 30
delay: 10
Expand All @@ -97,8 +100,8 @@
- assert:
that:
- not result.changed
- '"allocated_storage" in result.pending_modified_values or result.allocated_storage == 30'
- '"max_allocated_storage" in result.pending_modified_values or result.max_allocated_storage == 100'
- '"allocated_storage" in result.pending_modified_values or result.allocated_storage == io1_modified_allocated_storage'
- '"max_allocated_storage" in result.pending_modified_values or result.max_allocated_storage == 150'
- '"port" in result.pending_modified_values or result.endpoint.port == 1150'
- '"db_instance_class" in result.pending_modified_values or result.db_instance_class == modified_db_instance_class'
- '"engine_version" in result.pending_modified_values or result.engine_version == mariadb_engine_version_2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
- {"cidr": "10.122.122.128/28", "zone": "{{ aws_region }}a"}
- {"cidr": "10.122.122.144/28", "zone": "{{ aws_region }}b"}
- {"cidr": "10.122.122.160/28", "zone": "{{ aws_region }}c"}
- {"cidr": "10.122.122.176/28", "zone": "{{ aws_region }}d"}

- name: Create security groups
ec2_group:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
always:
- name: remove snapshot
rds_instance_snapshot:
db_snapshot_identifier: "{{ resource_prefix }}-test-snapshot"
db_snapshot_identifier: "{{ tiny_prefix }}-test-snapshot"
state: absent
wait: false
ignore_errors: yes
Expand Down

0 comments on commit 0a9f930

Please sign in to comment.