Example #1
0
 def testSuccess(self):
     expectedDict = {'timestamp':
                     {'date': '2014-03-18',
                      'interval': '60',
                      'network': {'net-dev': [{'iface': 'wlp3s0',
                                               'rxcmp': '0.00',
                                               'rxkB': '0.00',
                                               'rxmcst': '0.00',
                                               'rxpck': '0.00',
                                               'txcmp': '0.00',
                                               'txkB': '0.00',
                                               'txpck': '0.00'},
                                              {'iface': 'lo',
                                               'rxcmp': '0.00',
                                               'rxkB': '0.00',
                                               'rxmcst': '0.00',
                                               'rxpck': '0.00',
                                               'txcmp': '0.00',
                                               'txkB': '0.00',
                                               'txpck': '0.00'},
                                              {'iface': 'virbr0-nic',
                                               'rxcmp': '0.00',
                                               'rxkB': '0.00',
                                               'rxmcst': '0.00',
                                               'rxpck': '0.00',
                                               'txcmp': '0.00',
                                               'txkB': '0.00',
                                               'txpck': '0.00'},
                                              {'iface': 'virbr0',
                                               'rxcmp': '0.00',
                                               'rxkB': '0.00',
                                               'rxmcst': '0.00',
                                               'rxpck': '0.00',
                                               'txcmp': '0.00',
                                               'txkB': '0.00',
                                               'txpck': '0.00'},
                                              {'iface': 'enp0s26u1u2',
                                               'rxcmp': '0.00',
                                               'rxkB': '0.01',
                                               'rxmcst': '0.00',
                                               'rxpck': '0.13',
                                               'txcmp': '0.00',
                                               'txkB': '0.03',
                                               'txpck': '0.25'},
                                              {'iface': 'em1',
                                               'rxcmp': '0.00',
                                               'rxkB': '0.00',
                                               'rxmcst': '0.00',
                                               'rxpck': '0.00',
                                               'txcmp': '0.00',
                                               'txkB': '0.00',
                                               'txpck': '0.00'}],
                                  'per': 'second'},
                      'time': '13:53:01',
                      'utc': '1'}}
     with open("xml2dictSuccess.xml") as f:
         out = f.read()
         tree = etree.fromstring(out)
         outDict = utils.xml2dict(tree)
     self.assertEquals(expectedDict, outDict)
def getLatestStat(root, interval=1):
    try:
        el = root.findall('host/statistics/timestamp')[-1]
    except (_etreeExceptions + (IndexError,)):
        raise SadfXmlErrorException(err=[etree.tostring(root)])

    d = utils.xml2dict(el)
    statTime = datetime.strptime("%s %s" % (d['timestamp']['date'],
                                            d['timestamp']['time']),
                                 "%Y-%m-%d %H:%M:%S")
    minutes = timedelta(minutes=interval)
    now = utcnow()
    if (now - statTime) <= minutes:
        return d['timestamp']
    else:
        return None
Example #3
0
def getLatestStat(root, interval=1):
    try:
        el = root.findall('host/statistics/timestamp')[-1]
    except (_etreeExceptions + (IndexError, )):
        raise SadfXmlErrorException(err=[etree.tostring(root)])

    d = utils.xml2dict(el)
    statTime = datetime.strptime(
        "%s %s" % (d['timestamp']['date'], d['timestamp']['time']),
        "%Y-%m-%d %H:%M:%S")
    minutes = timedelta(minutes=interval)
    now = utcnow()
    if (now - statTime) <= minutes:
        return d['timestamp']
    else:
        return None
Example #4
0
 def _xml2dict():
     utils.xml2dict("not an etree object")