예제 #1
0
def test_MarkForDeployProcess_goes_to_mfd_failed_when_mark_for_deployment_fails(
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_get_authors,
    mock_periodically_update_slack,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service='service',
        block=False,  # shouldn't matter for this test
        auto_rollback=False,  # shouldn't matter for this test
        deploy_info=None,
        deploy_group=None,
        commit='asbjkslerj',
        old_git_sha='abscerwerr',
        git_url=None,
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
    )

    mock_mark_for_deployment.return_value = 1
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 0
    assert retval == 1
    assert mfdp.state == 'mfd_failed'
예제 #2
0
def test_MarkForDeployProcess_handles_wait_for_deployment_cancelled(
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_get_authors,
    mock_periodically_update_slack,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service='service',
        block=True,
        # For this test, auto_rollback must be True so that the deploy_cancelled trigger takes us to start_rollback
        # instead of deploy_errored.
        auto_rollback=True,
        deploy_info=None,
        deploy_group=None,
        commit='abc123512',
        old_git_sha='asgdser23',
        git_url=None,
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = KeyboardInterrupt()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert retval == 1
    assert mfdp.state == 'deploy_cancelled'
예제 #3
0
def test_MarkForDeployProcess_skips_wait_for_deployment_when_block_is_False(
    mock_get_slack_events,
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_Thread,
    mock_get_authors,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service='service',
        block=False,
        auto_rollback=False,
        deploy_info=None,
        deploy_group=None,
        commit='abc123456789',
        old_git_sha='oldsha1234',
        git_url=None,
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 0
    assert retval == 0
    assert mfdp.state == 'deploying'
예제 #4
0
def test_MarkForDeployProcess_goes_to_mfd_failed_when_mark_for_deployment_fails(
    mock_load_system_paasta_config,
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_get_authors,
    mock_periodically_update_slack,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service="service",
        block=False,  # shouldn't matter for this test
        auto_rollback=False,  # shouldn't matter for this test
        deploy_info=MagicMock(),
        deploy_group=None,
        commit="asbjkslerj",
        old_git_sha="abscerwerr",
        git_url="[email protected]:services/repo1",
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
        auto_rollback_delay=1,
    )

    mock_mark_for_deployment.return_value = 1
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 0
    assert retval == 1
    assert mfdp.state == "mfd_failed"
예제 #5
0
def test_MarkForDeployProcess_handles_wait_for_deployment_failure(
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_get_authors,
    mock_periodically_update_slack,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service='service',
        block=True,
        auto_rollback=True,
        deploy_info=None,
        deploy_group=None,
        commit='abc123432u49',
        old_git_sha='abc123455',
        git_url=None,
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 1
    assert mfdp.state == 'deploy_errored'
    assert retval == 2
예제 #6
0
def test_MarkForDeployProcess_handles_wait_for_deployment_cancelled(
    mock_load_system_paasta_config,
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_get_authors,
    mock_periodically_update_slack,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service="service",
        block=True,
        # For this test, auto_rollback must be True so that the deploy_cancelled trigger takes us to start_rollback
        # instead of deploy_errored.
        auto_rollback=True,
        deploy_info=MagicMock(),
        deploy_group=None,
        commit="abc123512",
        old_git_sha="asgdser23",
        git_url="[email protected]:services/repo1",
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
        auto_rollback_delay=1,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = KeyboardInterrupt()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert retval == 1
    assert mfdp.state == "deploy_cancelled"
예제 #7
0
def test_MarkForDeployProcess_skips_wait_for_deployment_when_block_is_False(
    mock_load_system_paasta_config,
    mock_get_slack_events,
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_Thread,
    mock_get_authors,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service="service",
        block=False,
        auto_rollback=False,
        deploy_info=MagicMock(),
        deploy_group=None,
        commit="abc123456789",
        old_git_sha="oldsha1234",
        git_url="[email protected]:services/repo1",
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
        auto_rollback_delay=1,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 0
    assert retval == 0
    assert mfdp.state == "deploying"
예제 #8
0
def test_MarkForDeployProcess_get_authors_diffs_against_prod_deploy_group(
    mock_load_system_paasta_config,
    mock_get_slack_client,
    mock_get_currently_deployed_sha,
    mock_get_authors_to_be_notified,
):
    # get_authors should calculate authors since the production_deploy_group's
    # current SHA, when available.
    mock_get_currently_deployed_sha.return_value = "aaaaaaaa"
    mark_for_deployment.MarkForDeploymentProcess(
        service="service",
        block=True,
        auto_rollback=False,
        deploy_info={"production_deploy_group": "prod"},
        deploy_group=None,
        commit="abc123512",
        old_git_sha="asgdser23",
        git_url="[email protected]:services/repo",
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
        auto_rollback_delay=1,
        authors=["fakeuser1"],
    )
    mock_get_authors_to_be_notified.assert_called_once_with(
        git_url="[email protected]:services/repo",
        from_sha="aaaaaaaa",
        to_sha="abc123512",
        authors=["fakeuser1"],
    )
예제 #9
0
def test_MarkForDeployProcess_get_authors_falls_back_to_current_deploy_group(
    mock_load_system_paasta_config,
    mock_get_slack_client,
    mock_get_currently_deployed_sha,
    mock_get_authors_to_be_notified,
):
    # When there's no production_deploy_group configured, get_authors should
    # fall back to calculating authors using the previous SHA for this deploy
    # group.
    mark_for_deployment.MarkForDeploymentProcess(
        service="service",
        block=True,
        auto_rollback=False,
        # No production_deploy_group!
        deploy_info={},
        deploy_group=None,
        commit="abc123512",
        old_git_sha="asgdser23",
        git_url="[email protected]:services/repo1",
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
        auto_rollback_delay=1,
        authors="fakeuser1",
    )
    mock_get_authors_to_be_notified.assert_called_once_with(
        git_url="[email protected]:services/repo1",
        from_sha="asgdser23",
        to_sha="abc123512",
        authors="fakeuser1",
    )
예제 #10
0
def test_MarkForDeployProcess_handles_first_time_deploys(
    mock_load_system_paasta_config,
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_get_authors,
    mock_periodically_update_slack,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service="service",
        block=True,
        auto_rollback=True,
        deploy_info=MagicMock(),
        deploy_group=None,
        commit="abc123432u49",
        old_git_sha=None,
        git_url="[email protected]:services/repo",
        soa_dir=None,
        timeout=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
        auto_rollback_delay=1,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 1
    assert mfdp.state == "deploy_errored"
    assert retval == 2
def test_MarkForDeployProcess_goes_to_mfd_failed_when_mark_for_deployment_fails(
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_SlackDeployNotifier,
):
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service='service',
        block=False,  # shouldn't matter for this test
        auto_rollback=False,  # shouldn't matter for this test
        deploy_info=None,
        deploy_group=None,
        commit=None,
        old_git_sha=None,
        git_url=None,
        soa_dir=None,
        timeout=None,
    )

    mock_mark_for_deployment.return_value = 1
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 0
    assert retval == 1
    assert mfdp.state == 'mfd_failed'
def test_MarkForDeployProcess_skips_wait_for_deployment_when_block_is_False(
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_SlackDeployNotifier,
):
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service='service',
        block=False,
        auto_rollback=False,
        deploy_info=None,
        deploy_group=None,
        commit=None,
        old_git_sha=None,
        git_url=None,
        soa_dir=None,
        timeout=None,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 0
    assert retval == 0
    assert mfdp.state == 'deploying'
def test_MarkForDeployProcess_handles_wait_for_deployment_cancelled(
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_SlackDeployNotifier,
):
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service='service',
        block=True,
        # For this test, auto_rollback must be True so that the deploy_cancelled trigger takes us to start_rollback
        # instead of deploy_aborted.
        auto_rollback=True,
        deploy_info=None,
        deploy_group=None,
        commit=None,
        old_git_sha=None,
        git_url=None,
        soa_dir=None,
        timeout=None,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = KeyboardInterrupt()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 1
    assert retval == 1
    assert mfdp.state == 'start_rollback'
예제 #14
0
def test_MarkForDeployProcess_handles_wait_for_deployment_failure(
    mock_get_slos_for_service,
    mock_load_system_paasta_config,
    mock_wait_for_deployment,
    mock_mark_for_deployment,
    mock_get_slack_client,
    mock_get_authors,
    mock__log_audit,
    mock_get_instance_configs,
):
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    mfdp = mark_for_deployment.MarkForDeploymentProcess(
        service="service",
        block=True,
        auto_rollback=True,
        deploy_info={
            "pipeline": [{
                "step": "test_deploy_group",
                "slack_notify": False
            }],
            "slack_channels": ["#test"],
        },
        deploy_group="test_deploy_group",
        commit="abc123432u49",
        old_git_sha="abc123455",
        git_url="[email protected]:services/repo",
        soa_dir=None,
        timeout=None,
        warn_pct=None,
        auto_certify_delay=1,
        auto_abandon_delay=1,
        auto_rollback_delay=1,
    )

    mock_mark_for_deployment.return_value = 0
    mock_wait_for_deployment.side_effect = Exception()

    retval = mfdp.run()

    assert mock_mark_for_deployment.call_count == 1
    assert mock_wait_for_deployment.call_count == 1
    assert mfdp.state == "deploy_errored"
    assert retval == 2
    assert not mock__log_audit.called