First time-based test (one warning)
This commit is contained in:
parent
6710b2d36f
commit
0b7c05f4c7
|
@ -17,10 +17,10 @@ set -x
|
|||
# prepare
|
||||
setup
|
||||
checkEnvironment
|
||||
# disableTimeSync
|
||||
disableTimeSync
|
||||
|
||||
# # set timezone
|
||||
# ln -sf /usr/share/zoneinfo/Europe/Vienna /etc/localtime
|
||||
# set timezone
|
||||
ln -sf /usr/share/zoneinfo/Europe/Vienna /etc/localtime
|
||||
|
||||
# timestamp=$START
|
||||
|
||||
|
|
|
@ -11,6 +11,27 @@
|
|||
yearly = 0
|
||||
autosnap = yes
|
||||
autoprune = no
|
||||
hourly_warn = 90m
|
||||
hourly_crit = 360m
|
||||
daily_warn = 28h
|
||||
daily_crit = 32h
|
||||
weekly_warn = 0
|
||||
weekly_crit = 0
|
||||
monthly_warn = 32d
|
||||
monthly_crit = 40d
|
||||
yearly_warn = 0
|
||||
yearly_crit = 0
|
||||
|
||||
|
||||
[template_demo]
|
||||
daily = 60
|
||||
daily = 60
|
||||
hourly_warn = 290m
|
||||
hourly_crit = 360m
|
||||
daily_warn = 28h
|
||||
daily_crit = 48h
|
||||
weekly_warn = 0
|
||||
weekly_crit = 0
|
||||
monthly_warn = 32d
|
||||
monthly_crit = 40d
|
||||
yearly_warn = 0
|
||||
yearly_crit = 0
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import os
|
||||
import subprocess
|
||||
from tabnanny import check
|
||||
import time
|
||||
import unittest
|
||||
|
||||
|
||||
|
@ -28,6 +28,22 @@ def run_sanoid_cron_command():
|
|||
return_info = subprocess.run([sanoid_cmd, "--cron", "--verbose"], capture_output=True, check=True)
|
||||
return return_info
|
||||
|
||||
def advance_time(seconds):
|
||||
"""Advances the system clock by seconds"""
|
||||
|
||||
# Get the current time
|
||||
clk_id = time.CLOCK_REALTIME
|
||||
time_seconds = time.clock_gettime(clk_id)
|
||||
print("Current unix time is", time_seconds, "or", time.asctime(time.gmtime(time_seconds)), "in GMT")
|
||||
|
||||
# Set the clock to the current time plus seconds
|
||||
time.clock_settime(clk_id, time_seconds + seconds)
|
||||
|
||||
# Print the new time
|
||||
time_seconds = time.clock_gettime(clk_id)
|
||||
print("Current unix time is", time_seconds, "or", time.asctime(time.gmtime(time_seconds)), "in GMT")
|
||||
return time_seconds
|
||||
|
||||
|
||||
class TestMonitoringOutput(unittest.TestCase):
|
||||
def test_no_zpool(self):
|
||||
|
@ -74,6 +90,17 @@ class TestsWithZpool(unittest.TestCase):
|
|||
self.assertEqual(return_info.stdout, b"OK: all monitored datasets (sanoid-test-1, sanoid-test-2) have fresh snapshots\n")
|
||||
self.assertEqual(return_info.returncode, 0)
|
||||
|
||||
def test_one_warning(self):
|
||||
"""Test one warning, no criticals"""
|
||||
|
||||
run_sanoid_cron_command()
|
||||
|
||||
# Advance 100 mins to trigger the hourly warning on sanoid-test-1 but nothing else
|
||||
advance_time(100 * 60)
|
||||
return_info = monitor_snapshots_command()
|
||||
self.assertEqual(return_info.stdout, b"OK: all monitored datasets (sanoid-test-1, sanoid-test-2) have fresh snapshots\n")
|
||||
self.assertEqual(return_info.returncode, 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue