RDS Filtering on db-cluster-id (#5101)

This commit is contained in:
mattBrzezinski 2022-05-06 12:11:55 -05:00 committed by GitHub
parent beb05662e4
commit 3f948aa5ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -307,7 +307,7 @@ class ClusterSnapshot(BaseModel):
class Database(CloudFormationModel): class Database(CloudFormationModel):
SUPPORTED_FILTERS = { SUPPORTED_FILTERS = {
"db-cluster-id": FilterDef(None, "DB Cluster Identifiers"), "db-cluster-id": FilterDef(["db_cluster_identifier"], "DB Cluster Identifiers"),
"db-instance-id": FilterDef( "db-instance-id": FilterDef(
["db_instance_arn", "db_instance_identifier"], "DB Instance Identifiers" ["db_instance_arn", "db_instance_identifier"], "DB Instance Identifiers"
), ),
@ -357,6 +357,7 @@ class Database(CloudFormationModel):
self.allocated_storage = Database.default_allocated_storage( self.allocated_storage = Database.default_allocated_storage(
engine=self.engine, storage_type=self.storage_type engine=self.engine, storage_type=self.storage_type
) )
self.db_cluster_identifier = kwargs.get("db_cluster_identifier")
self.db_instance_identifier = kwargs.get("db_instance_identifier") self.db_instance_identifier = kwargs.get("db_instance_identifier")
self.source_db_identifier = kwargs.get("source_db_identifier") self.source_db_identifier = kwargs.get("source_db_identifier")
self.db_instance_class = kwargs.get("db_instance_class") self.db_instance_class = kwargs.get("db_instance_class")
@ -494,6 +495,7 @@ class Database(CloudFormationModel):
</VpcSecurityGroupMembership> </VpcSecurityGroupMembership>
{% endfor %} {% endfor %}
</VpcSecurityGroups> </VpcSecurityGroups>
<DBClusterIdentifier>{{ database.db_cluster_identifier }}</DBClusterIdentifier>
<DBInstanceIdentifier>{{ database.db_instance_identifier }}</DBInstanceIdentifier> <DBInstanceIdentifier>{{ database.db_instance_identifier }}</DBInstanceIdentifier>
<DbiResourceId>{{ database.dbi_resource_id }}</DbiResourceId> <DbiResourceId>{{ database.dbi_resource_id }}</DbiResourceId>
<InstanceCreateTime>{{ database.instance_create_time }}</InstanceCreateTime> <InstanceCreateTime>{{ database.instance_create_time }}</InstanceCreateTime>
@ -740,6 +742,7 @@ class Database(CloudFormationModel):
"BackupRetentionPeriod": "{{ database.backup_retention_period }}", "BackupRetentionPeriod": "{{ database.backup_retention_period }}",
"CharacterSetName": {%- if database.character_set_name -%}{{ database.character_set_name }}{%- else %} null{%- endif -%}, "CharacterSetName": {%- if database.character_set_name -%}{{ database.character_set_name }}{%- else %} null{%- endif -%},
"DBInstanceClass": "{{ database.db_instance_class }}", "DBInstanceClass": "{{ database.db_instance_class }}",
"DBClusterIdentifier": "{{ database.db_cluster_identifier }}",
"DBInstanceIdentifier": "{{ database.db_instance_identifier }}", "DBInstanceIdentifier": "{{ database.db_instance_identifier }}",
"DBInstanceStatus": "{{ database.status }}", "DBInstanceStatus": "{{ database.status }}",
"DBName": {%- if database.db_name -%}"{{ database.db_name }}"{%- else %} null{%- endif -%}, "DBName": {%- if database.db_name -%}"{{ database.db_name }}"{%- else %} null{%- endif -%},

View File

@ -19,6 +19,7 @@ class RDSResponse(BaseResponse):
"backup_retention_period": self._get_param("BackupRetentionPeriod"), "backup_retention_period": self._get_param("BackupRetentionPeriod"),
"copy_tags_to_snapshot": self._get_param("CopyTagsToSnapshot"), "copy_tags_to_snapshot": self._get_param("CopyTagsToSnapshot"),
"db_instance_class": self._get_param("DBInstanceClass"), "db_instance_class": self._get_param("DBInstanceClass"),
"db_cluster_identifier": self._get_param("DBClusterIdentifier"),
"db_instance_identifier": self._get_param("DBInstanceIdentifier"), "db_instance_identifier": self._get_param("DBInstanceIdentifier"),
"db_name": self._get_param("DBName"), "db_name": self._get_param("DBName"),
"db_parameter_group_name": self._get_param("DBParameterGroupName"), "db_parameter_group_name": self._get_param("DBParameterGroupName"),

View File

@ -15,10 +15,12 @@ class TestDBInstanceFilters(object):
cls.mock.start() cls.mock.start()
client = boto3.client("rds", region_name="us-west-2") client = boto3.client("rds", region_name="us-west-2")
for i in range(10): for i in range(10):
identifier = "db-instance-{}".format(i) instance_identifier = "db-instance-{}".format(i)
cluster_identifier = "db-cluster-{}".format(i)
engine = "postgres" if (i % 3) else "mysql" engine = "postgres" if (i % 3) else "mysql"
client.create_db_instance( client.create_db_instance(
DBInstanceIdentifier=identifier, DBInstanceIdentifier=instance_identifier,
DBClusterIdentifier=cluster_identifier,
Engine=engine, Engine=engine,
DBInstanceClass="db.m1.small", DBInstanceClass="db.m1.small",
) )
@ -49,6 +51,16 @@ class TestDBInstanceFilters(object):
ex.value.response["Error"]["Code"].should.equal("InvalidParameterCombination") ex.value.response["Error"]["Code"].should.equal("InvalidParameterCombination")
ex.value.response["Error"]["Message"].should.contain("must not be empty") ex.value.response["Error"]["Message"].should.contain("must not be empty")
def test_db_cluster_id_filter(self):
resp = self.client.describe_db_instances()
db_cluster_identifier = resp["DBInstances"][0]["DBClusterIdentifier"]
db_instances = self.client.describe_db_instances(
Filters=[{"Name": "db-cluster-id", "Values": [db_cluster_identifier]}]
).get("DBInstances")
db_instances.should.have.length_of(1)
db_instances[0]["DBClusterIdentifier"].should.equal(db_cluster_identifier)
def test_db_instance_id_filter(self): def test_db_instance_id_filter(self):
resp = self.client.describe_db_instances() resp = self.client.describe_db_instances()
db_instance_identifier = resp["DBInstances"][0]["DBInstanceIdentifier"] db_instance_identifier = resp["DBInstances"][0]["DBInstanceIdentifier"]