Example #1
0
def test_try_again(monkeypatch):
    push.push_to_try('fuzzy', 'Fuzzy message', ['foo', 'bar'],
                     {'artifact': True})

    assert os.path.isfile(push.history_path)
    with open(push.history_path, 'r') as fh:
        assert len(fh.readlines()) == 1

    def fake_push_to_try(*args, **kwargs):
        return args, kwargs

    monkeypatch.setattr(push, 'push_to_try', fake_push_to_try)
    reload(again)

    args, kwargs = again.run_try_again()

    assert args[0] == 'again'
    assert args[1] == 'Fuzzy message'

    try_task_config = kwargs.pop('try_task_config')
    assert sorted(try_task_config.get('tasks')) == sorted(['foo', 'bar'])
    assert try_task_config.get('templates') == {
        'artifact': True,
        'env': {
            'TRY_SELECTOR': 'fuzzy'
        },
    }

    with open(push.history_path, 'r') as fh:
        assert len(fh.readlines()) == 1
Example #2
0
def test_try_again(monkeypatch):
    push.push_to_try(
        "fuzzy",
        "Fuzzy message",
        try_task_config=push.generate_try_task_config(
            "fuzzy",
            ["foo", "bar"],
            {"use-artifact-builds": True},
        ),
    )

    assert os.path.isfile(push.history_path)
    with open(push.history_path, "r") as fh:
        assert len(fh.readlines()) == 1

    def fake_push_to_try(*args, **kwargs):
        return args, kwargs

    monkeypatch.setattr(push, "push_to_try", fake_push_to_try)
    reload(again)

    args, kwargs = again.run()

    assert args[0] == "again"
    assert args[1] == "Fuzzy message"

    try_task_config = kwargs.pop("try_task_config")
    assert sorted(try_task_config.get("tasks")) == sorted(["foo", "bar"])
    assert try_task_config.get("env") == {"TRY_SELECTOR": "fuzzy"}
    assert try_task_config.get('use-artifact-builds')

    with open(push.history_path, "r") as fh:
        assert len(fh.readlines()) == 1
Example #3
0
def test_no_push_does_not_generate_history(tmpdir):
    assert not os.path.isfile(push.history_path)

    push.push_to_try('fuzzy',
                     'Fuzzy', ['foo', 'bar'], {'artifact': True},
                     push=False)
    assert not os.path.isfile(push.history_path)
    assert again.run_try_again() == 1
Example #4
0
def test_no_push_does_not_generate_history(tmpdir):
    assert not os.path.isfile(push.history_path)

    push.push_to_try(
        "fuzzy",
        "Fuzzy",
        try_task_config=push.generate_try_task_config(
            "fuzzy", ["foo", "bar"], {"use-artifact-builds": True},
        ),
        push=False,
    )
    assert not os.path.isfile(push.history_path)
    assert again.run() == 1
Example #5
0
def run(update=False, query=None, templates=None, full=False, parameters=None,
        save=False, preset=None, mod_presets=False, push=True, message='{msg}',
        closed_tree=False):
    from .app import create_application
    check_working_directory(push)

    tg = generate_tasks(parameters, full)
    app = create_application(tg)

    if os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
        # we are in the reloader process, don't open the browser or do any try stuff
        app.run()
        return

    # give app a second to start before opening the browser
    url = 'http://127.0.0.1:5000'
    Timer(1, lambda: webbrowser.open(url)).start()
    print("Starting trychooser on {}".format(url))
    app.run()

    selected = app.tasks
    if not selected:
        print("no tasks selected")
        return

    msg = "Try Chooser Enhanced ({} tasks selected)".format(len(selected))
    return push_to_try('chooser', message.format(msg=msg), selected, templates, push=push,
                       closed_tree=closed_tree)
Example #6
0
def run(
    update=False,
    query=None,
    try_config=None,
    full=False,
    parameters=None,
    save=False,
    preset=None,
    mod_presets=False,
    push=True,
    message="{msg}",
    closed_tree=False,
):
    from .app import create_application

    check_working_directory(push)

    tg = generate_tasks(parameters, full)

    # Remove tasks that are not to be shown unless `--full` is specified.
    if not full:
        blacklisted_tasks = [
            label
            for label in tg.tasks.keys()
            if not filter_by_uncommon_try_tasks(label)
        ]
        for task in blacklisted_tasks:
            tg.tasks.pop(task)

    app = create_application(tg)

    if os.environ.get("WERKZEUG_RUN_MAIN") == "true":
        # we are in the reloader process, don't open the browser or do any try stuff
        app.run()
        return

    # give app a second to start before opening the browser
    url = "http://127.0.0.1:5000"
    Timer(1, lambda: webbrowser.open(url)).start()
    print("Starting trychooser on {}".format(url))
    app.run()

    selected = app.tasks
    if not selected:
        print("no tasks selected")
        return

    msg = "Try Chooser Enhanced ({} tasks selected)".format(len(selected))
    return push_to_try(
        "chooser",
        message.format(msg=msg),
        try_task_config=generate_try_task_config("chooser", selected, try_config),
        push=push,
        closed_tree=closed_tree,
    )
Example #7
0
    def run_perftest(self, **kwargs):
        push_to_try = kwargs.pop("push_to_try", False)
        if push_to_try:
            from pathlib import Path

            sys.path.append(str(Path(self.topsrcdir, "tools", "tryselect")))

            from tryselect.push import push_to_try

            platform = kwargs.pop("try_platform")
            if platform not in _TRY_PLATFORMS:
                # we can extend platform support here: linux, win, macOs, pixel2
                # by adding more jobs in taskcluster/ci/perftest/kind.yml
                # then picking up the right one here
                raise NotImplementedError("%r not supported yet" % platform)

            perftest_parameters = {}
            parser = get_perftest_parser()()
            for name, value in kwargs.items():
                # ignore values that are set to default
                if parser.get_default(name) == value:
                    continue
                perftest_parameters[name] = value

            parameters = {
                "try_task_config": {
                    "tasks": [_TRY_PLATFORMS[platform]],
                    "perftest-options": perftest_parameters,
                },
                "try_mode": "try_task_config",
            }

            task_config = {"parameters": parameters, "version": 2}
            push_to_try("perftest", "perftest", try_task_config=task_config)
            return

        # run locally
        MachCommandBase._activate_virtualenv(self)

        from mozperftest.runner import run_tests

        run_tests(mach_cmd=self, **kwargs)
Example #8
0
    def run_perftest(self, **kwargs):
        # original parser that brought us there
        original_parser = self.get_parser()

        from pathlib import Path

        # user selection with fuzzy UI
        from mozperftest.utils import ON_TRY
        from mozperftest.script import ScriptInfo, ScriptType, ParseError

        if not ON_TRY and kwargs.get("tests", []) == []:
            from moztest.resolve import TestResolver
            from mozperftest.fzf.fzf import select

            resolver = self._spawn(TestResolver)
            test_objects = list(
                resolver.resolve_tests(paths=None, flavor="perftest"))
            selected = select(test_objects)

            def full_path(selection):
                __, script_name, __, location = selection.split(" ")
                return str(
                    Path(
                        self.topsrcdir.rstrip(os.sep),
                        location.strip(os.sep),
                        script_name,
                    ))

            kwargs["tests"] = [full_path(s) for s in selected]

            if kwargs["tests"] == []:
                print("\nNo selection. Bye!")
                return

        if len(kwargs["tests"]) > 1:
            print("\nSorry no support yet for multiple local perftest")
            return

        sel = "\n".join(kwargs["tests"])
        print("\nGood job! Best selection.\n%s" % sel)
        # if the script is xpcshell, we can force the flavor here
        # XXX on multi-selection,  what happens if we have seeveral flavors?
        try:
            script_info = ScriptInfo(kwargs["tests"][0])
        except ParseError as e:
            if e.exception is IsADirectoryError:
                script_info = None
            else:
                raise
        else:
            if script_info.script_type == ScriptType.xpcshell:
                kwargs["flavor"] = script_info.script_type.name
            else:
                # we set the value only if not provided (so "mobile-browser"
                # can be picked)
                if "flavor" not in kwargs:
                    kwargs["flavor"] = "desktop-browser"

        push_to_try = kwargs.pop("push_to_try", False)
        if push_to_try:
            sys.path.append(str(Path(self.topsrcdir, "tools", "tryselect")))

            from tryselect.push import push_to_try

            perftest_parameters = {}
            args = script_info.update_args(
                **original_parser.get_user_args(kwargs))
            platform = args.pop("try_platform", "linux")
            if isinstance(platform, str):
                platform = [platform]

            platform = [
                "%s-%s" % (plat, script_info.script_type.name)
                for plat in platform
            ]

            for plat in platform:
                if plat not in _TRY_PLATFORMS:
                    # we can extend platform support here: linux, win, macOs, pixel2
                    # by adding more jobs in taskcluster/ci/perftest/kind.yml
                    # then picking up the right one here
                    raise NotImplementedError(
                        "%r doesn't exist or is not yet supported" % plat)

            def relative(path):
                if path.startswith(self.topsrcdir):
                    return path[len(self.topsrcdir):].lstrip(os.sep)
                return path

            for name, value in args.items():
                # ignore values that are set to default
                if original_parser.get_default(name) == value:
                    continue
                if name == "tests":
                    value = [relative(path) for path in value]
                perftest_parameters[name] = value

            parameters = {
                "try_task_config": {
                    "tasks": [_TRY_PLATFORMS[plat] for plat in platform],
                    "perftest-options": perftest_parameters,
                },
                "try_mode": "try_task_config",
            }

            task_config = {"parameters": parameters, "version": 2}
            if args["verbose"]:
                print("Pushing run to try...")
                print(json.dumps(task_config, indent=4, sort_keys=True))

            push_to_try("perftest", "perftest", try_task_config=task_config)
            return

        from mozperftest.runner import run_tests

        run_tests(self, kwargs, original_parser.get_user_args(kwargs))

        print("\nFirefox. Fast For Good.\n")