Exemplo n.º 1
0
 def test_restore_db_cluster_invalid_secrets(self, mock_rds,
                                             mock_secrets_client):
     os.environ['STAGE'] = 'QA'
     os.environ['CAN_DELETE_DB'] = 'false'
     my_secret_string = json.dumps({})
     mock_secret_payload = {"SecretString": my_secret_string}
     mock_secrets_client.get_secret_value.return_value = mock_secret_payload
     with self.assertRaises(Exception) as context:
         db_create_handler.restore_db_cluster({}, {})
     mock_rds.restore_db_cluster_from_snapshot.assert_not_called()
    def test_restore_db_cluster(self, mock_rds, mock_secrets_client):
        os.environ['STAGE'] = 'QA'
        os.environ['CAN_DELETE_DB'] = 'true'
        my_secret_string = json.dumps({
            "KMS_KEY_ID": "kms",
            "DB_SUBGROUP_NAME": "subgroup",
            "VPC_SECURITY_GROUP_ID": "vpc_id"
        })
        mock_secret_payload = {"SecretString": my_secret_string}
        mock_secrets_client.get_secret_value.return_value = mock_secret_payload

        db_create_handler.restore_db_cluster({}, {})
        mock_rds.restore_db_cluster_from_snapshot.assert_called_once()
Exemplo n.º 3
0
 def test_restore_db_cluster_invalid_tier(self, mock_rds,
                                          mock_secrets_client):
     os.environ['STAGE'] = 'QA'
     os.environ['CAN_DELETE_DB'] = 'false'
     my_secret_string = json.dumps({
         "KMS_KEY_ID": "kms",
         "DB_SUBGROUP_NAME": "subgroup",
         "VPC_SECURITY_GROUP_ID": "vpc_id"
     })
     mock_secret_payload = {"SecretString": my_secret_string}
     mock_secrets_client.get_secret_value.return_value = mock_secret_payload
     with self.assertRaises(Exception) as context:
         db_create_handler.restore_db_cluster({}, {})
     mock_rds.restore_db_cluster_from_snapshot.assert_not_called()
Exemplo n.º 4
0
    def test_restore_db_cluster(self, mock_rds, mock_secrets_client):
        os.environ['STAGE'] = 'QA'
        os.environ['CAN_DELETE_DB'] = 'true'
        my_secret_string = json.dumps({
            "KMS_KEY_ID": "kms",
            "DB_SUBGROUP_NAME": "subgroup",
            "VPC_SECURITY_GROUP_ID": "vpc_id"
        })
        mock_secret_payload = {"SecretString": my_secret_string}
        mock_secrets_client.get_secret_value.return_value = mock_secret_payload

        db_create_handler.restore_db_cluster({}, {})
        mock_rds.restore_db_cluster_from_snapshot.assert_called_once_with(
            DBClusterIdentifier=DEFAULT_DB_CLUSTER_IDENTIFIER,
            SnapshotIdentifier=db_create_handler.get_snapshot_identifier(),
            Engine='aurora-postgresql',
            EngineVersion='11.7',
            Port=5432,
            DBSubnetGroupName='subgroup',
            DatabaseName='nwcapture-qa',
            EnableIAMDatabaseAuthentication=False,
            EngineMode='provisioned',
            DBClusterParameterGroupName='aqts-capture',
            DeletionProtection=False,
            CopyTagsToSnapshot=False,
            KmsKeyId='kms',
            VpcSecurityGroupIds=['vpc_id'],
            Tags=[{
                'Key': 'Name',
                'Value': 'NWISWEB-CAPTURE-RDS-AURORA-TEST'
            }, {
                'Key': 'wma:applicationId',
                'Value': 'NWISWEB-CAPTURE'
            }, {
                'Key': 'wma:contact',
                'Value': 'tbd'
            }, {
                'Key': 'wma:costCenter',
                'Value': 'tbd'
            }, {
                'Key': 'wma:criticality',
                'Value': 'tbd'
            }, {
                'Key': 'wma:environment',
                'Value': 'qa'
            }, {
                'Key': 'wma:operationalHours',
                'Value': 'tbd'
            }, {
                'Key': 'wma:organization',
                'Value': 'IOW'
            }, {
                'Key': 'wma:role',
                'Value': 'database'
            }, {
                'Key': 'wma:system',
                'Value': 'NWIS'
            }, {
                'Key': 'wma:subSystem',
                'Value': 'NWISWeb-Capture'
            }, {
                'Key': 'taggingVersion',
                'Value': '0.0.1'
            }])