Merge pull request #1053 from rocky4570/rds-stop-start

Rds stop start
This commit is contained in:
Jack Danger 2017-08-14 17:53:32 -07:00 committed by GitHub
commit f6fc9c7d54
4 changed files with 212 additions and 5 deletions

View file

@ -19,9 +19,6 @@ def test_create_database():
MasterUserPassword='hunter2',
Port=1234,
DBSecurityGroups=["my_sg"])
database['DBInstance']['DBInstanceStatus'].should.equal('available')
database['DBInstance']['DBName'].should.equal('staging-postgres')
database['DBInstance']['DBInstanceIdentifier'].should.equal("db-master-1")
database['DBInstance']['AllocatedStorage'].should.equal(10)
database['DBInstance']['DBInstanceClass'].should.equal("db.m1.small")
database['DBInstance']['LicenseModel'].should.equal("license-included")
@ -30,6 +27,122 @@ def test_create_database():
'DBSecurityGroupName'].should.equal('my_sg')
database['DBInstance']['DBInstanceArn'].should.equal(
'arn:aws:rds:us-west-2:1234567890:db:db-master-1')
database['DBInstance']['DBInstanceStatus'].should.equal('available')
database['DBInstance']['DBName'].should.equal('staging-postgres')
database['DBInstance']['DBInstanceIdentifier'].should.equal("db-master-1")
@mock_rds2
def test_stop_database():
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"])
mydb = conn.describe_db_instances(DBInstanceIdentifier=database['DBInstance']['DBInstanceIdentifier'])['DBInstances'][0]
mydb['DBInstanceStatus'].should.equal('available')
# test stopping database should shutdown
response = conn.stop_db_instance(DBInstanceIdentifier=mydb['DBInstanceIdentifier'])
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
response['DBInstance']['DBInstanceStatus'].should.equal('shutdown')
# test rdsclient error when trying to stop an already stopped database
conn.stop_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier']).should.throw(ClientError)
# test stopping a stopped database with snapshot should error and no snapshot should exist for that call
conn.stop_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier'], DBSnapshotIdentifier='rocky4570-rds-snap').should.throw(ClientError)
response = conn.describe_db_snapshots()
response['DBSnapshots'].should.equal([])
@mock_rds2
def test_start_database():
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"])
mydb = conn.describe_db_instances(DBInstanceIdentifier=database['DBInstance']['DBInstanceIdentifier'])['DBInstances'][0]
mydb['DBInstanceStatus'].should.equal('available')
# test starting an already started database should error
conn.start_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier']).should.throw(ClientError)
# stop and test start - should go from shutdown to available, create snapshot and check snapshot
response = conn.stop_db_instance(DBInstanceIdentifier=mydb['DBInstanceIdentifier'], DBSnapshotIdentifier='rocky4570-rds-snap')
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
response['DBInstance']['DBInstanceStatus'].should.equal('shutdown')
response = conn.describe_db_snapshots()
response['DBSnapshots'][0]['DBSnapshotIdentifier'].should.equal('rocky4570-rds-snap')
response = conn.start_db_instance(DBInstanceIdentifier=mydb['DBInstanceIdentifier'])
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
response['DBInstance']['DBInstanceStatus'].should.equal('available')
# starting database should not remove snapshot
response = conn.describe_db_snapshots()
response['DBSnapshots'][0]['DBSnapshotIdentifier'].should.equal('rocky4570-rds-snap')
# test stopping database, create snapshot with existing snapshot already created should throw error
conn.stop_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier'], DBSnapshotIdentifier='rocky4570-rds-snap').should.throw(ClientError)
# test stopping database not invoking snapshot should succeed.
response = conn.stop_db_instance(DBInstanceIdentifier=mydb['DBInstanceIdentifier'])
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
response['DBInstance']['DBInstanceStatus'].should.equal('shutdown')
@mock_rds2
def test_fail_to_stop_multi_az():
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')
# multi-az databases arent allowed to be shutdown at this time.
conn.stop_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier']).should.throw(ClientError)
# multi-az databases arent allowed to be started up at this time.
conn.start_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier']).should.throw(ClientError)
@mock_rds2
def test_fail_to_stop_readreplica():
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"])
replica = conn.create_db_instance_read_replica(DBInstanceIdentifier="db-replica-1",
SourceDBInstanceIdentifier="db-master-1",
DBInstanceClass="db.m1.small")
mydb = conn.describe_db_instances(DBInstanceIdentifier=replica['DBInstance']['DBInstanceIdentifier'])['DBInstances'][0]
mydb['DBInstanceStatus'].should.equal('available')
# read-replicas are not allowed to be stopped at this time.
conn.stop_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier']).should.throw(ClientError)
# read-replicas are not allowed to be started at this time.
conn.start_db_instance.when.called_with(DBInstanceIdentifier=mydb['DBInstanceIdentifier']).should.throw(ClientError)
@mock_rds2