Exemple #1
0
def run_integration(func_container, ctx, *args, **kwargs):
    try:
        int_name = func_container.QONTRACT_INTEGRATION.replace('_', '-')
        running_state = RunningState()
        running_state.integration = int_name
    except AttributeError:
        sys.stderr.write("Integration missing QONTRACT_INTEGRATION.\n")
        sys.exit(ExitCodes.ERROR)

    try:
        gql.init_from_config(sha_url=ctx['gql_sha_url'],
                             integration=int_name,
                             validate_schemas=ctx['validate_schemas'],
                             print_url=ctx['gql_url_print'])
    except GqlApiIntegrationNotFound as e:
        sys.stderr.write(str(e) + "\n")
        sys.exit(ExitCodes.INTEGRATION_NOT_FOUND)

    unleash_feature_state = get_feature_toggle_state(int_name)
    if not unleash_feature_state:
        logging.info('Integration toggle is disabled, skipping integration.')
        sys.exit(ExitCodes.SUCCESS)

    dry_run = ctx.get('dry_run', False)

    try:
        func_container.run(dry_run, *args, **kwargs)
    except RunnerException as e:
        sys.stderr.write(str(e) + "\n")
        sys.exit(ExitCodes.ERROR)
    except GqlApiErrorForbiddenSchema as e:
        sys.stderr.write(str(e) + "\n")
        sys.exit(ExitCodes.FORBIDDEN_SCHEMA)
    except GqlApiError as e:
        if '409' in str(e):
            logging.info(f'Data changed during execution. This is fine.')
            # exit code to relect conflict
            # TODO: document this better
            sys.exit(ExitCodes.DATA_CHANGED)
        else:
            raise e
    finally:
        if ctx.get('dump_schemas_file'):
            gqlapi = gql.get_api()
            with open(ctx.get('dump_schemas_file'), 'w') as f:
                f.write(json.dumps(gqlapi.get_queried_schemas()))
Exemple #2
0
def run_integration(func_container, *args):
    integration_name = func_container.QONTRACT_INTEGRATION.replace('_', '-')
    unleash_feature_state = get_feature_toggle_state(integration_name)
    if not unleash_feature_state:
        logging.info('Integration toggle is disabled, skipping integration.')
        sys.exit(0)

    try:
        func_container.run(*args)
    except RunnerException as e:
        sys.stderr.write(str(e) + "\n")
        sys.exit(1)
    except GqlApiError as e:
        if '409' in str(e):
            logging.error(f'Data changed during execution. This is fine.')
            # exit code to relect conflict
            # TODO: document this better
            sys.exit(3)
        else:
            raise e