Bugfix: Allow stop_db_instance for compatible engines
From the RDS documentation: You can stop and start a DB instance whether it is configured for a single Availability Zone or for Multi-AZ, for database engines that support Multi-AZ deployments. You can't stop an Amazon RDS for SQL Server DB instance in a Multi-AZ configuration. https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_StopInstance.html#USER_StopInstance.Limitations
This commit is contained in:
parent
07c33105e5
commit
4dc46a697d
@ -865,7 +865,10 @@ class RDS2Backend(BaseBackend):
|
|||||||
def stop_database(self, db_instance_identifier, db_snapshot_identifier=None):
|
def stop_database(self, db_instance_identifier, db_snapshot_identifier=None):
|
||||||
database = self.describe_databases(db_instance_identifier)[0]
|
database = self.describe_databases(db_instance_identifier)[0]
|
||||||
# todo: certain rds types not allowed to be stopped at this time.
|
# todo: certain rds types not allowed to be stopped at this time.
|
||||||
if database.is_replica or database.multi_az:
|
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_StopInstance.html#USER_StopInstance.Limitations
|
||||||
|
if database.is_replica or (
|
||||||
|
database.multi_az and database.engine.lower().startswith("sqlserver")
|
||||||
|
):
|
||||||
# todo: more db types not supported by stop/start instance api
|
# todo: more db types not supported by stop/start instance api
|
||||||
raise InvalidDBClusterStateFaultError(db_instance_identifier)
|
raise InvalidDBClusterStateFaultError(db_instance_identifier)
|
||||||
if database.status != "available":
|
if database.status != "available":
|
||||||
|
@ -183,12 +183,12 @@ def test_start_database():
|
|||||||
|
|
||||||
|
|
||||||
@mock_rds2
|
@mock_rds2
|
||||||
def test_fail_to_stop_multi_az():
|
def test_fail_to_stop_multi_az_and_sqlserver():
|
||||||
conn = boto3.client("rds", region_name="us-west-2")
|
conn = boto3.client("rds", region_name="us-west-2")
|
||||||
database = conn.create_db_instance(
|
database = conn.create_db_instance(
|
||||||
DBInstanceIdentifier="db-master-1",
|
DBInstanceIdentifier="db-master-1",
|
||||||
AllocatedStorage=10,
|
AllocatedStorage=10,
|
||||||
Engine="postgres",
|
Engine="sqlserver-ee",
|
||||||
DBName="staging-postgres",
|
DBName="staging-postgres",
|
||||||
DBInstanceClass="db.m1.small",
|
DBInstanceClass="db.m1.small",
|
||||||
LicenseModel="license-included",
|
LicenseModel="license-included",
|
||||||
@ -213,6 +213,33 @@ def test_fail_to_stop_multi_az():
|
|||||||
).should.throw(ClientError)
|
).should.throw(ClientError)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_rds2
|
||||||
|
def test_stop_multi_az_postgres():
|
||||||
|
conn = boto3.client("rds", region_name="us-west-2")
|
||||||
|
database = conn.create_db_instance(
|
||||||
|
DBInstanceIdentifier="db-master-1",
|
||||||
|
AllocatedStorage=10,
|
||||||
|
Engine="postgres",
|
||||||
|
DBName="staging-postgres",
|
||||||
|
DBInstanceClass="db.m1.small",
|
||||||
|
LicenseModel="license-included",
|
||||||
|
MasterUsername="root",
|
||||||
|
MasterUserPassword="hunter2",
|
||||||
|
Port=1234,
|
||||||
|
DBSecurityGroups=["my_sg"],
|
||||||
|
MultiAZ=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
mydb = conn.describe_db_instances(
|
||||||
|
DBInstanceIdentifier=database["DBInstance"]["DBInstanceIdentifier"]
|
||||||
|
)["DBInstances"][0]
|
||||||
|
mydb["DBInstanceStatus"].should.equal("available")
|
||||||
|
|
||||||
|
response = conn.stop_db_instance(DBInstanceIdentifier=mydb["DBInstanceIdentifier"])
|
||||||
|
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||||
|
response["DBInstance"]["DBInstanceStatus"].should.equal("stopped")
|
||||||
|
|
||||||
|
|
||||||
@mock_rds2
|
@mock_rds2
|
||||||
def test_fail_to_stop_readreplica():
|
def test_fail_to_stop_readreplica():
|
||||||
conn = boto3.client("rds", region_name="us-west-2")
|
conn = boto3.client("rds", region_name="us-west-2")
|
||||||
|
Loading…
Reference in New Issue
Block a user