Esempio n. 1
0
def modify_or_add_monitor(deployment, monitor_id=None):
    global LOG # pylint: disable=W0603

    payload = get_api_payload(deployment, monitor_id)
    has_zero_replicas = deployment_util.has_zero_replicas(deployment)
    if monitor_id:

        LOG.debug('%s has zero replicas: "%s"',
            deployment_util.get_application_name(deployment), has_zero_replicas)
        LOG.debug('FEATURE_FLAG_UTR_DELETE_ON_ZERO_REPLICAS: %s',
            feature_flags.use_feature_flag_utr_delete_on_zero_replicas())

        if has_zero_replicas and feature_flags.use_feature_flag_utr_delete_on_zero_replicas():
            LOG.info('Deleting monitor with id "%s"', monitor_id)
            call_endpoint('/deleteMonitor', payload)
            call_slack_channel_with_deleted_monitor_message(deployment)
        else:
            LOG.info('Editing monitor with id "%s"', monitor_id)
            call_endpoint('/editMonitor', payload)
            call_slack_channel_with_monitor_url(deployment)
    else:
        if has_zero_replicas:
            LOG.info('Zero replicas, but no monitor exists - skip')
        else:
            LOG.info('Adding monitor with friendly name "%s"',
                deployment_util.get_friendly_name(deployment))
            call_endpoint('/newMonitor', payload)
            call_slack_channel_with_monitor_url(deployment)
Esempio n. 2
0
def create_deployment_message(deployment):  # pragma: no cover
    if deployment_util.has_zero_replicas(deployment):
        return (
            f'Started removing *{deployment_util.get_friendly_name(deployment)}* from *{deployment_util.get_cluster(deployment)}*, this may take up to 30 seconds.\n<https://confluence.sys.kth.se/confluence/pages/viewpage.action?pageId=44894619|Information how to remove a service>'
        )

    return (
        f'{deployment_util.get_replicas(deployment)} replica(s) of *{deployment_util.get_friendly_name(deployment)}* are being deployed'
        f' in *{deployment_util.get_cluster(deployment)}*, this may take up to 30 seconds.'
    )
Esempio n. 3
0
def handle_deployment(deployment):
    logger = logging.getLogger(__name__)
    if deployment_util.has_zero_replicas(deployment):
        logger.debug('Skipping testAccessibility, no replicas')
        return deployment

    if not deployment_util.get_test_accessibility(deployment):
        logger.debug('testAccessibility not set - skipping Lighthouse')
        return deployment
    if not environment.get_env(environment.SLACK_TOKEN):
        logger.info('No SLACK_TOKEN env provided. Cant run lighthouse')
        return deployment
    urls_to_scan = get_urls_to_scan(deployment)
    if urls_to_scan:
        for scan_url in urls_to_scan:
            process_url_to_scan(deployment, scan_url)
    return deployment
Esempio n. 4
0
def handle_deployment(deployment):

    if deployment_util.has_zero_replicas(deployment):
        if deployment_util.get_detectify_tokens(deployment):
            message = f'Don´t forget to remove Detectify for {deployment_util.get_friendly_name(deployment)}.'
            slack_util.call_slack_channels(deployment, message, "Detectify")

        return deployment

    if should_use_cluster(deployment):
        for api_key in environment.get_env_list(
                environment.DETECTIFY_API_KEYS):
            try:
                process_api_key(api_key, deployment)
            except DetectifyError:
                continue
    return deployment
Esempio n. 5
0
def handle_deployment(deployment):
    global LOG  # pylint: disable=W0603

    if deployment_util.has_zero_replicas(deployment):
        LOG.debug('Skipping lofsdalen, no replicas')
        return deployment

    url = get_url(deployment)
    committed = call_lofsdalen_endpoint_when(url)
    LOG.debug("Url %s responed %s.", url, committed)
    if committed is not None:
        LOG.debug("Calling Slack with commited when text.")
        call_slack(deployment, committed)
    else:
        LOG.info("Got no data for %s from Lofsdalen.",
                 deployment_util.get_application_name(deployment))

    return deployment
Esempio n. 6
0
def handle_deployment(deployment):
    if deployment_util.has_zero_replicas(deployment):
        return deployment

    call_slack_channel_with_application_endpoint_url(deployment)