Ejemplo n.º 1
0
 def test_get_current_report_error(self, fake_downloader):
     """Test get_current_report function with error."""
     downloader = ReportDownloader(customer_name='customer name',
                                   access_credential=self.fake_creds,
                                   report_source='hereiam',
                                   report_name='bestreport',
                                   provider_type=AMAZON_WEB_SERVICES)
     with patch.object(AWSReportDownloader,
                       'download_current_report',
                       side_effect=Exception('some error')):
         with self.assertRaises(ReportDownloaderError):
             downloader.get_current_report()
Ejemplo n.º 2
0
 def test_get_current_report(self, fake_downloader):
     """Test get_current_report function."""
     downloader = ReportDownloader(customer_name='customer name',
                                   access_credential=self.fake_creds,
                                   report_source='hereiam',
                                   report_name='bestreport',
                                   provider_type=AMAZON_WEB_SERVICES)
     with patch.object(AWSReportDownloader,
                       'download_current_report',
                       return_value=self.file_list):
         files = downloader.get_current_report()
         self.assertEqual(len(files), len(self.file_list))
Ejemplo n.º 3
0
def _get_report_files(customer_name,
                      authentication,
                      billing_source,
                      provider_type,
                      report_name=None):
    """
    Task to download a Report.

    Note that report_name will be not optional once Koku can specify
    what report we should download.

    Args:
        customer_name     (String): Name of the customer owning the cost usage report.
        access_credential (String): Credential needed to access cost usage report
                                    in the backend provider.
        report_source     (String): Location of the cost usage report in the backend provider.
        provider_type     (String): Koku defined provider type string.  Example: Amazon = 'AWS'
        report_name       (String): Name of the cost usage report to download.

    Returns:
        files (List) List of filenames with full local path.
               Example: ['/var/tmp/masu/region/aws/catch-clearly.csv',
                         '/var/tmp/masu/base/aws/professor-hour-industry-television.csv']

    """
    stmt = ('Downloading report for'
            ' credential: {},'
            ' source: {},'
            ' customer_name: {},'
            ' provider: {}')
    log_statement = stmt.format(authentication, billing_source, customer_name,
                                provider_type)
    LOG.info(log_statement)
    try:
        disk = psutil.disk_usage(Config.TMP_DIR)
        disk_msg = 'Avaiable disk space: {} bytes ({}%)'.format(
            disk.free, 100 - disk.percent)
    except OSError:
        disk_msg = 'Unable to find avaiable disk space. {} does not exist'.format(
            Config.TMP_DIR)
    LOG.info(disk_msg)

    try:
        downloader = ReportDownloader(customer_name=customer_name,
                                      access_credential=authentication,
                                      report_source=billing_source,
                                      provider_type=provider_type,
                                      report_name=report_name)
        return downloader.get_current_report()
    except (MasuProcessingError, MasuProviderError,
            ReportDownloaderError) as err:
        LOG.error(str(err))
        raise err