Exemple #1
0
    def test_ocp_on_azure_infrastructure_type(self):
        """Test that the provider infrastructure returns Azure when running on Azure."""
        credentials = {"cluster_id": "cluster_id_1002"}
        provider_authentication = ProviderAuthentication.objects.create(
            credentials=credentials)
        azure_provider = Provider.objects.filter(type="Azure-local").first()
        infrastructure = ProviderInfrastructureMap.objects.create(
            infrastructure_type=Provider.PROVIDER_AZURE,
            infrastructure_provider=azure_provider)
        with patch("masu.celery.tasks.check_report_updates"):
            provider = Provider.objects.create(
                name="ocpprovidername",
                type=Provider.PROVIDER_OCP,
                created_by=self.user,
                customer=self.customer,
                authentication=provider_authentication,
                infrastructure=infrastructure,
            )

        provider_uuid = provider.uuid
        manager = ProviderManager(provider_uuid)
        infrastructure_info = manager.get_infrastructure_info()
        self.assertEqual(infrastructure_info.get("type", ""),
                         Provider.PROVIDER_AZURE)
        self.assertEqual(infrastructure_info.get("uuid", ""),
                         azure_provider.uuid)
Exemple #2
0
    def test_ocp_infrastructure_type_error(self):
        """Test that the provider infrastructure returns Unknown when running stand alone."""
        credentials = {"cluster_id": "cluster_id_1001"}
        provider_authentication = ProviderAuthentication.objects.create(
            credentials=credentials)
        with patch("masu.celery.tasks.check_report_updates"):
            provider = Provider.objects.create(
                name="ocpprovidername",
                type=Provider.PROVIDER_OCP,
                created_by=self.user,
                customer=self.customer,
                authentication=provider_authentication,
            )

        provider_uuid = provider.uuid
        manager = ProviderManager(provider_uuid)
        infrastructure_info = manager.get_infrastructure_info()
        self.assertEqual(infrastructure_info, {})
Exemple #3
0
 def list(self, request, *args, **kwargs):
     """Obtain the list of sources."""
     response = super().list(request=request, args=args, kwargs=kwargs)
     _, tenant = self._get_account_and_tenant(request)
     for source in response.data["data"]:
         if (source.get("authentication")
                 and source.get("authentication").get("credentials")
                 and source.get("authentication").get("credentials").get(
                     "client_secret")):
             del source["authentication"]["credentials"]["client_secret"]
         try:
             manager = ProviderManager(source["uuid"])
         except ProviderManagerError:
             source["provider_linked"] = False
             source["active"] = False
             source["paused"] = False
             source["current_month_data"] = False
             source["previous_month_data"] = False
             source["has_data"] = False
             source["infrastructure"] = {}
             source["cost_models"] = []
             source["additional_context"] = {}
         else:
             source["provider_linked"] = True
             source["active"] = manager.get_active_status()
             source["paused"] = manager.get_paused_status()
             source[
                 "current_month_data"] = manager.get_current_month_data_exists(
                 )
             source[
                 "previous_month_data"] = manager.get_previous_month_data_exists(
                 )
             source["has_data"] = manager.get_any_data_exists()
             source["infrastructure"] = manager.get_infrastructure_info()
             source["cost_models"] = [{
                 "name": model.name,
                 "uuid": model.uuid
             } for model in manager.get_cost_models(tenant)]
             source["additional_context"] = manager.get_additional_context()
     return response
Exemple #4
0
    def retrieve(self, request, *args, **kwargs):
        """Get a source."""
        response = super().retrieve(request=request, args=args, kwargs=kwargs)
        _, tenant = self._get_account_and_tenant(request)

        if response.data.get("authentication",
                             {}).get("credentials", {}).get("client_secret"):
            del response.data["authentication"]["credentials"]["client_secret"]
        try:
            manager = ProviderManager(response.data["uuid"])
        except ProviderManagerError:
            response.data["provider_linked"] = False
            response.data["active"] = False
            response.data["paused"] = False
            response.data["current_month_data"] = False
            response.data["previous_month_data"] = False
            response.data["has_data"] = False
            response.data["infrastructure"] = {}
            response.data["cost_models"] = []
        else:
            response.data["provider_linked"] = True
            response.data["active"] = manager.get_active_status()
            response.data["paused"] = manager.get_paused_status()
            response.data[
                "current_month_data"] = manager.get_current_month_data_exists(
                )
            response.data[
                "previous_month_data"] = manager.get_previous_month_data_exists(
                )
            response.data["has_data"] = manager.get_any_data_exists()

            response.data["infrastructure"] = manager.get_infrastructure_info()
            response.data["cost_models"] = [{
                "name": model.name,
                "uuid": model.uuid
            } for model in manager.get_cost_models(tenant)]
        return response