Exemplo n.º 1
0
    def test_cost_usage_source_is_reachable_success(self, usage_reports):
        """Test that cost_usage_source_is_reachable succeeds."""
        service = MagicMock()
        usage_reports.return_value = service

        provider = IBMProvider()
        creds = {"iam_token": FAKE.word()}
        billing = {"enterprise_id": FAKE.word()}

        self.assertTrue(provider.cost_usage_source_is_reachable(
            creds, billing))
        service.get_resource_usage_report.assert_called_with(
            enterprise_id=billing.get("enterprise_id"), children=True, limit=1)
Exemplo n.º 2
0
    def test_cost_usage_source_is_reachable_bad_iam_token(self, usage_reports):
        """Test that cost_usage_source_is_reachable raises ValidationError on invalid IAM token."""
        service = MagicMock()
        service.get_resource_usage_report.side_effect = ApiException(
            code=400, message="API key is wrong")
        usage_reports.return_value = service

        provider = IBMProvider()
        creds = {"iam_token": FAKE.word()}
        billing = {"enterprise_id": FAKE.word()}

        with self.assertRaises(ValidationError) as ve:
            provider.cost_usage_source_is_reachable(creds, billing)
        self.assertIsNotNone(ve.exception.get_full_details().get(
            "credentials.iam_token", None))
Exemplo n.º 3
0
    def __init__(self, customer_name, data_source, **kwargs):
        """
        Constructor.

        Args:
            customer_name  (Strring) Name of the customer
            data_source    (Dict) dict containing IBM Enterprise ID

        """
        super().__init__(**kwargs)

        self.customer_name = customer_name.replace(" ", "_")
        self.credentials = kwargs.get("credentials", {})
        self.data_source = data_source
        self._provider_uuid = kwargs.get("provider_uuid")
        try:
            IBMProvider().cost_usage_source_is_reachable(self.credentials, self.data_source)
        except ValidationError as ex:
            msg = f"IBM source ({self._provider_uuid}) for {customer_name} is not reachable. Error: {str(ex)}"
            LOG.error(log_json(self.request_id, msg, self.context))
            raise IBMReportDownloaderError(str(ex))
Exemplo n.º 4
0
 def test_name(self):
     """Test name property."""
     provider = IBMProvider()
     self.assertEqual(provider.name(), Provider.PROVIDER_IBM)