本文整理汇总了Python中haproxy.logfile.Log.cmd_top_ips方法的典型用法代码示例。如果您正苦于以下问题:Python Log.cmd_top_ips方法的具体用法?Python Log.cmd_top_ips怎么用?Python Log.cmd_top_ips使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类haproxy.logfile.Log
的用法示例。
在下文中一共展示了Log.cmd_top_ips方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cmd_top_ips
# 需要导入模块: from haproxy.logfile import Log [as 别名]
# 或者: from haproxy.logfile.Log import cmd_top_ips [as 别名]
def test_cmd_top_ips(self):
"""Check that the top ips command reports as expected."""
log_file = Log(
logfile='haproxy/tests/files/top_ips.log',
)
top_ips = log_file.cmd_top_ips()
self.assertEqual(len(top_ips), 10)
self.assertEqual(top_ips[0], ('1.1.1.15', 6))
self.assertEqual(top_ips[1], ('1.1.1.11', 5))
# as the 3rd and 4th have the same repetitions their order is unknown
self.assertEqual(top_ips[2][1], 4)
self.assertEqual(top_ips[3][1], 4)
self.assertTrue(top_ips[2][0] in ('1.1.1.10', '1.1.1.19'))
self.assertTrue(top_ips[3][0] in ('1.1.1.10', '1.1.1.19'))
# the same as above for all the others
other_ips = [
'1.1.1.12',
'1.1.1.13',
'1.1.1.14',
'1.1.1.16',
'1.1.1.17',
'1.1.1.18',
]
for ip_info in top_ips[4:]:
self.assertEqual(ip_info[1], 2)
self.assertTrue(ip_info[0] in other_ips)
# remove the other_ips to ensure all ips are there
for position, current in enumerate(other_ips):
if current == ip_info[0]:
del other_ips[position]
break
self.assertEqual(other_ips, [])