Example #1
0
def get_file_from_storage(s3_connection, file_name):
    bucket = get_or_create_bucket(s3_connection)
    report = bucket.get_key(file_name)
    if report is None:
        raise Exception('Xml not found in bucket "{}"'.format(
            settings.S3_BUCKET_NAME))
    return report
Example #2
0
def get_file_from_storage(s3_connection, file_name):
    bucket = get_or_create_bucket(s3_connection)
    report = bucket.get_key(file_name)
    if report is None:
        raise Exception('Xml not found in bucket "{}"'.
                        format(settings.S3_BUCKET_NAME))
    return report
Example #3
0
    def post(self, request, filename, testplan_id=None, xunit_format=None):
        s3_connection = get_s3_connection()
        file_obj = request.data['file']

        launch_id = None
        params = None
        if xunit_format not in \
                ['junit', 'nunit', 'qttestxunit', 'xcprettyjunit']:
            return Response(data={'message': 'Unknown file format'},
                            status=status.HTTP_400_BAD_REQUEST)
        if 'file' not in request.data:
            return Response(status=status.HTTP_400_BAD_REQUEST,
                            data={'message': 'No file or empty file received'})
        if 'launch' in request.data:
            launch_id = request.data['launch']
        if 'data' in request.data:
            if isinstance(request.data['data'], InMemoryUploadedFile):
                params = request.data['data'].read().decode('utf8')
            elif request.data['data'] != '':
                params = request.data['data']

        log.info('Create launch')
        if testplan_id is not None:
            state = IN_PROGRESS if s3_connection is not None else FINISHED
            if launch_id is not None:
                launch = self.get_launch(launch_id)
            else:
                launch = self.create_launch(testplan_id, state=state)

            if s3_connection is not None:
                bucket = get_or_create_bucket(s3_connection)
                report_key = bucket.new_key(uuid())
                report_key.set_contents_from_string(file_obj.read())

                log.debug('Xml file "{}" created in bucket "{}"'.format(
                    report_key.name, settings.S3_BUCKET_NAME))

                parse_xml.apply_async(
                    kwargs={
                        's3_conn': True,
                        's3_key_name': report_key.name,
                        'xunit_format': xunit_format,
                        'launch_id': launch.id,
                        'params': params
                    })
            else:
                log.info('Connection to storage is not set in settings, '
                         'parse xml synchronously')
                parse_xml(xunit_format=xunit_format,
                          launch_id=launch.id,
                          params=params,
                          file_content=file_obj.read())
            return Response(status=status.HTTP_200_OK,
                            data={'launch_id': launch.id})
        return Response(status=status.HTTP_400_BAD_REQUEST)
Example #4
0
def delete_file_from_storage(s3_connection, file_name):
    bucket = get_or_create_bucket(s3_connection)
    bucket.delete_key(file_name)
Example #5
0
def delete_file_from_storage(s3_connection, file_name):
    bucket = get_or_create_bucket(s3_connection)
    bucket.delete_key(file_name)