1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-23 00:29:59 +02:00

add ntpq tests

This commit is contained in:
Kelly Brazil
2020-03-10 15:17:25 -07:00
parent 2c3e9ddfe4
commit 762a886d6f
8 changed files with 133 additions and 0 deletions

1
tests/fixtures/centos-7.7/ntpq-p.json vendored Normal file
View File

@ -0,0 +1 @@
[{"selection_state": null, "remote": "44.190.6.254", "refid": "127.67.113.92", "st": 2, "t": "u", "when": 1, "poll": 64, "reach": 1, "delay": 23.399, "offset": -2.805, "jitter": 2.131}, {"selection_state": null, "remote": "ntp.wdc1.us.lea", "refid": "130.133.1.10", "st": 2, "t": "u", "when": null, "poll": 64, "reach": 1, "delay": 93.053, "offset": -0.807, "jitter": 2.839}, {"selection_state": null, "remote": "clock.team-cymr", "refid": "204.9.54.119", "st": 2, "t": "u", "when": null, "poll": 64, "reach": 1, "delay": 70.337, "offset": -2.909, "jitter": 2.6}, {"selection_state": null, "remote": "mirror1.sjc02.s", "refid": "216.218.254.202", "st": 2, "t": "u", "when": 2, "poll": 64, "reach": 1, "delay": 29.325, "offset": 1.044, "jitter": 4.069}]

View File

@ -0,0 +1 @@
[{"selection_state": "+", "remote": "44.190.6.254", "refid": "127.67.113.92", "st": 2, "t": "u", "when": 66, "poll": 64, "reach": 377, "delay": 22.69, "offset": -0.392, "jitter": 2.085}, {"selection_state": "-", "remote": "108.59.2.24", "refid": "130.133.1.10", "st": 2, "t": "u", "when": 63, "poll": 64, "reach": 377, "delay": 90.805, "offset": 2.84, "jitter": 1.908}, {"selection_state": "+", "remote": "38.229.71.1", "refid": "204.9.54.119", "st": 2, "t": "u", "when": 64, "poll": 64, "reach": 377, "delay": 68.699, "offset": -0.61, "jitter": 2.576}, {"selection_state": "*", "remote": "72.5.72.15", "refid": "216.218.254.202", "st": 2, "t": "u", "when": 63, "poll": 64, "reach": 377, "delay": 22.654, "offset": 0.231, "jitter": 1.964}]

View File

@ -0,0 +1 @@
[{"selection_state": null, "remote": "0.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "1.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "2.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "3.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "ntp.ubuntu.com", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": "+", "remote": "216.126.233.109", "refid": "128.227.205.3", "st": 2, "t": "u", "when": 24, "poll": 64, "reach": 1, "delay": 95.876, "offset": -65.426, "jitter": 4.502}, {"selection_state": "+", "remote": "time.cloudflare", "refid": "10.4.0.197", "st": 3, "t": "u", "when": 33, "poll": 64, "reach": 1, "delay": 25.239, "offset": -69.809, "jitter": 3.313}, {"selection_state": "+", "remote": "titan.crash-ove", "refid": "139.78.97.128", "st": 2, "t": "u", "when": 35, "poll": 64, "reach": 1, "delay": 60.008, "offset": -70.991, "jitter": 2.884}, {"selection_state": "*", "remote": "clock.nyc.he.ne", "refid": ".CDMA.", "st": 1, "t": "u", "when": 31, "poll": 64, "reach": 1, "delay": 90.113, "offset": -65.938, "jitter": 4.621}, {"selection_state": "-", "remote": "vf2.bbnx.net", "refid": "252.74.143.178", "st": 2, "t": "u", "when": 34, "poll": 64, "reach": 1, "delay": 209.667, "offset": -81.337, "jitter": 5.547}, {"selection_state": "+", "remote": "t2.time.bf1.yah", "refid": "98.139.133.62", "st": 3, "t": "u", "when": 35, "poll": 64, "reach": 1, "delay": 104.541, "offset": -67.956, "jitter": 5.731}, {"selection_state": null, "remote": "pugot.canonical", "refid": "17.253.34.125", "st": 2, "t": "u", "when": 43, "poll": 64, "reach": 1, "delay": 176.609, "offset": -65.874, "jitter": 0.0}, {"selection_state": "-", "remote": "50-205-244-110-", "refid": "50.205.244.27", "st": 2, "t": "u", "when": 30, "poll": 64, "reach": 1, "delay": 76.322, "offset": -65.135, "jitter": 2.334}, {"selection_state": "+", "remote": "1.time.dbsinet.", "refid": "146.186.222.14", "st": 2, "t": "u", "when": 31, "poll": 64, "reach": 1, "delay": 110.723, "offset": -65.056, "jitter": 6.198}, {"selection_state": null, "remote": "golem.canonical", "refid": "17.253.34.123", "st": 2, "t": "u", "when": 40, "poll": 64, "reach": 1, "delay": 186.589, "offset": -61.769, "jitter": 0.0}, {"selection_state": "-", "remote": "103.105.51.156", "refid": "206.55.191.142", "st": 2, "t": "u", "when": 30, "poll": 64, "reach": 1, "delay": 38.164, "offset": -65.286, "jitter": 6.412}, {"selection_state": null, "remote": "alphyn.canonica", "refid": "17.253.108.125", "st": 2, "t": "u", "when": 44, "poll": 64, "reach": 1, "delay": 105.626, "offset": -63.73, "jitter": 0.0}, {"selection_state": "-", "remote": "vf1.bbnx.net", "refid": "253.109.221.150", "st": 2, "t": "u", "when": 31, "poll": 64, "reach": 1, "delay": 101.941, "offset": -73.597, "jitter": 3.39}, {"selection_state": null, "remote": "chilipepper.can", "refid": "145.238.203.14", "st": 2, "t": "u", "when": 40, "poll": 64, "reach": 1, "delay": 188.989, "offset": -59.352, "jitter": 0.0}]

21
tests/fixtures/ubuntu-18.04/ntpq-p.out vendored Normal file
View File

@ -0,0 +1,21 @@
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
+216.126.233.109 128.227.205.3 2 u 24 64 1 95.876 -65.426 4.502
+time.cloudflare 10.4.0.197 3 u 33 64 1 25.239 -69.809 3.313
+titan.crash-ove 139.78.97.128 2 u 35 64 1 60.008 -70.991 2.884
*clock.nyc.he.ne .CDMA. 1 u 31 64 1 90.113 -65.938 4.621
-vf2.bbnx.net 252.74.143.178 2 u 34 64 1 209.667 -81.337 5.547
+t2.time.bf1.yah 98.139.133.62 3 u 35 64 1 104.541 -67.956 5.731
pugot.canonical 17.253.34.125 2 u 43 64 1 176.609 -65.874 0.000
-50-205-244-110- 50.205.244.27 2 u 30 64 1 76.322 -65.135 2.334
+1.time.dbsinet. 146.186.222.14 2 u 31 64 1 110.723 -65.056 6.198
golem.canonical 17.253.34.123 2 u 40 64 1 186.589 -61.769 0.000
-103.105.51.156 206.55.191.142 2 u 30 64 1 38.164 -65.286 6.412
alphyn.canonica 17.253.108.125 2 u 44 64 1 105.626 -63.730 0.000
-vf1.bbnx.net 253.109.221.150 2 u 31 64 1 101.941 -73.597 3.390
chilipepper.can 145.238.203.14 2 u 40 64 1 188.989 -59.352 0.000

View File

@ -0,0 +1 @@
[{"selection_state": null, "remote": "0.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "1.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "2.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "3.ubuntu.pool.n", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": null, "remote": "ntp.ubuntu.com", "refid": ".POOL.", "st": 16, "t": "p", "when": null, "poll": 64, "reach": 0, "delay": 0.0, "offset": 0.0, "jitter": 0.0}, {"selection_state": "+", "remote": "216.126.233.109", "refid": "128.227.205.3", "st": 2, "t": "u", "when": 40, "poll": 64, "reach": 1, "delay": 95.876, "offset": -65.426, "jitter": 4.502}, {"selection_state": "+", "remote": "162.159.200.123", "refid": "10.4.0.197", "st": 3, "t": "u", "when": 39, "poll": 64, "reach": 1, "delay": 25.239, "offset": -69.809, "jitter": 3.313}, {"selection_state": "+", "remote": "47.190.36.235", "refid": "139.78.97.128", "st": 2, "t": "u", "when": 41, "poll": 64, "reach": 1, "delay": 60.008, "offset": -70.991, "jitter": 2.884}, {"selection_state": "*", "remote": "209.51.161.238", "refid": ".CDMA.", "st": 1, "t": "u", "when": 37, "poll": 64, "reach": 1, "delay": 90.113, "offset": -65.938, "jitter": 4.621}, {"selection_state": "-", "remote": "23.31.21.164", "refid": "252.74.143.178", "st": 2, "t": "u", "when": 40, "poll": 64, "reach": 1, "delay": 209.667, "offset": -81.337, "jitter": 5.547}, {"selection_state": "+", "remote": "72.30.35.88", "refid": "98.139.133.62", "st": 3, "t": "u", "when": 40, "poll": 64, "reach": 1, "delay": 104.541, "offset": -67.956, "jitter": 5.731}, {"selection_state": null, "remote": "91.189.94.4", "refid": "17.253.34.125", "st": 2, "t": "u", "when": 48, "poll": 64, "reach": 1, "delay": 176.609, "offset": -65.874, "jitter": 0.0}, {"selection_state": "-", "remote": "50.205.244.110", "refid": "50.205.244.27", "st": 2, "t": "u", "when": 35, "poll": 64, "reach": 1, "delay": 76.322, "offset": -65.135, "jitter": 2.334}, {"selection_state": "+", "remote": "199.223.248.99", "refid": "146.186.222.14", "st": 2, "t": "u", "when": 36, "poll": 64, "reach": 1, "delay": 110.723, "offset": -65.056, "jitter": 6.198}, {"selection_state": null, "remote": "91.189.89.199", "refid": "17.253.34.123", "st": 2, "t": "u", "when": 45, "poll": 64, "reach": 1, "delay": 186.589, "offset": -61.769, "jitter": 0.0}, {"selection_state": "-", "remote": "103.105.51.156", "refid": "206.55.191.142", "st": 2, "t": "u", "when": 34, "poll": 64, "reach": 1, "delay": 38.164, "offset": -65.286, "jitter": 6.412}, {"selection_state": null, "remote": "91.189.91.157", "refid": "17.253.108.125", "st": 2, "t": "u", "when": 48, "poll": 64, "reach": 1, "delay": 105.626, "offset": -63.73, "jitter": 0.0}, {"selection_state": "-", "remote": "23.31.21.163", "refid": "253.109.221.150", "st": 2, "t": "u", "when": 35, "poll": 64, "reach": 1, "delay": 101.941, "offset": -73.597, "jitter": 3.39}, {"selection_state": null, "remote": "91.189.89.198", "refid": "145.238.203.14", "st": 2, "t": "u", "when": 44, "poll": 64, "reach": 1, "delay": 188.989, "offset": -59.352, "jitter": 0.0}]

21
tests/fixtures/ubuntu-18.04/ntpq-pn.out vendored Normal file
View File

@ -0,0 +1,21 @@
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
+216.126.233.109 128.227.205.3 2 u 40 64 1 95.876 -65.426 4.502
+162.159.200.123 10.4.0.197 3 u 39 64 1 25.239 -69.809 3.313
+47.190.36.235 139.78.97.128 2 u 41 64 1 60.008 -70.991 2.884
*209.51.161.238 .CDMA. 1 u 37 64 1 90.113 -65.938 4.621
-23.31.21.164 252.74.143.178 2 u 40 64 1 209.667 -81.337 5.547
+72.30.35.88 98.139.133.62 3 u 40 64 1 104.541 -67.956 5.731
91.189.94.4 17.253.34.125 2 u 48 64 1 176.609 -65.874 0.000
-50.205.244.110 50.205.244.27 2 u 35 64 1 76.322 -65.135 2.334
+199.223.248.99 146.186.222.14 2 u 36 64 1 110.723 -65.056 6.198
91.189.89.199 17.253.34.123 2 u 45 64 1 186.589 -61.769 0.000
-103.105.51.156 206.55.191.142 2 u 34 64 1 38.164 -65.286 6.412
91.189.91.157 17.253.108.125 2 u 48 64 1 105.626 -63.730 0.000
-23.31.21.163 253.109.221.150 2 u 35 64 1 101.941 -73.597 3.390
91.189.89.198 145.238.203.14 2 u 44 64 1 188.989 -59.352 0.000

21
tests/fixtures/ubuntu-18.04/ntqp-p.out vendored Normal file
View File

@ -0,0 +1,21 @@
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
+216.126.233.109 128.227.205.3 2 u 24 64 1 95.876 -65.426 4.502
+time.cloudflare 10.4.0.197 3 u 33 64 1 25.239 -69.809 3.313
+titan.crash-ove 139.78.97.128 2 u 35 64 1 60.008 -70.991 2.884
*clock.nyc.he.ne .CDMA. 1 u 31 64 1 90.113 -65.938 4.621
-vf2.bbnx.net 252.74.143.178 2 u 34 64 1 209.667 -81.337 5.547
+t2.time.bf1.yah 98.139.133.62 3 u 35 64 1 104.541 -67.956 5.731
pugot.canonical 17.253.34.125 2 u 43 64 1 176.609 -65.874 0.000
-50-205-244-110- 50.205.244.27 2 u 30 64 1 76.322 -65.135 2.334
+1.time.dbsinet. 146.186.222.14 2 u 31 64 1 110.723 -65.056 6.198
golem.canonical 17.253.34.123 2 u 40 64 1 186.589 -61.769 0.000
-103.105.51.156 206.55.191.142 2 u 30 64 1 38.164 -65.286 6.412
alphyn.canonica 17.253.108.125 2 u 44 64 1 105.626 -63.730 0.000
-vf1.bbnx.net 253.109.221.150 2 u 31 64 1 101.941 -73.597 3.390
chilipepper.can 145.238.203.14 2 u 40 64 1 188.989 -59.352 0.000

66
tests/test_ntpq.py Normal file
View File

@ -0,0 +1,66 @@
import os
import unittest
import json
import jc.parsers.ntpq
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ntpq-p.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_ntpq_p = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ntpq-p.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_ntpq_p = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ntpq-pn.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_ntpq_pn = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ntpq-pn.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_ntpq_pn = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ntpq-p.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_ntpq_p_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ntpq-p.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_ntpq_p_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/ntpq-pn.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_ntpq_pn_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ntpq-pn.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_ntpq_pn_json = json.loads(f.read())
def test_ntpq_p_centos_7_7(self):
"""
Test 'ntpq -p' on Centos 7.7
"""
self.assertEqual(jc.parsers.ntpq.parse(self.centos_7_7_ntpq_p, quiet=True), self.centos_7_7_ntpq_p_json)
def test_ntpq_p_ubuntu_18_4(self):
"""
Test 'ntpq -p' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.ntpq.parse(self.ubuntu_18_4_ntpq_p, quiet=True), self.ubuntu_18_4_ntpq_p_json)
def test_ntpq_pn_centos_7_7(self):
"""
Test 'ntpq -pn' on Centos 7.7
"""
self.assertEqual(jc.parsers.ntpq.parse(self.centos_7_7_ntpq_pn, quiet=True), self.centos_7_7_ntpq_pn_json)
def test_ntpq_pn_ubuntu_18_4(self):
"""
Test 'ntpq -pn' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.ntpq.parse(self.ubuntu_18_4_ntpq_pn, quiet=True), self.ubuntu_18_4_ntpq_pn_json)
if __name__ == '__main__':
unittest.main()