コード例 #1
0
def source_status_beat():
    """Source Status push."""
    sources_query = Sources.objects.filter(source_id__isnull=False).all()
    for source in sources_query:
        try:
            status_pusher = SourceStatus(source.source_id)
            LOG.info("Delivering source status for Source ID: %s", source.source_id)
            status_pusher.push_status()
        except ObjectDoesNotExist:
            LOG.info(f"Source status not pushed.  Unable to find Source ID: {source.source_id}")
コード例 #2
0
    def test_push_status_gcp_table_discovery_completed(self,
                                                       mock_set_source_status):
        """Test that push_status for when GCP BigQuery table id is already known."""
        mock_status = {
            "availability_status": "available",
            "availability_status_error": ""
        }
        with patch.object(SourcesHTTPClient,
                          "build_source_status",
                          return_value=mock_status):
            test_source_id = 1
            # Insert a source with ID 1
            Sources.objects.create(
                source_id=test_source_id,
                name="New GCP Mock Test Source",
                source_type=Provider.PROVIDER_GCP,
                koku_uuid=faker.uuid4(),
                authentication={
                    "credentials": {
                        "project_id": "test_project_id"
                    }
                },
                billing_source={
                    "data_source": {
                        "dataset": "test_dataset",
                        "table_id": "billtable"
                    }
                },
                status={
                    "availability_status": "available",
                    "availability_status_error": ""
                },
                offset=1,
            )

            with patch.object(ProviderAccessor,
                              "cost_usage_source_ready",
                              returns=True):
                with patch.object(SourceStatus,
                                  "update_source_name",
                                  returns=True):
                    with patch.object(SourcesProviderCoordinator,
                                      "update_account",
                                      returns=True):
                        status_obj = SourceStatus(test_source_id)
                        status_obj.push_status()
                        mock_set_source_status.assert_called()
コード例 #3
0
    def test_push_status_first_gcp_table_discovery(self,
                                                   mock_set_source_status,
                                                   mock_update_account,
                                                   mock_create_account):
        """Test that push_status for initial discovery of GCP BigQuery table id."""
        mock_status = {
            "availability_status": "available",
            "availability_status_error": ""
        }
        with patch.object(SourcesHTTPClient,
                          "build_source_status",
                          return_value=mock_status):
            test_source_id = 1
            # Insert a source with ID 1
            Sources.objects.create(
                source_id=test_source_id,
                name="New GCP Mock Test Source",
                source_type=Provider.PROVIDER_GCP,
                authentication={
                    "credentials": {
                        "project_id": "test_project_id"
                    }
                },
                billing_source={
                    "data_source": {
                        "dataset": "test_dataset",
                        "table_id": "cost_table"
                    }
                },
                status={},
                offset=1,
            )

            with patch.object(ProviderAccessor,
                              "cost_usage_source_ready",
                              returns=True):
                with patch.object(SourceStatus,
                                  "update_source_name",
                                  returns=True):
                    status_obj = SourceStatus(test_source_id)
                    status_obj.push_status()
                    mock_set_source_status.assert_called()
                    mock_create_account.assert_called()
                    mock_update_account.assert_not_called()