Exemplo n.º 1
0
def issue_state_change_for_service(service_config, force_bounce, desired_state):
    ref_mutator = make_mutate_refs_func(
        service_config=service_config,
        force_bounce=force_bounce,
        desired_state=desired_state,
    )
    remote_git.create_remote_refs(utils.get_git_url(service_config.get_service()), ref_mutator)
    log_event(
        service_config=service_config,
        desired_state=desired_state,
    )
    if isinstance(service_config, MarathonServiceConfig):
        if desired_state == 'start':
            extra_message = (
                "A 'start' command will signal to Marathon that the service should have the normal "
                "instance count. A restart will cause new tasks to replace the old ones gracefully."
            )
        elif desired_state == 'stop':
            extra_message = (
                "A 'stop' command will signal to Marathon that the service should be in Marathon, "
                "but scaled down to 0 instances gracefully. Use 'paasta start' or make a new deployment to "
                "make the service start back up."
            )
    elif isinstance(service_config, ChronosJobConfig):
        if desired_state == 'start':
            extra_message = (
                "'Start' will tell Chronos to start scheduling the job. "
                "If you need the job to start regardless of the schedule, use 'paasta emergency-start'."
            )
        elif desired_state == 'stop':
            extra_message = (
                "'Stop' for a Chronos job will cause the job to be disabled until the "
                "next deploy or a 'start' command is issued."
            )
    print extra_message
def mark_for_deployment(git_url, deploy_group, service, commit):
    """Mark a docker image for deployment"""
    remote_branch = get_paasta_branch_from_deploy_group(identifier=deploy_group)
    ref_mutator = remote_git.make_force_push_mutate_refs_func(
        target_branches=[remote_branch],
        sha=commit,
    )
    try:
        remote_git.create_remote_refs(git_url=git_url, ref_mutator=ref_mutator, force=True)
    except Exception as e:
        loglines = ["Failed to mark %s in for deployment in deploy group %s!" % (commit, deploy_group)]
        for line in str(e).split('\n'):
            loglines.append(line)
        return_code = 1
    else:
        loglines = ["Marked %s in for deployment in deploy group %s" % (commit, deploy_group)]
        return_code = 0

    for logline in loglines:
        _log(
            service=service,
            line=logline,
            component='deploy',
            level='event',
        )
    return return_code
Exemplo n.º 3
0
def mark_for_deployment(git_url, cluster, instance, service, commit):
    """Mark a docker image for deployment"""
    remote_branch = get_paasta_branch(cluster=cluster, instance=instance)
    ref_mutator = remote_git.make_force_push_mutate_refs_func(
        target_branches=[remote_branch],
        sha=commit,
    )
    try:
        remote_git.create_remote_refs(git_url=git_url, ref_mutator=ref_mutator, force=True)
    except Exception as e:
        loglines = ["Failed to mark %s in for deployment on %s in the %s cluster!" % (commit, instance, cluster)]
        for line in str(e).split('\n'):
            loglines.append(line)
        return_code = 1
    else:
        loglines = ["Marked %s in for deployment on %s in the %s cluster" % (commit, instance, cluster)]
        return_code = 0

    for logline in loglines:
        _log(
            service=service,
            line=logline,
            component='deploy',
            level='event',
            cluster=cluster,
            instance=instance,
        )
    return return_code
Exemplo n.º 4
0
def issue_state_change_for_branches(service, instance, cluster, branches, force_bounce,
                                    desired_state):
    ref_mutator = make_mutate_refs_func(
        branches=branches,
        force_bounce=force_bounce,
        desired_state=desired_state
    )
    remote_git.create_remote_refs(utils.get_git_url(service), ref_mutator)
    log_event(service, instance, cluster, desired_state)
Exemplo n.º 5
0
def test_create_remote_refs_is_safe_by_default(mock_make_determine_wants_func, mock_dulwich_client):
    git_url = 'fake_git_url'
    ref_mutator = identity
    fake_git_client = mock.Mock()
    mock_dulwich_client.get_transport_and_path.return_value = fake_git_client, 'fake_path'
    remote_git.create_remote_refs(
        git_url=git_url,
        ref_mutator=ref_mutator,
    )
    fake_git_client.send_pack.assert_called_once_with(
        'fake_path', mock_make_determine_wants_func.return_value, mock.ANY)
Exemplo n.º 6
0
def issue_state_change_for_service(service_config, force_bounce, desired_state):
    ref_mutator = make_mutate_refs_func(
        service_config=service_config,
        force_bounce=force_bounce,
        desired_state=desired_state,
    )
    remote_git.create_remote_refs(utils.get_git_url(service_config.get_service()), ref_mutator)
    log_event(
        service_config=service_config,
        desired_state=desired_state,
    )
Exemplo n.º 7
0
def test_create_remote_refs_allows_force_and_uses_the_provided_mutator(mock_dulwich_client):
    git_url = 'fake_git_url'
    ref_mutator = identity
    fake_git_client = mock.Mock()
    mock_dulwich_client.get_transport_and_path.return_value = fake_git_client, 'fake_path'
    remote_git.create_remote_refs(
        git_url=git_url,
        ref_mutator=ref_mutator,
        force=True,
    )
    fake_git_client.send_pack.assert_called_once_with(
        'fake_path', ref_mutator, mock.ANY)
Exemplo n.º 8
0
def test_create_remote_refs_allows_force_and_uses_the_provided_mutator(mock_dulwich_client):
    git_url = 'fake_git_url'
    ref_mutator = identity
    fake_git_client = mock.Mock()
    mock_dulwich_client.get_transport_and_path.return_value = fake_git_client, 'fake_path'
    remote_git.create_remote_refs(
        git_url=git_url,
        ref_mutator=ref_mutator,
        force=True,
    )
    fake_git_client.send_pack.assert_called_once_with(
        'fake_path', ref_mutator, mock.ANY)
Exemplo n.º 9
0
def issue_state_change_for_service(service_config, force_bounce,
                                   desired_state):
    ref_mutator = make_mutate_refs_func(
        service_config=service_config,
        force_bounce=force_bounce,
        desired_state=desired_state,
    )
    git_url = utils.get_git_url(service_config.get_service())
    remote_git.create_remote_refs(git_url, ref_mutator)
    if "yelpcorp.com" in git_url:
        trigger_deploys(service_config.get_service())
    log_event(service_config=service_config, desired_state=desired_state)
Exemplo n.º 10
0
def issue_state_change_for_service(service_config, force_bounce,
                                   desired_state):
    ref_mutator = make_mutate_refs_func(
        service_config=service_config,
        force_bounce=force_bounce,
        desired_state=desired_state,
    )
    remote_git.create_remote_refs(
        utils.get_git_url(service_config.get_service()), ref_mutator)
    log_event(
        service_config=service_config,
        desired_state=desired_state,
    )
Exemplo n.º 11
0
def test_create_remote_refs_allows_force_and_uses_the_provided_mutator(
    mock_dulwich_client, ):
    git_url = "fake_git_url"
    fake_git_client = mock.Mock()
    mock_dulwich_client.get_transport_and_path.return_value = (
        fake_git_client,
        "fake_path",
    )
    remote_git.create_remote_refs(git_url=git_url,
                                  ref_mutator=mock.sentinel.ref_mutator,
                                  force=True)
    fake_git_client.send_pack.assert_called_once_with(
        "fake_path", mock.sentinel.ref_mutator, mock.ANY)
Exemplo n.º 12
0
def mark_for_deployment(git_url, deploy_group, service, commit):
    """Mark a docker image for deployment"""
    tag = get_paasta_tag_from_deploy_group(identifier=deploy_group,
                                           desired_state='deploy')
    remote_tag = format_tag(tag)
    ref_mutator = remote_git.make_force_push_mutate_refs_func(
        targets=[remote_tag],
        sha=commit,
    )

    max_attempts = 3
    for attempt in range(1, max_attempts + 1):
        try:
            remote_git.create_remote_refs(git_url=git_url,
                                          ref_mutator=ref_mutator,
                                          force=True)
        except Exception:
            logline = "Failed to mark {} for deployment in deploy group {}! (attempt {}/{})".format(
                commit,
                deploy_group,
                attempt,
                max_attempts,
            )
            _log(
                service=service,
                line=logline,
                component='deploy',
                level='event',
            )
            time.sleep(5 * attempt)
        else:
            logline = f"Marked {commit} for deployment in deploy group {deploy_group}"
            _log(
                service=service,
                line=logline,
                component='deploy',
                level='event',
            )

            audit_action_details = {
                'deploy_group': deploy_group,
                'commit': commit,
            }
            _log_audit(
                action='mark-for-deployment',
                action_details=audit_action_details,
                service=service,
            )

            return 0
    return 1
Exemplo n.º 13
0
def test_create_remote_refs_is_safe_by_default(mock_make_determine_wants_func,
                                               mock_dulwich_client):
    git_url = 'fake_git_url'
    fake_git_client = mock.Mock()
    mock_dulwich_client.get_transport_and_path.return_value = fake_git_client, 'fake_path'
    remote_git.create_remote_refs(
        git_url=git_url,
        ref_mutator=mock.sentinel.ref_mutator,
    )
    fake_git_client.send_pack.assert_called_once_with(
        'fake_path',
        mock_make_determine_wants_func.return_value,
        mock.ANY,
    )
Exemplo n.º 14
0
def mark_for_deployment(git_url, deploy_group, service, commit):
    """Mark a docker image for deployment"""
    remote_branch = 'refs/heads/%s' % get_paasta_branch_from_deploy_group(
        identifier=deploy_group)
    tag = get_paasta_tag_from_deploy_group(identifier=deploy_group,
                                           desired_state='deploy')
    remote_tag = format_tag(tag)
    ref_mutator = remote_git.make_force_push_mutate_refs_func(
        targets=[remote_branch, remote_tag],
        sha=commit,
    )
    try:
        remote_git.create_remote_refs(git_url=git_url,
                                      ref_mutator=ref_mutator,
                                      force=True)
    except Exception as e:
        loglines = [
            "Failed to mark %s in for deployment in deploy group %s!" %
            (commit, deploy_group)
        ]
        for line in str(e).split('\n'):
            loglines.append(line)
        return_code = 1
    else:
        loglines = [
            "Marked %s in for deployment in deploy group %s" %
            (commit, deploy_group)
        ]
        return_code = 0

    for logline in loglines:
        _log(
            service=service,
            line=logline,
            component='deploy',
            level='event',
        )
    return return_code
Exemplo n.º 15
0
def mark_for_deployment(git_url, cluster, instance, service, commit):
    """Mark a docker image for deployment"""
    remote_branch = get_paasta_branch(cluster=cluster, instance=instance)
    ref_mutator = remote_git.make_force_push_mutate_refs_func(
        target_branches=[remote_branch],
        sha=commit,
    )
    try:
        remote_git.create_remote_refs(git_url=git_url,
                                      ref_mutator=ref_mutator,
                                      force=True)
    except Exception as e:
        loglines = [
            "Failed to mark %s in for deployment on %s in the %s cluster!" %
            (commit, instance, cluster)
        ]
        for line in str(e).split('\n'):
            loglines.append(line)
        return_code = 1
    else:
        loglines = [
            "Marked %s in for deployment on %s in the %s cluster" %
            (commit, instance, cluster)
        ]
        return_code = 0

    for logline in loglines:
        _log(
            service=service,
            line=logline,
            component='deploy',
            level='event',
            cluster=cluster,
            instance=instance,
        )
    return return_code