Beispiel #1
0
def test_report_status_for_cluster_instance_sorts_in_deploy_order(
    mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master
):
    # paasta_status with no args displays deploy info
    service = "fake_service"
    planned_deployments = ["a_cluster.a_instance", "a_cluster.b_instance"]
    actual_deployments = {"a_cluster.a_instance": "533976a9", "a_cluster.b_instance": "533976a9"}
    instance_whitelist = []
    fake_status = "status: SOMETHING FAKE"
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = (
        "\n"
        "cluster: a_cluster\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n" % (PaastaColors.blue("a_instance"), fake_status, PaastaColors.blue("b_instance"), fake_status)
    )

    status.report_status_for_cluster(
        service=service,
        cluster="a_cluster",
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #2
0
def test_print_cluster_status_missing_deploys_in_red(
    mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master
):
    # paasta_status displays missing deploys in red
    service = "fake_service"
    planned_deployments = ["a_cluster.a_instance", "a_cluster.b_instance"]
    actual_deployments = {"a_cluster.a_instance": "533976a981679d586bed1cfb534fdba4b4e2c815"}
    instance_whitelist = []
    fake_status = "status: SOMETHING FAKE"
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = (
        "\n"
        "cluster: a_cluster\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        "  instance: %s\n"
        "    Git sha:    None\n" % (PaastaColors.blue("a_instance"), fake_status, PaastaColors.red("b_instance"))
    )

    status.report_status_for_cluster(
        service=service,
        cluster="a_cluster",
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #3
0
def test_get_deployments_strings_default_case_with_smartstack():
    with contextlib.nested(
            mock.patch('paasta_tools.cli.cmds.info.get_actual_deployments',
                       autospec=True),
            mock.patch('service_configuration_lib.read_service_configuration',
                       autospec=True),
    ) as (
            mock_get_actual_deployments,
            mock_read_service_configuration,
    ):
        mock_get_actual_deployments.return_value = [
            'clusterA.main', 'clusterB.main'
        ]
        mock_read_service_configuration.return_value = {
            'smartstack': {
                'main': {
                    'proxy_port': 9001
                }
            }
        }
        actual = info.get_deployments_strings('fake_service', '/fake/soa/dir')
        assert ' - clusterA (%s)' % PaastaColors.cyan(
            'http://fake_service.paasta-clusterA.yelp/') in actual
        assert ' - clusterB (%s)' % PaastaColors.cyan(
            'http://fake_service.paasta-clusterB.yelp/') in actual
Beispiel #4
0
def test_get_service_info():
    with contextlib.nested(
        mock.patch('paasta_tools.cli.cmds.info.get_team', autospec=True),
        mock.patch('paasta_tools.cli.cmds.info.get_runbook', autospec=True),
        mock.patch('paasta_tools.cli.cmds.info.read_service_configuration', autospec=True),
        mock.patch('service_configuration_lib.read_service_configuration', autospec=True),
        mock.patch('paasta_tools.cli.cmds.info.get_actual_deployments', autospec=True),
        mock.patch('paasta_tools.cli.cmds.info.get_smartstack_endpoints', autospec=True),
    ) as (
        mock_get_team,
        mock_get_runbook,
        mock_read_service_configuration,
        mock_scl_read_service_configuration,
        mock_get_actual_deployments,
        mock_get_smartstack_endpoints,
    ):
        mock_get_team.return_value = 'fake_team'
        mock_get_runbook.return_value = 'fake_runbook'
        mock_read_service_configuration.return_value = {
            'description': 'a fake service that does stuff',
            'external_link': 'http://bla',
            'smartstack': {
                'main': {
                    'proxy_port': 9001
                }
            }
        }
        mock_scl_read_service_configuration.return_value = {
            'description': 'a fake service that does stuff',
            'external_link': 'http://bla',
            'smartstack': {
                'main': {
                    'proxy_port': 9001
                }
            }
        }
        mock_get_actual_deployments.return_value = ['clusterA.main', 'clusterB.main']
        mock_get_smartstack_endpoints.return_value = ['http://*****:*****@git.yelpcorp.com:services/fake_service' in actual
        assert 'Jenkins Pipeline: ' in actual
        assert 'Deployed to the following' in actual
        assert 'clusterA (%s)' % PaastaColors.cyan('http://fake_service.paasta-clusterA.yelp/') in actual
        assert 'clusterB (%s)' % PaastaColors.cyan('http://fake_service.paasta-clusterB.yelp/') in actual
        assert 'Smartstack endpoint' in actual
        assert 'http://foo:1234' in actual
        assert 'tcp://bar:1234' in actual
        assert 'Dashboard' in actual
        assert '%s (Sensu Alerts)' % PaastaColors.cyan('https://uchiwa.yelpcorp.com/#/events?q=fake_service') in actual
        mock_get_team.assert_called_with(service='fake_service', overrides={})
        mock_get_runbook.assert_called_with(service='fake_service', overrides={})
Beispiel #5
0
def test_get_deployments_strings_protocol_tcp_case():
    with contextlib.nested(
        mock.patch("paasta_tools.cli.cmds.info.get_actual_deployments", autospec=True),
        mock.patch("paasta_tools.cli.cmds.info.load_service_namespace_config", autospec=True),
    ) as (mock_get_actual_deployments, mock_load_service_namespace_config):
        mock_get_actual_deployments.return_value = ["clusterA.main", "clusterB.main"]
        mock_load_service_namespace_config.return_value = ServiceNamespaceConfig({"mode": "tcp", "proxy_port": 8080})
        actual = info.get_deployments_strings("unused")
        assert " - clusterA (%s)" % PaastaColors.cyan("tcp://paasta-clusterA.yelp:8080/") in actual
        assert " - clusterB (%s)" % PaastaColors.cyan("tcp://paasta-clusterB.yelp:8080/") in actual
Beispiel #6
0
def test_get_deployments_strings_default_case_with_smartstack():
    with contextlib.nested(
        mock.patch("paasta_tools.cli.cmds.info.get_actual_deployments", autospec=True),
        mock.patch("service_configuration_lib.read_service_configuration", autospec=True),
    ) as (mock_get_actual_deployments, mock_read_service_configuration):
        mock_get_actual_deployments.return_value = ["clusterA.main", "clusterB.main"]
        mock_read_service_configuration.return_value = {"smartstack": {"main": {"proxy_port": 9001}}}
        actual = info.get_deployments_strings("fake_service")
        assert " - clusterA (%s)" % PaastaColors.cyan("http://fake_service.paasta-clusterA.yelp/") in actual
        assert " - clusterB (%s)" % PaastaColors.cyan("http://fake_service.paasta-clusterB.yelp/") in actual
Beispiel #7
0
def test_get_deployments_strings_protocol_tcp_case():
    with contextlib.nested(
        mock.patch('paasta_tools.cli.cmds.info.get_actual_deployments', autospec=True),
        mock.patch('paasta_tools.cli.cmds.info.load_service_namespace_config', autospec=True),
    ) as (mock_get_actual_deployments, mock_load_service_namespace_config):
        mock_get_actual_deployments.return_value = ['clusterA.main', 'clusterB.main']
        mock_load_service_namespace_config.return_value = ServiceNamespaceConfig({'mode': 'tcp', 'proxy_port': 8080})
        actual = info.get_deployments_strings('unused', '/fake/soa/dir')
        assert ' - clusterA (%s)' % PaastaColors.cyan('tcp://paasta-clusterA.yelp:8080/') in actual
        assert ' - clusterB (%s)' % PaastaColors.cyan('tcp://paasta-clusterB.yelp:8080/') in actual
def paasta_get_latest_deployment(args):
    service = args.service
    deploy_group = args.deploy_group
    soa_dir = args.soa_dir
    validate_service_name(service, soa_dir)

    git_sha = get_currently_deployed_sha(service=service, deploy_group=deploy_group, soa_dir=soa_dir)
    if not git_sha:
        print PaastaColors.red("A deployment could not be found for %s in %s" % (deploy_group, service))
        return 1
    else:
        print git_sha
        return 0
Beispiel #9
0
def test_get_service_info():
    with contextlib.nested(
        mock.patch("paasta_tools.cli.cmds.info.get_team", autospec=True),
        mock.patch("paasta_tools.cli.cmds.info.get_runbook", autospec=True),
        mock.patch("paasta_tools.cli.cmds.info.read_service_configuration", autospec=True),
        mock.patch("service_configuration_lib.read_service_configuration", autospec=True),
        mock.patch("paasta_tools.cli.cmds.info.get_actual_deployments", autospec=True),
        mock.patch("paasta_tools.cli.cmds.info.get_smartstack_endpoints", autospec=True),
    ) as (
        mock_get_team,
        mock_get_runbook,
        mock_read_service_configuration,
        mock_scl_read_service_configuration,
        mock_get_actual_deployments,
        mock_get_smartstack_endpoints,
    ):
        mock_get_team.return_value = "fake_team"
        mock_get_runbook.return_value = "fake_runbook"
        mock_read_service_configuration.return_value = {
            "description": "a fake service that does stuff",
            "external_link": "http://bla",
            "smartstack": {"main": {"proxy_port": 9001}},
        }
        mock_scl_read_service_configuration.return_value = {
            "description": "a fake service that does stuff",
            "external_link": "http://bla",
            "smartstack": {"main": {"proxy_port": 9001}},
        }
        mock_get_actual_deployments.return_value = ["clusterA.main", "clusterB.main"]
        mock_get_smartstack_endpoints.return_value = ["http://*****:*****@git.yelpcorp.com:services/fake_service" in actual
        assert "Jenkins Pipeline: " in actual
        assert "Deployed to the following" in actual
        assert "clusterA (%s)" % PaastaColors.cyan("http://fake_service.paasta-clusterA.yelp/") in actual
        assert "clusterB (%s)" % PaastaColors.cyan("http://fake_service.paasta-clusterB.yelp/") in actual
        assert "Smartstack endpoint" in actual
        assert "http://foo:1234" in actual
        assert "tcp://bar:1234" in actual
        assert "Dashboard" in actual
        assert "%s (Sensu Alerts)" % PaastaColors.cyan("https://uchiwa.yelpcorp.com/#/events?q=fake_service") in actual
        mock_get_team.assert_called_with(service="fake_service", overrides={})
        mock_get_runbook.assert_called_with(service="fake_service", overrides={})
Beispiel #10
0
def test_report_status_for_cluster_displays_deployed_service(
    mock_stdout, mock_report_invalid_whitelist_values, mock_execute_paasta_serviceinit_on_remote_master
):
    # paasta_status with no args displays deploy info - vanilla case
    service = "fake_service"
    planned_deployments = ["cluster.instance"]
    actual_deployments = {"cluster.instance": "sha"}
    instance_whitelist = []
    fake_status = "status: SOMETHING FAKE"
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = (
        "\n"
        "cluster: cluster\n"
        "  instance: %s\n"
        "    Git sha:    sha\n"
        "    %s\n" % (PaastaColors.blue("instance"), fake_status)
    )

    status.report_status_for_cluster(
        service=service,
        cluster="cluster",
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #11
0
def test_report_status_for_cluster_displays_deployed_service(
    mock_stdout,
    mock_report_invalid_whitelist_values,
    mock_execute_paasta_serviceinit_on_remote_master,
):
    # paasta_status with no args displays deploy info - vanilla case
    service = 'fake_service'
    planned_deployments = ['cluster.instance']
    actual_deployments = {'cluster.instance': 'sha'}
    instance_whitelist = []
    fake_status = 'status: SOMETHING FAKE'
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = ("\n"
                       "cluster: cluster\n"
                       "  instance: %s\n"
                       "    Git sha:    sha\n"
                       "    %s\n" % (
                           PaastaColors.blue('instance'),
                           fake_status,
                       ))

    status.report_status_for_cluster(
        service=service,
        cluster='cluster',
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #12
0
def test_report_status_for_cluster_instance_sorts_in_deploy_order(
    mock_stdout,
    mock_report_invalid_whitelist_values,
    mock_execute_paasta_serviceinit_on_remote_master,
):
    # paasta_status with no args displays deploy info
    service = 'fake_service'
    planned_deployments = [
        'a_cluster.a_instance',
        'a_cluster.b_instance',
    ]
    actual_deployments = {
        'a_cluster.a_instance': '533976a9',
        'a_cluster.b_instance': '533976a9',
    }
    instance_whitelist = []
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    fake_status = 'status: SOMETHING FAKE'
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = (
        "\n"
        "cluster: a_cluster\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        % (
            PaastaColors.blue('a_instance'),
            fake_status,
            PaastaColors.blue('b_instance'),
            fake_status,
        )
    )

    status.report_status_for_cluster(
        service=service,
        cluster='a_cluster',
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
        system_paasta_config=fake_system_paasta_config,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #13
0
def test_report_status_for_cluster_instance_sorts_in_deploy_order(
    mock_stdout,
    mock_report_invalid_whitelist_values,
    mock_execute_paasta_serviceinit_on_remote_master,
):
    # paasta_status with no args displays deploy info
    service = 'fake_service'
    planned_deployments = [
        'a_cluster.a_instance',
        'a_cluster.b_instance',
    ]
    actual_deployments = {
        'a_cluster.a_instance': '533976a9',
        'a_cluster.b_instance': '533976a9',
    }
    instance_whitelist = []
    fake_status = 'status: SOMETHING FAKE'
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = (
        "\n"
        "cluster: a_cluster\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        % (
            PaastaColors.blue('a_instance'),
            fake_status,
            PaastaColors.blue('b_instance'),
            fake_status,
        )
    )

    status.report_status_for_cluster(
        service=service,
        cluster='a_cluster',
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #14
0
def test_get_deployments_strings_default_case_with_smartstack():
    with contextlib.nested(
        mock.patch('paasta_tools.cli.cmds.info.get_actual_deployments', autospec=True),
        mock.patch('service_configuration_lib.read_service_configuration', autospec=True),
    ) as (
        mock_get_actual_deployments,
        mock_read_service_configuration,
    ):
        mock_get_actual_deployments.return_value = ['clusterA.main', 'clusterB.main']
        mock_read_service_configuration.return_value = {
            'smartstack': {
                'main': {
                    'proxy_port': 9001
                }
            }
        }
        actual = info.get_deployments_strings('fake_service', '/fake/soa/dir')
        assert ' - clusterA (%s)' % PaastaColors.cyan('http://fake_service.paasta-clusterA.yelp/') in actual
        assert ' - clusterB (%s)' % PaastaColors.cyan('http://fake_service.paasta-clusterB.yelp/') in actual
def paasta_get_latest_deployment(args):
    service = args.service
    deploy_group = args.deploy_group
    soa_dir = args.soa_dir
    validate_service_name(service, soa_dir)

    git_url = get_git_url(
        service=service,
        soa_dir=soa_dir,
    )
    remote_refs = list_remote_refs(git_url)

    _, git_sha = get_latest_deployment_tag(remote_refs, deploy_group)
    if not git_sha:
        print PaastaColors.red("A deployment could not be found for %s in %s" % (deploy_group, service))
        return 1
    else:
        print git_sha
        return 0
Beispiel #16
0
def test_print_cluster_status_missing_deploys_in_red(
    mock_stdout,
    mock_report_invalid_whitelist_values,
    mock_execute_paasta_serviceinit_on_remote_master,
):
    # paasta_status displays missing deploys in red
    service = 'fake_service'
    planned_deployments = [
        'a_cluster.a_instance',
        'a_cluster.b_instance',
    ]
    actual_deployments = {
        'a_cluster.a_instance': '533976a981679d586bed1cfb534fdba4b4e2c815',
    }
    instance_whitelist = []
    fake_status = 'status: SOMETHING FAKE'
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = (
        "\n"
        "cluster: a_cluster\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        "  instance: %s\n"
        "    Git sha:    None\n"
        % (
            PaastaColors.blue('a_instance'),
            fake_status,
            PaastaColors.red('b_instance'),
        )
    )

    status.report_status_for_cluster(
        service=service,
        cluster='a_cluster',
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
        system_paasta_config=fake_system_paasta_config,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #17
0
def paasta_get_latest_deployment(args):
    service = args.service
    deploy_group = args.deploy_group
    soa_dir = args.soa_dir
    validate_service_name(service, soa_dir)

    git_url = get_git_url(
        service=service,
        soa_dir=soa_dir,
    )
    remote_refs = list_remote_refs(git_url)

    _, git_sha = get_latest_deployment_tag(remote_refs, deploy_group)
    if not git_sha:
        print PaastaColors.red("A deployment could not be found for %s in %s" %
                               (deploy_group, service))
        return 1
    else:
        print git_sha
        return 0
Beispiel #18
0
def test_print_cluster_status_missing_deploys_in_red(
    mock_stdout,
    mock_report_invalid_whitelist_values,
    mock_execute_paasta_serviceinit_on_remote_master,
):
    # paasta_status displays missing deploys in red
    service = 'fake_service'
    planned_deployments = [
        'a_cluster.a_instance',
        'a_cluster.b_instance',
    ]
    actual_deployments = {
        'a_cluster.a_instance': '533976a981679d586bed1cfb534fdba4b4e2c815',
    }
    instance_whitelist = []
    fake_status = 'status: SOMETHING FAKE'
    mock_execute_paasta_serviceinit_on_remote_master.return_value = fake_status
    expected_output = (
        "\n"
        "cluster: a_cluster\n"
        "  instance: %s\n"
        "    Git sha:    533976a9\n"
        "    %s\n"
        "  instance: %s\n"
        "    Git sha:    None\n"
        % (
            PaastaColors.blue('a_instance'),
            fake_status,
            PaastaColors.red('b_instance'),
        )
    )

    status.report_status_for_cluster(
        service=service,
        cluster='a_cluster',
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
    )
    output = mock_stdout.getvalue()
    assert expected_output in output
Beispiel #19
0
def test_get_deployments_strings_protocol_tcp_case():
    with mock.patch(
            "paasta_tools.cli.cmds.info.get_actual_deployments",
            autospec=True) as mock_get_actual_deployments, mock.patch(
                "paasta_tools.cli.cmds.info.load_service_namespace_config",
                autospec=True) as mock_load_service_namespace_config:
        mock_get_actual_deployments.return_value = [
            "clusterA.main", "clusterB.main"
        ]
        mock_load_service_namespace_config.return_value = ServiceNamespaceConfig(
            {
                "mode": "tcp",
                "proxy_port": 8080
            })
        actual = info.get_deployments_strings("unused", "/fake/soa/dir")
        assert (" - clusterA (%s)" %
                PaastaColors.cyan("tcp://paasta-clusterA.yelp:8080/")
                in actual)
        assert (" - clusterB (%s)" %
                PaastaColors.cyan("tcp://paasta-clusterB.yelp:8080/")
                in actual)
Beispiel #20
0
def test_get_deployments_strings_protocol_tcp_case():
    with mock.patch(
            'paasta_tools.cli.cmds.info.get_actual_deployments',
            autospec=True,
    ) as mock_get_actual_deployments, mock.patch(
            'paasta_tools.cli.cmds.info.load_service_namespace_config',
            autospec=True,
    ) as mock_load_service_namespace_config:
        mock_get_actual_deployments.return_value = [
            'clusterA.main', 'clusterB.main'
        ]
        mock_load_service_namespace_config.return_value = ServiceNamespaceConfig(
            {
                'mode': 'tcp',
                'proxy_port': 8080
            })
        actual = info.get_deployments_strings('unused', '/fake/soa/dir')
        assert ' - clusterA (%s)' % PaastaColors.cyan(
            'tcp://paasta-clusterA.yelp:8080/') in actual
        assert ' - clusterB (%s)' % PaastaColors.cyan(
            'tcp://paasta-clusterB.yelp:8080/') in actual
Beispiel #21
0
def test_get_deployments_strings_default_case_with_smartstack():
    with mock.patch(
            "paasta_tools.cli.cmds.info.get_actual_deployments",
            autospec=True) as mock_get_actual_deployments, mock.patch(
                "service_configuration_lib.read_extra_service_information",
                autospec=True) as mock_read_extra_service_information:
        mock_get_actual_deployments.return_value = [
            "clusterA.main", "clusterB.main"
        ]
        mock_read_extra_service_information.return_value = {
            "main": {
                "proxy_port": 9001
            }
        }

        actual = info.get_deployments_strings("fake_service", "/fake/soa/dir")
        assert (" - clusterA (%s)" %
                PaastaColors.cyan("http://fake_service.paasta-clusterA.yelp/")
                in actual)
        assert (" - clusterB (%s)" %
                PaastaColors.cyan("http://fake_service.paasta-clusterB.yelp/")
                in actual)
Beispiel #22
0
def test_print_cluster_status_missing_deploys_in_red(
    mock_report_invalid_whitelist_values,
    mock_execute_paasta_serviceinit_on_remote_master,
    system_paasta_config,
):
    # paasta_status displays missing deploys in red
    service = 'fake_service'
    planned_deployments = [
        'a_cluster.a_instance',
        'a_cluster.b_instance',
    ]
    actual_deployments = {
        'a_cluster.a_instance': '533976a981679d586bed1cfb534fdba4b4e2c815',
    }
    instance_whitelist = []
    fake_status = 'status: SOMETHING FAKE'
    mock_execute_paasta_serviceinit_on_remote_master.return_value = (
        sentinel.return_value,
        fake_status,
    )
    expected_output = (
        "\n"
        "cluster: a_cluster\n"
        "  instance: %s\n"
        "    Git sha:    None (not deployed yet)\n"
        "    %s\n"
        % (
            PaastaColors.red('b_instance'),
            fake_status,
        )
    )

    _, output = status.report_status_for_cluster(
        service=service,
        cluster='a_cluster',
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        instance_whitelist=instance_whitelist,
        system_paasta_config=system_paasta_config,
    )

    output = '\n'.join(str(line) for line in output)
    assert expected_output in output
Beispiel #23
0
def paasta_get_latest_deployment(args):
    service = args.service
    deploy_group = args.deploy_group
    soa_dir = args.soa_dir
    validate_service_name(service, soa_dir)

    git_sha = get_currently_deployed_sha(service=service,
                                         deploy_group=deploy_group,
                                         soa_dir=soa_dir)
    if not git_sha:
        paasta_print(
            PaastaColors.red(
                f"A deployment could not be found for {deploy_group} in {service}"
            ),
            file=sys.stderr,
        )
        return 1
    else:
        paasta_print(git_sha)
        return 0
Beispiel #24
0
def paasta_get_docker_image(args):
    service = args.service
    deploy_group = args.deploy_group
    soa_dir = args.soa_dir
    validate_service_name(service, soa_dir)

    deployments = load_v2_deployments_json(service=service, soa_dir=soa_dir)
    docker_image = deployments.get_docker_image_for_deploy_group(deploy_group)

    if not docker_image:
        print(
            PaastaColors.red(
                f"There is no {service} docker_image for {deploy_group}. Has it been deployed yet?"
            ),
            file=sys.stderr,
        )
        return 1
    else:
        registry_uri = get_service_docker_registry(service=service,
                                                   soa_dir=soa_dir)
        docker_url = f"{registry_uri}/{docker_image}"
        print(docker_url)
        return 0
Beispiel #25
0
)

SCHEMA_NOT_FOUND = failure(
    "Failed to find schema to validate against. More info:",
    "http://paasta.readthedocs.io/en/latest/yelpsoa_configs.html",
)

FAILED_READING_FILE = failure(
    "Failed to read file. More info:",
    "http://paasta.readthedocs.io/en/latest/yelpsoa_configs.html",
)

UNKNOWN_SERVICE = "Unable to determine service to validate.\n" \
                  "Please supply the %s name you wish to " \
                  "validate with the %s option." \
                  % (PaastaColors.cyan('SERVICE'), PaastaColors.cyan('-s'))


def invalid_chronos_instance(cluster, instance, output):
    return failure(
        'chronos-%s.yaml has an invalid instance: %s.\n  %s\n  '
        'More info:' % (cluster, instance, output),
        "http://paasta.readthedocs.io/en/latest/yelpsoa_configs.html#chronos-clustername-yaml",
    )


def valid_chronos_instance(cluster, instance):
    return success(f'chronos-{cluster}.yaml has a valid instance: {instance}.')


def get_schema(file_type):
Beispiel #26
0
def test_get_service_info():
    with mock.patch(
            "paasta_tools.cli.cmds.info.get_team",
            autospec=True) as mock_get_team, mock.patch(
                "paasta_tools.cli.cmds.info.get_runbook", autospec=True
            ) as mock_get_runbook, mock.patch(
                "paasta_tools.cli.cmds.info.read_service_configuration",
                autospec=True) as mock_read_service_configuration, mock.patch(
                    "service_configuration_lib.read_service_configuration",
                    autospec=True
                ) as mock_scl_read_service_configuration, mock.patch(
                    "service_configuration_lib.read_extra_service_information",
                    autospec=True
                ) as mock_read_extra_service_information, mock.patch(
                    "paasta_tools.cli.cmds.info.get_actual_deployments",
                    autospec=True) as mock_get_actual_deployments, mock.patch(
                        "paasta_tools.cli.cmds.info.get_smartstack_endpoints",
                        autospec=True) as mock_get_smartstack_endpoints:
        mock_get_team.return_value = "fake_team"
        mock_get_runbook.return_value = "fake_runbook"
        mock_read_service_configuration.return_value = {
            "description": "a fake service that does stuff",
            "external_link": "http://bla",
            "smartstack": {
                "main": {
                    "proxy_port": 9001
                }
            },
        }
        mock_scl_read_service_configuration.return_value = (
            mock_read_service_configuration.return_value)
        mock_read_extra_service_information.return_value = mock_read_service_configuration.return_value[
            "smartstack"]

        mock_get_actual_deployments.return_value = [
            "clusterA.main", "clusterB.main"
        ]
        mock_get_smartstack_endpoints.return_value = [
            "http://*****:*****@github.yelpcorp.com:services/fake_service" in actual
        assert "Deployed to the following" in actual
        assert ("clusterA (%s)" %
                PaastaColors.cyan("http://fake_service.paasta-clusterA.yelp/")
                in actual)
        assert ("clusterB (%s)" %
                PaastaColors.cyan("http://fake_service.paasta-clusterB.yelp/")
                in actual)
        assert "Smartstack endpoint" in actual
        assert "http://foo:1234" in actual
        assert "tcp://bar:1234" in actual
        assert "Dashboard" in actual
        assert ("%s (Sensu Alerts)" % PaastaColors.cyan(
            "https://uchiwa.yelpcorp.com/#/events?q=fake_service") in actual)
        mock_get_team.assert_called_with(service="fake_service",
                                         overrides={},
                                         soa_dir="/fake/soa/dir")
        mock_get_runbook.assert_called_with(service="fake_service",
                                            overrides={},
                                            soa_dir="/fake/soa/dir")
Beispiel #27
0
def test_get_service_info():
    with mock.patch(
            'paasta_tools.cli.cmds.info.get_team',
            autospec=True,
    ) as mock_get_team, mock.patch(
            'paasta_tools.cli.cmds.info.get_runbook',
            autospec=True,
    ) as mock_get_runbook, mock.patch(
            'paasta_tools.cli.cmds.info.read_service_configuration',
            autospec=True,
    ) as mock_read_service_configuration, mock.patch(
            'service_configuration_lib.read_service_configuration',
            autospec=True,
    ) as mock_scl_read_service_configuration, mock.patch(
            'paasta_tools.cli.cmds.info.get_actual_deployments',
            autospec=True,
    ) as mock_get_actual_deployments, mock.patch(
            'paasta_tools.cli.cmds.info.get_smartstack_endpoints',
            autospec=True,
    ) as mock_get_smartstack_endpoints:
        mock_get_team.return_value = 'fake_team'
        mock_get_runbook.return_value = 'fake_runbook'
        mock_read_service_configuration.return_value = {
            'description': 'a fake service that does stuff',
            'external_link': 'http://bla',
            'smartstack': {
                'main': {
                    'proxy_port': 9001,
                },
            },
        }
        mock_scl_read_service_configuration.return_value = {
            'description': 'a fake service that does stuff',
            'external_link': 'http://bla',
            'smartstack': {
                'main': {
                    'proxy_port': 9001,
                },
            },
        }
        mock_get_actual_deployments.return_value = [
            'clusterA.main', 'clusterB.main'
        ]
        mock_get_smartstack_endpoints.return_value = [
            'http://*****:*****@git.yelpcorp.com:services/fake_service' in actual
        assert 'Deployed to the following' in actual
        assert 'clusterA (%s)' % PaastaColors.cyan(
            'http://fake_service.paasta-clusterA.yelp/') in actual
        assert 'clusterB (%s)' % PaastaColors.cyan(
            'http://fake_service.paasta-clusterB.yelp/') in actual
        assert 'Smartstack endpoint' in actual
        assert 'http://foo:1234' in actual
        assert 'tcp://bar:1234' in actual
        assert 'Dashboard' in actual
        assert '%s (Sensu Alerts)' % PaastaColors.cyan(
            'https://uchiwa.yelpcorp.com/#/events?q=fake_service') in actual
        mock_get_team.assert_called_with(service='fake_service', overrides={})
        mock_get_runbook.assert_called_with(service='fake_service',
                                            overrides={})
Beispiel #28
0
    "Failed to validate schema. More info:", "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html"
)

SCHEMA_NOT_FOUND = failure(
    "Failed to find schema to validate against. More info:",
    "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html",
)

FAILED_READING_FILE = failure(
    "Failed to read file. More info:", "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html"
)

UNKNOWN_SERVICE = (
    "Unable to determine service to validate.\n"
    "Please supply the %s name you wish to "
    "validate with the %s option." % (PaastaColors.cyan("SERVICE"), PaastaColors.cyan("-s"))
)


def invalid_chronos_instance(cluster, instance, output):
    return failure(
        "chronos-%s.yaml has an invalid instance: %s.\n  %s\n  " "More info:" % (cluster, instance, output),
        "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html#chronos-clustername-yaml",
    )


def valid_chronos_instance(cluster, instance):
    return success("chronos-%s.yaml has a valid instance: %s." % (cluster, instance))


def get_schema(file_type):
Beispiel #29
0
)

SCHEMA_NOT_FOUND = failure(
    "Failed to find schema to validate against. More info:",
    "http://paasta.readthedocs.io/en/latest/yelpsoa_configs.html",
)

FAILED_READING_FILE = failure(
    "Failed to read file. More info:",
    "http://paasta.readthedocs.io/en/latest/yelpsoa_configs.html",
)

UNKNOWN_SERVICE = ("Unable to determine service to validate.\n"
                   "Please supply the %s name you wish to "
                   "validate with the %s option." %
                   (PaastaColors.cyan("SERVICE"), PaastaColors.cyan("-s")))


def invalid_tron_namespace(cluster, output, filename):
    return failure(
        "%s is invalid:\n  %s\n  "
        "More info:" % (filename, output),
        "http://tron.readthedocs.io/en/latest/jobs.html",
    )


def valid_tron_namespace(cluster, filename):
    return success(f"{filename} is valid.")


def duplicate_instance_names_message(service, cluster, instance_names):
Beispiel #30
0
SCHEMA_INVALID = failure(
    "Failed to validate schema. More info:",
    "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html")

SCHEMA_NOT_FOUND = failure(
    "Failed to find schema to validate against. More info:",
    "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html")

FAILED_READING_FILE = failure(
    "Failed to read file. More info:",
    "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html")

UNKNOWN_SERVICE = "Unable to determine service to validate.\n" \
                  "Please supply the %s name you wish to " \
                  "validate with the %s option." \
                  % (PaastaColors.cyan('SERVICE'), PaastaColors.cyan('-s'))


def invalid_chronos_instance(cluster, instance, output):
    return failure(
        'chronos-%s.yaml has an invalid instance: %s.\n  %s\n  '
        'More info:' % (cluster, instance, output),
        "http://paasta.readthedocs.org/en/latest/yelpsoa_configs.html#chronos-clustername-yaml")


def valid_chronos_instance(cluster, instance):
    return success('chronos-%s.yaml has a valid instance: %s.' % (cluster, instance))


def get_schema(file_type):
    """Get the correct schema to use for validation