Skip to content

Commit

Permalink
RDS: Add AvailabilityZone to describe_db_instances (#5373)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3hG04T authored Aug 10, 2022
1 parent 9dab6cd commit c4965d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ def __init__(self, **kwargs):
if self.backup_retention_period is None:
self.backup_retention_period = 1
self.availability_zone = kwargs.get("availability_zone")
if not self.availability_zone:
self.availability_zone = f"{self.region_name}a"
self.multi_az = kwargs.get("multi_az")
self.db_subnet_group_name = kwargs.get("db_subnet_group_name")
if self.db_subnet_group_name:
Expand Down Expand Up @@ -495,6 +497,7 @@ def default_db_parameter_group_details(self):
def to_xml(self):
template = Template(
"""<DBInstance>
<AvailabilityZone>{{ database.availability_zone }}</AvailabilityZone>
<BackupRetentionPeriod>{{ database.backup_retention_period }}</BackupRetentionPeriod>
<DBInstanceStatus>{{ database.status }}</DBInstanceStatus>
{% if database.db_name %}<DBName>{{ database.db_name }}</DBName>{% endif %}
Expand Down
36 changes: 36 additions & 0 deletions tests/test_rds/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,3 +2019,39 @@ def test_create_db_instance_with_tags():

resp = client.describe_db_instances(DBInstanceIdentifier=db_instance_identifier)
resp["DBInstances"][0]["TagList"].should.equal(tags)


@mock_rds
def test_create_db_instance_without_availability_zone():
region = "us-east-1"
client = boto3.client("rds", region_name=region)
db_instance_identifier = "test-db-instance"
resp = client.create_db_instance(
DBInstanceIdentifier=db_instance_identifier,
Engine="postgres",
DBName="staging-postgres",
DBInstanceClass="db.m1.small",
)
resp["DBInstance"]["AvailabilityZone"].should.contain(region)

resp = client.describe_db_instances(DBInstanceIdentifier=db_instance_identifier)
resp["DBInstances"][0]["AvailabilityZone"].should.contain(region)


@mock_rds
def test_create_db_instance_with_availability_zone():
region = "us-east-1"
availability_zone = f"{region}c"
client = boto3.client("rds", region_name=region)
db_instance_identifier = "test-db-instance"
resp = client.create_db_instance(
DBInstanceIdentifier=db_instance_identifier,
Engine="postgres",
DBName="staging-postgres",
DBInstanceClass="db.m1.small",
AvailabilityZone=availability_zone,
)
resp["DBInstance"]["AvailabilityZone"].should.equal(availability_zone)

resp = client.describe_db_instances(DBInstanceIdentifier=db_instance_identifier)
resp["DBInstances"][0]["AvailabilityZone"].should.equal(availability_zone)

0 comments on commit c4965d1

Please sign in to comment.