Пример #1
0
    def test_post_status_provider_unavailable(self):
        """Test that the provider active flag is set to true when source is unavailable."""
        request = self.request_context.get("request")
        source_id = 1
        source_name = "New AWS Mock Test Source"

        with patch.object(ProviderAccessor,
                          "cost_usage_source_ready",
                          side_effect=ValidationError("test error")):
            provider = Provider.objects.create(name=source_name,
                                               created_by=request.user,
                                               customer=request.user.customer,
                                               active=True)

            Sources.objects.create(
                source_id=1,
                name=source_name,
                source_type=Provider.PROVIDER_AWS,
                authentication={"credentials": {
                    "role_arn": "fake-iam"
                }},
                billing_source={"data_source": {
                    "bucket": "my-bucket"
                }},
                koku_uuid=str(provider.uuid),
                offset=1,
            )
            status_obj = SourceStatus(request, source_id)
            status_obj.status()

            self.assertFalse(Provider.objects.get(uuid=provider.uuid).active)
Пример #2
0
    def test_post_status_wrong_provider(self):
        """Test for logs when provider mismatch is detected while setting status."""
        request = self.request_context.get("request")
        source_id = 1
        source_name = "New AWS Mock Test Source"

        with patch.object(ProviderAccessor,
                          "cost_usage_source_ready",
                          returns=True):
            Sources.objects.create(
                source_id=source_id,
                name=source_name,
                source_type=Provider.PROVIDER_AWS,
                authentication={"credentials": {
                    "role_arn": "fake-iam"
                }},
                billing_source={"data_source": {
                    "bucket": "my-bucket"
                }},
                koku_uuid=str(uuid4()),
                offset=1,
            )
            status_obj = SourceStatus(request, source_id)
            with self.assertLogs("sources.api.source_status",
                                 level="INFO") as logger:
                status_obj.status()
                expected = f"INFO:sources.api.source_status:No provider found for Source ID: {source_id}"
                self.assertIn(expected, logger.output)
Пример #3
0
 def status(self, request, *args, **kwargs):
     """Get source availability status."""
     source_id = kwargs.get('source_id')
     try:
         source_status_obj = SourceStatus(source_id)
         availability_status = source_status_obj.status()
         return Response(availability_status, status=status.HTTP_200_OK)
     except Sources.DoesNotExist:
         return Response(status=status.HTTP_404_NOT_FOUND)