Beispiel #1
0
    def test_ocp_infrastructure_type_error(self):
        """Test that the provider infrastructure returns Unknown when running stand alone."""
        provider_authentication = ProviderAuthentication.objects.create(
            provider_resource_name='cluster_id_1001')
        provider = Provider.objects.create(
            name='ocpprovidername',
            type=Provider.PROVIDER_OCP,
            created_by=self.user,
            customer=self.customer,
            authentication=provider_authentication,
        )
        data_generator = OCPAWSReportDataGenerator(self.tenant,
                                                   provider,
                                                   current_month_only=True)
        data_generator.create_ocp_provider('cool-cluster-id', 'awesome-alias')

        provider_uuid = data_generator.provider_uuid
        manager = ProviderManager(provider_uuid)
        with patch.object(ProviderAccessor,
                          'infrastructure_type',
                          side_effect=ProviderAccessorError('mock_error')):
            infrastructure_name = manager.get_infrastructure_name(self.tenant)
            self.assertEqual(infrastructure_name, 'Unknown-Error')

        data_generator.remove_data_from_tenant()
Beispiel #2
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", {}).get("credentials",
                                                 {}).get("client_secret"):
             del source["authentication"]["credentials"]["client_secret"]
         try:
             manager = ProviderManager(source["uuid"])
         except ProviderManagerError:
             source["provider_linked"] = False
             source["infrastructure"] = "Unknown"
             source["cost_models"] = []
         else:
             source["provider_linked"] = True
             source["infrastructure"] = manager.get_infrastructure_name()
             connection.set_tenant(tenant)
             source["cost_models"] = [{
                 "name": model.name,
                 "uuid": model.uuid
             } for model in manager.get_cost_models(tenant)]
             connection.set_schema_to_public()
     connection.set_schema_to_public()
     return response
Beispiel #3
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["current_month_data"] = False
         response.data["infrastructure"] = "Unknown"
         response.data["cost_models"] = []
     else:
         response.data["provider_linked"] = True
         response.data["active"] = manager.get_active_status()
         response.data[
             "current_month_data"] = manager.get_current_month_data_exists(
             )
         response.data["infrastructure"] = manager.get_infrastructure_name()
         response.data["cost_models"] = [{
             "name": model.name,
             "uuid": model.uuid
         } for model in manager.get_cost_models(tenant)]
     return response
Beispiel #4
0
    def test_ocp_infrastructure_type(self):
        """Test that the provider infrastructure returns Unknown when running stand alone."""
        provider_authentication = ProviderAuthentication.objects.create(
            provider_resource_name='cluster_id_1001')
        provider = Provider.objects.create(
            name='ocpprovidername',
            type=Provider.PROVIDER_OCP,
            created_by=self.user,
            customer=self.customer,
            authentication=provider_authentication,
        )
        ocp_aws_data_generator = OCPAWSReportDataGenerator(
            self.tenant, provider, current_month_only=True)
        data_generator = OCPReportDataGenerator(self.tenant,
                                                provider,
                                                current_month_only=True)
        data_generator.add_data_to_tenant()
        ocp_aws_data_generator.create_ocp_provider(
            data_generator.cluster_id, data_generator.cluster_alias)

        provider_uuid = ocp_aws_data_generator.provider_uuid
        manager = ProviderManager(provider_uuid)
        infrastructure_name = manager.get_infrastructure_name(self.tenant)
        self.assertEqual(infrastructure_name, 'Unknown')

        data_generator.remove_data_from_tenant()
        ocp_aws_data_generator.remove_data_from_tenant()
    def test_ocp_infrastructure_type_error(self):
        """Test that the provider infrastructure returns Unknown when running stand alone."""
        data_generator = OCPAWSReportDataGenerator(self.tenant, current_month_only=True)
        data_generator.create_ocp_provider('cool-cluster-id', 'awesome-alias')

        provider_uuid = data_generator.provider_uuid
        manager = ProviderManager(provider_uuid)
        with patch.object(ProviderAccessor, 'infrastructure_type', side_effect=ProviderAccessorError('mock_error')):
            infrastructure_name = manager.get_infrastructure_name(self.tenant)
            self.assertEqual(infrastructure_name, 'Unknown-Error')

        data_generator.remove_data_from_tenant()
    def test_ocp_on_aws_infrastructure_type(self):
        """Test that the provider infrastructure returns AWS when running on AWS."""
        data_generator = OCPAWSReportDataGenerator(self.tenant, current_month_only=True)
        data_generator.add_data_to_tenant()
        data_generator.add_aws_data_to_tenant()
        data_generator.create_ocp_provider(data_generator.cluster_id, data_generator.cluster_alias)

        provider_uuid = data_generator.provider_uuid
        manager = ProviderManager(provider_uuid)
        infrastructure_name = manager.get_infrastructure_name(self.tenant)
        self.assertEqual(infrastructure_name, 'AWS')

        data_generator.remove_data_from_tenant()
Beispiel #7
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_name = manager.get_infrastructure_name()
        self.assertEqual(infrastructure_name, "Unknown")
    def test_ocp_on_azure_infrastructure_type(self):
        """Test that the provider infrastructure returns Azure when running on Azure."""
        provider_authentication = ProviderAuthentication.objects.create(provider_resource_name='cluster_id_1002')
        provider = Provider.objects.create(name='ocpprovidername',
                                           type='AZURE',
                                           created_by=self.user,
                                           customer=self.customer,
                                           authentication=provider_authentication,)
        data_generator = OCPAzureReportDataGenerator(self.tenant, provider, current_month_only=True)
        data_generator.add_data_to_tenant()
        data_generator.create_ocp_provider(data_generator.cluster_id, data_generator.cluster_alias)

        provider_uuid = data_generator.provider_uuid
        manager = ProviderManager(provider_uuid)
        infrastructure_name = manager.get_infrastructure_name(self.tenant)
        self.assertEqual(infrastructure_name, 'AZURE')

        data_generator.remove_data_from_tenant()
Beispiel #9
0
    def test_ocp_infrastructure_type_error(self):
        """Test that the provider infrastructure returns Unknown when running stand alone."""
        provider_authentication = ProviderAuthentication.objects.create(provider_resource_name="cluster_id_1001")
        provider = Provider.objects.create(
            name="ocpprovidername",
            type=Provider.PROVIDER_OCP,
            created_by=self.user,
            customer=self.customer,
            authentication=provider_authentication,
        )
        data_generator = OCPAWSReportDataGenerator(self.tenant, provider, current_month_only=True)
        data_generator.create_ocp_provider("cool-cluster-id", "awesome-alias")

        provider_uuid = data_generator.provider_uuid
        manager = ProviderManager(provider_uuid)
        infrastructure_name = manager.get_infrastructure_name()
        self.assertEqual(infrastructure_name, "Unknown")

        data_generator.remove_data_from_tenant()
Beispiel #10
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_name = manager.get_infrastructure_name()
        self.assertEqual(infrastructure_name, Provider.PROVIDER_AZURE)
Beispiel #11
0
    def test_ocp_on_aws_infrastructure_type(self):
        """Test that the provider infrastructure returns AWS when running on AWS."""
        provider_authentication = ProviderAuthentication.objects.create(
            provider_resource_name="cluster_id_1001")
        aws_provider = Provider.objects.filter(type="AWS-local").first()
        infrastructure = ProviderInfrastructureMap.objects.create(
            infrastructure_type=Provider.PROVIDER_AWS,
            infrastructure_provider=aws_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_name = manager.get_infrastructure_name()
        self.assertEqual(infrastructure_name, Provider.PROVIDER_AWS)
Beispiel #12
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["current_month_data"] = False
             source["previous_month_data"] = False
             source["has_data"] = False
             source["infrastructure"] = "Unknown"
             source["cost_models"] = []
         else:
             source["provider_linked"] = True
             source["active"] = manager.get_active_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_name()
             source["cost_models"] = [{
                 "name": model.name,
                 "uuid": model.uuid
             } for model in manager.get_cost_models(tenant)]
     return response
Beispiel #13
0
    def test_ocp_on_aws_infrastructure_type(self):
        """Test that the provider infrastructure returns AWS when running on AWS."""
        provider_authentication = ProviderAuthentication.objects.create(provider_resource_name="cluster_id_1001")
        provider = Provider.objects.create(
            name="ocpprovidername",
            type=Provider.PROVIDER_AWS,
            created_by=self.user,
            customer=self.customer,
            authentication=provider_authentication,
        )

        data_generator = OCPAWSReportDataGenerator(self.tenant, provider, current_month_only=True)
        data_generator.add_data_to_tenant()
        data_generator.add_aws_data_to_tenant()
        data_generator.create_ocp_provider(
            data_generator.cluster_id, data_generator.cluster_alias, infrastructure_type=Provider.PROVIDER_AWS
        )

        provider_uuid = data_generator.provider_uuid
        manager = ProviderManager(provider_uuid)
        infrastructure_name = manager.get_infrastructure_name()
        self.assertEqual(infrastructure_name, Provider.PROVIDER_AWS)

        data_generator.remove_data_from_tenant()