def test_upload_archive(self):
        mock = mock_s3()
        mock.start()

        config_01 = {
            'AWS': {
                's3_bucket_name': 'my_bucket',
                's3_region': 'eu-west-1',
                'price_per_gb': '0.0023',
                'budget_cost': '30',
            }
        }

        self.assertTrue(
            post_recording.upload_archive(self.db_test, config_01['AWS']))

        self.__creates_archives()
        s3 = boto3.resource('s3')
        s3.create_bucket(Bucket=config_01['AWS']['s3_bucket_name'])
        self.assertTrue(
            post_recording.upload_archive(self.db_test, config_01['AWS']))
        mock.stop()
        remove('./archive_02.zip')

        # Check if the Archive entry changed correctly
        self.assertEqual(2, len(get_archives_uploaded(self.db_test)))
Beispiel #2
0
def main():

    list_of_archives = query.get_archives_uploaded(db)
    for archive in list_of_archives:
        current_remote = archive.remote_path
        new_remote_path = current_remote.replace('.eu-', '.s3-eu-')
        archive.remote_path = new_remote_path
Beispiel #3
0
    def test_get_archives_uploaded(self):
        self.__populate_test_db()
        q = get_archives_uploaded(self.db_test)

        self.assertEqual(
            len(q),
            1
        )
Beispiel #4
0
def check_aws_budget(db, aws_config):
    """
    This routine checks if the budget used in AWS was exceeded or not
    :param db: Pony DB Connection
    :param aws_config: AWS Config Dict
    :return: Amount to reach budget (positive) or amount already over
            (negative)
    """

    budget_max = float(aws_config['budget_cost'])
    if budget_max == 0:
        return float('Inf')

    # Get all Archives already uploaded to AWS
    archives_uploaded = query.get_archives_uploaded(db)
    uploaded_gb = (sum(o.size for o in archives_uploaded) / 1024)

    current_amount = float(aws_config['price_per_gb']) * uploaded_gb
    return budget_max - current_amount
Beispiel #5
0
def remove_uploaded_archives(db):
    """
    Remove all archives Uploaded but in FileSystem
    :param db: DB Connection to Pony
    :return: List of removed Archives
    """

    list_of_local_archives = query.get_archives_uploaded(db)

    if len(list_of_local_archives) == 0:
        return 0

    removed_archives_list = list()
    for archive in list_of_local_archives:
        archive_path = archive.local_path

        if path.isfile(archive_path):
            remove(archive_path)
            archive.removed = True
            removed_archives_list.append(archive)

    return removed_archives_list