1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-26 21:04:16 +02:00

add proc-net-igmp parser and tests

This commit is contained in:
Kelly Brazil
2022-09-25 15:19:43 -07:00
parent fcfbbc6d84
commit e4a40704b5
7 changed files with 470 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
[{"index":1,"device":"lo","count":1,"querier":"V3","groups":[{"address":"010000E0","users":1,"timer":"0:00000000","reporter":0}]},{"index":2,"device":"ens33","count":1,"querier":"V3","groups":[{"address":"010000E0","users":1,"timer":"0:00000000","reporter":0}]}]
+30
View File
@@ -0,0 +1,30 @@
Idx Device : Count Querier Group Users Timer Reporter
0 lo : 0 V3
010000E0 1 0:00000000 0
2 eth0 : 26 V2
260301E0 1 0:00000000 1
9B0101E0 1 0:00000000 1
439501E0 1 0:00000000 1
990101E0 1 0:00000000 1
580101E0 1 0:00000000 1
2A0301E0 1 0:00000000 1
290301E0 1 0:00000000 1
280301E0 1 0:00000000 1
9BD901E0 1 0:00000000 1
2D0301E0 1 0:00000000 1
2C0301E0 1 0:00000000 1
370301E0 1 0:00000000 1
050101E0 1 0:00000000 1
620201E0 1 0:00000000 1
040201E0 1 0:00000000 1
5F0101E0 1 0:00000000 1
520101E0 1 0:00000000 1
2BEF01E0 1 0:00000000 1
4D0101E0 1 0:00000000 1
E00C01E0 1 0:00000000 1
400301E0 1 0:00000000 1
FB0000E0 1 0:00000000 1
010000E0 1 0:00000000 0
3 eth1 : 5 V2
FB0000E0 1 0:00000000 1
010000E0 1 0:00000000 0
+1
View File
@@ -0,0 +1 @@
[{"index":0,"device":"lo","count":0,"querier":"V3","groups":[{"address":"010000E0","users":1,"timer":"0:00000000","reporter":0}]},{"index":2,"device":"eth0","count":26,"querier":"V2","groups":[{"address":"260301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"9B0101E0","users":1,"timer":"0:00000000","reporter":1},{"address":"439501E0","users":1,"timer":"0:00000000","reporter":1},{"address":"990101E0","users":1,"timer":"0:00000000","reporter":1},{"address":"580101E0","users":1,"timer":"0:00000000","reporter":1},{"address":"2A0301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"290301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"280301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"9BD901E0","users":1,"timer":"0:00000000","reporter":1},{"address":"2D0301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"2C0301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"370301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"050101E0","users":1,"timer":"0:00000000","reporter":1},{"address":"620201E0","users":1,"timer":"0:00000000","reporter":1},{"address":"040201E0","users":1,"timer":"0:00000000","reporter":1},{"address":"5F0101E0","users":1,"timer":"0:00000000","reporter":1},{"address":"520101E0","users":1,"timer":"0:00000000","reporter":1},{"address":"2BEF01E0","users":1,"timer":"0:00000000","reporter":1},{"address":"4D0101E0","users":1,"timer":"0:00000000","reporter":1},{"address":"E00C01E0","users":1,"timer":"0:00000000","reporter":1},{"address":"400301E0","users":1,"timer":"0:00000000","reporter":1},{"address":"FB0000E0","users":1,"timer":"0:00000000","reporter":1},{"address":"010000E0","users":1,"timer":"0:00000000","reporter":0}]},{"index":3,"device":"eth1","count":5,"querier":"V2","groups":[{"address":"FB0000E0","users":1,"timer":"0:00000000","reporter":1},{"address":"010000E0","users":1,"timer":"0:00000000","reporter":0}]}]
+54
View File
@@ -0,0 +1,54 @@
import os
import unittest
import json
from typing import Dict
import jc.parsers.proc_net_igmp
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
f_in: Dict = {}
f_json: Dict = {}
@classmethod
def setUpClass(cls):
fixtures = {
'proc_net_igmp': (
'fixtures/linux-proc/net_igmp',
'fixtures/linux-proc/net_igmp.json'),
'proc_net_igmp_more': (
'fixtures/linux-proc/net_igmp_more',
'fixtures/linux-proc/net_igmp_more.json')
}
for file, filepaths in fixtures.items():
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
cls.f_in[file] = a.read()
cls.f_json[file] = json.loads(b.read())
def test_proc_net_igmp_nodata(self):
"""
Test 'proc_net_igmp' with no data
"""
self.assertEqual(jc.parsers.proc_net_igmp.parse('', quiet=True), [])
def test_proc_net_igmp(self):
"""
Test '/proc/net/igmp'
"""
self.assertEqual(jc.parsers.proc_net_igmp.parse(self.f_in['proc_net_igmp'], quiet=True),
self.f_json['proc_net_igmp'])
def test_proc_net_igmp_more(self):
"""
Test '/proc/net/igmp' additional file
"""
self.assertEqual(jc.parsers.proc_net_igmp.parse(self.f_in['proc_net_igmp_more'], quiet=True),
self.f_json['proc_net_igmp_more'])
if __name__ == '__main__':
unittest.main()