def test_create_03(mocker): """test push task creation""" taskcluster = mocker.patch("orion_decision.scheduler.Taskcluster", autospec=True) queue = taskcluster.get_service.return_value now = datetime.utcnow() root = FIXTURES / "services03" evt = mocker.Mock(spec=GithubEvent()) evt.repo.path = root evt.repo.git = mocker.Mock(return_value="\n".join( str(p) for p in root.glob("**/*"))) evt.commit = "commit" evt.branch = "push" evt.event_type = "push" evt.clone_url = "https://example.com" evt.pull_request = None sched = Scheduler(evt, now, "group", "secret", "push") sched.services["test1"].dirty = True sched.create_tasks() assert queue.createTask.call_count == 2 build_task_id, build_task = queue.createTask.call_args_list[0].args assert build_task == yaml_load( BUILD_TASK.substitute( clone_url="https://example.com", commit="commit", deadline=stringDate(now + DEADLINE), dockerfile="test1/Dockerfile", expires=stringDate(now + ARTIFACTS_EXPIRE), load_deps="0", max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, route="index.project.fuzzing.orion.test1.push", scheduler=SCHEDULER_ID, service_name="test1", source_url=SOURCE_URL, task_group="group", worker=WORKER_TYPE, )) _, push_task = queue.createTask.call_args_list[1].args push_expected = yaml_load( PUSH_TASK.substitute( clone_url="https://example.com", commit="commit", deadline=stringDate(now + DEADLINE), docker_secret="secret", max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, scheduler=SCHEDULER_ID, service_name="test1", source_url=SOURCE_URL, task_group="group", worker=WORKER_TYPE, )) push_expected["dependencies"].append(build_task_id) assert push_task == push_expected
def test_create_01(mocker): """test no task creation""" taskcluster = mocker.patch("orion_decision.scheduler.Taskcluster", autospec=True) queue = taskcluster.get_service.return_value now = datetime.utcnow() root = FIXTURES / "services03" evt = mocker.Mock(spec=GithubEvent()) evt.repo.path = root evt.repo.git = mocker.Mock(return_value="\n".join( str(p) for p in root.glob("**/*"))) sched = Scheduler(evt, now, "group", "secret", "push") sched.create_tasks() assert queue.createTask.call_count == 0
def test_create_05(mocker: MockerFixture) -> None: """test no tasks are created for release event""" taskcluster = mocker.patch("orion_decision.scheduler.Taskcluster", autospec=True) queue = taskcluster.get_service.return_value now = datetime.utcnow() root = FIXTURES / "services03" evt = mocker.Mock(spec=GithubEvent()) evt.repo.path = root evt.repo.git = mocker.Mock(return_value="\n".join( str(p) for p in root.glob("**/*"))) evt.event_type = "release" sched = Scheduler(evt, now, "group", "secret", "push") sched.services["test1"].dirty = True sched.create_tasks() assert queue.createTask.call_count == 0
def test_create_06(mocker): """test no tasks are created for --dry-run""" taskcluster = mocker.patch("orion_decision.scheduler.Taskcluster", autospec=True) queue = taskcluster.get_service.return_value now = datetime.utcnow() root = FIXTURES / "services03" evt = mocker.Mock(spec=GithubEvent()) evt.repo.path = root evt.repo.git = mocker.Mock(return_value="\n".join( str(p) for p in root.glob("**/*"))) evt.event_type = "push" evt.commit = "commit" evt.branch = "push" evt.pull_request = None evt.clone_url = "https://example.com" sched = Scheduler(evt, now, "group", "secret", "push", dry_run=True) sched.services["test1"].dirty = True sched.create_tasks() assert queue.createTask.call_count == 0
def test_create_09(mocker): """test recipe test task creation""" taskcluster = mocker.patch("orion_decision.scheduler.Taskcluster", autospec=True) queue = taskcluster.get_service.return_value now = datetime.utcnow() root = FIXTURES / "services03" evt = mocker.Mock(spec=GithubEvent()) evt.repo.path = root evt.repo.git = mocker.Mock(return_value="\n".join( str(p) for p in root.glob("**/*"))) evt.commit = "commit" evt.branch = "main" evt.clone_url = "https://example.com" evt.pull_request = None sched = Scheduler(evt, now, "group", "secret", "push") sched.services["test5"].dirty = True sched.services["test6"].dirty = True sched.services.recipes["withdep.sh"].dirty = True sched.create_tasks() assert queue.createTask.call_count == 3 task1_id, task1 = queue.createTask.call_args_list[0].args assert task1 == yaml_load( BUILD_TASK.substitute( clone_url="https://example.com", commit="commit", deadline=stringDate(now + DEADLINE), dockerfile="test5/Dockerfile", expires=stringDate(now + ARTIFACTS_EXPIRE), load_deps="0", max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, route="index.project.fuzzing.orion.test5.main", scheduler=SCHEDULER_ID, service_name="test5", source_url=SOURCE_URL, task_group="group", worker=WORKER_TYPE, )) task2_id, task2 = queue.createTask.call_args_list[1].args expected2 = yaml_load( RECIPE_TEST_TASK.substitute( clone_url="https://example.com", commit="commit", deadline=stringDate(now + DEADLINE), dockerfile="services/test-recipes/Dockerfile", max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, recipe_name="withdep.sh", scheduler=SCHEDULER_ID, source_url=SOURCE_URL, task_group="group", worker=WORKER_TYPE, )) expected2["dependencies"].append(task1_id) assert task2 == expected2 _, task3 = queue.createTask.call_args_list[2].args expected3 = yaml_load( BUILD_TASK.substitute( clone_url="https://example.com", commit="commit", deadline=stringDate(now + DEADLINE), dockerfile="test6/Dockerfile", expires=stringDate(now + ARTIFACTS_EXPIRE), load_deps="0", max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, route="index.project.fuzzing.orion.test6.main", scheduler=SCHEDULER_ID, service_name="test6", source_url=SOURCE_URL, task_group="group", worker=WORKER_TYPE, )) expected3["dependencies"].append(task2_id) assert task3 == expected3
def test_create_08(mocker, ci1_dirty, svc1_dirty, svc2_dirty, expected_image): """test "test" tasks creation with dirty ci image""" taskcluster = mocker.patch("orion_decision.scheduler.Taskcluster", autospec=True) queue = taskcluster.get_service.return_value now = datetime.utcnow() root = FIXTURES / "services06" evt = mocker.Mock(spec=GithubEvent()) evt.repo.path = root evt.repo.git = mocker.Mock(return_value="\n".join( str(p) for p in root.glob("**/*"))) evt.commit = "commit" evt.branch = "main" evt.fetch_ref = "fetch" evt.clone_url = "https://example.com" evt.pull_request = None sched = Scheduler(evt, now, "group", "secret", "push") sched.services["testci1"].dirty = ci1_dirty sched.services["svc1"].dirty = svc1_dirty sched.services["svc2"].dirty = svc2_dirty sched.create_tasks() assert queue.createTask.call_count == 3 if ci1_dirty else 2 call_idx = 0 if ci1_dirty: task1_id, task1 = queue.createTask.call_args_list[call_idx].args call_idx += 1 assert task1 == yaml_load( BUILD_TASK.substitute( clone_url="https://example.com", commit="commit", deadline=stringDate(now + DEADLINE), dockerfile="testci1/Dockerfile", expires=stringDate(now + ARTIFACTS_EXPIRE), load_deps="0", max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, route="index.project.fuzzing.orion.testci1.main", scheduler=SCHEDULER_ID, service_name="testci1", source_url=SOURCE_URL, task_group="group", worker=WORKER_TYPE, )) svc = "svc1" if svc1_dirty else "svc2" expected2 = yaml_load( TEST_TASK.substitute( commit="commit", commit_url="https://example.com", deadline=stringDate(now + DEADLINE), dockerfile=f"{svc}/Dockerfile", expires=stringDate(now + ARTIFACTS_EXPIRE), max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, route=f"index.project.fuzzing.orion.{svc}.main", scheduler=SCHEDULER_ID, service_name=svc, source_url=SOURCE_URL, task_group="group", test_name=f"{svc}test", worker=WORKER_TYPE, )) if ci1_dirty: expected_image["taskId"] = task1_id expected2["dependencies"].append(task1_id) expected2["payload"]["image"] = expected_image sched.services[svc].tests[0].update_task(expected2, "https://example.com", "fetch", "commit", svc) task2_id, task2 = queue.createTask.call_args_list[call_idx].args call_idx += 1 assert task2 == expected2 task3_id, task3 = queue.createTask.call_args_list[call_idx].args call_idx += 1 expected3 = yaml_load( BUILD_TASK.substitute( clone_url="https://example.com", commit="commit", deadline=stringDate(now + DEADLINE), dockerfile=f"{svc}/Dockerfile", expires=stringDate(now + ARTIFACTS_EXPIRE), load_deps="0", max_run_time=int(MAX_RUN_TIME.total_seconds()), now=stringDate(now), owner_email=OWNER_EMAIL, provisioner=PROVISIONER_ID, route=f"index.project.fuzzing.orion.{svc}.main", scheduler=SCHEDULER_ID, service_name=svc, source_url=SOURCE_URL, task_group="group", worker=WORKER_TYPE, )) expected3["dependencies"].append(task2_id) assert task3 == expected3