|
| 1 | +# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You may |
| 4 | +# not use this file except in compliance with the License. A copy of the |
| 5 | +# License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is distributed |
| 10 | +# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | +# express or implied. See the License for the specific language governing |
| 12 | +# permissions and limitations under the License. |
| 13 | + |
| 14 | +"""Integration tests for the RDS API DBParameterGroup resource |
| 15 | +""" |
| 16 | + |
| 17 | +import boto3 |
| 18 | +import datetime |
| 19 | +import logging |
| 20 | +import time |
| 21 | +from typing import Dict |
| 22 | + |
| 23 | +import pytest |
| 24 | + |
| 25 | +from acktest.k8s import resource as k8s |
| 26 | +from e2e import service_marker, CRD_GROUP, CRD_VERSION, load_rds_resource |
| 27 | +from e2e.replacement_values import REPLACEMENT_VALUES |
| 28 | +from e2e.bootstrap_resources import get_bootstrap_resources |
| 29 | + |
| 30 | +RESOURCE_PLURAL = 'dbparametergroups' |
| 31 | + |
| 32 | +DELETE_WAIT_AFTER_SECONDS = 10 |
| 33 | + |
| 34 | + |
| 35 | +@pytest.fixture(scope="module") |
| 36 | +def rds_client(): |
| 37 | + return boto3.client('rds') |
| 38 | + |
| 39 | + |
| 40 | +@service_marker |
| 41 | +@pytest.mark.canary |
| 42 | +class TestDBParameterGroup: |
| 43 | + def test_create_delete_postgres13_standard(self, rds_client): |
| 44 | + resource_name = "pg13-standard" |
| 45 | + resource_desc = "Parameters for PostgreSQL 13" |
| 46 | + |
| 47 | + replacements = REPLACEMENT_VALUES.copy() |
| 48 | + replacements["DB_PARAMETER_GROUP_NAME"] = resource_name |
| 49 | + replacements["DB_PARAMETER_GROUP_DESC"] = resource_desc |
| 50 | + |
| 51 | + resource_data = load_rds_resource( |
| 52 | + "db_parameter_group_postgres13_standard", |
| 53 | + additional_replacements=replacements, |
| 54 | + ) |
| 55 | + logging.debug(resource_data) |
| 56 | + |
| 57 | + # Create the k8s resource |
| 58 | + ref = k8s.CustomResourceReference( |
| 59 | + CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL, |
| 60 | + resource_name, namespace="default", |
| 61 | + ) |
| 62 | + k8s.create_custom_resource(ref, resource_data) |
| 63 | + cr = k8s.wait_resource_consumed_by_controller(ref) |
| 64 | + |
| 65 | + assert cr is not None |
| 66 | + assert k8s.get_resource_exists(ref) |
| 67 | + |
| 68 | + # Let's check that the DB parameter group appears in RDS |
| 69 | + aws_res = rds_client.describe_db_parameter_groups(DBParameterGroupName=resource_name) |
| 70 | + assert aws_res is not None |
| 71 | + assert len(aws_res['DBParameterGroups']) == 1 |
| 72 | + |
| 73 | + # Delete the k8s resource on teardown of the module |
| 74 | + k8s.delete_custom_resource(ref) |
| 75 | + |
| 76 | + time.sleep(DELETE_WAIT_AFTER_SECONDS) |
| 77 | + |
| 78 | + # DB parameter group should no longer appear in RDS |
| 79 | + try: |
| 80 | + aws_res = rds_client.describe_db_parameter_groups(DBParameterGroupName=resource_name) |
| 81 | + assert False |
| 82 | + except rds_client.exceptions.DBParameterGroupNotFoundFault: |
| 83 | + pass |
0 commit comments