예제 #1
0
    def _delete_objects(self, bucket_name: str,
                        storage_service: googleapiclient.discovery.Resource):
        """Delete all objects in the given bucket.

        Needed by clean_up_bucket.

        Args:
            bucket_name: Name of the cluster to delete.
            storage_service: Google client to make api calls.
        """
        request = storage_service.objects().list(bucket=bucket_name)
        response = request.execute(num_retries=5)
        if 'items' in response:  # This bucket might be empty
            object_names = [item['name'] for item in response['items']]
            for object_name in object_names:
                request = storage_service.objects().delete(bucket=bucket_name,
                                                           object=object_name)
                try:
                    request.execute(num_retries=5)
                except errors.HttpError:
                    # These functions are only used in tests and resource
                    # cleanings. These are not parts of workflows.
                    # In E2E tests, sometimes a the program fail to create an
                    # object, trying to delete it will cause errors to get
                    # thrown here. Error messages here is misleading and hides
                    # the real cause of test failures.
                    pass
예제 #2
0
    def _delete_objects(self, bucket_name: str,
                        storage_service: googleapiclient.discovery.Resource):
        """Delete all objects in the given bucket.

        Needed by clean_up_bucket.

        Args:
            bucket_name: Name of the cluster to delete.
            storage_service: Google client to make api calls.
        """
        request = storage_service.objects().list(bucket=bucket_name)
        response = request.execute()
        object_names = [item['name'] for item in response['items']]
        for object_name in object_names:
            request = storage_service.objects().delete(
                bucket=bucket_name, object=object_name)
            request.execute()