Skip to content

Commit

Permalink
Fix RDS validator for gp3 iops/allocated_storage ratio check (#2225)
Browse files Browse the repository at this point in the history
  • Loading branch information
markpeek authored Feb 14, 2024
1 parent 459609a commit 6b305cd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
35 changes: 35 additions & 0 deletions tests/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,41 @@ def test_allocated_storage_parameter_postgres(self):
)
i.validate()

def test_gp3_storage_performance(self):
# Using a Ref() will disable the gp3 ratio check
db_az = "us-east-1"
allocated_storage = Parameter("allocatedstorage", Type="int")
i = rds.DBInstance(
"Database1",
Engine="postgres",
EngineVersion="15.3",
StorageType="gp3",
AllocatedStorage=Ref(allocated_storage),
Iops=12000,
StorageThroughput=500,
MasterUsername="test",
MasterUserPassword="test",
)
i.validate()

# Specify invalid ratio for iops/allocated_storage for gp3
i = rds.DBInstance(
"Database2",
Engine="postgres",
EngineVersion="15.3",
StorageType="gp3",
AllocatedStorage="400",
Iops=200400,
StorageThroughput=500,
MasterUsername="test",
MasterUserPassword="test",
)
with self.assertRaisesRegex(
ValueError,
r"Invalid ratio of Iops to AllocatedStorage",
):
i.to_dict()

def test_io1_storage_type_and_iops(self):
i = rds.DBInstance(
"NoAZAndMultiAZ",
Expand Down
15 changes: 7 additions & 8 deletions troposphere/validators/rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,17 @@ def validate_dbinstance(self) -> None:
)

# Validate storage performance constraints for iops ratios
if not (
if (
not isinstance(allocated_storage, AWSHelperFn)
and not isinstance(iops, AWSHelperFn)
and (
min_iops_to_allocated_storage_ratio
< iops / int(allocated_storage)
< max_iops_to_allocated_storage_ratio
)
) and not (
min_iops_to_allocated_storage_ratio
< iops / int(allocated_storage)
< max_iops_to_allocated_storage_ratio
):
raise ValueError(
"Invalid ratio of Iops to AllocatedStorage. Minimum ratio for "
f"engine {engine} is {min_iops_to_allocated_storage_ratio} "
f"and maximum ratio is {max_iops_to_allocated_storage_ratio}"
f"current value is {iops / int(allocated_storage)}"
f"and maximum ratio is {max_iops_to_allocated_storage_ratio}. "
f"Current value is {iops / int(allocated_storage)}"
)

0 comments on commit 6b305cd

Please sign in to comment.