Merge "Improve parsing of cron schedule"
This commit is contained in:
commit
dcf0ef07c1
|
@ -103,9 +103,23 @@ def get_cron_interval(cronspec, base):
|
||||||
|
|
||||||
|
|
||||||
def get_stats_cron_schedule():
|
def get_stats_cron_schedule():
|
||||||
|
"""Returns the cron schedule from the stats CRONJOB spec file.
|
||||||
|
|
||||||
|
:return: a string containing the cron schedule
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
# TODO(wolsen) in general, the layout of this code makes a lot of
|
||||||
|
# assumptions about the files that are written, etc and is somewhat
|
||||||
|
# brittle for anything not specifically laid out by the charm. This
|
||||||
|
# should be revisited in the future.
|
||||||
with open(CRONJOB) as f:
|
with open(CRONJOB) as f:
|
||||||
cronjob = f.read()
|
cronjob = f.read()
|
||||||
return cronjob.split("root")[0].strip()
|
# The first 5 columns make up the cron spec, but the output of this
|
||||||
|
# function should be a string. Split the line on whitespace and reform
|
||||||
|
# the spec string from the necessary columns
|
||||||
|
# See LP#1939702
|
||||||
|
cron_spec = ' '.join(cronjob.split()[:5])
|
||||||
|
return cron_spec
|
||||||
|
|
||||||
|
|
||||||
def check_stats_file_freshness(stats_file, asof=None):
|
def check_stats_file_freshness(stats_file, asof=None):
|
||||||
|
|
|
@ -27,7 +27,7 @@ class CheckRabbitTest(unittest.TestCase):
|
||||||
cls.tmpdir = TemporaryDirectory()
|
cls.tmpdir = TemporaryDirectory()
|
||||||
cronjob = Path(cls.tmpdir.name) / "rabbitmq-stats"
|
cronjob = Path(cls.tmpdir.name) / "rabbitmq-stats"
|
||||||
with cronjob.open('w') as f:
|
with cronjob.open('w') as f:
|
||||||
f.write("*/5 * * * * root timeout -k 10s -s SIGINT 300 "
|
f.write("*/5 * * * * rabbitmq timeout -k 10s -s SIGINT 300 "
|
||||||
"/usr/local/bin/collect_rabbitmq_stats.sh 2>&1 | "
|
"/usr/local/bin/collect_rabbitmq_stats.sh 2>&1 | "
|
||||||
"logger -p local0.notice")
|
"logger -p local0.notice")
|
||||||
cls.old_cron = check_rabbitmq_queues.CRONJOB
|
cls.old_cron = check_rabbitmq_queues.CRONJOB
|
||||||
|
|
Loading…
Reference in New Issue