From 0da2e923ac0f06431f116064b9c05adda6416c2f Mon Sep 17 00:00:00 2001 From: Anton Kukushkin Date: Mon, 10 Jul 2023 14:00:37 +0100 Subject: [PATCH] tests: Add Aurora PostgreSQL Serverless --- test_infra/stacks/databases_stack.py | 56 ++++++++++++++++++++++++++++ tests/conftest.py | 38 ++++++++++--------- 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/test_infra/stacks/databases_stack.py b/test_infra/stacks/databases_stack.py index 1c339dc15..e8db7953e 100644 --- a/test_infra/stacks/databases_stack.py +++ b/test_infra/stacks/databases_stack.py @@ -45,6 +45,7 @@ def __init__( self._setup_redshift_serverless() if databases_context["postgresql"]: self._setup_postgresql() + self._setup_postgresql_serverless() if databases_context["mysql"]: self._setup_mysql() self._setup_mysql_serverless() @@ -577,6 +578,61 @@ def _setup_mysql_serverless(self) -> None: CfnOutput(self, "MysqlServerlessDatabase", value=database) CfnOutput(self, "MysqlServerlessSchema", value=schema) + def _setup_postgresql_serverless(self) -> None: + port = 5432 + database = "test" + schema = "test" + aurora_postgresql = rds.ServerlessCluster( + self, + "aws-sdk-pandas-aurora-cluster-postgresql-serverless", + removal_policy=RemovalPolicy.DESTROY, + engine=rds.DatabaseClusterEngine.aurora_postgres( + version=rds.AuroraPostgresEngineVersion.VER_11_19, + ), + cluster_identifier="postgresql-serverless-cluster-sdk-pandas", + default_database_name=database, + credentials=rds.Credentials.from_password( + username=self.db_username, + password=self.db_password_secret, + ), + scaling=rds.ServerlessScalingOptions( + auto_pause=Duration.minutes(5), + min_capacity=rds.AuroraCapacityUnit.ACU_1, + max_capacity=rds.AuroraCapacityUnit.ACU_1, + ), + backup_retention=Duration.days(1), + vpc=self.vpc, + subnet_group=self.rds_subnet_group, + security_groups=[self.db_security_group], + enable_data_api=True, + ) + secret = secrets.Secret( + self, + "aws-sdk-pandas-postgresql-serverless-secret", + secret_name="aws-sdk-pandas/postgresql-serverless", + description="PostgreSql serverless credentials", + generate_secret_string=secrets.SecretStringGenerator( + generate_string_key="dummy", + secret_string_template=json.dumps( + { + "username": self.db_username, + "password": self.db_password, + "engine": "postgresql", + "host": aurora_postgresql.cluster_endpoint.hostname, + "port": port, + "dbClusterIdentifier": aurora_postgresql.cluster_identifier, + "dbname": database, + } + ), + ), + ) + CfnOutput(self, "PostgresqlServerlessSecretArn", value=secret.secret_arn) + CfnOutput(self, "PostgresqlServerlessClusterArn", value=aurora_postgresql.cluster_arn) + CfnOutput(self, "PostgresqlServerlessAddress", value=aurora_postgresql.cluster_endpoint.hostname) + CfnOutput(self, "PostgresqlServerlessPort", value=str(port)) + CfnOutput(self, "PostgresqlServerlessDatabase", value=database) + CfnOutput(self, "PostgresqlServerlessSchema", value=schema) + def _setup_sqlserver(self) -> None: port = 1433 database = "test" diff --git a/tests/conftest.py b/tests/conftest.py index c7239c968..7087c14ff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -140,37 +140,41 @@ def databases_parameters(cloudformation_outputs, db_password): postgresql={}, mysql={}, redshift={}, sqlserver={}, mysql_serverless={}, oracle={}, redshift_serverless={} ) parameters["postgresql"]["host"] = cloudformation_outputs.get("PostgresqlAddress") - parameters["postgresql"]["port"] = 3306 - parameters["postgresql"]["schema"] = "public" - parameters["postgresql"]["database"] = "postgres" + parameters["postgresql"]["port"] = cloudformation_outputs.get("PostgresqlPort") + parameters["postgresql"]["schema"] = cloudformation_outputs.get("PostgresqlSchema") + parameters["postgresql"]["database"] = cloudformation_outputs.get("PostgresqlDatabase") parameters["mysql"]["host"] = cloudformation_outputs.get("MysqlAddress") - parameters["mysql"]["port"] = 3306 - parameters["mysql"]["schema"] = "test" - parameters["mysql"]["database"] = "test" + parameters["mysql"]["port"] = cloudformation_outputs.get("MysqlPort") + parameters["mysql"]["schema"] = cloudformation_outputs.get("MysqlDatabase") + parameters["mysql"]["database"] = cloudformation_outputs.get("MysqlSchema") parameters["redshift"]["secret_arn"] = cloudformation_outputs.get("RedshiftSecretArn") parameters["redshift"]["host"] = cloudformation_outputs.get("RedshiftAddress") parameters["redshift"]["port"] = cloudformation_outputs.get("RedshiftPort") parameters["redshift"]["identifier"] = cloudformation_outputs.get("RedshiftIdentifier") - parameters["redshift"]["schema"] = "public" - parameters["redshift"]["database"] = "test" + parameters["redshift"]["schema"] = cloudformation_outputs.get("RedshiftSchema") + parameters["redshift"]["database"] = cloudformation_outputs.get("RedshiftDatabase") parameters["redshift"]["role"] = cloudformation_outputs.get("RedshiftRole") parameters["password"] = db_password parameters["user"] = "test" parameters["sqlserver"]["host"] = cloudformation_outputs.get("SqlServerAddress") - parameters["sqlserver"]["port"] = 1433 - parameters["sqlserver"]["schema"] = "dbo" - parameters["sqlserver"]["database"] = "test" + parameters["sqlserver"]["port"] = cloudformation_outputs.get("SqlServerPort") + parameters["sqlserver"]["schema"] = cloudformation_outputs.get("SqlServerSchema") + parameters["sqlserver"]["database"] = cloudformation_outputs.get("SqlServerDatabase") parameters["mysql_serverless"]["secret_arn"] = cloudformation_outputs.get("MysqlServerlessSecretArn") - parameters["mysql_serverless"]["schema"] = "test" - parameters["mysql_serverless"]["database"] = "test" + parameters["mysql_serverless"]["schema"] = cloudformation_outputs.get("MysqlServerlessSchema") + parameters["mysql_serverless"]["database"] = cloudformation_outputs.get("MysqlServerlessDatabase") parameters["mysql_serverless"]["arn"] = cloudformation_outputs.get("MysqlServerlessClusterArn") + parameters["postgresql_serverless"]["secret_arn"] = cloudformation_outputs.get("PostgresqlServerlessSecretArn") + parameters["postgresql_serverless"]["schema"] = cloudformation_outputs.get("PostgresqlServerlessSchema") + parameters["postgresql_serverless"]["database"] = cloudformation_outputs.get("PostgresqlServerlessDatabase") + parameters["postgresql_serverless"]["arn"] = cloudformation_outputs.get("PostgresqlServerlessClusterArn") parameters["oracle"]["host"] = cloudformation_outputs.get("OracleAddress") - parameters["oracle"]["port"] = 1521 - parameters["oracle"]["schema"] = "TEST" - parameters["oracle"]["database"] = "ORCL" + parameters["oracle"]["port"] = cloudformation_outputs.get("OraclePort") + parameters["oracle"]["schema"] = cloudformation_outputs.get("OracleSchema") + parameters["oracle"]["database"] = cloudformation_outputs.get("OracleDatabase") parameters["redshift_serverless"]["secret_arn"] = cloudformation_outputs.get("RedshiftServerlessSecretArn") parameters["redshift_serverless"]["workgroup"] = cloudformation_outputs.get("RedshiftServerlessWorkgroup") - parameters["redshift_serverless"]["database"] = "test" + parameters["redshift_serverless"]["database"] = cloudformation_outputs.get("RedshiftServerlessDatabase") return parameters