コード例 #1
0
def test_signature_remover_when_notify_service_is_down(
    test_perf_signature,
    test_perf_signature_2,
    test_perf_data,
    mock_taskcluster_notify,
    mock_tc_prod_credentials,
):
    taskcluster.Notify().ping.side_effect = Exception('Email Service is down.')

    call_command('cycle_data', 'from:perfherder')

    assert taskcluster.Notify().ping.called_once
    assert not taskcluster.Notify().email.called
    assert len(PerformanceSignature.objects.all()) == 2
コード例 #2
0
def create_app(config=None):
    app = treestatus_api.lib.flask.create_app(
        project_name=treestatus_api.config.PROJECT_NAME,
        config=config,
        extensions=[
            "log", "security", "cors", "api", "auth", "db", "cache", "pulse"
        ],
        static_folder=None,
        static_url_path="/static",
    )

    if app.config["STATUSPAGE_ENABLE"]:
        app.notify = taskcluster.Notify(options=dict(
            rootUrl=app.config["TASKCLUSTER_ROOT_URL"],
            credentials=dict(
                clientId=app.config["TASKCLUSTER_CLIENT_ID"],
                accessToken=app.config["TASKCLUSTER_ACCESS_TOKEN"]),
        ))

    app.add_url_rule("/static/<path:filename>", "static_handler",
                     treestatus_api.view.static_handler)

    app.api.register(os.path.join(os.path.dirname(__file__), "api.yml"))

    return app
コード例 #3
0
def notify_matrix(body, room):
    """
    Send a message on the provided Matrix room
    using Taskcluster notify service
    """
    if not room:
        logger.warning("No Matrix room available in configuration")
        return

    formatted_body = markdown2.markdown(body)

    notify_service = taskcluster.Notify(get_taskcluster_options())
    try:
        notify_service.matrix(
            {
                "roomId": room,
                "body": body,
                "format": "org.matrix.custom.html",
                "formattedBody": formatted_body,
                "msgtype": "m.text",
            }
        )
    except Exception as e:
        logger.error(f"Failed to send the report on the Matrix room {room}: {e}")
        raise
コード例 #4
0
ファイル: __init__.py プロジェクト: garbas/treestatus
def create_app(config=None):
    app = treestatus_api.lib.flask.create_app(
        project_name=treestatus_api.config.PROJECT_NAME,
        config=config,
        extensions=[
            'log',
            'security',
            'cors',
            'api',
            'auth',
            'db',
            'cache',
            'pulse',
        ],
    )

    app.notify = taskcluster.Notify(options=dict(
        rootUrl=app.config['TASKCLUSTER_ROOT_URL'],
        credentials=dict(
            clientId=app.config['TASKCLUSTER_CLIENT_ID'],
            accessToken=app.config['TASKCLUSTER_ACCESS_TOKEN'],
        ),
    ), )

    app.api.register(os.path.join(os.path.dirname(__file__), 'api.yml'))

    return app
コード例 #5
0
ファイル: taskcluster.py プロジェクト: alex/services
 def get_notify_service(self):
     """
     Configured Queue Service
     """
     return taskcluster.Notify(
         self.build_options('notify/v1')
     )
コード例 #6
0
def test_signature_remover(
    test_perf_signature,
    test_perf_signature_2,
    test_perf_data,
    mock_taskcluster_notify,
    mock_tc_prod_credentials,
):
    cycler = PerfherderCycler(chunk_size=100, sleep_time=0)
    expired_timestamp = cycler.max_timestamp
    test_perf_signature_2.last_updated = expired_timestamp
    test_perf_signature_2.save()

    assert len(PerformanceSignature.objects.all()) == 2

    call_command('cycle_data', 'from:perfherder')

    assert taskcluster.Notify().ping.called_once
    assert taskcluster.Notify().email.call_count == 1
    assert len(PerformanceSignature.objects.all()) == 1
    assert PerformanceSignature.objects.first() == test_perf_signature
コード例 #7
0
def notify_matrix(body, room):
    """
    Send a message on the provided Matrix room
    using Taskcluster notify service
    """
    if not room:
        logger.warning("No Matrix room available in configuration")
        return

    notify_service = taskcluster.Notify(get_taskcluster_options())
    try:
        notify_service.matrix({"roomId": room, "body": body})
    except Exception as e:
        logger.warning(
            f"Failed to send the report on the Matrix room {room}: {e}")
コード例 #8
0
ファイル: taskcluster.py プロジェクト: somil24/treeherder
    def __init__(self, root_url, client_id=None, access_token=None):
        options = {'rootUrl': root_url}
        credentials = {}

        if client_id:
            credentials['clientId'] = client_id
        if access_token:
            credentials['accessToken'] = access_token

        # Taskcluster APIs
        self.hooks = taskcluster.Hooks({**options, 'credentials': credentials})
        self.notify = taskcluster.Notify({
            **options, 'credentials': credentials
        })

        # Following least-privilege principle, as services
        # bellow don't really need authorization credentials.
        self.queue = taskcluster.Queue(options)
        self.auth = taskcluster.Auth(options)
コード例 #9
0
def notify_email(subject, content, emails):
    """
    Send an email to all provided email addresses
    using Taskcluster notify service
    """
    if not emails:
        logger.warning("No email address available in configuration")
        return

    notify_service = taskcluster.Notify(get_taskcluster_options())
    for idx, email in enumerate(emails):
        try:
            notify_service.email({
                "address": email,
                "subject": f"Mozci | {subject}",
                "content": content,
            })
        except Exception as e:
            logger.warning(
                f"Failed to send the report by email to address n°{idx} ({email}): {e}"
            )
コード例 #10
0
def celery_call_command(job_data):
    """Loads a Django management command with task_name
    """

    command = job_data['task_name']
    logging.debug('command_name:{}'.format(command))
    task = 'ipmi' if command.startswith('ipmi') else command
    logging.debug('task_name:{}'.format(task))

    logging.debug('job_data:{}'.format(job_data))
    (hostname, ip) = dns_lookup(job_data['worker_id'])
    job_data['ip'] = str(ip)

    cmd_class = load_command_class('relops_hardware_controller.api', task)
    logging.debug('cmd_class:{}'.format(cmd_class))

    subject = '{}[{}] {}'.format(job_data['worker_id'], ip, command)
    logging.info(subject)

    stdout = StringIO()
    try:
        call_command(cmd_class,
                     hostname,
                     json.dumps(job_data),
                     stdout=stdout,
                     stderr=stdout)
    except subprocess.TimeoutExpired as e:
        logging.exception(e)
        message = 'timed out'
    except subprocess.CalledProcessError as e:
        logging.exception(e)
        message = e.output
    except KeyError as e:
        logging.exception(e)
        message = 'Key error: {}'.format(e)
    except Exception as e:
        logging.exception(e)
        message = e
    else:
        message = stdout.getvalue()
        logging.info(message)

    # Ignore most Notify logging
    log_level = logging.getLogger().level
    logging.getLogger().setLevel(logging.CRITICAL)

    notify = taskcluster.Notify()

    link = '{http_origin}/provisioners/{provisioner_id}/worker-types/{worker_type}/workers/{worker_group}/{worker_id}'.format(
        **job_data)
    text_link_max = 40
    mail_payload = {
        'subject': subject,
        'address': settings.NOTIFY_EMAIL,
        'replyTo': '*****@*****.**',
        'content': message,
        'template': 'fullscreen',
        'link': {
            'href': link,
            'text': link[:text_link_max]
        },
    }

    try:
        notify.email(mail_payload)

        client_id = job_data['client_id']
        username = re.search(
            '^mozilla(-auth0/ad\|Mozilla-LDAP\||-ldap\/)([^ @]+)(@mozilla\.com)?$',
            client_id).group(2)
        notify.email({
            **mail_payload, 'address':
            '{}@mozilla.com'.format(username)
        })
    except Exception as e:
        logging.warn(e)

    try:
        message = '{}: {}'.format(subject, message)
        irc_message_max = 510
        while message:
            chunk = message[:irc_message_max]
            notify.irc({
                'channel': settings.NOTIFY_IRC_CHANNEL,
                'message': chunk
            })
            notify.irc({'user': username, 'message': chunk})
            message = message[irc_message_max:]
    except Exception as e:
        logging.warn(e)

    logging.getLogger().setLevel(log_level)
コード例 #11
0
ファイル: report.py プロジェクト: seppeljordan/services
 def __init__(self, tc_options, emails):
     self.notify = taskcluster.Notify(tc_options)
     self.emails = emails
     self.merges = set()
コード例 #12
0
 def __init__(self, options=None, session=None):
     self._notify_adaptee = taskcluster.Notify(options, session)