def test_get_reports_error(self, fake_downloader): """Test get_reports 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, provider_id=1) with patch.object(AWSReportDownloader, 'get_report_context_for_date', side_effect=Exception('some error')): with self.assertRaises(ReportDownloaderError): downloader.get_reports()
def _get_report_files(customer_name, authentication, billing_source, provider_type, provider_uuid, 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' provider_uuid (String): Provider uuid. 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'] """ with ProviderDBAccessor(provider_uuid=provider_uuid) as provider_accessor: reports_processed = provider_accessor.get_setup_complete() provider_id = provider_accessor.get_provider().id if Config.INGEST_OVERRIDE or not reports_processed: number_of_months = Config.INITIAL_INGEST_NUM_MONTHS else: number_of_months = 2 stmt = ('Downloading report for' ' credential: {},' ' source: {},' ' customer_name: {},' ' provider: {},' ' number_of_months: {}') log_statement = stmt.format(str(authentication), str(billing_source), customer_name, provider_type, number_of_months) LOG.info(log_statement) try: disk = psutil.disk_usage(Config.PVC_DIR) disk_msg = 'Available disk space: {} bytes ({}%)'.format( disk.free, 100 - disk.percent) except OSError: disk_msg = 'Unable to find available disk space. {} does not exist'.format( Config.PVC_DIR) LOG.info(disk_msg) reports = None try: downloader = ReportDownloader(customer_name=customer_name, access_credential=authentication, report_source=billing_source, provider_type=provider_type, provider_id=provider_id, report_name=report_name) reports = downloader.get_reports(number_of_months) except (MasuProcessingError, MasuProviderError, ReportDownloaderError) as err: worker_stats.REPORT_FILE_DOWNLOAD_ERROR_COUNTER.labels( provider_type=provider_type).inc() LOG.error(str(err)) with ProviderStatus(provider_uuid) as status: status.set_error(error=err) raise err with ProviderStatus(provider_uuid) as status: status.set_status(ProviderStatusCode.READY) return reports