Skip to content

Commit

Permalink
Add additional tests for minimal/partial parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Sep 23, 2021
1 parent c21eac8 commit dc4cd6e
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 6 deletions.
15 changes: 9 additions & 6 deletions plugins/modules/redshift_subnet_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
options:
state:
description:
- Specifies whether the subnet should be present or absent.
- Specifies whether the subnet group should be present or absent.
default: 'present'
choices: ['present', 'absent' ]
type: str
Expand All @@ -35,6 +35,7 @@
subnets:
description:
- List of subnet IDs that make up the cluster subnet group.
- At least one subnet must be provided when creating a cluster subnet group.
aliases: ['group_subnets']
type: list
elements: str
Expand Down Expand Up @@ -122,11 +123,13 @@ def get_subnet_group(name):


def create_subnet_group(name, description, subnets):

if not subnets:
module.fail_json(msg='At least one subnet must be provided when creating a subnet group')

try:
if not description:
description = name
if not subnets:
subnets = []
client.create_cluster_subnet_group(
aws_retry=True,
ClusterSubnetGroupName=name,
Expand Down Expand Up @@ -198,9 +201,9 @@ def main():
)

state = module.params.get('state')
name = module.params.get('group_name')
description = module.params.get('group_description')
subnets = module.params.get('group_subnets')
name = module.params.get('name')
description = module.params.get('description')
subnets = module.params.get('subnets')

client = module.client('redshift', retry_decorator=AWSRetry.jittered_backoff())

Expand Down
120 changes: 120 additions & 0 deletions tests/integration/targets/redshift_subnet_group/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block:

# ============================================================

- name: Create Subnet Group with no subnets
redshift_subnet_group:
state: present
name: '{{ group_name }}'
register: create_group
ignore_errors: True

- name: Check result - Create Subnet Group with no subnets
assert:
that:
- create_group is failed
# Check we caught the issue before trying to create
- '"CreateClusterSubnetGroup" not in create_group.resource_actions'
# Check that we don't refer to the boto3 parameter
- '"subnetIds" not in create_group.msg'
# Loosely check the message
- '"subnet" in create_group.msg'
- '"At least" in create_group.msg'

# ============================================================
# Setup infra needed for tests
- name: create a VPC
Expand Down Expand Up @@ -56,6 +78,7 @@
subnet_id_b: '{{ vpc_subnet_create.results[1].subnet.id }}'
subnet_id_c: '{{ vpc_subnet_create.results[2].subnet.id }}'
subnet_id_d: '{{ vpc_subnet_create.results[3].subnet.id }}'

# ============================================================

- name: Create Subnet Group
Expand Down Expand Up @@ -216,6 +239,103 @@
that:
- delete_group is not changed

# ============================================================

- name: Create minimal Subnet Group
redshift_subnet_group:
state: present
name: '{{ group_name }}'
subnets:
- '{{ subnet_id_a }}'
register: create_group

- name: Check result - Create minimal Subnet Group
assert:
that:
- create_group is successful
- create_group is changed
- '"group" in create_group'
- '"name" in create_group.group'
- '"vpc_id" in create_group.group'
- create_group.group.name == group_name
- create_group.group.vpc_id == vpc_id

- name: Create minimal Subnet Group - idempotency
redshift_subnet_group:
state: present
name: '{{ group_name }}'
subnets:
- '{{ subnet_id_a }}'
register: create_group

- name: Check result - Create minimal Subnet Group - idempotency
assert:
that:
- create_group is successful
- create_group is not changed
- '"group" in create_group'
- '"name" in create_group.group'
- '"vpc_id" in create_group.group'
- create_group.group.name == group_name
- create_group.group.vpc_id == vpc_id

# ============================================================

- name: Full Update Subnet Group
redshift_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
register: update_complex

- name: Check result - Full Update Subnet Group
assert:
that:
- update_complex is successful
- update_complex is changed
- '"group" in update_complex'
- '"name" in update_complex.group'
- '"vpc_id" in update_complex.group'
- update_complex.group.name == group_name
- update_complex.group.vpc_id == vpc_id

- name: Full Update Subnet Group - idempotency
redshift_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
register: update_complex

- name: Check result - Full Update Subnet Group - idempotency
assert:
that:
- update_complex is successful
- update_complex is not changed
- '"group" in update_complex'
- '"name" in update_complex.group'
- '"vpc_id" in update_complex.group'
- update_complex.group.name == group_name
- update_complex.group.vpc_id == vpc_id

# ============================================================

- name: Delete Subnet Group
redshift_subnet_group:
state: absent
name: '{{ group_name }}'
register: delete_group

- name: Check result - Delete Subnet Group
assert:
that:
- delete_group is changed

always:

################################################
Expand Down

0 comments on commit dc4cd6e

Please sign in to comment.