Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AutoMinorVersionUpgrade in rds cluster and list_tables in timestream #8634

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def __init__(
db_cluster_identifier: str,
engine: str,
allocated_storage: Optional[int] = None,
auto_minor_version_upgrade: bool = True,
engine_version: Optional[str] = None,
master_username: Optional[str] = None,
master_user_password: Optional[str] = None,
Expand All @@ -413,6 +414,7 @@ def __init__(
self.database_name = database_name
self.db_cluster_identifier = db_cluster_identifier
self.db_cluster_instance_class = kwargs.get("db_cluster_instance_class")
self.auto_minor_version_upgrade = auto_minor_version_upgrade
self.deletion_protection = deletion_protection
self.engine = engine
if self.engine not in ClusterEngine.list_cluster_engines():
Expand Down
10 changes: 8 additions & 2 deletions moto/timestreamwrite/responses.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
from typing import Iterable

from moto.core.responses import BaseResponse
from moto.timestreamquery.models import TimestreamQueryBackend, timestreamquery_backends

from .models import TimestreamWriteBackend, timestreamwrite_backends
from .models import TimestreamTable, TimestreamWriteBackend, timestreamwrite_backends


class TimestreamWriteResponse(BaseResponse):
Expand Down Expand Up @@ -85,7 +86,12 @@ def describe_table(self) -> str:

def list_tables(self) -> str:
database_name = self._get_param("DatabaseName")
tables = self.timestreamwrite_backend.list_tables(database_name)
if database_name is None:
tables: Iterable[TimestreamTable] = []
for db in self.timestreamwrite_backend.list_databases():
tables = list(tables) + list(db.list_tables())
else:
tables = self.timestreamwrite_backend.list_tables(database_name)
return json.dumps(dict(Tables=[t.description() for t in tables]))

def update_table(self) -> str:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_rds/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_create_database(client):
DBSecurityGroups=["my_sg"],
VpcSecurityGroupIds=["sg-123456"],
EnableCloudwatchLogsExports=["audit", "error"],
AutoMinorVersionUpgrade=False,
)
db_instance = database["DBInstance"]
assert db_instance["AllocatedStorage"] == 10
Expand All @@ -83,6 +84,7 @@ def test_create_database(client):
assert db_instance["EnabledCloudwatchLogsExports"] == ["audit", "error"]
assert db_instance["Endpoint"]["Port"] == 1234
assert db_instance["DbInstancePort"] == 1234
assert db_instance["AutoMinorVersionUpgrade"] is False


@mock_aws
Expand Down
3 changes: 3 additions & 0 deletions tests/test_rds/test_rds_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,13 @@ def test_create_db_cluster_additional_parameters(client):
},
VpcSecurityGroupIds=["sg1", "sg2"],
EnableIAMDatabaseAuthentication=True,
AutoMinorVersionUpgrade=False,
)

cluster = resp["DBCluster"]

assert cluster["AutoMinorVersionUpgrade"] is False
assert cluster["DBClusterIdentifier"] == "cluster-id"
assert cluster["AvailabilityZones"] == ["eu-north-1b"]
assert cluster["DatabaseName"] == "users"
assert cluster["Engine"] == "aurora-postgresql"
Expand Down
33 changes: 33 additions & 0 deletions tests/test_timestreamwrite/test_timestreamwrite_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,39 @@ def test_create_multiple_tables():
assert {t["TableStatus"] for t in tables} == {"ACTIVE"}


@mock_aws
def test_list_tables_without_database():
ts = boto3.client("timestream-write", region_name="us-east-1")
ts.create_database(DatabaseName="mydatabase")

for idx in range(0, 5):
ts.create_table(
DatabaseName="mydatabase",
TableName=f"mytable_{idx}",
RetentionProperties={
"MemoryStoreRetentionPeriodInHours": 7,
"MagneticStoreRetentionPeriodInDays": 42,
},
)

database = ts.describe_database(DatabaseName="mydatabase")["Database"]

assert database["TableCount"] == 5

# database_name is optional in api call
tables = ts.list_tables()["Tables"]
assert len(tables) == 5
assert {t["DatabaseName"] for t in tables} == {"mydatabase"}
assert {t["TableName"] for t in tables} == {
"mytable_0",
"mytable_1",
"mytable_2",
"mytable_3",
"mytable_4",
}
assert {t["TableStatus"] for t in tables} == {"ACTIVE"}


@mock_aws
def test_delete_table():
ts = boto3.client("timestream-write", region_name="us-east-1")
Expand Down
Loading