Esempio n. 1
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()
Esempio n. 2
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()
Esempio n. 3
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()
Esempio n. 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()
Esempio n. 5
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()
Esempio n. 6
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()
Esempio n. 7
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()
Esempio n. 8
0
def test_getConfig():
    """ getConfigForHost

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    _sConf = lDB.getConfigForHost(1)

    lDB.cleanDB()
Esempio n. 9
0
def test_getConfig():
    """ getConfigForHost

    """
    global lDB

    lDB.cleanDB()

    _id = lDB.getUniqueId("test")

    _sConf = lDB.getConfigForHost(1)

    lDB.cleanDB()
Esempio n. 10
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()
Esempio n. 11
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()
Esempio n. 12
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()
Esempio n. 13
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()
Esempio n. 14
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()
Esempio n. 15
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()
Esempio n. 16
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()
Esempio n. 17
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()
Esempio n. 18
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()
Esempio n. 19
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()
Esempio n. 20
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()
Esempio n. 21
0
def ws_discover():
    """
    discover web service
    checks host in the configuration and returns its unique id
    """

    logging.debug("/discover")

    # global conf
    # global lDB

    if request.method == 'POST':
        if not (request.form.__contains__('hostId')
                and request.form.__contains__('ipv4')
                and request.form.__contains__('ipv6')
                and request.form.__contains__('version')):
            logging.error("probe passing bad args")
            return make_response(jsonify({"answer": "missing argument"}), 400)

        _sHostId = request.form['hostId']
        _sIpv4 = request.form['ipv4']
        _sIpv6 = request.form['ipv6']
        _sVersion = request.form['version']

        # if the probe is in the configuration db
        # update the probe db
        #

        if conf.checkHost(_sHostId):
            _id = lDB.getUniqueId(_sHostId)
            _hostConf = conf.getConfigForHost(_sHostId)

            lDB.updateHost(
                _sHostId, {
                    'uid': _id,
                    'discoverTime': time.time(),
                    'last': time.time(),
                    'ipv4': _sIpv4,
                    'ipv6': _sIpv6,
                    'version': _sVersion,
                    'name': _hostConf['probename']
                })

            # push to outputer
            data = {}

            d = {}
            d['timestamp'] = datetime.datetime.utcfromtimestamp(
                time.time()).isoformat()
            d['probe_ipv4'] = str(_sIpv4)
            d['probe_ipv6'] = str(_sIpv6)
            d['probe_version'] = str(_sVersion)
            d['probe_hostid'] = str(_sHostId)

            data['date'] = time.time()
            data['probename'] = _hostConf['probename']
            data['probeuid'] = _id
            data['name'] = str('DISCOVER')

            data['data'] = d

            for o in outputer:
                o.send(data)

            return make_response(jsonify({"answer": "OK", "uid": _id}), 200)
        else:
            logging.warning("probe not found {} {}".format(_sIpv4, _sIpv6))

            # push to outputer
            data = {}

            d = {}
            d['timestamp'] = datetime.datetime.utcfromtimestamp(
                time.time()).isoformat()
            d['probe_ipv4'] = str(_sIpv4)
            d['probe_ipv6'] = str(_sIpv6)
            d['probe_version'] = str(_sVersion)
            d['probe_hostid'] = str(_sHostId)

            data['date'] = time.time()
            data['probename'] = str('unknown')
            data['probeuid'] = int(0)
            data['name'] = str('DISCOVER')

            data['data'] = d

            for o in outputer:
                o.send(data)

            # inform probe
            return make_response(
                jsonify({
                    "answer": "KO",
                    "reason": "not found"
                }), 404)
Esempio n. 22
0
def ws_discover():
    """
    discover web service
    checks host in the configuration and returns its unique id
    """

    logging.debug("/discover")

    # global conf
    # global lDB

    if request.method == 'POST':
        if not (request.form.__contains__('hostId') and
                request.form.__contains__('ipv4') and
                request.form.__contains__('ipv6') and
                request.form.__contains__('version') ):
            logging.error("probe passing bad args")
            return make_response(jsonify({"answer" : "missing argument"}), 400)

        _sHostId = request.form['hostId']
        _sIpv4 = request.form['ipv4']
        _sIpv6 = request.form['ipv6']
        _sVersion = request.form['version']

        # if the probe is in the configuration db
        # update the probe db
        #

        if conf.checkHost(_sHostId):
            _id = lDB.getUniqueId(_sHostId)
            _hostConf = conf.getConfigForHost(_sHostId)

            lDB.updateHost(_sHostId, {'uid' : _id,
                                      'discoverTime': time.time(),
                                      'last': time.time(),
                                      'ipv4' : _sIpv4,
                                      'ipv6' : _sIpv6,
                                      'version' : _sVersion,
                                      'name': _hostConf['probename']})

            # push to outputer
            data = {}

            d = {}
            d['timestamp'] = datetime.datetime.utcfromtimestamp(time.time()).isoformat()
            d['probe_ipv4'] = str(_sIpv4)
            d['probe_ipv6'] = str(_sIpv6)
            d['probe_version'] = str(_sVersion)
            d['probe_hostid'] = str(_sHostId)

            data['date'] = time.time()
            data['probename'] = _hostConf['probename']
            data['probeuid'] = _id
            data['name'] = str('DISCOVER')

            data['data'] = d

            for o in outputer:
                o.send(data)

            return make_response(jsonify({"answer" : "OK",
                                          "uid" : _id}), 200)
        else:
            logging.warning("probe not found {} {}".format(_sIpv4, _sIpv6))

            # push to outputer
            data = {}

            d = {}
            d['timestamp'] = datetime.datetime.utcfromtimestamp(time.time()).isoformat()
            d['probe_ipv4'] = str(_sIpv4)
            d['probe_ipv6'] = str(_sIpv6)
            d['probe_version'] = str(_sVersion)
            d['probe_hostid'] = str(_sHostId)

            data['date'] = time.time()
            data['probename'] = str('unknown')
            data['probeuid'] = int(0)
            data['name'] = str('DISCOVER')

            data['data'] = d

            for o in outputer:
                o.send(data)

            # inform probe
            return make_response(jsonify({"answer" : "KO", "reason" : "not found"}), 404)