def integration(ctx, configfile, dry_run, log_level): ctx.ensure_object(dict) init_log_level(log_level) config.init_from_toml(configfile) gql.init_from_config() ctx.obj['dry_run'] = dry_run
def test(ctx, configfile, log_level): ctx.ensure_object(dict) level = getattr(logging, log_level) if log_level else logging.INFO logging.basicConfig(format='%(levelname)s: %(message)s', level=level) config.init_from_toml(configfile) gql.init_from_config()
def main(configfile, dry_run, log_level, gitlab_project_id, reports_path): config.init_from_toml(configfile) init_log_level(log_level) config.init_from_toml(configfile) gql.init_from_config() now = datetime.now() apps = get_apps_data(now) reports = [Report(app, now).to_message() for app in apps] for report in reports: logging.info(['create_report', report['file_path']]) if reports_path: report_file = os.path.join(reports_path, report['file_path']) try: os.makedirs(os.path.dirname(report_file)) except FileExistsError: pass with open(report_file, 'w') as f: f.write(report['content']) if not dry_run: email_body = """\ Hello, A new report by the App SRE team is now available at: https://visual-app-interface.devshift.net/reports You can use the Search bar to search by App. You can also view reports per service here: https://visual-app-interface.devshift.net/services Having problems? Ping us on #sd-app-sre on Slack! You are receiving this message because you are a member of app-interface or subscribed to a mailing list specified as owning a service being run by the App SRE team: https://gitlab.cee.redhat.com/service/app-interface """ mr_cli = mr_client_gateway.init(gitlab_project_id=gitlab_project_id, sqs_or_gitlab='gitlab') mr = CreateAppInterfaceReporter(reports=reports, email_body=textwrap.dedent(email_body), reports_path=reports_path) result = mr.submit(cli=mr_cli) logging.info(['created_mr', result.web_url])
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()))
def setup_method(self, method): config.init_from_toml(fxt.path('config.toml')) gql.init_from_config(sha_url=False)
def root(ctx, configfile): ctx.ensure_object(dict) config.init_from_toml(configfile) gql.init_from_config()