RDS Filtering on db-cluster-id (#5101)
This commit is contained in:
parent
beb05662e4
commit
3f948aa5ae
@ -307,7 +307,7 @@ class ClusterSnapshot(BaseModel):
|
||||
class Database(CloudFormationModel):
|
||||
|
||||
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_arn", "db_instance_identifier"], "DB Instance Identifiers"
|
||||
),
|
||||
@ -357,6 +357,7 @@ class Database(CloudFormationModel):
|
||||
self.allocated_storage = Database.default_allocated_storage(
|
||||
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.source_db_identifier = kwargs.get("source_db_identifier")
|
||||
self.db_instance_class = kwargs.get("db_instance_class")
|
||||
@ -494,6 +495,7 @@ class Database(CloudFormationModel):
|
||||
</VpcSecurityGroupMembership>
|
||||
{% endfor %}
|
||||
</VpcSecurityGroups>
|
||||
<DBClusterIdentifier>{{ database.db_cluster_identifier }}</DBClusterIdentifier>
|
||||
<DBInstanceIdentifier>{{ database.db_instance_identifier }}</DBInstanceIdentifier>
|
||||
<DbiResourceId>{{ database.dbi_resource_id }}</DbiResourceId>
|
||||
<InstanceCreateTime>{{ database.instance_create_time }}</InstanceCreateTime>
|
||||
@ -740,6 +742,7 @@ class Database(CloudFormationModel):
|
||||
"BackupRetentionPeriod": "{{ database.backup_retention_period }}",
|
||||
"CharacterSetName": {%- if database.character_set_name -%}{{ database.character_set_name }}{%- else %} null{%- endif -%},
|
||||
"DBInstanceClass": "{{ database.db_instance_class }}",
|
||||
"DBClusterIdentifier": "{{ database.db_cluster_identifier }}",
|
||||
"DBInstanceIdentifier": "{{ database.db_instance_identifier }}",
|
||||
"DBInstanceStatus": "{{ database.status }}",
|
||||
"DBName": {%- if database.db_name -%}"{{ database.db_name }}"{%- else %} null{%- endif -%},
|
||||
|
@ -19,6 +19,7 @@ class RDSResponse(BaseResponse):
|
||||
"backup_retention_period": self._get_param("BackupRetentionPeriod"),
|
||||
"copy_tags_to_snapshot": self._get_param("CopyTagsToSnapshot"),
|
||||
"db_instance_class": self._get_param("DBInstanceClass"),
|
||||
"db_cluster_identifier": self._get_param("DBClusterIdentifier"),
|
||||
"db_instance_identifier": self._get_param("DBInstanceIdentifier"),
|
||||
"db_name": self._get_param("DBName"),
|
||||
"db_parameter_group_name": self._get_param("DBParameterGroupName"),
|
||||
|
@ -15,10 +15,12 @@ class TestDBInstanceFilters(object):
|
||||
cls.mock.start()
|
||||
client = boto3.client("rds", region_name="us-west-2")
|
||||
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"
|
||||
client.create_db_instance(
|
||||
DBInstanceIdentifier=identifier,
|
||||
DBInstanceIdentifier=instance_identifier,
|
||||
DBClusterIdentifier=cluster_identifier,
|
||||
Engine=engine,
|
||||
DBInstanceClass="db.m1.small",
|
||||
)
|
||||
@ -49,6 +51,16 @@ class TestDBInstanceFilters(object):
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterCombination")
|
||||
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):
|
||||
resp = self.client.describe_db_instances()
|
||||
db_instance_identifier = resp["DBInstances"][0]["DBInstanceIdentifier"]
|
||||
|
Loading…
Reference in New Issue
Block a user