Ejemplo n.º 1
0
Archivo: check.py Proyecto: seco/paasta
def git_repo_check(service):
    git_url = get_git_url(service)
    cmd = 'git ls-remote %s' % git_url
    returncode, _ = _run(cmd, timeout=5)
    if returncode == 0:
        print PaastaCheckMessages.GIT_REPO_FOUND
    else:
        print PaastaCheckMessages.git_repo_missing(git_url)
Ejemplo n.º 2
0
def git_repo_check(service):
    git_url = get_git_url(service)
    cmd = 'git ls-remote %s' % git_url
    returncode, _ = _run(cmd, timeout=5)
    if returncode == 0:
        print PaastaCheckMessages.GIT_REPO_FOUND
    else:
        print PaastaCheckMessages.git_repo_missing(git_url)
Ejemplo n.º 3
0
def service_dir_check(service, soa_dir):
    """Check whether directory service exists in /nail/etc/services
    :param service: string of service name we wish to inspect
    """
    try:
        validate_service_name(service, soa_dir)
        print PaastaCheckMessages.service_dir_found(service, soa_dir)
    except NoSuchService:
        print PaastaCheckMessages.service_dir_missing(service, soa_dir)
Ejemplo n.º 4
0
Archivo: check.py Proyecto: seco/paasta
def service_dir_check(service, soa_dir):
    """Check whether directory service exists in /nail/etc/services
    :param service: string of service name we wish to inspect
    """
    try:
        validate_service_name(service, soa_dir)
        print PaastaCheckMessages.service_dir_found(service, soa_dir)
    except NoSuchService:
        print PaastaCheckMessages.service_dir_missing(service, soa_dir)
Ejemplo n.º 5
0
def sensu_check(service, service_path):
    """Check whether monitoring.yaml exists in service directory,
    and that the team name is declared.

    :param service: name of service currently being examined
    :param service_path: path to loction of monitoring.yaml file"""
    if is_file_in_dir('monitoring.yaml', service_path):
        print PaastaCheckMessages.SENSU_MONITORING_FOUND
        team = get_team(service=service, overrides={})
        if team is None:
            print PaastaCheckMessages.SENSU_TEAM_MISSING
        else:
            print PaastaCheckMessages.sensu_team_found(team)
    else:
        print PaastaCheckMessages.SENSU_MONITORING_MISSING
Ejemplo n.º 6
0
Archivo: check.py Proyecto: seco/paasta
def sensu_check(service, service_path, soa_dir):
    """Check whether monitoring.yaml exists in service directory,
    and that the team name is declared.

    :param service: name of service currently being examined
    :param service_path: path to loction of monitoring.yaml file"""
    if is_file_in_dir('monitoring.yaml', service_path):
        print PaastaCheckMessages.SENSU_MONITORING_FOUND
        team = get_team(service=service, overrides={}, soa_dir=soa_dir)
        if team is None:
            print PaastaCheckMessages.SENSU_TEAM_MISSING
        else:
            print PaastaCheckMessages.sensu_team_found(team)
    else:
        print PaastaCheckMessages.SENSU_MONITORING_MISSING
Ejemplo n.º 7
0
def smartstack_check(service, service_path, soa_dir):
    """Check whether smartstack.yaml exists in service directory, and the proxy
    ports are declared.  Print appropriate message depending on outcome.

    :param service: name of service currently being examined
    :param service_path: path to loction of smartstack.yaml file"""
    if is_file_in_dir('smartstack.yaml', service_path):
        paasta_print(PaastaCheckMessages.SMARTSTACK_YAML_FOUND)
        instances = get_all_namespaces_for_service(service=service,
                                                   soa_dir=soa_dir)
        if len(instances) > 0:
            for namespace, config in get_all_namespaces_for_service(
                    service=service,
                    soa_dir=soa_dir,
                    full_name=False,
            ):
                if 'proxy_port' in config:
                    paasta_print(
                        PaastaCheckMessages.smartstack_port_found(
                            namespace,
                            config.get('proxy_port'),
                        ))
                else:
                    paasta_print(PaastaCheckMessages.SMARTSTACK_PORT_MISSING)
        else:
            paasta_print(PaastaCheckMessages.SMARTSTACK_PORT_MISSING)
Ejemplo n.º 8
0
def test_check_smartstack_check_pass(
        mock_is_file_in_dir, mock_read_service_info, capfd,
):
    # smartstack.yaml exists and port is found

    mock_is_file_in_dir.return_value = True
    port = 80
    instance = 'main'
    smartstack_dict = {
        'smartstack': {
            instance: {
                'proxy_port': port,
            },
        },
    }
    mock_read_service_info.return_value = smartstack_dict
    expected_output = "%s\n%s\n" \
                      % (
                          PaastaCheckMessages.SMARTSTACK_YAML_FOUND,
                          PaastaCheckMessages.smartstack_port_found(
                              instance, port,
                          ),
                      )

    smartstack_check(service='fake_service', service_path='path', soa_dir='path')

    output, _ = capfd.readouterr()
    assert output == expected_output
Ejemplo n.º 9
0
def git_repo_check(service, soa_dir):
    git_url = get_git_url(service, soa_dir)
    cmd = "git ls-remote %s" % git_url
    returncode, _ = _run(cmd, timeout=5)
    if returncode == 0:
        print(PaastaCheckMessages.GIT_REPO_FOUND)
    else:
        print(PaastaCheckMessages.git_repo_missing(git_url))
Ejemplo n.º 10
0
def test_check_service_dir_check_pass(mock_stdout, mock_validate_service_name):
    mock_validate_service_name.return_value = None
    service = 'fake_service'
    expected_output = \
        "%s\n" % PaastaCheckMessages.service_dir_found(service)
    service_dir_check(service)
    output = mock_stdout.getvalue()

    assert output == expected_output
Ejemplo n.º 11
0
def test_check_service_dir_check_fail(mock_stdout, mock_validate_service_name):
    service = 'fake_service'
    mock_validate_service_name.side_effect = NoSuchService(service)
    expected_output = "%s\n" \
                      % PaastaCheckMessages.service_dir_missing(service)
    service_dir_check(service)
    output = mock_stdout.getvalue()

    assert output == expected_output
Ejemplo n.º 12
0
def test_check_service_dir_check_fail(mock_stdout, mock_validate_service_name):
    service = 'fake_service'
    mock_validate_service_name.side_effect = NoSuchService(service)
    expected_output = "%s\n" \
                      % PaastaCheckMessages.service_dir_missing(service)
    service_dir_check(service)
    output = mock_stdout.getvalue()

    assert output == expected_output
Ejemplo n.º 13
0
def test_check_service_dir_check_pass(mock_stdout, mock_validate_service_name):
    mock_validate_service_name.return_value = None
    service = 'fake_service'
    expected_output = \
        "%s\n" % PaastaCheckMessages.service_dir_found(service)
    service_dir_check(service)
    output = mock_stdout.getvalue()

    assert output == expected_output
Ejemplo n.º 14
0
def test_check_service_dir_check_pass(mock_validate_service_name, capfd):
    mock_validate_service_name.return_value = None
    service = "fake_service"
    soa_dir = "/fake_yelpsoa_configs"
    expected_output = "%s\n" % PaastaCheckMessages.service_dir_found(service, soa_dir)
    service_dir_check(service, soa_dir)

    output, _ = capfd.readouterr()
    assert output == expected_output
Ejemplo n.º 15
0
def test_check_service_dir_check_fail(mock_validate_service_name, capfd):
    service = "fake_service"
    soa_dir = "/fake_yelpsoa_configs"
    mock_validate_service_name.side_effect = NoSuchService(service)
    expected_output = "%s\n" % PaastaCheckMessages.service_dir_missing(service, soa_dir)
    service_dir_check(service, soa_dir)

    output, _ = capfd.readouterr()
    assert output == expected_output
Ejemplo n.º 16
0
def smartstack_check(service, service_path):
    """Check whether smartstack.yaml exists in service directory, and the proxy
    ports are declared.  Print appropriate message depending on outcome.

    :param service: name of service currently being examined
    :param service_path: path to loction of smartstack.yaml file"""
    if is_file_in_dir('smartstack.yaml', service_path):
        print PaastaCheckMessages.SMARTSTACK_YAML_FOUND
        instances = get_all_namespaces_for_service(service)
        if len(instances) > 0:
            for namespace, config in get_all_namespaces_for_service(service, full_name=False):
                if 'proxy_port' in config:
                    print PaastaCheckMessages.smartstack_port_found(
                        namespace, config.get('proxy_port'))
                else:
                    print PaastaCheckMessages.SMARTSTACK_PORT_MISSING
        else:
            print PaastaCheckMessages.SMARTSTACK_PORT_MISSING
Ejemplo n.º 17
0
def test_check_service_dir_check_fail(mock_stdout, mock_validate_service_name):
    service = 'fake_service'
    soa_dir = '/fake_yelpsoa_configs'
    mock_validate_service_name.side_effect = NoSuchService(service)
    expected_output = "%s\n" \
                      % PaastaCheckMessages.service_dir_missing(service, soa_dir)
    service_dir_check(service, soa_dir)
    output = mock_stdout.getvalue().decode('utf-8')

    assert output == expected_output
Ejemplo n.º 18
0
def test_check_service_dir_check_pass(mock_stdout, mock_validate_service_name):
    mock_validate_service_name.return_value = None
    service = 'fake_service'
    soa_dir = '/fake_yelpsoa_configs'
    expected_output = \
        "%s\n" % PaastaCheckMessages.service_dir_found(service, soa_dir)
    service_dir_check(service, soa_dir)
    output = mock_stdout.getvalue().decode('utf-8')

    assert output == expected_output
Ejemplo n.º 19
0
def test_check_sensu_check_pass(mock_stdout, mock_get_team,
                                mock_is_file_in_dir):
    # monitoring.yaml exists and team is found

    mock_is_file_in_dir.return_value = "/fake/path"
    team = 'team-service-infra'
    mock_get_team.return_value = team
    expected_output = "%s\n%s\n" % (PaastaCheckMessages.SENSU_MONITORING_FOUND,
                                    PaastaCheckMessages.sensu_team_found(team))

    sensu_check('fake_service', 'path')
    output = mock_stdout.getvalue()

    assert output == expected_output
    mock_get_team.assert_called_once_with(service='fake_service', overrides={})
Ejemplo n.º 20
0
def test_check_sensu_check_pass(mock_stdout, mock_get_team,
                                mock_is_file_in_dir):
    # monitoring.yaml exists and team is found

    mock_is_file_in_dir.return_value = "/fake/path"
    team = 'team-service-infra'
    mock_get_team.return_value = team
    expected_output = "%s\n%s\n" % (PaastaCheckMessages.SENSU_MONITORING_FOUND,
                                    PaastaCheckMessages.sensu_team_found(team))

    sensu_check('fake_service', 'path')
    output = mock_stdout.getvalue()

    assert output == expected_output
    mock_get_team.assert_called_once_with(service='fake_service', overrides={})
Ejemplo n.º 21
0
def test_check_sensu_check_pass(mock_get_team, mock_is_file_in_dir, capfd):
    # monitoring.yaml exists and team is found

    mock_is_file_in_dir.return_value = "/fake/path"
    team = "team-service-infra"
    mock_get_team.return_value = team
    expected_output = "{}\n{}\n".format(
        PaastaCheckMessages.SENSU_MONITORING_FOUND,
        PaastaCheckMessages.sensu_team_found(team),
    )

    sensu_check(service="fake_service", service_path="path", soa_dir="path")

    output, _ = capfd.readouterr()
    assert output == expected_output
    mock_get_team.assert_called_once_with(service="fake_service",
                                          overrides={},
                                          soa_dir="path")
Ejemplo n.º 22
0
def test_check_smartstack_check_pass(mock_stdout, mock_is_file_in_dir,
                                     mock_read_service_info):
    # smartstack.yaml exists and port is found

    mock_is_file_in_dir.return_value = True
    port = 80
    instance = 'main'
    smartstack_dict = {'smartstack': {instance: {'proxy_port': port}}}
    mock_read_service_info.return_value = smartstack_dict
    expected_output = "%s\n%s\n" \
                      % (PaastaCheckMessages.SMARTSTACK_YAML_FOUND,
                         PaastaCheckMessages.smartstack_port_found(
                             instance, port))

    smartstack_check('fake_service', 'path')
    output = mock_stdout.getvalue()

    assert output == expected_output
Ejemplo n.º 23
0
def test_check_smartstack_check_pass(
    mock_is_file_in_dir, mock_read_service_info, capfd
):
    # smartstack.yaml exists and port is found

    mock_is_file_in_dir.return_value = True
    port = 80
    instance = "main"
    smartstack_dict = {"smartstack": {instance: {"proxy_port": port}}}
    mock_read_service_info.return_value = smartstack_dict
    expected_output = "{}\n{}\n".format(
        PaastaCheckMessages.SMARTSTACK_YAML_FOUND,
        PaastaCheckMessages.smartstack_port_found(instance, port),
    )

    smartstack_check(service="fake_service", service_path="path", soa_dir="path")

    output, _ = capfd.readouterr()
    assert output == expected_output
Ejemplo n.º 24
0
def test_check_smartstack_check_pass(mock_stdout, mock_is_file_in_dir,
                                     mock_read_service_info):
    # smartstack.yaml exists and port is found

    mock_is_file_in_dir.return_value = True
    port = 80
    instance = 'main'
    smartstack_dict = {
        'smartstack': {
            instance: {
                'proxy_port': port
            }
        }
    }
    mock_read_service_info.return_value = smartstack_dict
    expected_output = "%s\n%s\n" \
                      % (PaastaCheckMessages.SMARTSTACK_YAML_FOUND,
                         PaastaCheckMessages.smartstack_port_found(
                             instance, port))

    smartstack_check('fake_service', 'path')
    output = mock_stdout.getvalue()

    assert output == expected_output