def get_account_from_cluster_id(cluster_id, request_id, context={}): """ Returns the provider details for a given OCP cluster id. Args: cluster_id (String): Cluster UUID. request_id (String): Identifier associated with the payload context (Dict): Context for logging (account, etc) Returns: (dict) - keys: value authentication: String, customer_name: String, billing_source: String, provider_type: String, schema_name: String, provider_uuid: String """ account = None provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id) if provider_uuid: msg = f"Found provider_uuid: {str(provider_uuid)} for cluster_id: {str(cluster_id)}" LOG.info(log_json(request_id, msg, context)) if context: context["provider_uuid"] = provider_uuid account = get_account(provider_uuid, request_id, context) return account
def process_report(report): """ Process line item report and kick off summarization celery task. Args: report (Dict) - keys: value file: String, cluster_id: String, payload_date: DateTime, manifest_path: String, uuid: String, manifest_path: String Returns: None """ cluster_id = report.get('cluster_id') provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id) if provider_uuid: LOG.info('Found provider_uuid: %s for cluster_id: %s', str(provider_uuid), str(cluster_id)) account = get_account(provider_uuid) LOG.info('Processing report for account %s', account) reports_to_summarize = get_report_files(**account) LOG.info('Processing complete for account %s', account) async_id = summarize_reports.delay(reports_to_summarize) LOG.info('Summarization celery uuid: %s', str(async_id)) else: LOG.error('Could not find provider_uuid for cluster_id: %s', str(cluster_id))
def test_get_provider_uuid_from_cluster_id(self): """Test that the provider uuid is returned for a cluster ID.""" cluster_id = self.ocp_provider_resource_name provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id) try: UUID(provider_uuid) except ValueError: self.fail('{} is not a valid uuid.'.format(str(provider_uuid)))
def test_get_provider_uuid_from_cluster_id(self): """Test that the provider uuid is returned for a cluster ID.""" cluster_id = self.ocp_cluster_id provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id) try: UUID(provider_uuid) except ValueError: self.fail(f"{str(provider_uuid)} is not a valid uuid.")
def get_account_from_cluster_id(cluster_id): """ Returns the provider details for a given OCP cluster id. Args: cluster_id (String): Cluster UUID. Returns: (dict) - keys: value authentication: String, customer_name: String, billing_source: String, provider_type: String, schema_name: String, provider_uuid: String """ account = None provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id) if provider_uuid: LOG.info("Found provider_uuid: %s for cluster_id: %s", str(provider_uuid), str(cluster_id)) account = get_account(provider_uuid) return account
def process_report(report): """ Process line item report and kick off summarization celery task. Args: report (Dict) - keys: value file: String, cluster_id: String, date: DateTime, manifest_path: String, uuid: String, manifest_path: String Returns: None """ cluster_id = report.get("cluster_id") provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id) if provider_uuid: LOG.info("Found provider_uuid: %s for cluster_id: %s", str(provider_uuid), str(cluster_id)) account = get_account(provider_uuid) if account: payload_date = report.get("date") report_month = payload_date.replace(day=1, second=1, microsecond=1).date() account["report_month"] = str(report_month) LOG.info("Processing %s report for account %s", payload_date.strftime("%B %Y"), account) reports_to_summarize = get_report_files(**account) LOG.info("Processing complete for account %s", account) async_id = summarize_reports.delay(reports_to_summarize) LOG.info("Summarization celery uuid: %s", str(async_id)) else: LOG.error("Could not find provider_uuid for cluster_id: %s", str(cluster_id))
def test_get_provider_uuid_from_invalid_cluster_id(self): """Test that the provider uuid is not returned for an invalid cluster ID.""" cluster_id = 'bad_cluster_id' provider_uuid = utils.get_provider_uuid_from_cluster_id(cluster_id) self.assertIsNone(provider_uuid)