Commit e33d0947 authored by Jérome Perrin's avatar Jérome Perrin

testing: introduce crontab mixin

Helper class to check crontabs in software release tests
parent 85e411bf
......@@ -29,6 +29,8 @@
import socket
import hashlib
import unittest
import os
import subprocess
from contextlib import closing
try:
......@@ -60,6 +62,36 @@ def getPortFromPath(path):
16) % (65535 - 1024)
class CrontabMixin(object):
computer_partition_root_path = None # type: str
def _getCrontabCommand(self, crontab_name):
# type: (str) -> str
"""Read a crontab and return the command that is executed.
"""
with open(
os.path.join(
self.computer_partition_root_path,
'etc',
'cron.d',
crontab_name,
)) as f:
crontab_spec = f.read()
return " ".join(crontab_spec.split()[5:])
def _executeCrontabAtDate(self, crontab_name, date):
# type: (str, str) -> None
"""Executes a crontab as if the current date was `date`.
`date` will be passed to faketime time command, it can also
be a relative time.
"""
crontab_command = self._getCrontabCommand(crontab_name)
subprocess.check_call(
"faketime {date} bash -o pipefail -e -c '{crontab_command}'".format(**locals()),
shell=True,
)
class ImageComparisonTestCase(unittest.TestCase):
"""TestCase with utility method to compare images.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment