当前位置: 首页>>代码示例>>Python>>正文


Python LogDB.heartbeat_report方法代码示例

本文整理汇总了Python中WMCore.Services.LogDB.LogDB.LogDB.heartbeat_report方法的典型用法代码示例。如果您正苦于以下问题:Python LogDB.heartbeat_report方法的具体用法?Python LogDB.heartbeat_report怎么用?Python LogDB.heartbeat_report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMCore.Services.LogDB.LogDB.LogDB的用法示例。


在下文中一共展示了LogDB.heartbeat_report方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LogDBTest

# 需要导入模块: from WMCore.Services.LogDB.LogDB import LogDB [as 别名]
# 或者: from WMCore.Services.LogDB.LogDB.LogDB import heartbeat_report [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(len(docs), 4) # this should result the same as above.

        docs1 = self.agent_inst.get(request, 'info')
        docs2 = self.agent_inst.get(request, 'info')
        req1 = set([r['request'] for r in docs1])
        self.assertEqual(len(req1), 1)
        req2 = set([r['request'] for r in docs2])
        self.assertEqual(len(req2), 1)
        self.assertEqual(req1, req2)

    def test_thread_name(self):
        "Test thread name support by LogDB APIs"
        request = 'abc'
        self.agent_inst2.post(request, 'msg1', 'info') # doc with different thread name
        self.agent_inst.post(request, 'msg1', 'info')
        self.agent_inst.post(request, 'msg2', 'info')
        self.agent_inst.post(request, 'msg3', 'warning')
        self.agent_inst.post(request, 'msg4', 'error')
        maindocs = self.agent_inst.get(request)
        self.assertEqual(len(maindocs), 4) # since we have two info records in agent_inst
        thr_docs = self.agent_inst2.get(request)
        self.assertEqual(len(thr_docs), 4) # number of docs in different thread
        req1 = set([r['request'] for r in maindocs])
        self.assertEqual(len(req1), 1)
        req2 = set([r['request'] for r in thr_docs])
        self.assertEqual(len(req2), 1)
        self.assertEqual(req1, req2)
        worker1 = set([r['thr'] for r in maindocs])
        self.assertEqual(worker1, set(["Test", "MainThread"]))
        worker2 = set([r['thr'] for r in thr_docs])
        self.assertEqual(worker2, set(["Test", "MainThread"]))

        docs = set([r['identifier'] for r in maindocs])
        self.assertEqual(docs, set([self.agent_inst.identifier]))
        docs = set([r['identifier'] for r in thr_docs])
        self.assertEqual(docs, set([self.agent_inst.identifier]))

    def test_checks(self):
        "Tests LogDB check/mtype functionality"
        request = 'abc'
        res = self.agent_inst.post(request, 'msg', 'ingo') # should be silent, i.o. no Exceptions
        self.assertEqual('post-error', res)
        args = (request, 'msg', 'ingo') # wrong type
        self.assertRaises(LogDBError, self.agent_inst.backend.agent_update, *args)
        args = (request, 'ingo') # wrong type
        self.assertRaises(LogDBError, self.agent_inst.backend.check, *args)
        args = ('', 'msg', 'info') # empty request string
        self.assertRaises(LogDBError, self.agent_inst.backend.agent_update, *args)
        args = ('', 'info') # empty request string
        self.assertRaises(LogDBError, self.agent_inst.backend.check, *args)

    def test_report(self):
        "Test LogDBReport APIs"
        request = 'abc'
        self.agent_inst.post(request, 'msg1', 'info')
        time.sleep(1)
        self.agent_inst.post(request, 'msg2', 'comment')
        time.sleep(1)
        self.agent_inst.post(request, 'msg3', 'warning')
        time.sleep(1)
        self.agent_inst.post(request, 'msg4', 'error')
        time.sleep(1)
        self.report.to_stdout(request)
        out = self.report.to_txt(request)
        print("\n### txt report\n", out)
        out = self.report.to_html(request)
        print("\n### html report\n", out)

        docs = self.agent_inst.get(request)
        tdocs = self.report.orderby(docs, order='ts')
        messages = [d['msg'] for d in tdocs]
        self.assertEqual(messages, ['msg4', 'msg3', 'msg2', 'msg1'])

    def test_heartbeat(self):
        "Test heartbeat_report function"
        threadName = 'MainThread'
        failThread = 'FailThread'
        self.agent_inst.post(msg="Test heartbeat", mtype="info")
        time.sleep(1)
        self.agent_inst.post(msg="Test heartbeatError", mtype="error")
        report = self.agent_inst.heartbeat_report()
        self.assertEqual(report[threadName]['type'], 'agent-error')

        report = self.agent_inst.wmstats_down_components_report([threadName])
        self.assertEqual(report['down_components'], [threadName])

        self.agent_inst.post(msg="Test heartbeat", mtype="info")
        report = self.agent_inst.wmstats_down_components_report([threadName])
        self.assertEqual(report['down_components'], [])

        report = self.agent_inst.wmstats_down_components_report([threadName, failThread])
        self.assertEqual(report['down_components'], [failThread])

        self.agent_inst.post(msg="Test heartbeatError2", mtype="error")
        report = self.agent_inst.wmstats_down_components_report([threadName])
        self.assertEqual(report['down_components'], [threadName])

        self.agent_inst.delete(mtype="error", this_thread=True)
        report = self.agent_inst.wmstats_down_components_report([threadName])
        self.assertEqual(report['down_components'], [])
开发者ID:alexanderrichards,项目名称:WMCore,代码行数:104,代码来源:LogDB_t.py


注:本文中的WMCore.Services.LogDB.LogDB.LogDB.heartbeat_report方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。