Exemplo n.º 1
0
 def get_hooks_service(self):
     """
     Configured Hooks Service
     """
     return taskcluster.Hooks(
         self.build_options('hooks/v1')
     )
Exemplo n.º 2
0
def main(env):
    hooks = taskcluster.Hooks()

    # List all tasks on the env
    all_tasks = list_tasks(env)

    # List non erroneous tasks
    skip_phids = [t['diff_phid'] for t in filter(is_not_error, all_tasks)]

    # Get tasks with a mach failure
    tasks = list(filter(is_mach_failure, all_tasks))

    # Trigger all mach error tasks
    total = 0
    for task in tasks:
        phid = task['diff_phid']
        print('Triggering {} > {}'.format(phid, task['title']))

        if phid in skip_phids:
            print(
                '>> Skipping, phid {} has already a non-erroneous task'.format(
                    phid))
            continue

        extra_env = {
            'ANALYSIS_SOURCE': 'phabricator',
            'ANALYSIS_ID': phid,
        }
        task = hooks.triggerHook('project-releng',
                                 'services-{}-staticanalysis/bot'.format(env),
                                 extra_env)
        print('>> New task {}'.format(task['status']['taskId']))
        total += 1

    print('Triggered {} tasks'.format(total))
Exemplo n.º 3
0
    def __init__(self,
                 root_url,
                 client_id=None,
                 access_token=None,
                 unit_testing_this=False):
        # TODO: remove when backfill tool' soft launch is complete ->
        if not unit_testing_this:
            raise RuntimeError(
                f"Must not instantiate real {self.__class__.__name__} instance "
                f"before backfill tool' soft launch is complete")
        # <- up to here
        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})

        # Following least-privilege principle, as services
        # bellow don't really need authorization credentials.
        self.queue = taskcluster.Queue(options)
        self.auth = taskcluster.Auth(options)
Exemplo n.º 4
0
    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})

        # Following least-privilege principle, as services
        # bellow don't really need authorization credentials.
        self.queue = taskcluster.Queue(options)
        self.auth = taskcluster.Auth(options)
Exemplo n.º 5
0
def get_taskcluster(branch='staging'):
    '''
    '''

    hooks = taskcluster.Hooks()
    queue = taskcluster.Queue()

    response = hooks.getHookStatus(
        'project-releng',
        'services-%s-releng_clobberer-taskcluster_cache' % branch)
    if response.get('lastFire', {}).get('result', '') != 'success':
        return {}

    return queue.getLatestArtifact(
        response['lastFire']['taskId'],
        'taskcluster_cache.json',
    )
Exemplo n.º 6
0
Arquivo: push.py Projeto: jmaher/mozci
    def list_groups_from_hook(self, group_id, hook_id):
        """List all decision tasks from the specified hook"""
        hooks = taskcluster.Hooks(get_taskcluster_options())
        fires = hooks.listLastFires(group_id, hook_id).get("lastFires", [])

        # Setup CLI progress bar
        progress = self.progress_bar(len(fires))
        progress.set_format("verbose")

        # Provide the decision task ID as it's the same value for group ID
        for fire in fires:
            yield fire["taskId"]

            progress.advance()

        # Cleanup progress bar
        progress.finish()
Exemplo n.º 7
0
    def _trigger_action(self, action, payload):
        tc_firefox_ci_credentials = config.get("taskcluster_firefox_ci", {})
        client_id = tc_firefox_ci_credentials.get("client_id")
        access_token = tc_firefox_ci_credentials.get("access_token")
        assert (
            client_id and access_token
        ), "Missing Taskcluster Firefox CI credentials in mozci config secret"

        options = taskcluster.optionsFromEnvironment()
        options["rootUrl"] = PRODUCTION_TASKCLUSTER_ROOT_URL
        options["credentials"] = {
            "clientId": client_id,
            "accessToken": access_token,
        }
        hooks = taskcluster.Hooks(options)

        result = hooks.triggerHook(action["hookGroupId"], action["hookId"],
                                   payload)
        return result["status"]["taskId"]
Exemplo n.º 8
0
def build_hook(target, args):
    """
    Read a hook definition file and either create or update the hook
    """
    hook_file_path = target.check_path(args.hook_file)

    hook_group_id = args.hook_group_id
    hook_id = args.hook_id

    with open(hook_file_path) as hook_file:
        payload = json.load(hook_file)

    # Load config from file/secret
    config = Configuration(args)

    hooks = taskcluster.Hooks(config.get_taskcluster_options())
    hooks.ping()

    hook_name = "{}/{}".format(hook_group_id, hook_id)
    logger.info("Checking if hook %s exists", hook_name)

    try:
        hooks.hook(hook_group_id, hook_id)
        hook_exists = True
        logger.info("Hook %s exists", hook_name)
    except taskcluster.exceptions.TaskclusterRestFailure:
        hook_exists = False
        logger.info("Hook %s does not exists", hook_name)

    if hook_exists:
        hooks.updateHook(hook_group_id, hook_id, payload)
        logger.info("Hook %s was successfully updated", hook_name)
    else:
        hooks.createHook(hook_group_id, hook_id, payload)
        logger.info("Hook %s was successfully created", hook_name)

    hook_url = taskcluster_urls.ui(
        config.get_root_url(), "hooks/{}/{}".format(hook_group_id, hook_id))
    logger.info("Hook URL for debugging: %r", hook_url)
Exemplo n.º 9
0
def main(args):
    options = get_taskcluster_options()

    queue = taskcluster.Queue(options)

    task = queue.task(os.environ["TASK_ID"])
    assert len(task["dependencies"]) > 0, "No task dependencies"

    artifacts = download_artifacts(queue, task["dependencies"])

    should_trigger = False
    for artifact in artifacts:
        with open(artifact, "r") as f:
            done = int(f.read()) == 1

        if not done:
            should_trigger = True
            break

    if should_trigger:
        hooks = taskcluster.Hooks(options)
        hooks.ping()
        hooks.triggerHook(args.group_id, args.id, {})
Exemplo n.º 10
0
def _hooks():
    return taskcluster.Hooks(_tc_params)
Exemplo n.º 11
0
def main(hooks, hooks_group, hooks_prefix, hooks_url, hooks_client_id,
         hooks_access_token, docker_push, docker_registry, docker_repo,
         docker_username, docker_password, debug):
    """ A tool for creating / updating taskcluster hooks (also creating and
        pushing docker images.
    """

    if debug:
        logging.basicConfig(level=logging.DEBUG)

    taskcluster_hooks = None

    if hooks_client_id is not None and hooks_access_token is not None:
        taskcluster_hooks = taskcluster.Hooks(options=dict(credentials=dict(
            clientId=hooks_client_id,
            accessToken=hooks_access_token,
        )))

    if hooks_url:
        taskcluster_hooks = taskcluster.Hooks(options=dict(baseUrl=hooks_url))

    if taskcluster_hooks is None:
        raise ClickException(
            "You either need to provide `--hooks-url` or both "
            "`--hooks-client-id` and `--hooks-access-token`.")

    hooks_all = json.load(hooks)
    click.echo("Expected hooks:%s" %
               "\n - ".join([""] + list(hooks_all.keys())))

    log.debug(
        "Gathering existing hooks for group `%s`. Might take some time ..." %
        hooks_group)
    hooks_existing = {
        hook['hookId']: hook
        for hook in taskcluster_hooks.listHooks(hooks_group).get('hooks', [])
        if hook.get('hookId', '').startswith(hooks_prefix)
    }

    click.echo("Existing hooks: %s" %
               "\n - ".join([""] + list(hooks_existing.keys())))

    hooks_create, hooks_update, hooks_remove = diff_hooks(
        hooks_all,
        hooks_existing,
        hooks_prefix,
        docker_repo,
    )

    log.debug("Hooks to create:%s" %
              "\n - ".join([""] + list(hooks_create.keys())))
    log.debug("Hooks to update:%s" %
              "\n - ".join([""] + list(hooks_update.keys())))
    log.debug("Hooks to remove:%s" %
              "\n - ".join([""] + list(hooks_remove.keys())))

    click.echo("Pushing images to docker_registry:")

    for hookId, hook in hooks_create.items():
        hook_image = push_docker_image(hook['task']['payload']['image'],
                                       docker_push, docker_registry,
                                       docker_repo, docker_username,
                                       docker_password)
        hooks_create[hookId]['task']['payload']['image'] = hook_image

    for hookId, hook in hooks_update.items():
        hook_image = push_docker_image(hook['task']['payload']['image'],
                                       docker_push, docker_registry,
                                       docker_repo, docker_username,
                                       docker_password)
        hooks_update[hookId]['task']['payload']['image'] = hook_image

    click.echo("Creating new hooks:")

    for hookId, hook in hooks_create.items():
        click.echo(" - %s/%s" % (hooks_group, hookId))
        taskcluster_hooks.createHook(hooks_group, hookId, hook)

    click.echo("Updating hooks:")

    for hookId, hook in hooks_update.items():
        click.echo(" - %s/%s" % (hooks_group, hookId))
        taskcluster_hooks.updateHook(hooks_group, hookId, hook)

    click.echo("Removing hooks:")

    for hookId, hook in hooks_remove.items():
        click.echo(" - %s/%s" % (hooks_group, hookId))
        taskcluster_hooks.removeHook(hooks_group, hookId)