Beispiel #1
0
def test_verify_url_internal_failure(exec_result, expect):
    check = Kibana(execute_module=lambda *_: dict(failed=True, msg=exec_result))
    check._get_kibana_url = lambda: 'url'

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.check_kibana_route()
    assert expect == excinfo.value.name
def test_verify_url_internal_failure(exec_result, expect):
    check = Kibana(execute_module=lambda *_: dict(failed=True, msg=exec_result))
    check._get_kibana_url = lambda: 'url'

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.check_kibana_route()
    assert expect == excinfo.value.name
Beispiel #3
0
def test_verify_url_internal_failure(exec_result, expect):
    check = Kibana(
        execute_module=lambda *_: dict(failed=True, msg=exec_result))
    check._get_kibana_url = lambda: ('url', None)

    error = check._check_kibana_route()
    assert_error(error, expect)
def test_get_kibana_url_error(comment, route, expect_error):
    check = Kibana()
    check.exec_oc = lambda *_: json.dumps(route) if route else ""

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check._get_kibana_url()
    assert excinfo.value.name == expect_error
Beispiel #5
0
def test_get_kibana_url_error(comment, route, expect_error):
    check = Kibana()
    check.exec_oc = lambda *_: json.dumps(route) if route else ""

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check._get_kibana_url()
    assert excinfo.value.name == expect_error
def test_get_kibana_url(route, expect_url, expect_error):
    check = Kibana()
    check.exec_oc = lambda ns, cmd, args: json.dumps(route) if route else ""

    url, error = check._get_kibana_url()
    if expect_url:
        assert url == expect_url
    else:
        assert not url
    if expect_error:
        assert error == expect_error
    else:
        assert not error
Beispiel #7
0
def test_verify_url_external_failure(lib_result, expect, monkeypatch):

    class _http_return:

        def __init__(self, code):
            self.code = code

        def getcode(self):
            return self.code

    def urlopen(url, context):
        if type(lib_result) is int:
            return _http_return(lib_result)
        raise lib_result
    monkeypatch.setattr(request, 'urlopen', urlopen)

    check = Kibana()
    check._get_kibana_url = lambda: 'url'
    check._verify_url_internal = lambda url: None

    if not expect:
        check.check_kibana_route()
        return

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.check_kibana_route()
    assert expect == excinfo.value.name
def test_verify_url_external_failure(lib_result, expect, monkeypatch):

    class _http_return:

        def __init__(self, code):
            self.code = code

        def getcode(self):
            return self.code

    def urlopen(url, context):
        if type(lib_result) is int:
            return _http_return(lib_result)
        raise lib_result
    monkeypatch.setattr(urllib2, 'urlopen', urlopen)

    check = Kibana()
    check._get_kibana_url = lambda: 'url'
    check._verify_url_internal = lambda url: None

    if not expect:
        check.check_kibana_route()
        return

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.check_kibana_route()
    assert expect == excinfo.value.name
def test_verify_url_external_failure(lib_result, expect, monkeypatch):
    class _http_return:
        def __init__(self, code):
            self.code = code

        def getcode(self):
            return self.code

    def urlopen(url, context):
        if type(lib_result) is int:
            return _http_return(lib_result)
        raise lib_result

    monkeypatch.setattr(urllib2, 'urlopen', urlopen)

    check = Kibana()
    check._get_kibana_url = lambda: ('url', None)
    check._verify_url_internal = lambda url: None

    error = check._check_kibana_route()
    assert_error(error, expect)
Beispiel #10
0
def test_run():
    pods = ["foo"]
    ran = dict(check_kibana=False, check_route=False)

    def check_kibana(pod_list):
        ran["check_kibana"] = True
        assert pod_list == pods

    def check_kibana_route():
        ran["check_route"] = True

    check = Kibana()
    check.get_pods_for_component = lambda *_: pods
    check.check_kibana = check_kibana
    check.check_kibana_route = check_kibana_route

    check.run()
    assert ran["check_kibana"] and ran["check_route"]
def test_run():
    pods = ["foo"]
    ran = dict(check_kibana=False, check_route=False)

    def check_kibana(pod_list):
        ran["check_kibana"] = True
        assert pod_list == pods

    def check_kibana_route():
        ran["check_route"] = True

    check = Kibana()
    check.get_pods_for_component = lambda *_: pods
    check.check_kibana = check_kibana
    check.check_kibana_route = check_kibana_route

    check.run()
    assert ran["check_kibana"] and ran["check_route"]
def test_verify_url_external_skip():
    check = Kibana(lambda *_: {}, dict(openshift_check_efk_kibana_external="false"))
    check._get_kibana_url = lambda: 'url'
    check.check_kibana_route()
Beispiel #13
0
def canned_kibana(exec_oc=None):
    """Create a Kibana check object with canned exec_oc method"""
    check = Kibana()  # fails if a module is actually invoked
    if exec_oc:
        check._exec_oc = exec_oc
    return check
def test_verify_url_internal_failure(exec_result, expect):
    check = Kibana(execute_module=lambda module_name, args, task_vars: dict(failed=True, msg=exec_result))
    check._get_kibana_url = lambda task_vars: ('url', None)

    error = check._check_kibana_route({})
    assert_error(error, expect)
def canned_kibana(exec_oc=None):
    """Create a Kibana check object with canned exec_oc method"""
    check = Kibana("dummy")  # fails if a module is actually invoked
    if exec_oc:
        check._exec_oc = exec_oc
    return check
def test_check_kibana(pods, expect_error):
    check = Kibana()
    error = check.check_kibana(pods)
    assert_error(error, expect_error)
Beispiel #17
0
def test_verify_url_external_skip():
    check = Kibana(lambda *_: {}, dict(openshift_check_efk_kibana_external="false"))
    check._get_kibana_url = lambda: 'url'
    check.check_kibana_route()
Beispiel #18
0
def test_get_kibana_url(comment, route, expect_url):
    check = Kibana()
    check.exec_oc = lambda *_: json.dumps(route)
    assert expect_url == check._get_kibana_url()
def test_get_kibana_url(comment, route, expect_url):
    check = Kibana()
    check.exec_oc = lambda *_: json.dumps(route)
    assert expect_url == check._get_kibana_url()
Beispiel #20
0
def test_check_kibana():
    # should run without exception:
    Kibana().check_kibana([plain_kibana_pod])
Beispiel #21
0
def test_check_kibana_error(pods, expect_error):
    with pytest.raises(OpenShiftCheckException) as excinfo:
        Kibana().check_kibana(pods)
    assert expect_error == excinfo.value.name