Example #1
0
def test_result_2():
    """check push result with compression

    """

    global app
    global conf
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    aJobs = [{"id": 1, "job": "health", "freq": 10, "version": 1, "data": {}}]

    uid = insertOneHost("p1", "test_res", aJobs, "127.2.0.1", ":2:1")

    d = {}

    d['timestamp'] = time.time()
    d['probeuid'] = "aa"
    d['probename'] = "test_res"
    d['date'] = time.time()
    rv = c.post("/results",
                data=dict(uid=uid,
                          compressed="yes",
                          data=b64encode(zlib.compress(json.dumps([d])))))

    j = json.loads(rv.data)
    print j
    if j['answer'] != 'OK':
        assert False, "action error"
Example #2
0
def test_getHostContent():
    """ getHostContentByUid

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid' : _id, "a":1, "b":2})

    _sHost = lDB.getHostContentByUid(1)

    if _sHost['b'] != 2:
        assert False, "should return 2 as content of the b part"

    # check unknown id for coverage
    _sHost = lDB.getHostContentByUid(10)

    if _sHost != None:
        assert False, "show not found the host"

    lDB.cleanDB()
Example #3
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 #4
0
def test_getJobName():
    """ getJobsForHost + getNameForHost

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")
    lDB.updateHost(
        "test", {
            'uid': _id,
            "ipv4": 1,
            "ipv6": 2,
            "name": "test",
            "last": time.time(),
            "version": "1.1.2"
        })

    _sJob = lDB.getJobsForHost(1)
    _sName = lDB.getNameForHost(1)

    _sList = lDB.getListProbes()

    lDB.cleanDB()
Example #5
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 #6
0
def test_result_2():
    """check push result with compression

    """

    global app
    global conf
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p1", "test_res", aJobs, "127.2.0.1", ":2:1")

    d = {}

    d['timestamp'] = time.time()
    d['probeuid'] = "aa"
    d['probename'] = "test_res"
    d['date'] = time.time()
    rv = c.post("/results", data=dict(uid=uid, compressed="yes", data=b64encode(zlib.compress(json.dumps([d])))))

    j = json.loads(rv.data)
    print j
    if j['answer'] != 'OK':
        assert False, "action error"
Example #7
0
def test_template_empty():
    """ try to create an empty template configuration
    """
    global app
    global lDB
    lDB.cleanDB()

    dConf = {
        "template": [],
        "output": [{
            "engine": "debug",
            "parameters": [],
            "active": "False"
        }],
        "probe": [{
            "id": "temp01",
            "probename": "temp01",
            "template": ["T01"]
        }]
    }

    sConf = string.replace(str(dConf), "'", '"')

    try:
        f = file("test_config.conf", 'w')
    except IOError:
        logging.error("accessing config file {}".format(sFile))
        return False

    f.write(sConf)
    f.close()

    global conf
    conf.loadFile('test_config.conf')
Example #8
0
def test_result_badprobe():
    """check push result bad probe

    """

    global app
    global conf
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p1", "test_res", aJobs, "127.2.0.1", ":2:1")

    # without data
    rv = c.post("/results", data=dict(uid=uid+1, data=''))

    j = json.loads(rv.data)
    print j
    if j['answer'] != 'KO':
        assert False, "action error"
Example #9
0
def test_result_nob64():
    """check push result wo base64 data

    """

    global app
    global conf
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p1", "test_res", aJobs, "127.2.0.1", ":2:1")

    # without base64
    d = {}
    rv = c.post("/results", data=dict(uid=uid, data=json.dumps(d)))

    j = json.loads(rv.data)
    if j['answer'] != 'KO':
        assert False, "action error"
Example #10
0
def test_upgrade_6():
    """upgrade with unknown probe

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()

    insertConf()

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p6", "test_up6", aJobs, "127.2.0.6", ":2:6", "0.6.6")

    rv = c.post("/upgrade", data=dict(uid=123))

    j = json.loads(rv.data)
    if rv.status_code != 404 and j['reason'] != "probe not found":
        assert False, "probe not found"
Example #11
0
def test_upgrade_4():
    """upgrade fw version with pprod 0.6.2 -> 0.6.3

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()

    insertConf()

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p4", "test_up4", aJobs, "127.2.0.4", ":2:4", "0.6.2", "preprod")

    rv = c.post("/upgrade", data=dict(uid=uid))

    s = rv.data
    s = s.strip()

    if s != '0.6.3':
        assert False, "bad version downloaded"
Example #12
0
def test_upgrade_5():
    """upgrade fw version with not found

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()

    insertConf()

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p5", "test_up5", aJobs, "127.2.0.5", ":2:5", "0.6.1", "not_found")

    rv = c.post("/upgrade", data=dict(uid=uid))

    if rv.status_code != 404:
        assert False, "file not found {}".format(rv.status_code)
Example #13
0
def test_getHostVersion():
    """ getHostVersionByUid

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid': _id, "a": 1, "b": 2})

    _sVersion = lDB.getHostVersionByUid(1)
    if _sVersion != None:
        assert False, "host has no version"

    lDB.updateHost("test", {'uid': _id, "a": 1, "b": 2, "version": "1.1.2"})
    _sVersion = lDB.getHostVersionByUid(1)
    if _sVersion != "1.1.2":
        assert False, "wrong version"

    _sVersion = lDB.getHostVersionByUid(2)
    if _sVersion != None:
        assert False, "host not found"

    lDB.cleanDB()
Example #14
0
def test_upgrade_3():
    """upgrade fw version with prod 0.6.2 -> 0.6.2

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()

    insertConf()

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p3", "test_up3", aJobs, "127.2.0.3", ":2:3", "0.6.2", "prod")

    rv = c.post("/upgrade", data=dict(uid=uid))

    j = json.loads(rv.data)
    if rv.status_code != 201 and j['reason'] != "no need for upgrade":
        assert False, "no need for upgrade"
Example #15
0
def test_upgrade_4():
    """upgrade fw version with pprod 0.6.2 -> 0.6.3

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()

    insertConf()

    c = app.test_client()

    aJobs = [{"id": 1, "job": "health", "freq": 10, "version": 1, "data": {}}]

    uid = insertOneHost("p4", "test_up4", aJobs, "127.2.0.4", ":2:4", "0.6.2",
                        "preprod")

    rv = c.post("/upgrade", data=dict(uid=uid))

    s = rv.data
    s = s.strip()

    if s != '0.6.3':
        assert False, "bad version downloaded"
Example #16
0
def test_getHostVersion():
    """ getHostVersionByUid

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid' : _id, "a":1, "b":2})

    _sVersion = lDB.getHostVersionByUid(1)
    if _sVersion != None:
        assert False, "host has no version"

    lDB.updateHost("test", {'uid' : _id, "a":1, "b":2, "version": "1.1.2"})    
    _sVersion = lDB.getHostVersionByUid(1)
    if _sVersion != "1.1.2":
        assert False, "wrong version"

    _sVersion = lDB.getHostVersionByUid(2)
    if _sVersion != None:
        assert False, "host not found"

    lDB.cleanDB()
Example #17
0
def test_noprobe():
    """ no probe in the configuration
    """
    global app
    global lDB
    lDB.cleanDB()

    dConf = {}

    sConf = string.replace(str(dConf), "'", '"')

    try:
        f = file("test_config.conf", 'w')
    except IOError:
        logging.error("accessing config file {}".format(sFile))
        return False

    f.write(sConf)
    f.close()

    global conf

    try:
        conf.loadFile('test_config.conf')
    except:
        return

    assert False, "test for no probe"
Example #18
0
def test_getHostContent():
    """ getHostContentByUid

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid': _id, "a": 1, "b": 2})

    _sHost = lDB.getHostContentByUid(1)

    if _sHost['b'] != 2:
        assert False, "should return 2 as content of the b part"

    # check unknown id for coverage
    _sHost = lDB.getHostContentByUid(10)

    if _sHost != None:
        assert False, "show not found the host"

    lDB.cleanDB()
def test_restart():
    """check restart 

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()
    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p1", "test_push1", aJobs, "127.2.0.1", ":2:1")

    rv = c.post("/pushAction", data=dict(uid=uid, action="restart"))

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

    # check restart job without job specification
    rv = c.post("/pushAction", data=dict(uid=uid, action="restart", module="job"))

    j = json.loads(rv.data)
    if j['answer'] != 'KO':
        assert False, "action error"
def test_push_2():
    """check action ws : restart all

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

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p2", "test_push2", aJobs, "127.2.0.2", ":2:2")

    rv = c.post("/pushAction", data=dict(uid=uid, action="restart", module="all"))

    j = json.loads(rv.data)
    if j['answer'] != 'OK':
        assert False, "action error {}".format(j)

    # ping the server and check the return
    rv = c.post("/ping", data=dict(uid=uid, hostId="p2"))

    j = json.loads(rv.data)

    if j['answer'] != "OK":
        assert False, "ping known host"
    a = j['action']
    if a['name'] != "restart" or type(a['args']) != dict:
        assert False, "action not in ping reply"
Example #21
0
def test_404():
    """get 404"""
    global app
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    # get /unknown
    rv = c.get("/unknown")
    if rv.status_code != 404:
        assert False, "404 expected"
Example #22
0
def test_404():
    """get 404"""
    global app
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    # get /unknown
    rv = c.get("/unknown")
    if rv.status_code != 404:
        assert False, "404 expected"
Example #23
0
def test_main():
    """get /"""
    global app
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    # get /
    rv = c.get("/")
    j = json.loads(rv.data)
    if j['status'] != "OK":
        assert False, "get / failed"
Example #24
0
def test_main():
    """get /"""
    global app
    global lDB
    lDB.cleanDB()

    c = app.test_client()

    # get /
    rv = c.get("/")
    j = json.loads(rv.data)
    if j['status'] != "OK":
        assert False, "get / failed"
Example #25
0
def test_getConfig():
    """ getConfigForHost

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    _sConf = lDB.getConfigForHost(1)

    lDB.cleanDB()
Example #26
0
def test_getConfig():
    """ getConfigForHost

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    _sConf = lDB.getConfigForHost(1)

    lDB.cleanDB()
Example #27
0
def test_template_syntaxerror():
    """ check template syntax error trap
    """
    global app
    global lDB
    lDB.cleanDB()

    dConf = {
        "template": [{
            "name":
            "T01",
            "jobs": [{
                "active": "True",
                "job": "health",
                "freq": 15,
                "version": 1,
                "data": {}
            }]
        }],
        "output": [{
            "engine": "debug",
            "parameters": [],
            "active": "False"
        }],
        "probe": [{
            "id": "temp01",
            "probename": "temp01",
            "template": ["T01"]
        }]
    }

    sConf = string.replace(str(dConf), "'", '"')
    sConf = string.replace(sConf, "],", ']')

    try:
        f = file("test_config.conf", 'w')
    except IOError:
        logging.error("accessing config file {}".format(sFile))
        return False

    f.write(sConf)
    f.close()

    global conf

    try:
        conf.loadFile('test_config.conf')
    except Exception as ex:
        return

    assert False, "configuration syntax error not trapped"
Example #28
0
def test_discover_empty():
    """/discover empty

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

    c = app.test_client()
    rv = c.post("/discover", data=dict())

    j = json.loads(rv.data)
    if j['answer'] != "missing argument":
        assert False, "discover empty not detected"
Example #29
0
def test_getUniqueId():
    """ test unique id

    """
    global lDB
    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    # print lDB.dump()
    lDB.cleanDB()
Example #30
0
def test_getUniqueId():
    """ test unique id

    """
    global lDB
    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    # print lDB.dump()
    lDB.cleanDB()
Example #31
0
def test_upgrade_7():
    """configuration without current firmware

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()

    insertConf_woCurrent()

    conf.getCurrentFWVersion()
    conf.getFWVersion('prod')
    conf.getFWVersion('unknown')
Example #32
0
def test_upgrade_7():
    """configuration without current firmware

    """
    global app
    global conf
    global lDB

    lDB.cleanDB()

    insertConf_woCurrent()

    conf.getCurrentFWVersion()
    conf.getFWVersion('prod')
    conf.getFWVersion('unknown')
Example #33
0
def test_discover_get():
    """/discover GET

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

    c = app.test_client()
    rv = c.get("/discover")

    print rv.status

    if rv.status != "405 METHOD NOT ALLOWED":
        assert False, "discover GET should not be allowed"
Example #34
0
def test_discover_1():
    """/discover 127.1.0.1 not in db

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

    installConfig()

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

    j = json.loads(rv.data)
    if j['answer'] != "KO" and j['reason'] != "not found":
        assert False, "should not found this host"
Example #35
0
def test_pingHost_ukn():
    """/ping host ukn

    """
    global lDB

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

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

    j = json.loads(rv.data)
    if j['answer'] != "bad probe matching id and hostid":
        assert False, "ping known ukn id"
Example #36
0
def test_pingHost_ukn():
    """/ping host ukn

    """
    global lDB

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

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

    j = json.loads(rv.data)
    if j['answer'] != "bad probe matching id and hostid":
        assert False, "ping known ukn id"
Example #37
0
def test_template_noname():
    """ template without name
    """
    global app
    global lDB
    lDB.cleanDB()

    dConf = {
        "template": [{
            "jobs": [{
                "active": "True",
                "job": "health",
                "freq": 15,
                "version": 1,
                "data": {}
            }]
        }],
        "output": [{
            "engine": "debug",
            "parameters": [],
            "active": "False"
        }],
        "probe": [{
            "id": "temp01",
            "probename": "temp01",
            "template": ["T01"]
        }]
    }

    sConf = string.replace(str(dConf), "'", '"')

    try:
        f = file("test_config.conf", 'w')
    except IOError:
        logging.error("accessing config file {}".format(sFile))
        return False

    f.write(sConf)
    f.close()

    global conf
    try:
        conf.loadFile('test_config.conf')
    except:
        return

    assert False, "should have a name in a template section"
Example #38
0
def test_template_2loads():
    """ load twice the conf
    """
    global app
    global lDB
    lDB.cleanDB()

    dConf = {
        "template": [{
            "name":
            "T01",
            "jobs": [{
                "active": "True",
                "job": "health",
                "freq": 15,
                "version": 1,
                "data": {}
            }]
        }],
        "output": [{
            "engine": "debug",
            "parameters": [],
            "active": "True"
        }],
        "probe": [{
            "id": "temp01",
            "probename": "temp01",
            "hostname": "host",
            "template": ["T01"]
        }]
    }

    sConf = string.replace(str(dConf), "'", '"')

    try:
        f = file("test_config.conf", 'w')
    except IOError:
        logging.error("accessing config file {}".format(sFile))
        return False

    f.write(sConf)
    f.close()

    global conf
    conf.loadFile('test_config.conf')
    conf.loadFile('test_config.conf')
Example #39
0
def test_clean():
    """ cleanOldProbes

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    lDB.updateHost("test", {'uid' : _id,
                            "ipv4":1,
                            "ipv6":2,
                            "name": "test",
                            "last": 0,
                            "version": "1.1.2"})    

    lDB.cleanOldProbes()
    lDB.dump()
Example #40
0
def test_getAction():
    """ getAction

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    lDB.updateHost(
        "test", {
            'uid': _id,
            "ipv4": 1,
            "ipv6": 2,
            "name": "test",
            "last": time.time(),
            "version": "1.1.2"
        })

    lDB.getAction(1)

    lDB.updateHost(
        "test", {
            'uid': _id,
            "ipv4": 1,
            "ipv6": 2,
            "name": "test",
            "last": time.time(),
            "action": "test_action",
            "version": "1.1.2"
        })

    a = lDB.getAction("test")
    if a != "test_action":
        assert False, "should have an action"

    a = lDB.getAction("test")
    if a != None:
        assert False, "should not have an action"

    lDB.cleanDB()
Example #41
0
def test_getHost_not():
    """ getHostByUid return false on unknown host

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid' : _id})

    _sHost = lDB.getHostByUid(2)

    if _sHost != None:
        assert False, "should return None"
    lDB.cleanDB()
Example #42
0
def test_getProbes():
    """/admin/getProbes

    """
    global app
    global lDB

    # clean DB first
    lDB.cleanDB()

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

    j = json.loads(rv.data)
    if not j.__contains__('answer'):
        print(j)
        assert False, "no answer"

    if j['answer'] != "OK":
        assert False, "db should be browsable"
Example #43
0
def test_getUniqueId_2():
    """

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id : {}".format(_id)

    lDB.updateHost("test", {'uid' : _id})

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"
    lDB.cleanDB()
Example #44
0
def test_getHost():
    """ getHostByUid

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid' : _id})

    _sHost = lDB.getHostByUid(1)

    if _sHost != "test":
        assert False, "should return name of the host"
    lDB.cleanDB()
Example #45
0
def test_getHost_not():
    """ getHostByUid return false on unknown host

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid': _id})

    _sHost = lDB.getHostByUid(2)

    if _sHost != None:
        assert False, "should return None"
    lDB.cleanDB()
Example #46
0
def test_getHost():
    """ getHostByUid

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"

    lDB.updateHost("test", {'uid': _id})

    _sHost = lDB.getHostByUid(1)

    if _sHost != "test":
        assert False, "should return name of the host"
    lDB.cleanDB()
Example #47
0
def test_getUniqueId_2():
    """

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id : {}".format(_id)

    lDB.updateHost("test", {'uid': _id})

    _id = lDB.getUniqueId("test")

    if _id != 1:
        assert False, "should return 1 as first id"
    lDB.cleanDB()
Example #48
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 #49
0
def test_getJobName():
    """ getJobsForHost + getNameForHost

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")
    lDB.updateHost("test", {'uid' : _id,
                            "ipv4":1,
                            "ipv6":2,
                            "name": "test",
                            "last": time.time(),
                            "version": "1.1.2"})    

    _sJob = lDB.getJobsForHost(1)
    _sName = lDB.getNameForHost(1)

    _sList = lDB.getListProbes()

    lDB.cleanDB()
Example #50
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 #51
0
def test_clean():
    """ cleanOldProbes

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    lDB.updateHost(
        "test", {
            'uid': _id,
            "ipv4": 1,
            "ipv6": 2,
            "name": "test",
            "last": 0,
            "version": "1.1.2"
        })

    lDB.cleanOldProbes()
    lDB.dump()
def test_push_1():
    """check action ws with bad action

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

    c = app.test_client()

    aJobs = [{"id" : 1,
             "job" : "health",
             "freq" : 10,
             "version" : 1,
             "data" : {}}]

    uid = insertOneHost("p1", "test_push1", aJobs, "127.2.0.1", ":2:1")

    rv = c.post("/pushAction", data=dict(uid=uid, action="no action"))

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