Beispiel #1
0
 def test_update_provider_exception(self):
     """Test to update a provider with a connection error."""
     client = ProviderBuilder(auth_header=Config.SOURCES_FAKE_HEADER)
     expected_uuid = faker.uuid4()
     with self.assertRaises(Provider.DoesNotExist):
         client.update_provider(expected_uuid, "Aws Test",
                                Provider.PROVIDER_AWS,
                                {"resource_name": "arn:test"},
                                {"bucket": "bucket"})
Beispiel #2
0
 def test_update_provider_error(self):
     """Test to update a provider with a koku server error."""
     client = ProviderBuilder(auth_header=Config.SOURCES_FAKE_HEADER)
     source_uuid = faker.uuid4()
     with patch.object(ProviderAccessor,
                       "cost_usage_source_ready",
                       returns=True):
         client.create_provider(self.name, self.provider_type,
                                self.authentication, self.billing_source,
                                source_uuid)
     with self.assertRaises(ValidationError):
         client.update_provider(source_uuid, "Aws Test",
                                Provider.PROVIDER_AWS,
                                {"resource_name": "arn:test"},
                                {"bucket": "bucket"})
Beispiel #3
0
 def test_update_provider(self):
     """Test to update a provider."""
     client = ProviderBuilder(auth_header=Config.SOURCES_FAKE_HEADER)
     source_uuid = faker.uuid4()
     with patch.object(ProviderAccessor,
                       "cost_usage_source_ready",
                       returns=True):
         provider = client.create_provider(self.name, self.provider_type,
                                           self.authentication,
                                           self.billing_source, source_uuid)
         new_name = "Aws Test"
         updated_provider = client.update_provider(
             source_uuid, new_name, Provider.PROVIDER_AWS,
             {"resource_name": "arn:test"}, {"bucket": "bucket"})
         self.assertEqual(updated_provider.uuid, provider.uuid)
         self.assertEqual(updated_provider.name, new_name)
Beispiel #4
0
class SourcesProviderCoordinator:
    """Coordinator to control source and provider operations."""
    def __init__(self, source_id, auth_header):
        """Initialize the client."""
        header = {"x-rh-identity": auth_header, "sources-client": "True"}
        self._source_id = source_id
        self._identity_header = header
        self._provider_builder = ProviderBuilder(self._identity_header)

    def create_account(self,
                       name,
                       provider_type,
                       authentication,
                       billing_source,
                       source_uuid=None):
        """Call to create provider."""
        try:
            provider = self._provider_builder.create_provider(
                name, provider_type, authentication, billing_source,
                source_uuid)
            add_provider_koku_uuid(self._source_id, provider.uuid)
        except ProviderBuilderError as provider_err:
            raise SourcesProviderCoordinatorError(str(provider_err))
        return provider

    def update_account(self, provider_uuid, name, provider_type,
                       authentication, billing_source):
        """Call to update provider."""
        try:
            provider = self._provider_builder.update_provider(
                provider_uuid, name, provider_type, authentication,
                billing_source)
            clear_update_flag(self._source_id)
        except ProviderBuilderError as provider_err:
            raise SourcesProviderCoordinatorError(str(provider_err))
        return provider

    def destroy_account(self, provider_uuid):
        """Call to destroy provider."""
        try:
            self._provider_builder.destroy_provider(provider_uuid)
            destroy_source_event(self._source_id)
        except ProviderBuilderError as provider_err:
            LOG.error(f"Failed to remove provider. Error: {str(provider_err)}")