我已经加的2个case,是set debug dir 和backup dir
TSCSetting.py:
# # This library is created for operator: TSCSetting # Author: [email protected] # Created Date: date_now # ## Import python modules here ## Build in mudules are preferred import os import time ## Below is the must import sys import glob import subprocess import platform if 'libs' not in sys.path: sys.path.append(os.getcwd() + '/libs') import TestIDCELib import ConfigIDCE class TSCSetting: """ This library is created to make TestDCE command for TSCSetting 1. TSCSetting """ def __init__(self): self._testDCE = TestIDCELib.TestIDCELib() def TSCSetting(self, case_id, param): """ Run operator: TSCSetting @Param: case_id: Unique ID of test case Return: None Example: | TSCSetting | CASE_ID | """ TestDCE_command = 'TestiDCE -level=5 -ptn=TSCSetting.ptn -assign=%s %s' %(case_id, param) self._testDCE._execute_case(TestDCE_command, case_id) def log_decryptor_with_logFolder(self,debug_folder): """ IDCE debug log decryption,and decrypted file named TSCDebug2.log @Param: debug_folder : for decrpytor debug logs under this folder Return: If no error occur, it will return True """ if not os.access(debug_folder,os.F_OK): print "\n*WARN*>> No debug log for decryption" return False #os.chdir(de bug_folder) debug_logs = glob.glob('%s/debug*.log' %debug_folder) if(len(debug_logs) == 0): print "\n*WARN*>> Can't find debug log" else: debug_log = debug_logs[0] os.rename(debug_log,'%s/TSCDebug_temp.log'%debug_folder) decryption_command = ConfigIDCE.TESTENV_DIR + '/iLogDecryptor /Users/mac/TestIDCE/testenv/target/TSCSetting/debug/TSCDebug_temp.log /Users/mac/TestIDCE/testenv/target/TSCSetting/debug/TSCDebug2.log' subprocess.call(decryption_command,stdout=subprocess.PIPE,shell = True) def restore_TSCSetting(self,case_id): filelist=self.sort_file_by_date() count=len(filelist) if 0==count:raise AssertionError(">> Error: No restore file has exist") TestDCE_command = 'TestiDCE -level=5 -restore=' for newfile in filelist: restorefile="/Users/mac/TestIDCE/testenv/backup/"+newfile TestDCE_command +='%s:' % restorefile TestDCE_command= TestDCE_command[:-1] self._testDCE._execute_case(TestDCE_command, case_id) def sort_file_by_date(self): date_file_list=[] for folder in glob.glob("/Users/mac/TestIDCE/testenv/backup"): for file in glob.glob(folder+'/*.*'): stats=os.stat(file) lastmod_date=time.localtime(stats[8]) date_file_tuple=lastmod_date, file date_file_list.append(date_file_tuple) date_file_list.sort() date_file_list.reverse() returnFile=[] for file in date_file_list: folder, filename=os.path.split(file[1]) if '.dat' in filename or '.DAT' in filename: returnFile.append(filename) print '>>Now the backup file is %s' %filename return returnFile def create_specified_size_file(self, filename, filesize): """ Run Operator: create_specified_size_file open the file in read mode @Param: filename the file to be opened fiesize filesize*1G Example: |create_specified_size_file| /Users/mac/TestIDCE/targetfile | 2 """ try: f = open(filename, 'w') block='1'*1024 realsize=filesize*1024 for i in range(realsize): f.write(block) f.close() except Exception, e: raise AssertionError(str(e))
@TSC_SETTING { id=1 fmt=tsc_policy get_os() } @tscsetting001 { id=1 fmt=tsc_clean vsapiptn=tscsetting001,tscsetting002,tscsetting003,tscsetting004,tscsetting008 set_TSC_flag(VIRUS_FOUND, "true") CleanSection file_del("/Users/mac/TestIDCE/testenv/target/TSCSetting/TestDaemon_1") jne(1) END :END } @tscsetting005_1 { id=1 fmt=tsc_clean vsapiptn=tscsetting005 set_TSC_flag(VIRUS_FOUND, "true") CleanSection file_del("/Users/mac/TestIDCE/testenv/target/TSCSetting/1.txt") jne(1) END :END } @tscsetting005_2 { id=1 fmt=tsc_clean vsapiptn=tscsetting005 set_TSC_flag(VIRUS_FOUND, "true") CleanSection file_del("/Users/mac/TestIDCE/testenv/target/TSCSetting/2.txt") jne(1) END :END } @tscsetting005_3 { id=1 fmt=tsc_clean vsapiptn=tscsetting005 set_TSC_flag(VIRUS_FOUND, "true") CleanSection file_del("/Users/mac/TestIDCE/testenv/target/TSCSetting/3.txt") jne(1) END :END } @tscsetting006 { id=1 fmt=tsc_clean vsapiptn=tscsetting006 file_exist("/Users/mac/TestIDCE/testenv/target/TSCSetting/normal.txt") jne(1) END file_exist("/Users/mac/TestIDCE/testenv/target/TSCSetting/second.txt") jne(1) END set_TSC_flag(VIRUS_FOUND, "true") CleanSection file_del("/Users/mac/TestIDCE/testenv/target/TSCSetting/normal.txt") jne(1) END file_del("/Users/mac/TestIDCE/testenv/target/TSCSetting/second.txt") :END } @tscsetting007 { id=1 fmt=tsc_clean vsapiptn=tscsetting007 file_exist("/Users/mac/TestIDCE/testenv/target/TSCSetting/normal.txt") jne(1) END set_TSC_flag(VIRUS_FOUND, "true") CleanSection :END }
*** Settings *** Suite Setup Prepare Suite Test Environment Suite Teardown Clean Suite Test Environment Test Teardown Clean Test Environment Force Tags TSCSetting Test Timeout 5 minutes Metadata Author xuan_qi Metadata Date 2015/3/12 Library Operating System Library TSCSetting.py Library TestIDCELib Library FileAndFolder Variables ../../../Libs/ConfigIDCE.py *** Variables *** ${TARGET_FOLDER} /Users/mac/TestIDCE/testenv/target/TSCSetting *** Test Cases *** tscsetting001 [Documentation] *change debug dir by TestiDCE set tsc setting and expect can work* copyfile /users/mac/TestIDCE/samples/process/normal/TestDaemon_1 ${TARGET_FOLDER}/TestDaemon_1 create directory ${TARGET_FOLDER}/debug TSCSetting ${TEST_NAME} -DebugDir=${TARGET_FOLDER}/debug log_decryptor_with_logFolder ${TARGET_FOLDER}/debug log should contain ${TARGET_FOLDER}/debug/TSCDebug2.log file_del.*ret=1 ${1} File Should Not Exist ${TARGET_FOLDER}/TestDaemon_1 tscsetting002 [Documentation] *change backup dir by TestiDCE set tsc setting and expect can work* copyfile /users/mac/TestIDCE/samples/process/normal/TestDaemon_1 ${TARGET_FOLDER}/TestDaemon_1 create directory ${TARGET_FOLDER}/backup TSCSetting ${TEST_NAME} -BackupDir=${TARGET_FOLDER}/backup debug log should contain BACKUPMODE:Dir=\\[${TARGET_FOLDER}/backup\\] Directory Should Not Be Empty ${TARGET_FOLDER}/backup File Should Not Exist ${TARGET_FOLDER}/TestDaemon_1 [Teardown] Clean 002 Test Environment ${TARGET_FOLDER}/backup tscsetting003 [Documentation] *set report dir by TestiDCE set tsc setting and expect can work* copyfile /users/mac/TestIDCE/samples/process/normal/TestDaemon_1 ${TARGET_FOLDER}/TestDaemon_1 create directory ${TARGET_FOLDER}/report TSCSetting ${TEST_NAME} -ReportDir=${TARGET_FOLDER}/report debug log should contain file_del.*ret=1 ${1} Directory Should Not Be Empty ${TARGET_FOLDER}/report File Should Not Exist ${TARGET_FOLDER}/TestDaemon_1 tscsetting004 [Documentation] *set pattern dir by TestiDCE set tsc setting and expect can work* copy file /users/mac/TestIDCE/samples/process/normal/TestDaemon_1 ${TARGET_FOLDER}/TestDaemon_1 create directory ${TARGET_FOLDER}/PatternDir copy file ${TESTENV_DIR}/TSCSetting.ptn ${TARGET_FOLDER}/PatternDir TSCSetting ${TEST_NAME} -ptnpath=${TARGET_FOLDER}/PatternDir #copy file ${TESTENV_DIR}/TSCSetting.ptn ${TESTENV_DIR}/tsc.ptn debug log should contain file_del.*ret=1 ${1} report log should contain ${TARGET_FOLDER}/PatternDir/TSCSetting.ptn File Should Not Exist ${TARGET_FOLDER}/TestDaemon_1 tscsetting005 [Documentation] *set maxbackupfilenumber=1 by TestiDCE set tsc setting and expect can work* copy file ${SAMPLE_DIR}/file/normal.txt ${TARGET_FOLDER}/1.txt copy file ${SAMPLE_DIR}/file/normal.txt ${TARGET_FOLDER}/2.txt copy file ${SAMPLE_DIR}/file/normal.txt ${TARGET_FOLDER}/3.txt TSCSetting ${TEST_NAME} -BackupFileNumber=${1} debug log should contain file_del.*ret=1 ${3} #debug log should contain BackupFile.*${TARGET_FOLDER} ${1} directory should be empty ${TARGET_FOLDER} restore_TSCSetting ${TEST_NAME} file should exist ${TARGET_FOLDER}/1.txt file should not exist ${TARGET_FOLDER}/2.txt file should not exist ${TARGET_FOLDER}/3.txt file should be equal ${TARGET_FOLDER}/1.txt ${SAMPLE_DIR}/file/normal.txt tscsetting006 [Documentation] *set maxbackupfileitemsize=1 by TestiDCE set tsc setting and expect can work* copy file ${SAMPLE_DIR}/file/normal.txt ${TARGET_FOLDER}/normal.txt create specified size file ${TARGET_FOLDER}/second.txt ${2} TSCSetting ${TEST_NAME} -BackupFileItemSize=${1} directory should be empty ${TARGET_FOLDER} directory should not be empty /Users/mac/TestIDCE/testenv/backup restore_TSCSetting ${TEST_NAME} file should exist ${TARGET_FOLDER}/normal.txt file should not exist ${TARGET_FOLDER}/second.txt file should be equal ${TARGET_FOLDER}/normal.txt ${SAMPLE_DIR}/file/normal.txt tscsetting007 [Documentation] *set maxdebuglogfilenumber by TestiDCE set tsc setting and expect can work* copy file ${SAMPLE_DIR}/file/normal.txt ${TARGET_FOLDER}/normal.txt TSCSetting ${TEST_NAME} -DebuglogFileNumber=3 -superlab -loop=5 ${count}= Count Files In Directory /Users/mac/TestIDCE/testenv/debug debug_*.log Should Be Equal ${${count}+${1}} ${5} Command log should contain Execute Time: ${5} ${count1}= Count Files In Directory /Users/mac/TestIDCE/testenv/debug *_0_*.log ${count2}= Count Files In Directory /Users/mac/TestIDCE/testenv/debug *_1_*.log Should Be Equal ${count1} ${0} Should Be Equal ${count2} ${1} tscsetting008 [Documentation] *For Coverage Test, to hit ExistPatternMapping* copyfile /users/mac/TestIDCE/samples/process/normal/TestDaemon_1 ${TARGET_FOLDER}/TestDaemon_1 TSCSetting ${TEST_NAME} -initDCEEX *** Keywords *** Clean Test Environment Empty Directory ${TARGET_FOLDER} Prepare Suite Test Environment Create Directory ${TARGET_FOLDER} #Copy File /Users/mac/TestIDCE/testcases/DCEIniAndLib/TSCSetting/TSCSetting.ptn /Users/mac/TestIDCE/testenv/TSCSetting.ptn Build Pattern /Users/mac/TestIDCE/testcases/DCEIniAndLib/TSCSetting/TSCSetting.in Clean Suite Test Environment Clean Test Environment Remove Directory ${TARGET_FOLDER} remove file /users/mac/TestIDCE/testenv/tsc.ptn Clean 002 Test Environment [Arguments] ${arg1} Force Del Folders ${arg1}