예제 #1
0
    def test_NTPPeer3(self):
        # check the parsing done by NTPCheck
        ntp = NTPCheck(testdata[3].split("\n"))
        self.assertEqual(ntp.ntpdata.get('syncpeer'), None)
        self.assertEqual(ntp.ntpdata.get('offsetsyncpeer'), None)
        self.assertEqual(ntp.ntpdata['survivors'], 0)
        self.assertEqual(ntp.ntpdata.get('averageoffsetsurvivors'), None)
        self.assertEqual(ntp.ntpdata['discards'], 1)
        self.assertEqual(ntp.ntpdata['averageoffsetdiscards'], 0.913)
        self.assertEqual(ntp.ntpdata['peers'], 1)
        self.assertEqual(ntp.ntpdata['averageoffset'], 0.913)
        self.assertEqual(ntp.ntpdata['reachability'], 37.5)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetdiscards']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 0, 'Low offset non-OK')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 2, 'Low peers non-critical')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 2,
                         'Low reachability non-critical')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 2, 'Missing sync peer not detected')
        self.assertEqual(ntp.check_offset(), 1, 'Missing sync peer/survivor offset non-warning')
        self.assertEqual(ntp.check_peers(), 2, 'Low peers non-critical')
        self.assertEqual(ntp.check_reachability(), 2, 'Low reachability non-critical')
예제 #2
0
    def test_NTPPeer1(self):
        # check the parsing done by NTPCheck
        ntp = NTPCheck(testdata[1].split("\n"))
        self.assertEqual(ntp.ntpdata['syncpeer'], '202.60.94.11')
        self.assertEqual(ntp.ntpdata['offsetsyncpeer'], 0.259)
        self.assertEqual(ntp.ntpdata['survivors'], 3)
        self.assertEqual(ntp.ntpdata['averageoffsetsurvivors'], 0.21133333333333335)
        self.assertEqual(ntp.ntpdata['discards'], 3)
        self.assertEqual(ntp.ntpdata['averageoffsetdiscards'], 1.024)
        self.assertEqual(ntp.ntpdata['peers'], 6)
        self.assertEqual(ntp.ntpdata['averageoffset'], 0.6176666666666667)
        self.assertEqual(ntp.ntpdata['reachability'], 100)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.sync(ntp.ntpdata['syncpeer']), 0, 'Sync peer not detected')
        self.assertEqual(check.offset(ntp.ntpdata['offsetsyncpeer']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetsurvivors']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetdiscards']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 0, 'Low offset non-OK')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 0, 'High peers non-OK')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 0,
                         'High reachability non-OK')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 0, 'Sync peer not detected')
        self.assertEqual(ntp.check_offset(), 0, 'Low offset non-OK')
        self.assertEqual(ntp.check_peers(), 0, 'High peers non-OK')
        self.assertEqual(ntp.check_reachability(), 0, 'High reachability non-OK')
예제 #3
0
    def test_NTPPeer2(self):
        # check the parsing done by NTPCheck
        ntp = NTPCheck(testdata[2].split("\n"))
        self.assertEqual(ntp.ntpdata['syncpeer'], '91.189.94.4')
        self.assertEqual(ntp.ntpdata['offsetsyncpeer'], 194.54)
        self.assertEqual(ntp.ntpdata['survivors'], 1)
        self.assertEqual(ntp.ntpdata['averageoffsetsurvivors'], 194.54)
        self.assertEqual(ntp.ntpdata['discards'], 0)
        self.assertEqual(ntp.ntpdata.get('averageoffsetdiscards'), None)
        self.assertEqual(ntp.ntpdata['peers'], 1)
        self.assertEqual(ntp.ntpdata['averageoffset'], 194.54)
        self.assertEqual(ntp.ntpdata['reachability'], 100)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.sync(ntp.ntpdata['syncpeer']), 0, 'Sync peer not detected')
        self.assertEqual(check.offset(ntp.ntpdata['offsetsyncpeer']), 2, 'High offset non-critical')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetsurvivors']), 2, 'High offset non-critical')
        self.assertEqual(ntp.ntpdata.get('averageoffsetdiscards'), None)
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 2, 'High offset non-critical')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 2, 'Low peers non-critical')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 0,
                         'High reachability non-OK')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 0, 'Sync peer not detected')
        self.assertEqual(ntp.check_offset(), 2, 'High offset non-critical')
        self.assertEqual(ntp.check_peers(), 2, 'Low peers non-critical')
        self.assertEqual(ntp.check_reachability(), 0, 'High reachability non-OK')
예제 #4
0
 def test_demos(self):
     """Ensure that demo data is parsed successfully and doesn't produce exceptions or unknown results"""
     for d in demodata:
         ntp = NTPCheck(d.split("\n"))
         ntp.dump()
         methods = [ntp.check_offset, ntp.check_peers, ntp.check_reachability,
                    ntp.check_sync, ntp.checks]
         for method in methods:
             ret = method()
             self.assertIn(
                 ret, [0, 1, 2],
                 "Method %s returned invalid result parsing demo data:\n%s\nTry running with --show-demos." % (method, d))
예제 #5
0
def demo():
    """Duplicate of test_demos which shows full output"""
    i = 0
    for d in demodata:
        print("Parsing demo data %d: %s" % (i, d))
        ntp = NTPCheck(d.split("\n"))
        i += 1
        ntp.dump()
        methods = [ntp.check_offset, ntp.check_peers, ntp.check_reachability,
                   ntp.check_sync, ntp.checks]
        for method in methods:
            ret = method()
            if ret not in [0, 1, 2]:
                print("Method %s returned invalid result parsing demo data:\n%s" % (method, d))
                sys.exit(3)
예제 #6
0
 def test_demos(self):
     """Ensure that demo data is parsed successfully and doesn't produce exceptions or unknown results"""
     for d in demodata:
         ntp = NTPCheck(d.split("\n"))
         ntp.dump()
         methods = [
             ntp.check_offset, ntp.check_peers, ntp.check_reachability,
             ntp.check_sync, ntp.checks
         ]
         for method in methods:
             ret = method()
             self.assertIn(
                 ret, [0, 1, 2],
                 "Method %s returned invalid result parsing demo data:\n%s\nTry running with --show-demos."
                 % (method, d))
예제 #7
0
def demo():
    """Duplicate of test_demos which shows full output"""
    i = 0
    for d in demodata:
        print("Parsing demo data %d: %s" % (i, d))
        ntp = NTPCheck(d.split("\n"))
        i += 1
        ntp.dump()
        methods = [
            ntp.check_offset, ntp.check_peers, ntp.check_reachability,
            ntp.check_sync, ntp.checks
        ]
        for method in methods:
            ret = method()
            if ret not in [0, 1, 2]:
                print(
                    "Method %s returned invalid result parsing demo data:\n%s"
                    % (method, d))
                sys.exit(3)
예제 #8
0
    def test_NTPPeer3(self):
        # check the parsing done by NTPCheck
        ntp = NTPCheck(testdata[3].split("\n"))
        self.assertEqual(ntp.ntpdata.get('syncpeer'), None)
        self.assertEqual(ntp.ntpdata.get('offsetsyncpeer'), None)
        self.assertEqual(ntp.ntpdata['survivors'], 0)
        self.assertEqual(ntp.ntpdata.get('averageoffsetsurvivors'), None)
        self.assertEqual(ntp.ntpdata['discards'], 1)
        self.assertEqual(ntp.ntpdata['averageoffsetdiscards'], 0.913)
        self.assertEqual(ntp.ntpdata['peers'], 1)
        self.assertEqual(ntp.ntpdata['averageoffset'], 0.913)
        self.assertEqual(ntp.ntpdata['reachability'], 37.5)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetdiscards']), 0,
                         'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 0,
                         'Low offset non-OK')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 2,
                         'Low peers non-critical')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 2,
                         'Low reachability non-critical')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 2, 'Missing sync peer not detected')
        self.assertEqual(ntp.check_offset(), 1,
                         'Missing sync peer/survivor offset non-warning')
        self.assertEqual(ntp.check_peers(), 2, 'Low peers non-critical')
        self.assertEqual(ntp.check_reachability(), 2,
                         'Low reachability non-critical')
예제 #9
0
    def test_NTPPeer2(self):
        # check the parsing done by NTPCheck
        ntp = NTPCheck(testdata[2].split("\n"))
        self.assertEqual(ntp.ntpdata['syncpeer'], '91.189.94.4')
        self.assertEqual(ntp.ntpdata['offsetsyncpeer'], 194.54)
        self.assertEqual(ntp.ntpdata['survivors'], 1)
        self.assertEqual(ntp.ntpdata['averageoffsetsurvivors'], 194.54)
        self.assertEqual(ntp.ntpdata['discards'], 0)
        self.assertEqual(ntp.ntpdata.get('averageoffsetdiscards'), None)
        self.assertEqual(ntp.ntpdata['peers'], 1)
        self.assertEqual(ntp.ntpdata['averageoffset'], 194.54)
        self.assertEqual(ntp.ntpdata['reachability'], 100)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.sync(ntp.ntpdata['syncpeer']), 0,
                         'Sync peer not detected')
        self.assertEqual(check.offset(ntp.ntpdata['offsetsyncpeer']), 2,
                         'High offset non-critical')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetsurvivors']),
                         2, 'High offset non-critical')
        self.assertEqual(ntp.ntpdata.get('averageoffsetdiscards'), None)
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 2,
                         'High offset non-critical')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 2,
                         'Low peers non-critical')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 0,
                         'High reachability non-OK')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 0, 'Sync peer not detected')
        self.assertEqual(ntp.check_offset(), 2, 'High offset non-critical')
        self.assertEqual(ntp.check_peers(), 2, 'Low peers non-critical')
        self.assertEqual(ntp.check_reachability(), 0,
                         'High reachability non-OK')
예제 #10
0
    def test_NTPPeer1(self):
        # check the parsing done by NTPCheck
        ntp = NTPCheck(testdata[1].split("\n"))
        self.assertEqual(ntp.ntpdata['syncpeer'], '202.60.94.11')
        self.assertEqual(ntp.ntpdata['offsetsyncpeer'], 0.259)
        self.assertEqual(ntp.ntpdata['survivors'], 3)
        self.assertEqual(ntp.ntpdata['averageoffsetsurvivors'],
                         0.21133333333333335)
        self.assertEqual(ntp.ntpdata['discards'], 3)
        self.assertEqual(ntp.ntpdata['averageoffsetdiscards'], 1.024)
        self.assertEqual(ntp.ntpdata['peers'], 6)
        self.assertEqual(ntp.ntpdata['averageoffset'], 0.6176666666666667)
        self.assertEqual(ntp.ntpdata['reachability'], 100)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.sync(ntp.ntpdata['syncpeer']), 0,
                         'Sync peer not detected')
        self.assertEqual(check.offset(ntp.ntpdata['offsetsyncpeer']), 0,
                         'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetsurvivors']),
                         0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetdiscards']), 0,
                         'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 0,
                         'Low offset non-OK')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 0,
                         'High peers non-OK')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 0,
                         'High reachability non-OK')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 0, 'Sync peer not detected')
        self.assertEqual(ntp.check_offset(), 0, 'Low offset non-OK')
        self.assertEqual(ntp.check_peers(), 0, 'High peers non-OK')
        self.assertEqual(ntp.check_reachability(), 0,
                         'High reachability non-OK')