Skip to content

Commit

Permalink
tests: Add Aurora PostgreSQL Serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
kukushking committed Jul 10, 2023
1 parent 5f6cb6a commit 0da2e92
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 17 deletions.
56 changes: 56 additions & 0 deletions test_infra/stacks/databases_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down
38 changes: 21 additions & 17 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 0da2e92

Please sign in to comment.