Skip to content

Commit

Permalink
[rds] add create-delete test for DB security group
Browse files Browse the repository at this point in the history
Adds a super simple create, read, and delete test for a DB security
group in the RDS API.

Handling allow and revoke of an EC2 security group or IPRange member of
a DB Security Group will be handled in a followup patch after the
rds-controller's DBSecurityGroup resource manager gets custom code that
handles those attributes.

Issue aws-controllers-k8s#237
  • Loading branch information
jaypipes committed Mar 23, 2021
1 parent 9d9f86b commit 06f95b6
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
8 changes: 8 additions & 0 deletions test/e2e/rds/resources/db_security_group_simple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: rds.services.k8s.aws/v1alpha1
kind: DBSecurityGroup
metadata:
name: $DB_SECURITY_GROUP_NAME
spec:
name: $DB_SECURITY_GROUP_NAME
description: $DB_SECURITY_GROUP_DESC

88 changes: 88 additions & 0 deletions test/e2e/rds/tests/test_db_security_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

"""Integration tests for the RDS API DBSecurityGroup resource
"""

import boto3
import datetime
import logging
import time
from typing import Dict

import pytest

from rds import SERVICE_NAME, service_marker, CRD_GROUP, CRD_VERSION
from rds.bootstrap_resources import get_bootstrap_resources
from rds.replacement_values import REPLACEMENT_VALUES
from common.resources import load_resource_file, random_suffix_name
from common import k8s

RESOURCE_PLURAL = 'dbsecuritygroups'

DELETE_WAIT_AFTER_SECONDS = 10


@pytest.fixture(scope="module")
def rds_client():
return boto3.client('rds')


@service_marker
@pytest.mark.canary
class TestDBSecurityGroup:
def test_create_delete_simple(self, rds_client):
resource_name = "my-db-security-group"
resource_desc = "my-db-security-group description"

br_resources = get_bootstrap_resources()

replacements = REPLACEMENT_VALUES.copy()
replacements["DB_SECURITY_GROUP_NAME"] = resource_name
replacements["DB_SECURITY_GROUP_DESC"] = resource_desc

resource_data = load_resource_file(
SERVICE_NAME,
"db_security_group_simple",
additional_replacements=replacements,
)
logging.debug(resource_data)

# Create the k8s resource
ref = k8s.CustomResourceReference(
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
resource_name, namespace="default",
)
k8s.create_custom_resource(ref, resource_data)
cr = k8s.wait_resource_consumed_by_controller(ref)

assert cr is not None
assert k8s.get_resource_exists(ref)

# Let's check that the DB security group appears in RDS
aws_res = rds_client.describe_db_security_groups(DBSecurityGroupName=resource_name)
assert aws_res is not None
assert len(aws_res['DBSecurityGroups']) == 1

# Delete the k8s resource on teardown of the module
k8s.delete_custom_resource(ref)

time.sleep(DELETE_WAIT_AFTER_SECONDS)

# DB security group should no longer appear in RDS
try:
aws_res = rds_client.describe_db_security_groups(DBSecurityGroupName=resource_name)
assert False
except rds_client.exceptions.DBSecurityGroupNotFoundFault:
pass

6 changes: 3 additions & 3 deletions test/e2e/rds/tests/test_db_subnet_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def rds_client():

@service_marker
@pytest.mark.canary
class TestDBSubnetgroup:
class TestDBSubnetGroup:
def test_create_delete_2az(self, rds_client):
resource_name = "my-subnet-group"
resource_desc = "my-subnet-group description"
resource_name = "my-db-subnet-group"
resource_desc = "my-db-subnet-group description"

br_resources = get_bootstrap_resources()

Expand Down

0 comments on commit 06f95b6

Please sign in to comment.