示例#1
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
示例#2
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)
示例#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'

    with pytest.raises(OpenShiftCheckException) as excinfo:
        check.check_kibana_route()
    assert expect == excinfo.value.name
示例#4
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
示例#6
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_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)
示例#8
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_check_kibana(pods, expect_error):
    check = Kibana()
    error = check.check_kibana(pods)
    assert_error(error, expect_error)
示例#10
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
示例#11
0
def test_check_kibana():
    # should run without exception:
    Kibana().check_kibana([plain_kibana_pod])
示例#12
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()
示例#13
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()