Exemplo n.º 1
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)
Exemplo 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)
Exemplo n.º 3
0
def service_dir_check(service):
    """Check whether directory service exists in /nail/etc/services
    :param service: string of service name we wish to inspect
    """
    try:
        validate_service_name(service)
        print PaastaCheckMessages.service_dir_found(service)
    except NoSuchService:
        print PaastaCheckMessages.service_dir_missing(service)
Exemplo n.º 4
0
def service_dir_check(service):
    """Check whether directory service exists in /nail/etc/services
    :param service: string of service name we wish to inspect
    """
    try:
        validate_service_name(service)
        print PaastaCheckMessages.service_dir_found(service)
    except NoSuchService:
        print PaastaCheckMessages.service_dir_missing(service)
Exemplo 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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
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={})
Exemplo n.º 14
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={})
Exemplo n.º 15
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
Exemplo n.º 16
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