Best Python code snippet using avocado_python
rule_texts_for_tests.py
Source:rule_texts_for_tests.py
1rule_files = {}2rule_files['irods_rule_engine_plugin-irods_rule_language'] = 'core.re'3rule_files['irods_rule_engine_plugin-python'] = 'core.py'4rule_texts = {}5#==============================================================6#==================== iRODS Rule Language =====================7#==============================================================8rule_texts['irods_rule_engine_plugin-irods_rule_language'] = {}9#===== Test_IAdmin =====10rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Iadmin'] = {}11rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Iadmin'] ['test_msiset_default_resc__2712'] = ''' 12acSetRescSchemeForCreate{13 msiSetDefaultResc('TestResc', 'forced');14}15'''16rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Iadmin'] ['test_host_access_control'] = ''' 17acChkHostAccessControl {18 msiCheckHostAccessControl;19}20'''21rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Iadmin'] ['test_issue_2420'] = ''' 22acAclPolicy {23 ON($userNameClient == "quickshare") { }24}25'''26#===== Test_AllRules =====27rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_AllRules'] = {}28rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_AllRules']['test_msiTarFileExtract_big_file__issue_4118'] = '''29myTestRule {{30 msiTarFileExtract(*File,*Coll,*Resc,*Status);31 writeLine("stdout","Extract files from a tar file *File into collection *Coll on resource *Resc");32}}33INPUT *File="{logical_path_to_tar_file}", *Coll="{logical_path_to_untar_coll}", *Resc="demoResc"34OUTPUT ruleExecOut35'''36#===== Test_ICommands_File_Operations =====37rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ICommands_File_Operations'] = {}38rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ICommands_File_Operations'] ['test_delay_in_dynamic_pep__3342'] = ''' 39pep_resource_write_post(*A,*B,*C,*D,*E) {40 delay("<PLUSET>1s</PLUSET>") {41 writeLine("serverLog","dynamic pep in delay");42 }43}44'''45rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ICommands_File_Operations'] ['test_iput_bulk_check_acpostprocforput__2841'] = ''' 46acBulkPutPostProcPolicy { 47 msiSetBulkPutPostProcPolicy("on"); 48}49acPostProcForPut { 50 writeLine("serverLog", "acPostProcForPut called for $objPath"); 51}52'''53rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ICommands_File_Operations'] ['test_iput_resc_scheme_forced'] = ''' 54acSetRescSchemeForCreate { 55 msiSetDefaultResc("demoResc","forced"); 56}57'''58rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ICommands_File_Operations'] ['test_iput_resc_scheme_preferred'] = ''' 59acSetRescSchemeForCreate { 60 msiSetDefaultResc("demoResc","preferred"); 61}62'''63rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ICommands_File_Operations'] ['test_iput_resc_scheme_null'] = ''' 64acSetRescSchemeForCreate { 65 msiSetDefaultResc("demoResc","null"); 66}67'''68#===== Test_Native_Rule_Engine_Plugin =====69rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin'] = {}70rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_network_pep'] = '''71pep_network_agent_start_pre(*INST,*CTX,*OUT) {72 *OUT = "THIS IS AN OUT VARIABLE"73}74pep_network_agent_start_post(*INST,*CTX,*OUT){75 writeLine( 'serverLog', '*OUT')76}77'''78rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_auth_pep'] = '''79pep_resource_resolve_hierarchy_pre(*INSTANCE,*CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){80 *OUT = "THIS IS AN OUT VARIABLE"81}82pep_resource_resolve_hierarchy_post(*INSTANCE,*CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){83 writeLine( 'serverLog', '*OUT')84}85'''86rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_out_variable'] = '''87pep_resource_resolve_hierarchy_pre(*INSTANCE,*CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){88 *OUT = "THIS IS AN OUT VARIABLE"89}90pep_resource_resolve_hierarchy_post(*INSTANCE,*CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){91 writeLine( 'serverLog', '*OUT')92}93'''94rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_re_serialization'] = '''95pep_resource_resolve_hierarchy_pre(*INSTANCE,*CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){96 writeLine("serverLog", "pep_resource_resolve_hierarchy_pre - [*INSTANCE] [*CONTEXT] [*OUT] [*OPERATION] [*HOST] [*PARSER] [*VOTE]");97}98'''99rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_api_plugin'] = '''100pep_api_hello_world_pre(*INST, *OUT, *HELLO_IN, *HELLO_OUT) {101 writeLine("serverLog", "pep_api_hello_world_pre - *INST *OUT *HELLO_IN, *HELLO_OUT");102}103pep_api_hello_world_post(*INST, *OUT, *HELLO_IN, *HELLO_OUT) {104 writeLine("serverLog", "pep_api_hello_world_post - *INST *OUT *HELLO_IN, *HELLO_OUT");105} 106'''107rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_out_string'] = '''108test(*OUT) { *OUT = "this_is_the_out_string"; }109acPostProcForPut {110 test(*out_string);111 writeLine("serverLog", "out_string = *out_string");112}113'''114rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2242_1'] = '''115test { 116 $userNameClient = "foobar";117}118 119INPUT *A="status"120OUTPUT ruleExecOut121'''122rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2242_2'] = '''123test {124 $status = \"1\";125}126 127acPreProcForWriteSessionVariable(*x) {128 writeLine(\"stdout\", \"bwahahaha\");129 succeed;130}131INPUT *A=\"status\"132OUTPUT ruleExecOut133'''134rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2309_1'] = '''135acSetNumThreads() {136 writeLine("serverLog", "test_rule_engine_2309: put: acSetNumThreads oprType [$oprType]");137}138'''139rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2309_2'] = '''140acSetNumThreads() {141 writeLine("serverLog", "test_rule_engine_2309: get: acSetNumThreads oprType [$oprType]");142}143'''144rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Native_Rule_Engine_Plugin']['test_msiSegFault'] = '''145test_msiSegFault {{146 writeLine("stdout", "We are about to segfault...");147 msiSegFault();148 writeLine("stdout", "You should never see this line.");149}}150OUTPUT ruleExecOut151'''152#===== Test_Quotas =====153rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Quotas'] = {}154rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Quotas']['test_iquota__3044'] = '''155acRescQuotaPolicy {156 msiSetRescQuotaPolicy("on");157}158'''159#===== Test_Resource_Compound =====160rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound'] = {}161rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound']['test_msiDataObjRsync__2976'] = '''162test_msiDataObjRepl {{163 *err = errormsg( msiDataObjRsync(*SourceFile,"IRODS_TO_IRODS",*Resource,*DestFile,*status), *msg );164 if( 0 != *err ) {{165 writeLine( "stdout", "*err - *msg" );166 }}167}}168INPUT *SourceFile="{logical_path}", *Resource="{dest_resc}", *DestFile="{logical_path_rsync}"169OUTPUT ruleExecOut170'''171rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound']['test_msiCollRsync__2976'] = '''172test_msiCollRepl {{173 *err = errormsg( msiCollRsync(*SourceColl,*DestColl,*Resource,"IRODS_TO_IRODS",*status), *msg );174 if( 0 != *err ) {{175 writeLine( "stdout", "*err - *msg" );176 }}177}}178INPUT *SourceColl="{logical_path}", *Resource="{dest_resc}", *DestColl="{logical_path_rsync}"179OUTPUT ruleExecOut180'''181rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound']['test_msiDataObjUnlink__2983'] = '''182test_msiDataObjUnlink {{183 *err = errormsg( msiDataObjUnlink("objPath=*SourceFile++++unreg=",*Status), *msg );184 if( 0 != *err ) {{185 writeLine( "stdout", "*err - *msg" );186 }}187}}188INPUT *SourceFile="{logical_path}"189OUTPUT ruleExecOut190'''191rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound']['test_msiDataObjRepl_as_admin__2988'] = '''192test_msiDataObjRepl {{ 193 *err = errormsg( msiDataObjRepl(*SourceFile,"destRescName=*Resource++++irodsAdmin=",*Status), *msg );194 if( 0 != *err ) {{195 writeLine( "stdout", "*err - *msg" );196 }}197}}198 199INPUT *SourceFile="{logical_path}", *Resource="{dest_resc}"200OUTPUT ruleExecOut201'''202rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound']['test_msisync_to_archive__2962'] = '''203test_msisync_to_archive {{204 *err = errormsg( msisync_to_archive(*RescHier,*PhysicalPath,*LogicalPath), *msg );205 if( 0 != *err ) {{206 writeLine( "stdout", "*err - *msg" );207 }}208}}209INPUT *LogicalPath="{logical_path}", *PhysicalPath="{physical_path}",*RescHier="{resc_hier}"210OUTPUT ruleExecOut211'''212rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound']['test_iget_prefer_from_archive_corrupt_archive__ticket_3145'] = '''213pep_resource_resolve_hierarchy_pre(*INSTANCE, *CONTEXT, *OUT, *OPERATION, *HOST, *PARSER, *VOTE){214 *OUT="compound_resource_cache_refresh_policy=always";215}216'''217rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Compound']['test_iget_prefer_from_archive__ticket_1660'] = '''218pep_resource_resolve_hierarchy_pre(*INSTANCE, *CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){219 *OUT="compound_resource_cache_refresh_policy=always";220}221'''222#===== Test_Resource_ReplicationToTwoCompound =====223rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_ReplicationToTwoCompound'] = {}224rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_ReplicationToTwoCompound']['test_iget_prefer_from_archive__ticket_1660'] = '''225pep_resource_resolve_hierarchy_pre(*INSTANCE, *CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){226 *OUT="compound_resource_cache_refresh_policy=always";227}228'''229#===== Test_Resource_ReplicationToTwoCompoundResourcesWithPreferArchive ====230rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_ReplicationToTwoCompoundResourcesWithPreferArchive'] = {}231rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_ReplicationToTwoCompoundResourcesWithPreferArchive']['setUp'] = '''232pep_resource_resolve_hierarchy_pre(*INSTANCE, *CONTEXT,*OUT,*OPERATION,*HOST,*PARSER,*VOTE){233 *OUT="compound_resource_cache_refresh_policy=always";234}235'''236#===== Test_Resource_Session_Vars__3024 =====237rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Session_Vars__3024'] = {}238rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Session_Vars__3024']['test_acPreprocForDataObjOpen'] = '''239test_{pep_name} {{240 msiDataObjOpen("{target_obj}", *FD);241 msiDataObjClose(*FD, *Status);242}}243INPUT null244OUTPUT ruleExecOut245'''246rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Session_Vars__3024']['test_acPostProcForOpen'] = '''247test_{pep_name} {{248 msiDataObjOpen("{target_obj}", *FD);249 msiDataObjClose(*FD, *Status);250}}251INPUT null252OUTPUT ruleExecOut253'''254rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Session_Vars__3024']['test_acSetNumThreads'] = '''msiSetNumThreads("default", "0", "default");255'''256#===== Test_Resource_Unixfilesystem =====257rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Unixfilesystem'] = {}258rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Resource_Unixfilesystem']['test_msi_update_unixfilesystem_resource_free_space_and_acPostProcForParallelTransferReceived'] = '''259acPostProcForParallelTransferReceived(*leaf_resource) {260 msi_update_unixfilesystem_resource_free_space(*leaf_resource);261}262'''263#===== Test_Rulebase =====264rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase'] = {}265rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_client_server_negotiation__2564'] = '''266acPreConnect(*OUT) {267 *OUT = 'CS_NEG_REQUIRE';268}269'''270rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_msiDataObjWrite__2795_1'] = '''271test_msiDataObjWrite__2795 {272 ### write a string to a file in irods273 msiDataObjCreate("*TEST_ROOT" ++ "/test_file.txt","null",*FD);274 msiDataObjWrite(*FD,"this_is_a_test_string",*LEN);275 msiDataObjClose(*FD,*Status);276}277INPUT *TEST_ROOT="'''278rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_msiDataObjWrite__2795_2'] = '''"279OUTPUT ruleExecOut280'''281rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_irods_re_infinite_recursion_3169'] = '''282call_with_wrong_number_of_string_arguments(*A, *B, *C) {283}284acPostProcForPut {285 call_with_wrong_number_of_string_arguments("a", "b");286}287acPostProcForPut { }288'''289rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_acPostProcForPut_replicate_to_multiple_resources'] = '''290# multiple replication rule291replicateMultiple(*destRgStr) {292 *destRgList = split(*destRgStr, ',');293 writeLine("serverLog", " acPostProcForPut multiple replicate $objPath $filePath -> *destRgStr");294 foreach (*destRg in *destRgList) {295 writeLine("serverLog", " acPostProcForPut replicate $objPath $filePath -> *destRg");296 *e = errorcode(msiSysReplDataObj(*destRg,"null"));297 if (*e != 0) {298 if(*e == -808000) {299 writeLine("serverLog", "$objPath cannot be found");300 $status = 0;301 succeed;302 } else {303 fail(*e);304 }305 }306 }307}308acPostProcForPut {309 replicateMultiple( "r1, r2" )310}311'''312rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_dynamic_pep_with_rscomm_usage'] = '''313pep_resource_open_pre(*OUT, *FOO, *BAR) {314 msiGetSystemTime( *junk, '' );315}316'''317rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_rulebase_update__2585_1'] = '''318my_rule {319 delay("<PLUSET>1s</PLUSET>") {320 do_some_stuff();321 }322}323INPUT null324OUTPUT ruleExecOut325'''326rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_rulebase_update__2585_2'] = '''327do_some_stuff() {328 writeLine("serverLog", "TEST_STRING_TO_FIND_1_2585");329}330'''331rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_rulebase_update__2585_3'] = '''332do_some_stuff() {333 writeLine("serverLog", "TEST_STRING_TO_FIND_2_2585");334}335'''336rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_rulebase_update_without_delay_1'] = '''337my_rule {338 do_some_stuff();339}340INPUT null341OUTPUT ruleExecOut342'''343rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_rulebase_update_without_delay_2'] = '''344do_some_stuff() {345 writeLine("serverLog", "TEST_STRING_TO_FIND_1_NODELAY");346}347'''348rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_rulebase_update_without_delay_3'] = '''349do_some_stuff() {350 writeLine("serverLog", "TEST_STRING_TO_FIND_2_NODELAY");351}352'''353rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Rulebase']['test_argument_preservation__3236'] = '''354test_msiDataObjWrite__3236 {355 msiTakeThreeArgumentsAndDoNothing(*arg1, *arg2, *arg3);356 writeLine("stdout", "AFTER arg1=*arg1 arg2=*arg2 arg3=*arg3");357} 358INPUT *arg1="abc", *arg2="def", *arg3="ghi"359OUTPUT ruleExecOut360'''361#===== Test_Remote_Exec =====362rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Remote_Exec'] = {}363rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Remote_Exec']['test_remote_no_writeline'] = '''364test_remote_no_writeLine {{365 remote("{host}", "<ZONE>{zone}</ZONE>") {{366 *a = "remote";367 }}368 writeLine("stdout", "a=*a");369}}370INPUT *a="input"371OUTPUT ruleExecOut372'''373rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Remote_Exec']['test_remote_writeline'] = '''374test_remote_writeLine {{375 remote("{host}", "<ZONE>{zone}</ZONE>") {{376 writeLine("stdout", "Remote writeLine");377 }}378}}379INPUT null380OUTPUT ruleExecOut381'''382rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Remote_Exec']['test_remote_in_remote_writeline'] = '''383test_remote_writeLine {{384 remote("{host}", "<ZONE>{zone}</ZONE>") {{385 remote("{host}", "<ZONE>{zone}</ZONE>") {{386 writeLine("stdout", "Remote in remote writeLine");387 }}388 writeLine("stdout", "Remote writeLine");389 }}390}}391INPUT null392OUTPUT ruleExecOut393'''394rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Remote_Exec']['test_remote_in_delay_writeline'] = '''395test_remote_writeLine {{396 delay("<PLUSET>1s</PLUSET>") {{397 remote("{host}", "<ZONE>{zone}</ZONE>") {{398 writeLine("serverLog", "Remote in delay writeLine");399 }}400 writeLine("serverLog", "Delay writeLine");401 }}402}}403INPUT null404OUTPUT ruleExecOut405'''406rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Remote_Exec']['test_delay_in_remote_writeline'] = '''407test_remote_writeLine {{408 remote("{host}", "<ZONE>{zone}</ZONE>") {{409 delay("<PLUSET>1s</PLUSET>") {{410 writeLine("serverLog", "Delay in remote writeLine");411 }}412 writeLine("stdout", "Remote writeLine");413 }}414}}415INPUT null416OUTPUT ruleExecOut417'''418#===== Test_Delay_Queue =====419rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue'] = {}420rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue']['test_batch_delay_processing__3941'] = '''421test_batch_delay_processing {{422 for(*i = 0; *i < {expected_count}; *i = *i + 1) {{423 delay("<PLUSET>0.1s</PLUSET>") {{424 writeLine("serverLog", "delay *i");425 }}426 }}427}}428OUTPUT ruleExecOut429'''430rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue']['test_delay_block_with_output_param__3906'] = '''431test_delay_with_output_param {{432 delay("<PLUSET>0.1s</PLUSET>") {{433 writeLine("serverLog", "delayed rule executed");434 }}435 *status = "rule queued";436}}437INPUT null438OUTPUT *status439'''440rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue']['test_delay_queue_with_long_job'] = '''441test_delay_queue_with_long_job {{442 delay("<PLUSET>0.1s</PLUSET>") {{443 writeLine("serverLog", "Sleeping...");444 msiSleep("{long_job_run_time}", "0");445 writeLine("serverLog", "Waking!");446 }}447 for(*i = 0; *i < {delay_job_batch_size}; *i = *i + 1) {{448 delay("<PLUSET>{sooner_delay}s</PLUSET>") {{449 writeLine("serverLog", "sooner: *i");450 }}451 }}452 for(*i = 0; *i < {delay_job_batch_size}; *i = *i + 1) {{453 delay("<PLUSET>{later_delay}s</PLUSET>") {{454 writeLine("serverLog", "later: *i");455 }}456 }}457}}458OUTPUT ruleExecOut459'''460rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue']['test_delay_queue_connection_refresh'] = '''461test_delay_queue_with_long_job {{462 delay("<PLUSET>0.1s</PLUSET>") {{463 writeLine("serverLog", "sleep 1...");464 msiSleep("{sleep_time}", "0");465 writeLine("serverLog", "wakeup 1!");466 }}467 delay("<PLUSET>0.1s</PLUSET>") {{468 writeLine("serverLog", "sleep 2...");469 msiSleep("{sleep_time}", "0");470 writeLine("serverLog", "wakeup 2!");471 }}472}}473OUTPUT ruleExecOut474'''475rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue']['test_failed_delay_job'] = '''476test_delay_with_output_param {{477 delay("<PLUSET>0.1s</PLUSET>") {{478 writeLine("serverLog", "We are about to fail...");479 msiGoodFailure();480 writeLine("serverLog", "You should never see this line.");481 }}482 writeLine("stdout", "rule queued");483}}484OUTPUT ruleExecOut485'''486rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue']['test_sigpipe_in_delay_server'] = '''487test_sigpipe_in_delay_server {{488 delay("<PLUSET>0.1s</PLUSET>") {{489 writeLine("serverLog", "We are about to segfault...");490 msiSegFault();491 writeLine("serverLog", "You should never see this line.");492 }}493 delay("<PLUSET>{longer_delay_time}s</PLUSET>") {{494 writeLine("serverLog", "Follow-up rule executed later!");495 }}496 writeLine("stdout", "rule queued");497}}498OUTPUT ruleExecOut499'''500rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Delay_Queue']['test_exception_in_delay_server'] = '''501test_exception_in_delay_server {{502 delay("<PLUSET>0.1s</PLUSET>") {{503 writeLine("serverLog", "Sleeping now...");504 msiSleep("{sleep_time}", "0");505 msiSegFault();506 }}507 delay("<PLUSET>{longer_delay_time}s</PLUSET>") {{508 writeLine("serverLog", "Follow-up rule executed later!");509 }}510}}511OUTPUT ruleExecOut512'''513#===== Test_Execution_Frequency =====514rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Execution_Frequency'] = {}515rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Execution_Frequency']['test_repeat_n_times'] = '''516test_delay_with_output_param {{517 delay("<PLUSET>{repeat_delay}s</PLUSET><EF>{repeat_delay}s REPEAT {repeat_n} TIMES</EF>") {{518 writeLine("serverLog", "{repeat_string}");519 }}520}}521INPUT null522OUTPUT *status523'''524rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_Execution_Frequency']['test_double_n_times'] = '''525test_delay_with_output_param {{526 delay("<PLUSET>{repeat_delay}s</PLUSET><EF>{repeat_delay}s DOUBLE {repeat_n} TIMES</EF>") {{527 writeLine("serverLog", "{repeat_string}");528 }}529}}530INPUT null531OUTPUT *status532'''533#==============================================================534#========================== Python ============================535#==============================================================536rule_texts['irods_rule_engine_plugin-python'] = {}537#===== Test_IAdmin =====538rule_texts['irods_rule_engine_plugin-python']['Test_Iadmin'] = {}539rule_texts['irods_rule_engine_plugin-python']['Test_Iadmin'] ['test_msiset_default_resc__2712'] = ''' 540def acSetRescSchemeForCreate(rule_args, callback, rei):541 callback.msiSetDefaultResc('TestResc', 'forced');542'''543rule_texts['irods_rule_engine_plugin-python']['Test_Iadmin'] ['test_host_access_control'] = ''' 544def acChkHostAccessControl(rule_args, callback, rei):545 callback.msiCheckHostAccessControl()546'''547rule_texts['irods_rule_engine_plugin-python']['Test_Iadmin'] ['test_issue_2420'] = ''' 548def acAclPolicy(rule_args, callback, rei):549 userNameClient = str(rei.uoic.userName if rei.uoic else rei.rsComm.clientUser.userName)550 if (userNameClient == 'quickshare'):551 pass552'''553# ON($userNameClient == "quickshare") { }554#===== Test_ICommands_File_Operations =====555rule_texts['irods_rule_engine_plugin-python']['Test_ICommands_File_Operations'] = {}556rule_texts['irods_rule_engine_plugin-python']['Test_ICommands_File_Operations'] ['test_re_serialization__prep_13'] = '''557def pep_resource_create_post(rule_args,callback,rei):558 d = rule_args[1].map()559 callback.writeLine("serverLog","physical_path=" + d["physical_path"] + " ") # write out variables from pluginContext560 callback.writeLine("serverLog","logical_path=" + d["logical_path"] + " ")561 callback.writeLine("serverLog","proxy_user_name=" + d["proxy_user_name"] + " ")562'''563rule_texts['irods_rule_engine_plugin-python']['Test_ICommands_File_Operations'] ['test_delay_in_dynamic_pep__3342'] = ''' 564def pep_resource_write_post(rule_args, callback, rei):565 callback.delayExec('<PLUSET>1s</PLUSET>', 'callback.writeLine("serverLog", "dynamic pep in delay")', '')566'''567rule_texts['irods_rule_engine_plugin-python']['Test_ICommands_File_Operations'] ['test_iput_bulk_check_acpostprocforput__2841'] = ''' 568def acBulkPutPostProcPolicy(rule_args, callback, rei):569 callback.msiSetBulkPutPostProcPolicy('on'); 570def acPostProcForPut(rule_args, callback, rei):571 obj_path = str(rei.doi.objPath if rei.doi else rei.doinp.objPath)572 callback.writeLine('serverLog', 'acPostProcForPut called for ' + obj_path); 573'''574rule_texts['irods_rule_engine_plugin-python']['Test_ICommands_File_Operations'] ['test_iput_resc_scheme_forced'] = ''' 575def acSetRescSchemeForCreate(rule_args, callback, rei):576 callback.msiSetDefaultResc('demoResc','forced'); 577'''578rule_texts['irods_rule_engine_plugin-python']['Test_ICommands_File_Operations'] ['test_iput_resc_scheme_preferred'] = ''' 579def acSetRescSchemeForCreate(rule_args, callback, rei):580 callback.msiSetDefaultResc('demoResc','preferred'); 581'''582rule_texts['irods_rule_engine_plugin-python']['Test_ICommands_File_Operations'] ['test_iput_resc_scheme_null'] = ''' 583def acSetRescSchemeForCreate(rule_args, callback, rei): 584 callback.msiSetDefaultResc('demoResc','null');585'''586#===== Test_Native_Rule_Engine_Plugin =====587rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin'] = {}588rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_remote_rule_execution'] = '''589def main(rule_args, callback, rei):590 rule_code = "def main(rule_args, callback, rei):\\n print('XXXX - PREP REMOTE EXEC TEST')"591 callback.py_remote('icat.example.org', '', rule_code, '')592INPUT null593OUTPUT ruleExecOut594'''595rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_network_pep'] = '''596def pep_network_agent_start_pre(rule_args, callback, rei):597 rule_args[2] = 'THIS IS AN OUT VARIABLE'598def pep_network_agent_start_post(rule_args, callback, rei):599 callback.writeLine('serverLog', rule_args[2])600'''601rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_auth_pep'] = '''602def pep_resource_resolve_hierarchy_pre(rule_args, callback, rei):603 rule_args[2] = 'THIS IS AN OUT VARIABLE'604def pep_resource_resolve_hierarchy_post(rule_args, callback, rei):605 callback.writeLine('serverLog', rule_args[2])606'''607rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_out_variable'] = '''608def pep_resource_resolve_hierarchy_pre(rule_args, callback, rei):609 rule_args[2] = 'THIS IS AN OUT VARIABLE'610def pep_resource_resolve_hierarchy_post(rule_args, callback, rei):611 callback.writeLine('serverLog', rule_args[2])612'''613rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_re_serialization'] = '''614def pep_resource_resolve_hierarchy_pre(rule_args, callback, rei):615 callback.writeLine('serverLog', 'pep_resource_resolve_hierarchy_pre - [{0}] [{1}] [{2}] [{3}] [{4}] [{5}] [{6}]'.format(rule_args[0], rule_args[1], rule_args[2], rule_args[3], rule_args[4], rule_args[5], rule_args[6]))616'''617rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_api_plugin'] = '''618def pep_api_hello_world_pre(rule_args, callback, rei):619 hello_inp = rule_args[2]620 hello_inp_string = ', '.join([k + '=' + hello_inp[k] for k in hello_inp])621 hello_out = rule_args[3]622 hello_out_string = ', '.join([k + '=' + hello_out[k] for k in hello_out])623 callback.writeLine('serverLog', 'pep_api_hello_world_pre - {0} {1} {2}, {3}'.format(rule_args[0], rule_args[1], hello_inp_string, hello_out_string))624def pep_api_hello_world_post(rule_args, callback, rei):625 hello_inp = rule_args[2]626 hello_inp_string = ', '.join([k + '=' + hello_inp[k] for k in hello_inp])627 hello_out = rule_args[3]628 hello_out_string = ', '.join([k + '=' + hello_out[k] for k in hello_out])629 callback.writeLine('serverLog', 'pep_api_hello_world_post - {0} {1} {2}, {3}'.format(rule_args[0], rule_args[1], hello_inp_string, hello_out_string))630'''631rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_out_string'] = '''632def test(rule_args, callback, rei):633 rule_args[0] = 'this_is_the_out_string'634def acPostProcForPut(rule_args, callback, rei):635 callback.writeLine("serverLog", callback.test('')['arguments'][0]);636'''637# SKIP TEST test_rule_engine_2242 FOR PYTHON RULE LANGUAGE638# Python REP can't update session vars639#rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2242_1'] = '''640#test { 641# $userNameClient = "foobar";642#}643# 644#INPUT *A="status"645#OUTPUT ruleExecOut646#'''647#rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2242_2'] = '''648#test {649# $status = \"1\";650#}651# 652#acPreProcForWriteSessionVariable(*x) {653# writeLine(\"stdout\", \"bwahahaha\");654# succeed;655#}656#657#INPUT *A=\"status\"658#OUTPUT ruleExecOut659#'''660rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2309_1'] = '''661def acSetNumThreads(rule_args, callback, rei):662 opr_type = str(rei.doinp.oprType)663 callback.writeLine('serverLog', 'test_rule_engine_2309: put: acSetNumThreads oprType [' + str(opr_type) + ']')664'''665rule_texts['irods_rule_engine_plugin-python']['Test_Native_Rule_Engine_Plugin']['test_rule_engine_2309_2'] = '''666def acSetNumThreads(rule_args, callback, rei):667 opr_type = str(rei.doinp.oprType)668 callback.writeLine('serverLog', 'test_rule_engine_2309: get: acSetNumThreads oprType [' + str(opr_type) + ']')669'''670#===== Test_Quotas =====671rule_texts['irods_rule_engine_plugin-python']['Test_Quotas'] = {}672rule_texts['irods_rule_engine_plugin-python']['Test_Quotas']['test_iquota__3044'] = '''673def acRescQuotaPolicy(rule_args, callback, rei):674 callback.msiSetRescQuotaPolicy('on')675'''676#===== Test_Resource_Compound =====677rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound'] = {}678rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound']['test_msiDataObjRsync__2976'] = '''def main(rule_args, callback, rei):679 out_dict = callback.msiDataObjRsync(global_vars['*SourceFile'][1:-1], 'IRODS_TO_IRODS', global_vars['*Resource'][1:-1], global_vars['*DestFile'][1:-1], 0)680 if not out_dict['status']:681 callback.writeLine('stdout', 'ERROR: ' + str(out_dict['code']))682INPUT *SourceFile="{logical_path}", *Resource="{dest_resc}", *DestFile="{logical_path_rsync}"683OUTPUT ruleExecOut684'''685rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound']['test_msiCollRsync__2976'] = '''def main(rule_args, callback, rei):686 out_dict = callback.msiCollRsync(global_vars['*SourceColl'][1:-1], global_vars['*DestColl'][1:-1], global_vars['*Resource'][1:-1], 'IRODS_TO_IRODS', 0)687 if not out_dict['status']:688 callback.writeLine('stdout', 'ERROR: ' + str(out_dict['code']))689INPUT *SourceColl="{logical_path}", *Resource="{dest_resc}", *DestColl="{logical_path_rsync}"690OUTPUT ruleExecOut691'''692rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound']['test_msiDataObjUnlink__2983'] = '''def main(rule_args, callback, rei):693 out_dict = callback.msiDataObjUnlink('objPath=' + global_vars['*SourceFile'][1:-1] + '++++unreg=', 0)694 if not out_dict['status']:695 callback.writeLine('stdout', 'ERROR: ' + str(out_dict['code']))696INPUT *SourceFile="{logical_path}"697OUTPUT ruleExecOut698'''699rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound']['test_msiDataObjRepl_as_admin__2988'] = '''def main(rule_args, callback, rei):700 out_dict = callback.msiDataObjRepl(global_vars['*SourceFile'][1:-1], 'destRescName=' + global_vars['*Resource'][1:-1] + '++++irodsAdmin=', 0)701 if not out_dict['status']:702 callback.writeLine('stdout', 'ERROR: ' + str(out_dict['code']))703INPUT *SourceFile="{logical_path}", *Resource="{dest_resc}"704OUTPUT ruleExecOut705'''706rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound']['test_msisync_to_archive__2962'] = '''def main(rule_args, callback, rei):707 out_dict = callback.msisync_to_archive(global_vars['*RescHier'][1:-1], global_vars['*PhysicalPath'][1:-1], global_vars['*LogicalPath'][1:-1])708 if not out_dict['status']:709 callback.writeLine('stdout', 'ERROR: ' + str(out_dict['code']))710 711INPUT *LogicalPath="{logical_path}", *PhysicalPath="{physical_path}",*RescHier="{resc_hier}"712OUTPUT ruleExecOut713'''714rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound']['test_iget_prefer_from_archive_corrupt_archive__ticket_3145'] = '''715def pep_resource_resolve_hierarchy_pre(rule_args, callback, rei):716 rule_args[2] = 'compound_resource_cache_refresh_policy=always'717'''718rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Compound']['test_iget_prefer_from_archive__ticket_1660'] = '''719def pep_resource_resolve_hierarchy_pre(rule_args, callback, rei):720 rule_args[2] = 'compound_resource_cache_refresh_policy=always'721'''722#===== Test_Resource_ReplicationToTwoCompound =====723rule_texts['irods_rule_engine_plugin-python']['Test_Resource_ReplicationToTwoCompound'] = {}724rule_texts['irods_rule_engine_plugin-python']['Test_Resource_ReplicationToTwoCompound']['test_iget_prefer_from_archive__ticket_1660'] = '''725def pep_resource_resolve_hierarchy_pre(rule_args, callback, rei):726 rule_args[2] = 'compound_resource_cache_refresh_policy=always'727'''728#===== Test_Resource_ReplicationToTwoCompoundResourcesWithPreferArchive ====729rule_texts['irods_rule_engine_plugin-python']['Test_Resource_ReplicationToTwoCompoundResourcesWithPreferArchive'] = {}730rule_texts['irods_rule_engine_plugin-python']['Test_Resource_ReplicationToTwoCompoundResourcesWithPreferArchive']['setUp'] = '''731def pep_resource_resolve_hierarchy_pre(rule_args, callback, rei):732 rule_args[2] = 'compound_resource_cache_refresh_policy=always'733'''734#===== Test_Resource_Session_Vars__3024 =====735rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Session_Vars__3024'] = {}736rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Session_Vars__3024']['test_acPreprocForDataObjOpen'] = '''def main(rule_args, callback, rei):737 out_dict = callback.msiDataObjOpen("{target_obj}", 0)738 file_desc = out_dict['arguments'][1]739 out_dict = callback.msiDataObjClose(file_desc, 0)740INPUT null741OUTPUT ruleExecOut742'''743rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Session_Vars__3024']['test_acPostProcForOpen'] = '''def main(rule_args, callback, rei):744 out_dict = callback.msiDataObjOpen("{target_obj}", 0)745 file_desc = out_dict['arguments'][1]746 out_dict = callback.msiDataObjClose(file_desc, 0)747INPUT null748OUTPUT ruleExecOut749'''750rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Session_Vars__3024']['test_acSetNumThreads'] = ''' callback.msiSetNumThreads('default', '0', 'default')751'''752#===== Test_Resource_Unixfilesystem =====753rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Unixfilesystem'] = {}754rule_texts['irods_rule_engine_plugin-python']['Test_Resource_Unixfilesystem']['test_msi_update_unixfilesystem_resource_free_space_and_acPostProcForParallelTransferReceived'] = '''755def acPostProcForParallelTransferReceived(rule_args, callback, rei):756 callback.msi_update_unixfilesystem_resource_free_space(rule_args[0])757'''758#===== Test_Rulebase =====759rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase'] = {}760rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_client_server_negotiation__2564'] = '''761def acPreConnect(rule_args, callback, rei):762 rule_args[0] = 'CS_NEG_REQUIRE'763'''764rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_msiDataObjWrite__2795_1'] = '''def main(rule_args, callback, rei):765 out_dict = callback.msiDataObjCreate(global_vars['*TEST_ROOT'][1:-1] + '/test_file.txt', 'null', 0)766 file_desc = out_dict['arguments'][2]767 out_dict = callback.msiDataObjWrite(file_desc, 'this_is_a_test_string', 0)768 out_dict = callback.msiDataObjClose(file_desc, 0)769INPUT *TEST_ROOT="'''770rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_msiDataObjWrite__2795_2'] = '''"771OUTPUT ruleExecOut772'''773# SKIP TEST test_irods_re_infinite_recursion_3169 for PYTHON REP774#rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_irods_re_infinite_recursion_3169'] = '''775#call_with_wrong_number_of_string_arguments(*A, *B, *C) {776#}777#778#acPostProcForPut {779# call_with_wrong_number_of_string_arguments("a", "b");780#}781#'''782rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_acPostProcForPut_replicate_to_multiple_resources'] = '''783# multiple replication rule784def replicateMultiple(dest_list, callback, rei):785 obj_path = str(rei.doi.objPath if rei.doi is not None else rei.doinp.objPath)786 filepath = str(rei.doi.filePath)787 callback.writeLine('serverLog', ' acPostProcForPut multiple replicate ' + obj_path + ' ' + filepath + ' -> ' + str(dest_list))788 for dest in dest_list:789 callback.writeLine('serverLog', 'acPostProcForPut replicate ' + obj_path + ' ' + filepath + ' -> ' + dest)790 out_dict = callback.msiSysReplDataObj(dest, 'null')791 if not out_dict['code'] == 0:792 if out_dict['code'] == -808000:793 callback.writeLine('serverLog', obj_path + ' cannot be found')794 return 0795 else:796 callback.writeLine('serverLog', 'ERROR: ' + out_dict['code'])797 return int(out_dict['code'])798def acPostProcForPut(rule_args, callback, rei):799 replicateMultiple(["r1","r2"], callback, rei)800'''801rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_dynamic_pep_with_rscomm_usage'] = '''802def pep_resource_open_pre(rule_args, callback, rei):803 retStr = ''804 callback.msiGetSystemTime( retStr, '' )805'''806rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ImetaSet'] = {}807rule_texts['irods_rule_engine_plugin-irods_rule_language']['Test_ImetaSet']['test_mod_avu_msvc_with_rodsuser_invoking_rule_4521'] = '''808test {809 msiModAVUMetadata("-C", "*homeColln","set","a1","v1","x")810 *a.a1 = "v1"811 *a.a2 = "v2"812 msiAssociateKeyValuePairsToObj(*a ,"*homeColln","-C" )813 msiModAVUMetadata("-C", "*homeColln","add","a2","v2","u2")814 printmeta("1",*b)815 msiModAVUMetadata("-C", "*homeColln","set","a2","v2","u")816 printmeta("2",*b)817 msiModAVUMetadata("-C", "*homeColln","rmw","%","%","")818 printmeta("3",*b)819 msiModAVUMetadata("-C", "*homeColln","rmw","%","%","%")820 printmeta("4",*b)821}822printmeta(*id,*z) {823 msiString2KeyValPair("",*z)824 foreach (*x in select META_COLL_ATTR_NAME,825 META_COLL_ATTR_VALUE,826 META_COLL_ATTR_UNITS827 where META_COLL_ATTR_NAME like 'a_' and828 COLL_NAME like '*homeColln') {829 *key = *x.META_COLL_ATTR_NAME ++ ":" ++ *x.META_COLL_ATTR_VALUE830 ++ ":" ++ *x.META_COLL_ATTR_UNITS831 *z.*key = "*id"832 writeLine("stdout","(*id,*key)")833 }834}835INPUT *homeColln="/$rodsZoneClient/home/$userNameClient"836OUTPUT ruleExecOut837'''838# SKIP TEST test_rulebase_update__2585 FOR NON IRODS_RULE_LANGUAGE REPS839# Only applicable if using a rule cache840#rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_rulebase_update__2585'] = '''841#my_rule {842# delay("<PLUSET>1s</PLUSET>") {843# do_some_stuff();844# }845#}846#INPUT null847#OUTPUT ruleExecOut848#'''849# SKIP TEST test_rulebase_update__2585 FOR NON IRODS_RULE_LANGUAGE REPS850# Only applicable if using a rule cache851#rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_rulebase_update_without_delay'] = '''852#my_rule {853# do_some_stuff();854#}855#INPUT null856#OUTPUT ruleExecOut857#'''858# SKIP TEST test_argument_preservation__3236 FOR PYTHON REP859# Python REP does not guarantee arguments cannot be changed860# (They're just elements in a dict)861#rule_texts['irods_rule_engine_plugin-python']['Test_Rulebase']['test_argument_preservation__3236'] = '''862#test_msiDataObjWrite__3236 {863# msiTakeThreeArgumentsAndDoNothing(*arg1, *arg2, *arg3);864# writeLine("stdout", "AFTER arg1=*arg1 arg2=*arg2 arg3=*arg3");865#} 866#INPUT *arg1="abc", *arg2="def", *arg3="ghi"867#OUTPUT ruleExecOut...
test_rulebase.py
Source:test_rulebase.py
1from __future__ import print_function2import sys3if sys.version_info >= (2, 7):4 import unittest5else:6 import unittest2 as unittest7import copy8import inspect9import json10import os11import socket12import tempfile13import time # remove once file hash fix is commited #227914import subprocess15from .. import lib16from .. import paths17from .. import test18from . import settings19from .resource_suite import ResourceBase20from ..configuration import IrodsConfig21from ..controller import IrodsController22from ..core_file import temporary_core_file23from .rule_texts_for_tests import rule_texts24def delayAssert(a, interval=1, maxrep=100):25 for i in range(maxrep):26 time.sleep(interval) # wait for test to fire27 if a():28 break29 assert a()30class Test_Rulebase(ResourceBase, unittest.TestCase):31 plugin_name = IrodsConfig().default_rule_engine_plugin32 class_name = 'Test_Rulebase'33 def setUp(self):34 super(Test_Rulebase, self).setUp()35 def tearDown(self):36 super(Test_Rulebase, self).tearDown()37 def test_client_server_negotiation__2564(self):38 with temporary_core_file() as core:39 time.sleep(1) # remove once file hash fix is committed #227940 core.add_rule(rule_texts[self.plugin_name][self.class_name][inspect.currentframe().f_code.co_name])41 time.sleep(1) # remove once file hash fix is committed #227942 client_update = {43 'irods_client_server_policy': 'CS_NEG_REFUSE'44 }45 session_env_backup = copy.deepcopy(self.admin.environment_file_contents)46 self.admin.environment_file_contents.update(client_update)47 self.admin.assert_icommand( 'ils','STDERR_SINGLELINE','CLIENT_NEGOTIATION_ERROR')48 self.admin.environment_file_contents = session_env_backup49 def test_msiDataObjWrite__2795(self):50 rule_file = "test_rule_file.r"51 rule_string = rule_texts[self.plugin_name][self.class_name]['test_msiDataObjWrite__2795_1'] + self.admin.session_collection + rule_texts[self.plugin_name][self.class_name]['test_msiDataObjWrite__2795_2']52 with open(rule_file, 'wt') as f:53 print(rule_string, file=f, end='')54 test_file = self.admin.session_collection+'/test_file.txt'55 self.admin.assert_icommand('irule -F ' + rule_file)56 self.admin.assert_icommand('ils -l','STDOUT_SINGLELINE','test_file')57 self.admin.assert_icommand('iget -f '+test_file)58 with open("test_file.txt", 'r') as f:59 file_contents = f.read()60 assert( not file_contents.endswith('\0') )61 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Skip for Python REP')62 def test_irods_re_infinite_recursion_3169(self):63 with temporary_core_file() as core:64 time.sleep(1) # remove once file hash fix is committed #227965 core.add_rule(rule_texts[self.plugin_name][self.class_name][inspect.currentframe().f_code.co_name])66 time.sleep(1) # remove once file hash fix is committed #227967 test_file = 'rulebasetestfile'68 lib.touch(test_file)69 self.admin.assert_icommand(['iput', test_file])70 def test_acPostProcForPut_replicate_to_multiple_resources(self):71 # create new resources72 hostname = socket.gethostname()73 self.admin.assert_icommand("iadmin mkresc r1 unixfilesystem " + hostname + ":/tmp/irods/r1", 'STDOUT_SINGLELINE', "Creating")74 self.admin.assert_icommand("iadmin mkresc r2 unixfilesystem " + hostname + ":/tmp/irods/r2", 'STDOUT_SINGLELINE', "Creating")75 with temporary_core_file() as core:76 time.sleep(1) # remove once file hash fix is committed #227977 core.add_rule(rule_texts[self.plugin_name][self.class_name][inspect.currentframe().f_code.co_name])78 time.sleep(1) # remove once file hash fix is committed #227979 # put data80 tfile = "rulebasetestfile"81 lib.touch(tfile)82 self.admin.assert_icommand(['iput', tfile])83 # check replicas84 self.admin.assert_icommand(['ils', '-L', tfile], 'STDOUT_MULTILINE', [' demoResc ', ' r1 ', ' r2 '])85 # clean up and remove new resources86 self.admin.assert_icommand("irm -rf " + tfile)87 self.admin.assert_icommand("iadmin rmresc r1")88 self.admin.assert_icommand("iadmin rmresc r2")89 time.sleep(2) # remove once file hash fix is commited #227990 def test_dynamic_pep_with_rscomm_usage(self):91 with temporary_core_file() as core:92 time.sleep(1) # remove once file hash fix is committed #227993 core.add_rule(rule_texts[self.plugin_name][self.class_name][inspect.currentframe().f_code.co_name])94 time.sleep(1) # remove once file hash fix is committed #227995 # check rei functioning96 self.admin.assert_icommand("iget " + self.testfile + " - ", 'STDOUT_SINGLELINE', self.testfile)97 @unittest.skipIf(test.settings.TOPOLOGY_FROM_RESOURCE_SERVER, 'Skip for topology testing from resource server: reads re server log')98 @unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-irods_rule_language', 'tests cache update - only applicable for irods_rule_language REP')99 def test_rulebase_update__2585(self):100 my_rule = rule_texts[self.plugin_name][self.class_name]['test_rulebase_update__2585_1']101 rule_file = 'my_rule.r'102 with open(rule_file, 'wt') as f:103 print(my_rule, file=f, end='')104 server_config_filename = paths.server_config_path()105 # load server_config.json to inject a new rule base106 with open(server_config_filename) as f:107 svr_cfg = json.load(f)108 # inject a new rule base into the native rule engine109 svr_cfg['plugin_configuration']['rule_engines'][0]['plugin_specific_configuration']['re_rulebase_set'] = ["test", "core"]110 # dump to a string to repave the existing server_config.json111 new_server_config=json.dumps(svr_cfg, sort_keys=True,indent=4, separators=(',', ': '))112 with lib.file_backed_up(paths.server_config_path()):113 test_re = os.path.join(paths.core_re_directory(), 'test.re')114 # write new rule file to config dir115 with open(test_re, 'wt') as f:116 print(rule_texts[self.plugin_name][self.class_name]['test_rulebase_update__2585_2'], file=f, end='')117 # repave the existing server_config.json118 with open(server_config_filename, 'w') as f:119 f.write(new_server_config)120 IrodsController().restart()121 # checkpoint log to know where to look for the string122 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())123 self.admin.assert_icommand('irule -F ' + rule_file)124 delayAssert(lambda: lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'TEST_STRING_TO_FIND_1_2585', start_index=initial_log_size))125 # repave rule with new string126 os.unlink(test_re)127 with open(test_re, 'wt') as f:128 print(rule_texts[self.plugin_name][self.class_name]['test_rulebase_update__2585_3'], file=f, end='')129 # checkpoint log to know where to look for the string130 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())131 self.admin.assert_icommand('irule -F ' + rule_file)132 delayAssert(lambda: lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'TEST_STRING_TO_FIND_2_2585', start_index=initial_log_size))133 # cleanup134 IrodsController().restart()135 os.unlink(test_re)136 os.unlink(rule_file)137 @unittest.skipIf(test.settings.TOPOLOGY_FROM_RESOURCE_SERVER, 'Skip for topology testing from resource server: reads re server log')138 @unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-irods_rule_language', 'tests cache update - only applicable for irods_rule_language REP')139 def test_update_core_multiple_agents__3184(self):140 with temporary_core_file() as core:141 for l in range(100):142 time.sleep(1) # remove once file hash fix is committed #2279143 core.add_rule("multiple_agents {}")144 time.sleep(1) # remove once file hash fix is committed #2279145 processes = []146 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())147 for i in range(100):148 processes.append(subprocess.Popen(["ils"]))149 for p in processes:150 p.wait()151 assert lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'stack trace', start_index=initial_log_size) == 0152 153 @unittest.skipIf(test.settings.TOPOLOGY_FROM_RESOURCE_SERVER, 'Skip for topology testing from resource server: reads re server log')154 @unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-irods_rule_language', 'tests cache update - only applicable for irods_rule_language REP')155 def test_fast_updates__2279(self):156 rc, _, _ = self.admin.assert_icommand("bash rulebase_fastswap_test_2276.sh", 'STDOUT_SINGLELINE', 'etc')157 assert rc == 0158 159 @unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-irods_rule_language', 'tests cache update - only applicable for irods_rule_language REP')160 def test_rulebase_update_without_delay(self):161 my_rule = rule_texts[self.plugin_name][self.class_name]['test_rulebase_update_without_delay_1']162 rule_file = 'my_rule.r'163 with open(rule_file, 'wt') as f:164 print(my_rule, file=f, end='')165 server_config_filename = paths.server_config_path()166 # load server_config.json to inject a new rule base167 with open(server_config_filename) as f:168 svr_cfg = json.load(f)169 # inject a new rule base into the native rule engine170 svr_cfg['plugin_configuration']['rule_engines'][0]['plugin_specific_configuration']['re_rulebase_set'] = ["test", "core"]171 # dump to a string to repave the existing server_config.json172 new_server_config=json.dumps(svr_cfg, sort_keys=True,indent=4, separators=(',', ': '))173 with lib.file_backed_up(paths.server_config_path()):174 test_re = os.path.join(paths.core_re_directory(), 'test.re')175 # write new rule file to config dir176 with open(test_re, 'wt') as f:177 print(rule_texts[self.plugin_name][self.class_name]['test_rulebase_update_without_delay_2'], file=f, end='')178 # repave the existing server_config.json179 with open(server_config_filename, 'w') as f:180 f.write(new_server_config)181 # checkpoint log to know where to look for the string182 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())183 self.admin.assert_icommand('irule -F ' + rule_file)184 assert lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'TEST_STRING_TO_FIND_1_NODELAY', start_index=initial_log_size)185 time.sleep(5) # ensure modify time is sufficiently different186 # repave rule with new string187 os.unlink(test_re)188 with open(test_re, 'wt') as f:189 print(rule_texts[self.plugin_name][self.class_name]['test_rulebase_update_without_delay_3'], file=f, end='')190 # checkpoint log to know where to look for the string191 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())192 self.admin.assert_icommand('irule -F ' + rule_file)193 #time.sleep(35) # wait for test to fire194 assert lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'TEST_STRING_TO_FIND_2_NODELAY', start_index=initial_log_size)195 # cleanup196 os.unlink(test_re)197 os.unlink(rule_file)198 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Python REP does not guarantee argument preservation')199 def test_argument_preservation__3236(self):200 with tempfile.NamedTemporaryFile(suffix='.r') as f:201 rule_string = rule_texts[self.plugin_name][self.class_name]['test_argument_preservation__3236']202 f.write(rule_string)203 f.flush()204 self.admin.assert_icommand('irule -F ' + f.name, 'STDOUT_SINGLELINE', 'AFTER arg1=abc arg2=def arg3=ghi')205 @unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-irods_rule_language', 'Skip for non-rule-language REP')206 def test_rulebase_update_sixty_four_chars__3560(self):207 irods_config = IrodsConfig()208 server_config_filename = irods_config.server_config_path209 # load server_config.json to inject a new rule base210 with open(server_config_filename) as f:211 svr_cfg = json.load(f)212 # inject several new rules into the native rule engine213 svr_cfg['plugin_configuration']['rule_engines'][0]['plugin_specific_configuration']['re_rulebase_set'] = [214 "rulefile1", "rulefile2", "rulefile3", "rulefile4", "rulefile5", "rulefile6", "rulefile7","rulefile8", "core"]215 # dump to a string to repave the existing server_config.json216 new_server_config = json.dumps(svr_cfg, sort_keys=True, indent=4, separators=(',', ': '))217 with lib.file_backed_up(irods_config.server_config_path):218 rulefile1 = os.path.join(irods_config.core_re_directory, 'rulefile1.re')219 rulefile2 = os.path.join(irods_config.core_re_directory, 'rulefile2.re')220 rulefile3 = os.path.join(irods_config.core_re_directory, 'rulefile3.re')221 rulefile4 = os.path.join(irods_config.core_re_directory, 'rulefile4.re')222 rulefile5 = os.path.join(irods_config.core_re_directory, 'rulefile5.re')223 rulefile6 = os.path.join(irods_config.core_re_directory, 'rulefile6.re')224 rulefile7 = os.path.join(irods_config.core_re_directory, 'rulefile7.re')225 rulefile8 = os.path.join(irods_config.core_re_directory, 'rulefile8.re')226 # write new rule files to config dir227 with open(rulefile1, 'wt') as f:228 print('dummyRule{ }', file=f, end='')229 with open(rulefile2, 'wt') as f:230 print('dummyRule{ }', file=f, end='')231 with open(rulefile3, 'wt') as f:232 print('dummyRule{ }', file=f, end='')233 with open(rulefile4, 'wt') as f:234 print('dummyRule{ }', file=f, end='')235 with open(rulefile5, 'wt') as f:236 print('dummyRule{ }', file=f, end='')237 with open(rulefile6, 'wt') as f:238 print('dummyRule{ }', file=f, end='')239 with open(rulefile7, 'wt') as f:240 print('dummyRule{ }', file=f, end='')241 with open(rulefile8, 'wt') as f:242 print('acPostProcForPut{ writeLine( "serverLog", "TEST_STRING_TO_FIND_DEFECT_3560" ); }', file=f, end='')243 # repave the existing server_config.json244 with open(server_config_filename, 'w') as f:245 f.write(new_server_config)246 IrodsController().restart()247 # checkpoint log to know where to look for the string248 initial_log_size = lib.get_file_size_by_path(irods_config.server_log_path)249 filename = "defect3560.txt"250 filepath = lib.create_local_testfile(filename)251 put_resource = self.testresc252 self.user0.assert_icommand("iput -R {put_resource} {filename}".format(**locals()), "EMPTY")253 assert lib.count_occurrences_of_string_in_log(irods_config.server_log_path,254 "TEST_STRING_TO_FIND_DEFECT_3560", start_index=initial_log_size)255 # cleanup256 IrodsController().restart()257 os.unlink(rulefile1)258 os.unlink(rulefile2)259 os.unlink(rulefile3)260 os.unlink(rulefile4)261 os.unlink(rulefile5)262 os.unlink(rulefile6)263 os.unlink(rulefile7)264 os.unlink(rulefile8)265 266 @unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-irods_rule_language', 'only applicable for irods_rule_language REP')267 def test_acPreProcForExecCmd__3867(self):268 with temporary_core_file() as core:269 core.add_rule('acPreProcForExecCmd(*cmd, *args, *addr, *hint){ writeLine("serverLog", "TEST_MARKER_test_acPreProcForExecCmd__3867")}')270 rule_file = 'test_acPreProcForExecCmd__3867.r'271 rule_string = '''272test_acPreProcForExecCmd__3867_rule {273 msiExecCmd('hello', '', '', '', '', *out)274}275INPUT null276OUTPUT ruleExecOut277'''278 with open(rule_file, 'w') as f:279 f.write(rule_string)280 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())281 self.admin.assert_icommand('irule -F ' + rule_file)282 os.unlink(rule_file)283 log_count = lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'TEST_MARKER_test_acPreProcForExecCmd__3867', start_index=initial_log_size)284 assert 1 == log_count285@unittest.skipIf(test.settings.TOPOLOGY_FROM_RESOURCE_SERVER, 'Skip for topology testing from resource server: reads rods server log')286class Test_Resource_Session_Vars__3024(ResourceBase, unittest.TestCase):287 plugin_name = IrodsConfig().default_rule_engine_plugin288 class_name = 'Test_Resource_Session_Vars__3024'289 def setUp(self):290 super(Test_Resource_Session_Vars__3024, self).setUp()291 # get PEP name292 self.pep_name = self._testMethodName.split('_')[1]293 # make large test file294 self.large_file = '/tmp/largefile'295 lib.make_file(self.large_file, '64M', 'arbitrary')296 def tearDown(self):297 del self.pep_name298 # remove large test file299 os.unlink(self.large_file)300 super(Test_Resource_Session_Vars__3024, self).tearDown()301 def test_acPostProcForPut(self):302 self.pep_test_helper(commands=['iput -f {testfile}'])303 def test_acSetNumThreads(self):304 rule_body = rule_texts[self.plugin_name][self.class_name]['test_acSetNumThreads']305 self.pep_test_helper(commands=['iput -f {large_file}'], rule_body=rule_body)306 def test_acDataDeletePolicy(self):307 self.pep_test_helper(precommands=['iput -f {testfile}'], commands=['irm -f {testfile}'])308 def test_acPostProcForDelete(self):309 self.pep_test_helper(precommands=['iput -f {testfile}'], commands=['irm -f {testfile}'])310 def test_acSetChkFilePathPerm(self):311 # regular user will try to register a system file312 # e.g: /var/lib/irods/VERSION.json313 path_to_register = paths.version_path()314 commands = [('ireg {path_to_register} {{target_obj}}'.format(**locals()), 'STDERR_SINGLELINE', 'PATH_REG_NOT_ALLOWED')]315 self.pep_test_helper(commands=commands, target_name=os.path.basename(path_to_register))316 def test_acPostProcForFilePathReg(self):317 # admin user will register a file318 sess=self.admin319 # make new physical file in user's vault320 reg_file_path = os.path.join(sess.get_vault_session_path(), 'reg_test_file')321 lib.make_dir_p(os.path.dirname(reg_file_path))322 lib.touch(reg_file_path)323 commands = ['ireg {reg_file_path} {{target_obj}}'.format(**locals())]324 self.pep_test_helper(commands=commands, target_name=os.path.basename(reg_file_path), user_session=sess)325 def test_acPostProcForCopy(self):326 self.pep_test_helper(precommands=['iput -f {testfile}'], commands=['icp {testfile} {testfile}_copy'])327 def test_acSetVaultPathPolicy(self):328 self.pep_test_helper(commands=['iput -f {testfile}'])329 def test_acPreprocForDataObjOpen(self):330 client_rule = rule_texts[self.plugin_name][self.class_name][inspect.currentframe().f_code.co_name]331 self.pep_test_helper(precommands=['iput -f {testfile}'], commands=['irule -F {client_rule_file}'], client_rule=client_rule)332 def test_acPostProcForOpen(self):333 # prepare rule file334 client_rule = rule_texts[self.plugin_name][self.class_name][inspect.currentframe().f_code.co_name]335 self.pep_test_helper(precommands=['iput -f {testfile}'], commands=['irule -F {client_rule_file}'], client_rule=client_rule)336 def get_resource_property_list(self, session):337 # query for resource properties338 columns = ('RESC_ZONE_NAME, '339 'RESC_FREE_SPACE, '340 'RESC_STATUS, '341 'RESC_ID, '342 'RESC_NAME, '343 'RESC_TYPE_NAME, '344 'RESC_LOC, '345 'RESC_CLASS_NAME, '346 'RESC_VAULT_PATH, '347 'RESC_INFO, '348 'RESC_COMMENT, '349 'RESC_CREATE_TIME, '350 'RESC_MODIFY_TIME')351 resource = session.default_resource352 query = '''iquest "SELECT {columns} WHERE RESC_NAME ='{resource}'"'''.format(**locals())353 result = session.run_icommand(query)[0]354 # last line is iquest default formatting separator355 resource_property_list = result.splitlines()[:-1]356 # make sure property list is not empty357 self.assertTrue(len(resource_property_list))358 return resource_property_list359 def make_pep_rule(self, pep_name, rule_body):360 # prepare rule361 # rule will write PEP name as well as362 # resource related rule session vars to server log363 write_statements = 'writeLine("serverLog", "{pep_name}");'.format(**locals())364 write_statements += ('writeLine("serverLog", $KVPairs.zoneName);'365 'writeLine("serverLog", $KVPairs.freeSpace);'366 'writeLine("serverLog", $KVPairs.quotaLimit);'367 'writeLine("serverLog", $KVPairs.rescStatus);'368 'writeLine("serverLog", $KVPairs.rescId);'369 'writeLine("serverLog", $KVPairs.rescName);'370 'writeLine("serverLog", $KVPairs.rescType);'371 'writeLine("serverLog", $KVPairs.rescLoc);'372 'writeLine("serverLog", $KVPairs.rescClass);'373 'writeLine("serverLog", $KVPairs.rescVaultPath);'374 'writeLine("serverLog", $KVPairs.rescInfo);'375 'writeLine("serverLog", $KVPairs.rescComments);'376 'writeLine("serverLog", $KVPairs.rescCreate);'377 'writeLine("serverLog", $KVPairs.rescModify)')378 return '{pep_name} {{ {write_statements};{rule_body} }}'.format(**locals())379 380 def make_pep_rule_python(self, pep_name, rule_body):381 # prepare rule382 # rule will write PEP name as well as383 # resource related rule session vars to server log384 write_statements = ' callback.writeLine("serverLog", "{pep_name}")\n'.format(**locals())385 write_statements += (' callback.writeLine("serverLog", rei.condInputData["zoneName"])\n'386 ' callback.writeLine("serverLog", rei.condInputData["freeSpace"])\n'387 ' callback.writeLine("serverLog", rei.condInputData["quotaLimit"])\n'388 ' callback.writeLine("serverLog", rei.condInputData["rescStatus"])\n'389 ' callback.writeLine("serverLog", rei.condInputData["rescId"])\n'390 ' callback.writeLine("serverLog", rei.condInputData["rescName"])\n'391 ' callback.writeLine("serverLog", rei.condInputData["rescType"])\n'392 ' callback.writeLine("serverLog", rei.condInputData["rescLoc"])\n'393 ' callback.writeLine("serverLog", rei.condInputData["rescClass"])\n'394 ' callback.writeLine("serverLog", rei.condInputData["rescVaultPath"])\n'395 ' callback.writeLine("serverLog", rei.condInputData["rescInfo"])\n'396 ' callback.writeLine("serverLog", rei.condInputData["rescComments"])\n'397 ' callback.writeLine("serverLog", rei.condInputData["rescCreate"])\n'398 ' callback.writeLine("serverLog", rei.condInputData["rescModify"])\n')399 return 'def {pep_name}(rule_args, callback, rei):\n{write_statements}\n{rule_body}'.format(**locals())400# def make_new_server_config_json(self, server_config_filename):401# # load server_config.json to inject a new rule base402# with open(server_config_filename) as f:403# svr_cfg = json.load(f)404#405# # inject a new rule base into the native rule engine406# svr_cfg['plugin_configuration']['rule_engines'][0]['plugin_specific_configuration']['re_rulebase_set'] = ["test", "core"]407#408# # dump to a string to repave the existing server_config.json409# return json.dumps(svr_cfg, sort_keys=True,indent=4, separators=(',', ': '))410 def pep_test_helper(self, precommands=[], commands=[], rule_body='', client_rule=None, target_name=None, user_session=None):411 pep_name = self.pep_name412 # user session413 if user_session is None:414 if client_rule is None:415 user_session = self.user0416 else:417 # Python rule engine needs admin privileges to run irule418 user_session = self.admin419 # local vars to format command strings420 testfile = self.testfile421 large_file = self.large_file422 if target_name is None:423 target_name = testfile424 target_obj = '/'.join([user_session.session_collection, target_name])425 # query for resource properties426 resource_property_list = self.get_resource_property_list(user_session)427 with temporary_core_file() as core:428 # make pep rule429 if self.plugin_name == 'irods_rule_engine_plugin-irods_rule_language':430 test_rule = self.make_pep_rule(pep_name, rule_body)431 elif self.plugin_name == 'irods_rule_engine_plugin-python':432 test_rule = self.make_pep_rule_python(pep_name, rule_body)433 # write pep rule into test_re434# with open(test_re, 'w') as f:435# f.write(test_rule)436 time.sleep(1) # remove once file hash fix is committed #2279437 core.add_rule(test_rule)438 time.sleep(1) # remove once file hash fix is committed #2279439# # repave the existing server_config.json to add test_re440# with open(server_config_filename, 'w') as f:441# f.write(new_server_config)442 # make client-side rule file443 if client_rule is not None:444 client_rule_file = "test_rule_file.r"445 with open(client_rule_file, 'w') as f:446 f.write(client_rule.format(**locals()))447 # perform precommands448 for c in precommands:449 if isinstance(c, tuple):450 user_session.assert_icommand(c[0].format(**locals()), c[1], c[2])451 else:452 user_session.assert_icommand(c.format(**locals()))453 # checkpoint log to know where to look for the string454 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())455 # perform commands to hit PEP456 for c in commands:457 if isinstance(c, tuple):458 user_session.assert_icommand(c[0].format(**locals()), c[1], c[2])459 else:460 user_session.assert_icommand(c.format(**locals()))461 # delete client-side rule file462 if client_rule is not None:463 os.unlink(client_rule_file)464 # confirm that PEP was hit by looking for pep name in server log465 assert lib.count_occurrences_of_string_in_log(paths.server_log_path(), pep_name, start_index=initial_log_size)466 # check that resource session vars were written to the server log467 for line in resource_property_list:468 column = line.rsplit('=', 1)[0].strip()469 property = line.rsplit('=', 1)[1].strip()470 if property:471 if column != 'RESC_MODIFY_TIME':472 assert lib.count_occurrences_of_string_in_log(paths.server_log_path(), property, start_index=initial_log_size)473 # cleanup474 user_session.run_icommand('irm -f {target_obj}'.format(**locals()))475# os.unlink(test_re)476 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Skip for Python REP')477 def test_genquery_foreach_MAX_SQL_ROWS_multiple__3489(self):478 MAX_SQL_ROWS = 256 # needs to be the same as constant in server code479 filename = 'test_genquery_foreach_MAX_SQL_ROWS_multiple__3489_dummy_file'480 lib.make_file(filename, 1)481 data_object_prefix = 'loiuaxnlaskdfpiewrnsliuserd'482 for i in range(MAX_SQL_ROWS):483 self.admin.assert_icommand(['iput', filename, '{0}_file_{1}'.format(data_object_prefix, i)])484 rule_file = 'test_genquery_foreach_MAX_SQL_ROWS_multiple__3489.r'485 rule_string = '''486test_genquery_foreach_MAX_SQL_ROWS_multiple__3489 {{487 foreach(*rows in select DATA_ID where DATA_NAME like '{0}%') {{488 *id = *rows.DATA_ID;489 writeLine("serverLog", "GGGGGGGGGGGGGGG *id");490 }}491}}492INPUT null493OUTPUT ruleExecOut494'''.format(data_object_prefix)495 with open(rule_file, 'w') as f:496 f.write(rule_string)497 self.admin.assert_icommand(['irule', '-F', rule_file])498 os.unlink(rule_file)499class Test_Remote_Exec(ResourceBase, unittest.TestCase):500 plugin_name = IrodsConfig().default_rule_engine_plugin501 class_name = 'Test_Remote_Exec'502 def setUp(self):503 super(Test_Remote_Exec, self).setUp()504 def tearDown(self):505 super(Test_Remote_Exec, self).tearDown()506 def create_rule_file(self, rule_text_key):507 rule_file_path = rule_text_key + '.r'508 parameters = {}509 parameters['host'] = test.settings.ICAT_HOSTNAME510 parameters['zone'] = 'tempZone'511 rule_str = rule_texts[self.plugin_name][self.class_name][rule_text_key].format(**parameters)512 with open(rule_file_path, 'w') as rule_file:513 rule_file.write(rule_str)514 return rule_file_path515 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Skip for Python REP')516 def test_remote_no_writeline(self):517 rule_file_path = self.create_rule_file('test_remote_no_writeline')518 try:519 self.admin.assert_icommand(['irule', '-F', rule_file_path], 'STDOUT', 'a=remote')520 finally:521 if os.path.exists(rule_file_path):522 os.unlink(rule_file_path)523 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Skip for Python REP')524 def test_remote_writeline(self):525 rule_file_path = self.create_rule_file('test_remote_writeline')526 try:527 self.admin.assert_icommand(['irule', '-F', rule_file_path], 'STDOUT', 'Remote writeLine')528 finally:529 if os.path.exists(rule_file_path):530 os.unlink(rule_file_path)531 @unittest.skip('Remove skip with resolution of #4262')532 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Skip for Python REP')533 def test_remote_in_remote_writeline(self):534 rule_file_path = self.create_rule_file('test_remote_in_remote_writeline')535 try:536 self.admin.assert_icommand(['irule', '-F', rule_file_path], 'STDOUT_MULTILINE', ['Remote in remote writeLine', 'Remote writeLine'])537 finally:538 if os.path.exists(rule_file_path):539 os.unlink(rule_file_path)540 @unittest.skipIf(test.settings.TOPOLOGY_FROM_RESOURCE_SERVER, 'Skip for topology testing from resource server: reads server log')541 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Skip for Python REP')542 def test_delay_in_remote_writeline(self):543 rule_file_path = self.create_rule_file('test_delay_in_remote_writeline')544 try:545 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())546 self.admin.assert_icommand(['irule', '-F', rule_file_path], 'STDOUT', 'Remote writeLine')547 delayAssert(lambda: lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'Delay in remote writeLine', start_index=initial_log_size))548 finally:549 if os.path.exists(rule_file_path):550 os.unlink(rule_file_path)551 @unittest.skipIf(test.settings.TOPOLOGY_FROM_RESOURCE_SERVER, 'Skip for topology testing from resource server: reads server log')552 @unittest.skipIf(plugin_name == 'irods_rule_engine_plugin-python', 'Skip for Python REP')553 def test_remote_in_delay_writeline(self):554 rule_file_path = self.create_rule_file('test_remote_in_delay_writeline')555 try:556 initial_log_size = lib.get_file_size_by_path(paths.server_log_path())557 self.admin.assert_icommand(['irule', '-F', rule_file_path])558 delayAssert(lambda: lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'Remote in delay writeLine', start_index=initial_log_size))559 delayAssert(lambda: lib.count_occurrences_of_string_in_log(paths.server_log_path(), 'Delay writeLine', start_index=initial_log_size))560 finally:561 if os.path.exists(rule_file_path):...
test_common.py
Source:test_common.py
...118 ssh_mock.connect.side_effect = Exception("")119 # Run120 with self.assertRaises(Exception):121 ssh_to("user", "ip", u"key")122 def test_remote_exec(self):123 # Setup124 ssh_mock = Mock()125 sftp_mock = Mock()126 ssh_mock.open_sftp.return_value = sftp_mock127 stdout_mock = Mock()128 stdout_mock.channel.exit_status_ready.return_value = True129 stdout_mock.channel.recv_exit_status.return_value = 0130 ssh_mock.exec_command.return_value = (None, stdout_mock, None)131 # Run132 retval = remote_exec(ssh_mock, "script")133 # Assert134 self.assertEqual(0, retval)135 sftp_mock.open.assert_called()136 sftp_mock.remove.assert_called()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!