Example #1
0
def mocked_repo_config(mock_repo_config):
    mock_repo_config({
        "test": {
            "mozilla-central":
            Repo(
                "mozilla-central",
                SCM_LEVEL_3,
                "",
                "",
                "",
                False,
                "http://hg.test",
                False,
            ),
            "mozilla-uplift":
            Repo(
                "mozilla-uplift",
                SCM_LEVEL_3,
                "",
                "",
                "",
                False,
                "http://hg.test/uplift",
                True,
            ),
        }
    })
Example #2
0
def mocked_repo_config(mock_repo_config):
    mock_repo_config(
        {
            "test": {
                "mozilla-central": Repo(
                    tree="mozilla-central",
                    url="http://hg.test",
                    access_group=SCM_LEVEL_3,
                    approval_required=False,
                    legacy_transplant=True,
                ),
                "mozilla-uplift": Repo(
                    tree="mozilla-uplift",
                    url="http://hg.test/uplift",
                    access_group=SCM_LEVEL_3,
                    approval_required=True,
                    legacy_transplant=True,
                ),
                "mozilla-new": Repo(
                    tree="mozilla-new",
                    url="http://hg.test/new",
                    access_group=SCM_LEVEL_3,
                    commit_flags=[("VALIDFLAG1", "testing"), ("VALIDFLAG2", "testing")],
                ),
            }
        }
    )
def mocked_repo_config(mock_repo_config):
    mock_repo_config({
        "test": {
            "mozilla-central":
            Repo("mozilla-central", SCM_LEVEL_3, "", "http://hg.test")
        }
    })
Example #4
0
def test_lose_push_race(app, db, s3, mock_repo_config, hg_server, hg_clone,
                        treestatusdouble, upload_patch):
    treestatus = treestatusdouble.get_treestatus_client()
    treestatusdouble.open_tree("mozilla-central")
    repo = Repo(
        tree="mozilla-central",
        url=hg_server,
        access_group=SCM_LEVEL_3,
        push_path=hg_server,
        pull_path=hg_server,
    )
    hgrepo = HgRepo(hg_clone.strpath)
    upload_patch(1, patch=PATCH_PUSH_LOSER)
    job = LandingJob(
        id=1234,
        status=LandingJobStatus.IN_PROGRESS,
        requester_email="*****@*****.**",
        repository_name="mozilla-central",
        revision_to_diff_id={"1": 1},
        revision_order=["1"],
        attempts=1,
    )

    worker = LandingWorker(sleep_seconds=0)

    assert not worker.run_job(job, repo, hgrepo, treestatus,
                              "landoapi.test.bucket")
    assert job.status is LandingJobStatus.DEFERRED
Example #5
0
def test_integrated_execute_job(app, db, s3, mock_repo_config, hg_server,
                                hg_clone, treestatusdouble, upload_patch):
    treestatus = treestatusdouble.get_treestatus_client()
    treestatusdouble.open_tree("mozilla-central")
    repo = Repo(
        tree="mozilla-central",
        url=hg_server,
        access_group=SCM_LEVEL_3,
        push_path=hg_server,
        pull_path=hg_server,
        legacy_transplant=False,
    )
    hgrepo = HgRepo(hg_clone.strpath)
    upload_patch(1)
    upload_patch(2)
    job = LandingJob(
        status=LandingJobStatus.IN_PROGRESS,
        requester_email="*****@*****.**",
        repository_name="mozilla-central",
        revision_to_diff_id={
            "1": 1,
            "2": 2
        },
        revision_order=["1", "2"],
        attempts=1,
    )

    worker = LandingWorker(sleep_seconds=0.01)

    assert worker.run_job(job, repo, hgrepo, treestatus,
                          "landoapi.test.bucket")
    assert job.status is LandingJobStatus.LANDED
    assert len(job.landed_commit_id) == 40
Example #6
0
def mocked_repo_config(mock_repo_config):
    mock_repo_config(
        {
            'test': {
                'mozilla-central': Repo('mozilla-central', SCM_LEVEL_3, ''),
            },
        }
    )
Example #7
0
def mocked_repo_config(mock_repo_config):
    mock_repo_config(
        {
            'test': {
                'mozilla-central': Repo(
                    'mozilla-central', SCM_LEVEL_3, '', 'http://hg.test'
                ),
            },
        }
    )  # yapf: disable
Example #8
0
def test_integrated_push_bookmark_sent_when_supported_repo(
    db,
    client,
    phabdouble,
    monkeypatch,
    s3,
    auth0_mock,
    get_phab_client,
    mock_repo_config,
):
    # Mock the repo to have a push bookmark.
    mock_repo_config(
        {
            "test": {
                "mozilla-central": Repo(
                    "mozilla-central",
                    SCM_LEVEL_3,
                    "@",
                    "",
                    "",
                    False,
                    "http://hg.test",
                    False,
                )
            }
        }
    )

    # Mock the phabricator response data
    repo = phabdouble.repo(name="mozilla-central")
    d1 = phabdouble.diff()
    r1 = phabdouble.revision(diff=d1, repo=repo)
    phabdouble.reviewer(r1, phabdouble.user(username="******"))
    patch_url = patches.url("landoapi.test.bucket", patches.name(r1["id"], d1["id"]))

    tsclient = MagicMock(spec=TransplantClient)
    tsclient().land.return_value = 1
    monkeypatch.setattr("landoapi.api.transplants.TransplantClient", tsclient)
    client.post(
        "/transplants",
        json={
            "landing_path": [
                {"revision_id": "D{}".format(r1["id"]), "diff_id": d1["id"]}
            ]
        },
        headers=auth0_mock.mock_headers,
    )
    tsclient().land.assert_called_once_with(
        revision_id=r1["id"],
        ldap_username="******",
        patch_urls=[patch_url],
        tree="mozilla-central",
        pingback="{}/landings/update".format(os.getenv("PINGBACK_HOST_URL")),
        push_bookmark="@",
    )
Example #9
0
def test_failed_landing_job_notification(
    app,
    db,
    s3,
    mock_repo_config,
    hg_server,
    hg_clone,
    treestatusdouble,
    monkeypatch,
    upload_patch,
):
    """Ensure that a failed landings triggers a user notification.
    """
    treestatus = treestatusdouble.get_treestatus_client()
    treestatusdouble.open_tree("mozilla-central")
    repo = Repo("mozilla-central", SCM_LEVEL_3, "", hg_server, hg_server, True,
                hg_server, False)
    hgrepo = HgRepo(hg_clone.strpath)
    upload_patch(1)
    upload_patch(2)
    job = LandingJob(
        status=LandingJobStatus.IN_PROGRESS,
        requester_email="*****@*****.**",
        repository_name="mozilla-central",
        revision_to_diff_id={
            "1": 1,
            "2": 2
        },
        revision_order=["1", "2"],
        attempts=1,
    )

    worker = LandingWorker(sleep_seconds=0.01)

    # Mock `hgrepo.update_repo` so we can force a failed landing.
    mock_update_repo = mock.MagicMock()
    mock_update_repo.side_effect = Exception("Forcing a failed landing")
    monkeypatch.setattr(hgrepo, "update_repo", mock_update_repo)

    # Mock `notify_user_of_landing_failure` so we can make sure that it was called.
    mock_notify = mock.MagicMock()
    monkeypatch.setattr(
        "landoapi.landing_worker.notify_user_of_landing_failure", mock_notify)

    assert worker.run_job(job, repo, hgrepo, treestatus,
                          "landoapi.test.bucket")
    assert job.status is LandingJobStatus.FAILED
    assert mock_notify.call_count == 1
Example #10
0
def test_integrated_push_bookmark_sent_when_supported_repo(
    db, client, phabdouble, monkeypatch, s3, auth0_mock, get_phab_client,
    mock_repo_config
):
    # Mock the repo to have a push bookmark.
    mock_repo_config(
        {
            'test': {
                'mozilla-central': Repo(
                    'mozilla-central', SCM_LEVEL_3, '@', 'http://hg.test'
                )
            },
        }
    )  # yapf: disable

    # Mock the phabricator response data
    repo = phabdouble.repo(name='mozilla-central')
    d1 = phabdouble.diff()
    r1 = phabdouble.revision(diff=d1, repo=repo)
    phabdouble.reviewer(r1, phabdouble.user(username='******'))
    patch_url = patches.url(
        'landoapi.test.bucket', patches.name(r1['id'], d1['id'])
    )

    tsclient = MagicMock(spec=TransplantClient)
    tsclient().land.return_value = 1
    monkeypatch.setattr('landoapi.api.transplants.TransplantClient', tsclient)
    client.post(
        '/transplants',
        json={
            'landing_path': [
                {
                    'revision_id': 'D{}'.format(r1['id']),
                    'diff_id': d1['id'],
                },
            ],
        },
        headers=auth0_mock.mock_headers,
    )
    tsclient().land.assert_called_once_with(
        revision_id=r1['id'],
        ldap_username='******',
        patch_urls=[patch_url],
        tree='mozilla-central',
        pingback='{}/landings/update'.format(os.getenv('PINGBACK_HOST_URL')),
        push_bookmark='@'
    )
Example #11
0
def test_integrated_execute_job(
    app, db, s3, mock_repo_config, hg_server, hg_clone, treestatusdouble
):
    treestatus = treestatusdouble.get_treestatus_client()
    treestatusdouble.open_tree("mozilla-central")
    repo = Repo(
        "mozilla-central", SCM_LEVEL_3, "", hg_server, hg_server, True, hg_server, False
    )
    hgrepo = HgRepo(hg_clone.strpath)
    patches.upload(
        1,
        1,
        PATCH_NORMAL_1,
        "landoapi.test.bucket",
        aws_access_key=None,
        aws_secret_key=None,
    )
    patches.upload(
        2,
        2,
        PATCH_NORMAL_2,
        "landoapi.test.bucket",
        aws_access_key=None,
        aws_secret_key=None,
    )
    job = LandingJob(
        status=LandingJobStatus.IN_PROGRESS,
        requester_email="*****@*****.**",
        repository_name="mozilla-central",
        revision_to_diff_id={"1": 1, "2": 2},
        revision_order=["1", "2"],
        attempts=1,
    )

    worker = LandingWorker(sleep_seconds=0.01)

    assert worker.run_job(job, repo, hgrepo, treestatus, "landoapi.test.bucket")
    assert job.status is LandingJobStatus.LANDED
    assert len(job.landed_commit_id) == 40