def test_check_service_results_FAIL_unknown(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_services', return_value=['FOO', 'BAR']):
        with patch('check_docker.check_swarm.get_service_info', return_value=('', 500)):
            check_swarm.perform_checks(args)
            assert check_swarm.rc == cs.UNKNOWN_RC
def test_check_service_results_FAIL_unknown(check_swarm, fs):
    fs.CreateFile(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_services', return_value=['FOO', 'BAR']):
        with patch('check_docker.check_swarm.get_service_info', return_value=('', 500)):
            check_swarm.perform_checks(args)
            assert check_swarm.rc == cs.UNKNOWN_RC
def test_check_service_called(check_swarm, services, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_url', return_value=(services, 200)):
        with patch('check_docker.check_swarm.check_service') as patched:
            check_swarm.perform_checks(args)
            assert patched.call_count == 1
def test_check_service_called(check_swarm, services, fs):
    fs.CreateFile(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_url', return_value=(services, 200)):
        with patch('check_docker.check_swarm.check_service') as patched:
            check_swarm.perform_checks(args)
            assert patched.call_count == 1
Example #5
0
def test_check_not_swarm_service(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET,
                   contents='',
                   st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing4']
    with patch('check_docker.check_swarm.get_url', return_value=('', 406)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC
Example #6
0
def test_check_swarm_results_CRITICAL(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET,
                   contents='',
                   st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--swarm']
    with patch('check_docker.check_swarm.get_swarm_status', return_value=406):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC
Example #7
0
def test_check_swarm_called(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET,
                   contents='',
                   st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--swarm']
    with patch('check_docker.check_swarm.check_swarm') as patched:
        check_swarm.perform_checks(args)
        assert patched.call_count == 1
Example #8
0
def test_check_missing_service(check_swarm, fs):
    service_info = {'Spec': {'Name': 'FOO', 'Mode': {'Global': {}}}}
    fs.create_file(check_swarm.DEFAULT_SOCKET,
                   contents='',
                   st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing3']
    with patch('check_docker.check_swarm.get_url',
               return_value=([service_info], 200)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC
Example #9
0
def test_check_service_results_OK(check_swarm, services, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET,
                   contents='',
                   st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_services',
               return_value=['FOO', 'BAR']):
        with patch('check_docker.check_swarm.get_service_info',
                   return_value=(services, 200)):
            check_swarm.perform_checks(args)
            assert check_swarm.rc == cs.OK_RC
Example #10
0
def test_check_service_called(check_swarm, fs):
    service_info = {'Spec': {'Mode': {'Replicated': {'Replicas': 1}}}}

    fs.create_file(check_swarm.DEFAULT_SOCKET,
                   contents='',
                   st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'FOO']
    with patch('check_docker.check_swarm.get_services',
               return_value=[service_info]):
        with patch('check_docker.check_swarm.check_service') as patched:
            check_swarm.perform_checks(args)
            assert patched.call_count == 1
Example #11
0
def test_check_not_swarm_service(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing4']
    with patch('check_docker.check_swarm.get_url', return_value=('', 406)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC
Example #12
0
def test_check_swarm_results_CRITICAL(check_swarm, fs):
    fs.create_file(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--swarm']
    with patch('check_docker.check_swarm.get_swarm_status', return_value=406):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC
Example #13
0
def test_check_service_results_FAIL_missing(check_swarm, services, fs):
    fs.CreateFile(check_swarm.DEFAULT_SOCKET, contents='', st_mode=(stat.S_IFSOCK | 0o666))
    args = ['--service', 'missing1']
    with patch('check_docker.check_swarm.get_url', return_value=(services, 200)):
        check_swarm.perform_checks(args)
        assert check_swarm.rc == cs.CRITICAL_RC