1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add ping tests

This commit is contained in:
Kelly Brazil
2024-01-28 17:23:27 -08:00
parent 2b9b6550a7
commit afbc46076e
9 changed files with 67 additions and 4 deletions

View File

@ -1,6 +1,6 @@
jc changelog
20240125 v1.24.1
20240126 v1.24.1
- Add `kv-dup` parser for Key/Value files with duplicate keys
- TODO: Add `path-list` string parser to parse path list strings found in env variables
- Add `--slurp` functionality to wrap output from multiple lines into a single array.
@ -13,6 +13,7 @@ jc changelog
For `/proc` file magic syntax, this is a list of `/proc` filenames in order. This can help with
identifying which input matches to which output when using `--slurp` or when converting multiple
files via `/proc` file magic syntax.
- Enhance `ping` and `ping-s` parsers to support the `-I` command option
- Enhance `proc-net-tcp` parser to add opposite endian support for architectures
like the s390x
- Enhance `url` parser to add `parent`, `filename`, `stem`, and `extension` fields

View File

@ -167,7 +167,7 @@ import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.10'
version = '1.11'
description = '`ping` and `ping6` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'

View File

@ -88,7 +88,7 @@ from jc.exceptions import ParseError
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.4'
version = '1.5'
description = '`ping` and `ping6` command streaming parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'

View File

@ -0,0 +1 @@
[{"type":"reply","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"10.0.0.1","icmp_seq":1,"ttl":119,"time_ms":1.0,"duplicate":false},{"type":"reply","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"10.0.0.1","icmp_seq":2,"ttl":119,"time_ms":1.0,"duplicate":false},{"type":"reply","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"10.0.0.1","icmp_seq":3,"ttl":119,"time_ms":1.0,"duplicate":false},{"type":"summary","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"packets_transmitted":3,"packets_received":3,"packet_loss_percent":0.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":2000.0,"round_trip_ms_min":1.0,"round_trip_ms_avg":1.0,"round_trip_ms_max":1.0,"round_trip_ms_stddev":1.0}]

View File

@ -0,0 +1 @@
[{"type":"reply","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"10.0.0.1","icmp_seq":1,"ttl":119,"time_ms":1.0,"duplicate":false},{"type":"reply","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"10.0.0.1","icmp_seq":2,"ttl":119,"time_ms":1.0,"duplicate":false},{"type":"reply","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"10.0.0.1","icmp_seq":3,"ttl":119,"time_ms":1.0,"duplicate":false},{"type":"summary","destination_ip":"10.0.0.1","sent_bytes":56,"pattern":null,"packets_transmitted":3,"packets_received":3,"packet_loss_percent":0.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":2000.0,"round_trip_ms_min":1.0,"round_trip_ms_avg":1.0,"round_trip_ms_max":1.0,"round_trip_ms_stddev":1.0}]

View File

@ -0,0 +1 @@
[{"type":"reply","destination_ip":"2001:0db8::1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"2001:0db8::1","icmp_seq":1,"ttl":114,"time_ms":15.7,"duplicate":false},{"type":"reply","destination_ip":"2001:0db8::1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"2001:0db8::1","icmp_seq":2,"ttl":114,"time_ms":11.3,"duplicate":false},{"type":"summary","destination_ip":"2001:0db8::1","sent_bytes":56,"pattern":null,"packets_transmitted":2,"packets_received":2,"packet_loss_percent":0.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":1001.0,"round_trip_ms_min":11.314,"round_trip_ms_avg":13.495,"round_trip_ms_max":15.676,"round_trip_ms_stddev":2.181}]

View File

@ -0,0 +1 @@
[{"type":"reply","destination_ip":"2001:0db8::1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"2001:0db8::1","icmp_seq":1,"ttl":114,"time_ms":13.4,"duplicate":false},{"type":"reply","destination_ip":"2001:0db8::1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"2001:0db8::1","icmp_seq":2,"ttl":114,"time_ms":11.0,"duplicate":false},{"type":"reply","destination_ip":"2001:0db8::1","sent_bytes":56,"pattern":null,"timestamp":null,"response_bytes":64,"response_ip":"2001:0db8::1","icmp_seq":2,"ttl":114,"time_ms":11.0,"duplicate":false},{"type":"summary","destination_ip":"2001:0db8::1","sent_bytes":56,"pattern":null,"packets_transmitted":2,"packets_received":2,"packet_loss_percent":0.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":1002.0,"round_trip_ms_min":11.021,"round_trip_ms_avg":12.204,"round_trip_ms_max":13.388,"round_trip_ms_stddev":1.183}]

View File

@ -84,12 +84,16 @@ class MyTests(unittest.TestCase):
# ubuntu 22.4
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-dest-unreachable.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_dest_unreachable = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-ip-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_ip_source_ip = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-hostname-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_hostname_source_ip = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-ip-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_ip_source_ip = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-hostname-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_hostname_source_ip = f.read()
@ -300,12 +304,16 @@ class MyTests(unittest.TestCase):
# ubuntu 22.4
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-dest-unreachable.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_dest_unreachable_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-ip-source-ip.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_ip_source_ip_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-hostname-source-ip.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_hostname_source_ip_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-ip-source-ip.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_ip_source_ip_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-hostname-source-ip.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_hostname_source_ip_json = json.loads(f.read())

View File

@ -90,6 +90,18 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-dest-unreachable.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_dest_unreachable = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-ip-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_ip_source_ip = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-hostname-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_hostname_source_ip = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-ip-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_ip_source_ip = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-hostname-source-ip.out'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_hostname_source_ip = f.read()
# fedora
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/ping-ip-O.out'), 'r', encoding='utf-8') as f:
fedora32_ping_ip_O = f.read()
@ -288,6 +300,18 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-dest-unreachable-streaming.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_dest_unreachable_streaming_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-hostname-source-ip-streaming.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_hostname_I_streaming_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping-ip-source-ip-streaming.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping_ip_I_streaming_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-ip-source-ip-streaming.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_ip_I_streaming_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-22.04/ping6-hostname-source-ip-streaming.json'), 'r', encoding='utf-8') as f:
ubuntu_22_4_ping6_hostname_I_streaming_json = json.loads(f.read())
# fedora
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/ping-ip-O-streaming.json'), 'r', encoding='utf-8') as f:
fedora32_ping_ip_O_streaming_json = json.loads(f.read())
@ -569,12 +593,38 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(list(jc.parsers.ping_s.parse(self.ubuntu_18_4_ping6_hostname_O_D_p_s.splitlines(), quiet=True)), self.ubuntu_18_4_ping6_hostname_O_D_p_s_streaming_json)
def test_ping_dest_unreachable_ubuntu_22_4(self):
def test_ping_s_dest_unreachable_ubuntu_22_4(self):
"""
Test 'ping' on Ubuntu 22.4 with destination unreachable message
"""
self.assertEqual(list(jc.parsers.ping_s.parse(self.ubuntu_22_4_ping_dest_unreachable.splitlines(), quiet=True)), [self.ubuntu_22_4_ping_dest_unreachable_streaming_json])
def test_ping_s_hostname_I_ubuntu_22_4(self):
"""
Test 'ping <hostname> -I' on ubuntu 22.04
"""
self.assertEqual(list(jc.parsers.ping_s.parse(self.ubuntu_22_4_ping_hostname_source_ip.splitlines(), quiet=True)), self.ubuntu_22_4_ping_hostname_I_streaming_json)
def test_ping_s_ip_I_ubuntu_22_4(self):
"""
Test 'ping <ip> -I' on ubuntu 22.04
"""
self.assertEqual(list(jc.parsers.ping_s.parse(self.ubuntu_22_4_ping_ip_source_ip.splitlines(), quiet=True)), self.ubuntu_22_4_ping_ip_I_streaming_json)
def test_ping6_s_ip_I_ubuntu_22_4(self):
"""
Test 'ping6 <ip> -I' on ubuntu 22.04
"""
self.assertEqual(list(jc.parsers.ping_s.parse(self.ubuntu_22_4_ping6_ip_source_ip.splitlines(), quiet=True)), self.ubuntu_22_4_ping6_ip_I_streaming_json)
def test_ping6_s_hostname_I_ubuntu_22_4(self):
"""
Test 'ping6 <hostname> -I' on ubuntu 22.04
"""
self.assertEqual(list(jc.parsers.ping_s.parse(self.ubuntu_22_4_ping6_hostname_source_ip.splitlines(), quiet=True)), self.ubuntu_22_4_ping6_hostname_I_streaming_json)
def test_ping_s_ip_O_fedora32(self):
"""
Test 'ping <ip> -O' on fedora32