Beispiel #1
0
def test_delete_expired_snapshots():
    rds = client('rds', region_name='ap-southeast-2')
    save_service.logger = MagicMock()
    rds.create_db_instance(DBInstanceIdentifier='failsafe_database_5',
                           AllocatedStorage=10,
                           Engine='postgres',
                           DBName='staging-postgres',
                           DBInstanceClass='db.m1.small',
                           LicenseModel='license-included',
                           MasterUsername='******',
                           MasterUserPassword='******',
                           Port=3000,
                           Tags=[
                               {
                                   'Key': 'Failsafe',
                                   'Value': 'true'
                               },
                           ],
                           DBSecurityGroups=["my_sg"])

    rds.create_db_snapshot(DBSnapshotIdentifier='failsafe-snapshot-5', DBInstanceIdentifier='failsafe_database_5')
    manual_snapshot = save_service.get_snapshots(rds, db_instance_id='failsafe_database_5', snapshot_type='manual')[0]
    save_service.perform_delete = MagicMock()
    save_service.delete_expired_snapshots(manual_snapshot, rds, datetime.timedelta(50))
    save_service.perform_delete.assert_called()
Beispiel #2
0
def test_get_snapshots_with_instance_name():
    rds = client('rds', region_name='ap-southeast-2')
    rds.create_db_instance(DBInstanceIdentifier='failsafe_database_2',
                           AllocatedStorage=10,
                           Engine='postgres',
                           DBName='staging-postgres',
                           DBInstanceClass='db.m1.small',
                           LicenseModel='license-included',
                           MasterUsername='******',
                           MasterUserPassword='******',
                           Port=3000,
                           Tags=[
                               {
                                   'Key': 'Failsafe',
                                   'Value': 'true'
                               },
                           ],
                           DBSecurityGroups=["my_sg"])

    rds.create_db_snapshot(DBSnapshotIdentifier='failsafe-snapshot-2', DBInstanceIdentifier='failsafe_database_2')

    instance = 'failsafe_database_2'
    snapshot_type = 'manual'
    list_of_snapshots = save_service.get_snapshots(rds, db_instance_id=instance, snapshot_type=snapshot_type)
    type(list_of_snapshots).should.be(list)
    list_of_snapshots[0]['DBSnapshotIdentifier'].should_not.be.empty
Beispiel #3
0
def test_delete_snapshot_before_copying():
    rds = client('rds', region_name='ap-southeast-2')
    save_service.logger = MagicMock()
    rds.create_db_instance(DBInstanceIdentifier='failsafe_database_5',
                           AllocatedStorage=10,
                           Engine='postgres',
                           DBName='staging-postgres',
                           DBInstanceClass='db.m1.small',
                           LicenseModel='license-included',
                           MasterUsername='******',
                           MasterUserPassword='******',
                           Port=3000,
                           Tags=[
                               {
                                   'Key': 'Failsafe',
                                   'Value': 'true'
                               },
                           ],
                           DBSecurityGroups=["my_sg"])

    rds.create_db_snapshot(DBSnapshotIdentifier='failsafe-snapshot-5', DBInstanceIdentifier='failsafe_database_5')
    manual_snapshots = save_service.get_snapshots(rds, db_instance_id='failsafe_database_5', snapshot_type='manual')
    save_service.local_snapshot_deletion_required('failsafe-snapshot-5', manual_snapshots)
    save_service.logger. \
        warn.assert_called_with('Local copy of failsafe-snapshot-5 already exists - deleting it before copying')
Beispiel #4
0
def test_evaluate_snapshot_age():
    rds = client('rds', region_name='ap-southeast-2')
    save_service.logger = MagicMock()
    rds.create_db_instance(DBInstanceIdentifier='failsafe_database_5',
                           AllocatedStorage=10,
                           Engine='postgres',
                           DBName='staging-postgres',
                           DBInstanceClass='db.m1.small',
                           LicenseModel='license-included',
                           MasterUsername='******',
                           MasterUserPassword='******',
                           Port=3000,
                           Tags=[
                               {
                                   'Key': 'Failsafe',
                                   'Value': 'true'
                               },
                           ],
                           DBSecurityGroups=["my_sg"])

    rds.create_db_snapshot(DBSnapshotIdentifier='failsafe-snapshot-5', DBInstanceIdentifier='failsafe_database_5')
    manual_snapshot = save_service.get_snapshots(rds, db_instance_id='failsafe_database_5', snapshot_type='manual')[0]
    age = save_service.evaluate_snapshot_age(manual_snapshot)
    age.days.should.be(-1)