1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-06 22:32:54 +02:00

add test for older netstat version fix

This commit is contained in:
Kelly Brazil
2021-11-15 12:52:43 -08:00
parent 83371edd8f
commit 20830528f0
4 changed files with 28 additions and 0 deletions

View File

@ -2,6 +2,7 @@ jc changelog
20211104 v1.17.2 (in progress) 20211104 v1.17.2 (in progress)
- Fix ping parser to add Alpine linux support - Fix ping parser to add Alpine linux support
- Fix netstat parser for older versions of netstat on linux
20211030 v1.17.1 20211030 v1.17.1
- Fix file parser for gzip files - Fix file parser for gzip files

View File

@ -0,0 +1 @@
[{"proto":"tcp","recv_q":0,"send_q":0,"local_address":"0.0.0.0","foreign_address":"0.0.0.0","state":"LISTEN","program_name":"systemd","kind":"network","pid":1,"local_port":"111","foreign_port":"*","transport_protocol":"tcp","network_protocol":"ipv4","local_port_num":111},{"proto":"udp","recv_q":0,"send_q":0,"local_address":"200.4.30.128","foreign_address":"0.0.0.0","state":null,"program_name":"NetworkManager","kind":"network","pid":903,"local_port":"68","foreign_port":"*","transport_protocol":"udp","network_protocol":"ipv4","local_port_num":68},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":18438,"program_name":"systemd","path":"/run/lvm/lvmpolld.socket","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":null,"type":"DGRAM","state":null,"inode":23569,"program_name":"chronyd","path":"/var/run/chrony/chronyd.sock","kind":"socket","pid":871},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":23584,"program_name":"gssproxy","path":"/run/gssproxy.sock","kind":"socket","pid":872},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":18511,"program_name":"systemd","path":"/run/rpcbind.sock","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":"ACC","type":"SEQPACKET","state":"LISTENING","inode":18521,"program_name":"systemd","path":"/run/udev/control","kind":"socket","pid":1},{"proto":"unix","refcnt":3,"flags":null,"type":"DGRAM","state":null,"inode":11098,"program_name":"systemd","path":"/run/systemd/notify","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":null,"type":"DGRAM","state":null,"inode":11100,"program_name":"systemd","path":"/run/systemd/cgroups-agent","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":24236,"program_name":"sssd","path":"/var/lib/sss/pipes/private/sbus-monitor","kind":"socket","pid":863}]

14
tests/fixtures/generic/netstat-old.out vendored Normal file
View File

@ -0,0 +1,14 @@
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
udp 0 0 200.4.30.128:68 0.0.0.0:* 903/NetworkManager
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 18438 1/systemd /run/lvm/lvmpolld.socket
unix 2 [ ] DGRAM 23569 871/chronyd /var/run/chrony/chronyd.sock
unix 2 [ ACC ] STREAM LISTENING 23584 872/gssproxy /run/gssproxy.sock
unix 2 [ ACC ] STREAM LISTENING 18511 1/systemd /run/rpcbind.sock
unix 2 [ ACC ] SEQPACKET LISTENING 18521 1/systemd /run/udev/control
unix 3 [ ] DGRAM 11098 1/systemd /run/systemd/notify
unix 2 [ ] DGRAM 11100 1/systemd /run/systemd/cgroups-agent
unix 2 [ ACC ] STREAM LISTENING 24236 863/sssd /var/lib/sss/pipes/private/sbus-monitor

View File

@ -74,6 +74,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-aT.out'), 'r', encoding='utf-8') as f: with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-aT.out'), 'r', encoding='utf-8') as f:
self.freebsd12_netstat_aT = f.read() self.freebsd12_netstat_aT = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-old.out'), 'r', encoding='utf-8') as f:
self.generic_netstat_old = f.read()
# netstat -r # netstat -r
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.out'), 'r', encoding='utf-8') as f: with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_r = f.read() self.centos_7_7_netstat_r = f.read()
@ -183,6 +186,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-an.json'), 'r', encoding='utf-8') as f: with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-an.json'), 'r', encoding='utf-8') as f:
self.freebsd12_netstat_an_json = json.loads(f.read()) self.freebsd12_netstat_an_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-old.json'), 'r', encoding='utf-8') as f:
self.generic_netstat_old_json = json.loads(f.read())
# netsat -r # netsat -r
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.json'), 'r', encoding='utf-8') as f: with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_netstat_r_json = json.loads(f.read()) self.centos_7_7_netstat_r_json = json.loads(f.read())
@ -353,6 +359,12 @@ class MyTests(unittest.TestCase):
""" """
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_an, quiet=True), self.freebsd12_netstat_an_json) self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_an, quiet=True), self.freebsd12_netstat_an_json)
def test_netstat_old_generic(self):
"""
Test 'netstat' with older version of netstat on linux
"""
self.assertEqual(jc.parsers.netstat.parse(self.generic_netstat_old, quiet=True), self.generic_netstat_old_json)
def test_netstat_r_centos_7_7(self): def test_netstat_r_centos_7_7(self):
""" """
Test 'netstat -r' on Centos 7.7 Test 'netstat -r' on Centos 7.7