本文整理匯總了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, [])