The module tests the functionality of crontab of the system. Crontab depends upon the binary run-parts, which is used to run all scripts under a directory.An entry in the crontab is added by creating an entry in /etc/crontab. The module uses the run-parts to execute a script(named cron) created under /etc/cron.d/ and the script is made to execute every 60 seconds.The script writes a certain string to a file(/tmp/autotest_cron-<date>).The count of the string after t seconds decides whether the test succeeded or not. The two files used along with run-parts for selective execution of scripts (jobs.allow and jobs.deny) are also covered under the test. jobs.allow specifies the scripts to be run and deny specifies scripts to be ignored.These conditions are also checked.
--- crontab/control | 22 ++++++++ crontab/crontab.py | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++ crontab/crontab.pyc | Bin 3 files changed, 164 insertions(+) create mode 100644 crontab/control create mode 100644 crontab/crontab.py create mode 100644 crontab/crontab.pyc diff --git a/crontab/control b/crontab/control new file mode 100644 index 0000000..6d605a3 --- /dev/null +++ b/crontab/control @@ -0,0 +1,22 @@ +AUTHOR = "Rajeev S <[email protected]>" +NAME = "crontab" +TEST_CATEGORY = "Functional" +TEST_CLASS = "Kernel" +TEST_TYPE = "client" +TIME = 'SHORT' +DOC = ''' +Test for testing the crontab. + +Uses run-parts to execute the scripts under the standard cron directories,/etc/cron.xxxx. +Automation is done using the /etc/crontab file. + +Args: + wait_time:Duration of the sleep time.Should be greater than 60(sec) +''' +from datetime import datetime + +LOGFILE='/tmp/autotest_cron-%s'%(str(datetime.now())[:10]) + +tests=['normalCron','denyCron','allowCron'] +for i in range(0,3): + job.run_test('crontab',test=tests[i],wait_time=65,tag=tests[i],log=LOGFILE) diff --git a/crontab/crontab.py b/crontab/crontab.py new file mode 100644 index 0000000..0ef509a --- /dev/null +++ b/crontab/crontab.py @@ -0,0 +1,142 @@ +#!/bin/python +import os, shutil, glob, logging +from autotest.client import test, utils +from autotest.client.shared import error +from time import sleep + + +class crontab(test.test): + ''' + Autotest module for crontab. + + Creates a new cron job that creates a log entry in log.The count of + log entry is compared before and after a period of 80 sec.Difference decide + s whether the cron executed + successfully. + + @author :Rajeev S <[email protected]> + ''' + version = 1 + initialCount = 0 + log='' + + def count_log(self,string): + '''returns count of the 'string' in log''' + count=0 + try: + f=open(self.log) + except IOError: + utils.open_write_close(self.log,'') + f=open(self.log) + for i in f.readlines(): + if string in i: + count+=1 + f.close() + return count + + def initialize(self,test,log): + '''Does the init part of the test + 1.Finds initial count of entry in log + 2.Creates a file 'cron' under cron.d + 3.Backs up /etc/crontab + 4.Modifies /etc/crontab ''' + self.log=log + + self.initialCount=self.count_log('Cron automation') + f=open('/etc/cron.d/cron','w') + f.write('''#!/bin/bash +touch %s +echo 'Cron automation' >> %s + '''%(self.log,self.log)) + f.close() + utils.system('chmod +x /etc/cron.d/cron') + utils.system('cat /etc/crontab > /tmp/backup') + f=open('/etc/crontab','w') + f.write('* * * * * root run-parts /etc/cron.d/\n') + f.close() + if test == 'denyCron': + if os.path.exists('/etc/cron.d/jobs.deny'): + utils.system('mv /etc/cron.d/jobs.deny /tmp/jobs.deny 2>/dev/null') + f=open('/etc/cron.d/jobs.deny','w') + f.write('cron') + f.close() + elif test =='allowCron' : + utils.system('rm /etc/cron.d/jobs.deny') + if os.path.exists('/etc/cron.d/jobs.allow'): + utils.system('mv /etc/cron.d/jobs.allow /tmp/jobs.allow 2>/dev/null') + f=open('/etc/cron.d/jobs.allow','w') + f.write('cron') + f.close() + + + def allowCron(self,wait_time): + if self.count_log('Cron automation')>self.initialCount: + utils.open_write_close(self.results_path,'''Test Successful. + Test time:%s + Test mode:2(run-parts with jobs.allow)'''%(wait_time)) + else: + utils.open_write_close(self.results_path,'''Test Failed. + There were no new entries in log. + Job not executed inspite of jobs.allow entry. + Test time:%s + Test mode:2 (run-parts with jobs.allow)'''%(wait_time)) + + + def normalCron(self,wait_time): + if self.count_log('Cron automation')>self.initialCount: + utils.open_write_close(self.results_path,'''Test successful. + Test time:%s + Test mode:0(normal test for run-parts)'''%(wait_time)) + else: + utils.open_write_close(self.results_path,'''Test Failed. + There were no new entries in log. + Test time:%s + Test mode:0 (normal test for run-parts)'''%(wait_time)) + + + def denyCron(self,wait_time): + if self.count_log('Cron automation')>self.initialCount: + utils.open_write_close(self.results_path,'''Test Failed. + run-parts overrides jobs.deny. + Test time:%s + Test mode:1(run-parts with jobs.deny)'''%(wait_time)) + else: + utils.open_write_close(self.results_path,'''Test Successful. + There were no new entries in log. + Test time:%s + Test mode:1 (run-parts with jobs.deny)'''%(wait_time)) + + + def make_fun(self,test,wait_time): + '''Calls the function with the name <test> ''' + test=getattr(self,test) + test(wait_time) + + def run_once(self,test,wait_time): + '''Runs the test,writes test success if cron successfully executes,else + writes test failed. + Resets /etc/crontab + Pass 0:Normal operation of run-parts + Pass 1:run-parts with jobs.deny + Pass 2:run-parts with jobs.allow + ''' + os.chdir(self.srcdir) + self.test=test + self.results_path = os.path.join(self.resultsdir, + 'raw_output_mode_%s'%test) + try: + sleep(wait_time) + self.make_fun(test,wait_time) + except Exception as e: + logging.error('\nTest failed:%s'%e) + + def cleanup(self): + utils.system('cat /tmp/backup > /etc/crontab') + if os.path.exists('/etc/cron.d/jobs.allow'): + utils.system('rm /etc/cron.d/jobs.allow /etc/cron.d/cron') + else: + utils.system('rm /etc/cron.d/cron') + if os.path.exists('/tmp/jobs.allow'): + utils.system('mv /tmp/jobs.allow /etc/cron.d/jobs.allow 2>/dev/null') + if os.path.exists('/tmp/jobs.deny'): + utils.system('mv /tmp/jobs.allow /etc/cron.d/jobs.allow 2>/dev/null') diff --git a/crontab/crontab.pyc b/crontab/crontab.pyc new file mode 100644 index 0000000000000000000000000000000000000000..771c4f2e80797c1ddfd556db1509eb01da7c4e75 GIT binary patch literal 6247 zcmd5=e{UQ|8J@j6pM4iQb{t5`uXd_5_)^+C#{rdEkrkS>0z}<tT@<har}gffZ|%L^ zV`naoQ6d2;LPFy6@E?f(`2>6d{^tY0^SpbvcXph#1-aDrj%W6rdFP#ZpZC{R|FzWo z$DjXxKUCwND*oTWW1pdk@aL&Ssok>gsa<dKzM^(3lYUk0R;6E2Nlgvr)b5-b)YWcX zdE`=6$-EjY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FA0qmL^bM4~O(}byC=Z2@=PsxNe1X97YEk{L&P5F} zu2xr(GWjEvs=QO)=3A0ZVa(_^_Q5*t6&3!}Cnv{~h-%+5i7mbfFv8<!mP7CP0PY)9 ztTSmX^5fZveLt{PuWxP_9vr1^F8Ms;b!q3%&A+)>(h7)_+3j;vH_n_YiAOotvM|bn zqi!~G!;$MUW9eSEk_<J)Xp3_pz1eOpVXn`bps1?*QJhPnY4Z@>BE9@N$ppkf7N_EC z$MK&tXc4{u_H|BUitzs95MQkTc=-T;dU+pT4tyHM>BN=Dmh%0avjr(UaLL^aAA&44 zl{-=kD_#Tn=?ZH2ruP-}LI6tfp|FDXPtYmQUKH$Jk&YI*D2zVuOvtE=;RDj8$+#xt z>2#^n^IuNLMWxQdTJl>moac)CH_y$Ggq9Y%J+05C1sTh;nUeEm1<jk_aaJKz6fh+h zR6(qwEWP5X>GGbHhE#;p6tt|BDA)A$RI(G5)ojsbFP`AW&`?AMs=;UJCh+tLLjN0R z#9fMaJm;iBKD#C+NJqopV_&JsRZ+%NiehHfYf*YZSGP;2-tCHgbZK<>B#I%qbh}X& zj{Au57N${T)g%^4_BYvMPV2wMhF9;?p!^$bsJQ8ArFR}*xqKQqfo6H{^=93Z-%8_R z<62{>v504`u_|AI3!fp?YM<Y*#XsyP*`B|KrH&Apd|PW5-_{CWLajPh6sM?d+vhi3 j@e;y|B}Cy@DAX5lc+ukRLT_6V#d#C!-WB+VmFj;01PRL` literal 0 HcmV?d00001 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
