Example #1
0
def insertOneHost(id, probename, jobs, ipv4, ipv6):
    """adds one host 

    """
    global app
    global conf

    conf.addHost({"id": id, "probename": probename, "jobs": jobs})

    c = app.test_client()
    rv = c.post("/discover",
                data=dict(hostId=id, ipv4=ipv4, ipv6=ipv6, version="0.0"))

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "should have found this host"

    rv = c.get("/admin/getProbes")

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "error in getProbes"

    uid = -1

    for p in j['probes']:
        if p['ipv4'] == ipv4:
            uid = p['uid']

    if uid == -1:
        assert False, "bad uid for {}".format(probename)

    return uid
Example #2
0
def test_discover_2():
    """/discover 127.1.0.2 in db

    """
    global app
    global conf
    global lDB
    lDB.cleanDB()

    installConfig()

    conf.addHost( {"id" : "x2",
                   "probename": "test_db2",
                   "jobs" : [{"id" : 1,
                              "job" : "health",
                              "freq" : 10,
                              "version" : 1,
                              "data" : {}}]})

    c = app.test_client()
    rv = c.post("/discover", data=dict(hostId="x2",ipv4="127.1.0.2",ipv6="::1",version="0.0"))

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "should have found this host"
Example #3
0
def test_discover_4():
    """/discover 127.1.0.4 in probe list with good version
    check with ws getProbes

    """
    global app
    global conf
    global lDB
    lDB.cleanDB()

    conf.addHost( {"id" : "x4",
                   "probename": "test_db4",
                   "jobs" : [{"id" : 1,
                              "job" : "health",
                              "freq" : 10,
                              "version" : 1,
                              "data" : {}}]})

    c = app.test_client()
    rv = c.post("/discover", data=dict(hostId="x4",ipv4="127.1.0.4",ipv6="::4",version="1.3"))

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "should have found this host"

    rv = c.get("/admin/getProbes")

    j = json.loads(rv.data)
    if j['answer'] != "OK" or j['probes'][0]['version'] != "1.3":
        assert False, "probe not found with good version"
Example #4
0
def test_getConf():
    """get config for a host

    """
    global conf

    conf.addHost({
        "id":
        "xx5",
        "probename":
        "test5",
        "jobs": [{
            "id": 1,
            "job": "health",
            "freq": 10,
            "version": 1,
            "data": {}
        }]
    })

    a = conf.getJobsForHost("xx5")
    if a[0]['job'] != "health":
        assert False, "bad job returned"

    if conf.getJobsForHost("xx5_ukn") != None:
        assert False, "should not return jobs"
Example #5
0
def test_probeNoName():
    """ coverage test for probe without name section

    """
    global conf

    conf.addHost({"id": "xx7", "jobs": []})
Example #6
0
def insertOneHost(id, probename, jobs, ipv4, ipv6, version="1.0", fw="prod"):
    """check action ws with bad action

    """
    global app
    global conf

    conf.addHost( {"id" : id,
                   "probename": probename,
                   "firmware": fw,
                   "jobs" : jobs} )

    c = app.test_client()
    rv = c.post("/discover", data=dict(hostId=id,ipv4=ipv4,ipv6=ipv6,version=version))

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "should have found this host"

    rv = c.get("/admin/getProbes")

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "error in getProbes"

    uid = -1

    for p in j['probes']:
        if p['ipv4'] == ipv4:
            uid = p['uid']

    if uid == -1:
        assert False, "bad uid for {}".format(probename)
    
    return uid
Example #7
0
def test_duplicateProbeId():
    """ check duplicate id in config

    """
    global conf

    conf.addHost({"id": "xx5", "probename": "test5.0", "jobs": []})

    conf.addHost({"id": "xx5.1", "probename": "test5.0", "jobs": []})
Example #8
0
def test_noConfig():
    """ coverage test for host not in config

    """
    global conf

    conf.addHost({"id": "xx8", "probename": "test8", "jobs": []})

    if conf.getConfigForHost("xx9_unknonw") != None:
        assert False, "should not have found host"
Example #9
0
def test_addHost():
    """ add host

    """
    global conf

    conf.addHost({"id": "xx1", "probename": "test1", "jobs": []})

    a = conf.dump()
    if not a.__contains__("xx1"):
        assert False, "add not working"
Example #10
0
def test_checkHost():
    """ check insertion in the db

    """
    global conf

    conf.addHost({"id": "xx3", "probename": "test3", "jobs": []})

    if not conf.checkHost("xx3"):
        assert False, "not found"

    if conf.checkHost("yy3"):
        assert False, "found"
Example #11
0
def test_duplicateProbeName():
    """ check duplicate probename in config

    """
    global conf

    conf.addHost({"id": "xx4", "probename": "test4.0", "jobs": []})

    conf.addHost({"id": "xx4", "probename": "test4.1", "jobs": []})

    name = conf.getNameForHost("xx4")

    if name != "test4.1":
        assert False, "bad probename for duplicate"
Example #12
0
def test_probename():
    """ check probename

    """
    global conf

    conf.addHost({"id": "xx2", "probename": "test2", "jobs": []})

    name = conf.getNameForHost("xx2")

    if name != "test2":
        assert False, "bad probename"

    if conf.getNameForHost("xx2_ukn") != "unknown":
        assert False, "bad probename ukn"
Example #13
0
def test_pingHost_ok():
    """/ping host ok

    """

    global conf
    conf.addHost({"id": "xx1", "probename": "test", "jobs": []})
    global lDB

    lDB.cleanDB()

    lDB.updateHost("xx1", {'uid': 1})

    global app
    c = app.test_client()
    rv = c.post("/ping", data=dict(uid="1", hostId="xx1"))

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "ping known host"
Example #14
0
def test_pingHost_ok():
    """/ping host ok

    """

    global conf
    conf.addHost( {"id" : "xx1",
                   "probename": "test",
                   "jobs" : []} )
    global lDB

    lDB.cleanDB()

    lDB.updateHost("xx1", {'uid' : 1})

    global app
    c = app.test_client()
    rv = c.post("/ping", data=dict(uid="1", hostId="xx1"))

    j = json.loads(rv.data)
    if j['answer'] != "OK":
        assert False, "ping known host"