def test_get_label_details_unsupported(self): """Test getting label details for supported provider.""" auth = {"role_arn": "roleARN"} accessor = AccountLabel(auth, "acct10001", "unsupported") account_id, alias = accessor.get_label_details() self.assertIsNone(account_id) self.assertIsNone(alias)
def test_get_label_details(self): """Test getting label details for supported provider.""" auth = {"role_arn": "roleARN"} accessor = AccountLabel(auth, "acct10001", "AWS") mock_id = 333 mock_alias = "three" with patch.object(AWSAccountAlias, "update_account_alias", return_value=(mock_id, mock_alias)): account_id, alias = accessor.get_label_details() self.assertEqual(account_id, 333) self.assertEqual(alias, "three")
def prepare(self): """ Prepare a processing request for each account. Scans the database for providers that have reports that need to be processed. Any report it finds is queued to the appropriate celery task to download and process those reports. Args: None Returns: (celery.result.AsyncResult) Async result for download request. """ for account in self._polling_accounts: accounts_labeled = False provider_uuid = account.get("provider_uuid") report_months = self.get_reports(provider_uuid) for month in report_months: LOG.info( "Getting %s report files for account (provider uuid): %s", month.strftime("%B %Y"), provider_uuid) account["report_month"] = month try: _, reports_tasks_queued = self.start_manifest_processing( **account) except ReportDownloaderError as err: LOG.warning( f"Unable to download manifest for provider: {provider_uuid}. Error: {str(err)}." ) continue except Exception as err: # Broad exception catching is important here because any errors thrown can # block all subsequent account processing. LOG.error( f"Unexpected manifest processing error for provider: {provider_uuid}. Error: {str(err)}." ) continue # update labels if reports_tasks_queued and not accounts_labeled: LOG.info("Running AccountLabel to get account aliases.") labeler = AccountLabel( auth=account.get("credentials"), schema=account.get("schema_name"), provider_type=account.get("provider_type"), ) account_number, label = labeler.get_label_details() accounts_labeled = True if account_number: LOG.info("Account: %s Label: %s updated.", account_number, label) return
def test_get_label_details(self): """Test getting label details for supported provider.""" accessor = AccountLabel('roleARN', 'acct10001', 'AWS') mock_id = 333 mock_alias = 'three' with patch.object( AWSAccountAlias, 'update_account_alias', return_value=(mock_id, mock_alias) ): account_id, alias = accessor.get_label_details() self.assertEqual(account_id, 333) self.assertEqual(alias, 'three')
def prepare(self): """ Prepare a processing request for each account. Scans the database for providers that have reports that need to be processed. Any report it finds is queued to the appropriate celery task to download and process those reports. Args: None Returns: (celery.result.AsyncResult) Async result for download request. """ async_result = None for account in self._polling_accounts: provider_uuid = account.get("provider_uuid") report_months = self.get_reports(provider_uuid) for month in report_months: provider_status = ProviderStatus(provider_uuid) if provider_status.is_valid( ) and not provider_status.is_backing_off(): LOG.info( "Getting %s report files for account (provider uuid): %s", month.strftime("%B %Y"), provider_uuid, ) account["report_month"] = month async_result = (get_report_files.s(**account) | summarize_reports.s()).apply_async() LOG.info("Download queued - schema_name: %s, Task ID: %s", account.get("schema_name"), str(async_result)) # update labels labeler = AccountLabel( auth=account.get("authentication"), schema=account.get("schema_name"), provider_type=account.get("provider_type"), ) account_number, label = labeler.get_label_details() if account_number: LOG.info("Account: %s Label: %s updated.", account_number, label) else: LOG.info( "Provider skipped: %s Valid: %s Backing off: %s", account.get("provider_uuid"), provider_status.is_valid(), provider_status.is_backing_off(), ) return async_result
def prepare(self): """ Prepare a processing request for each account. Args: None Returns: (celery.result.AsyncResult) Async result for download request. """ async_result = None for account in self._polling_accounts: provider_uuid = account.get('provider_uuid') report_months = self.get_reports(provider_uuid) for month in report_months: provider_status = ProviderStatus(provider_uuid) if provider_status.is_valid( ) and not provider_status.is_backing_off(): LOG.info( 'Getting %s report files for account (provider uuid): %s', month.strftime('%B %Y'), provider_uuid) account['report_month'] = month async_result = (get_report_files.s(**account) | summarize_reports.s()).\ apply_async() LOG.info('Download queued - schema_name: %s, Task ID: %s', account.get('schema_name'), str(async_result)) # update labels labeler = AccountLabel( auth=account.get('authentication'), schema=account.get('schema_name'), provider_type=account.get('provider_type')) account_number, label = labeler.get_label_details() if account_number: LOG.info('Account: %s Label: %s updated.', account_number, label) else: LOG.info('Provider skipped: %s Valid: %s Backing off: %s', account.get('provider_uuid'), provider_status.is_valid(), provider_status.is_backing_off()) return async_result
def test_initializer_not_supported_provider(self): """Test AccountLabel initializer for unsupported provider.""" auth = {"role_arn": "roleARN"} accessor = AccountLabel(auth, "acct10001", "unsupported") self.assertIsNone(accessor.label)
def test_initializer(self): """Test AccountLabel initializer.""" auth = {"role_arn": "roleARN"} accessor = AccountLabel(auth, "acct10001", "AWS") self.assertIsInstance(accessor.label, AWSAccountAlias)
def test_get_label_details_unsupported(self): """Test getting label details for supported provider.""" accessor = AccountLabel('roleARN', 'acct10001', 'unsupported') account_id, alias = accessor.get_label_details() self.assertIsNone(account_id) self.assertIsNone(alias)
def test_initializer_not_supported_provider(self): """Test AccountLabel initializer for unsupported provider.""" accessor = AccountLabel('roleARN', 'acct10001', 'unsupported') self.assertIsNone(accessor.label)
def test_initializer(self): """Test AccountLabel initializer.""" accessor = AccountLabel('roleARN', 'acct10001', 'AWS') self.assertIsInstance(accessor.label, AWSAccountAlias)