#!/usr/bin/env expect ############################################################################ # Purpose: Test of Slurm functionality # sacctmgr modify multiple users ############################################################################ # Copyright (C) 2008-2010 Lawrence Livermore National Security. # Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). # Written by Joseph Donaghy # CODE-OCEC-09-009. All rights reserved. # # This file is part of Slurm, a resource management program. # For details, see . # Please also read the included file: DISCLAIMER. # # Slurm is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # Slurm is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along # with Slurm; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ############################################################################ source ./globals_accounting set exit_code 0 set tc1 "test$test_id-cluster-1" set tc2 "test$test_id-cluster-2" set tc3 "test$test_id-cluster-3" set ta1 "test$test_id-account.1" set ta2 "test$test_id-account.2" set ta3 "test$test_id-account.3" set tu1 "test$test_id-user.1" set tu2 "test$test_id-user.2" set tu3 "test$test_id-user.3" set access_err 0 # Cluster array set clus_req {} # Accounts array set acct_req {} set acct_req(cluster) $tc1,$tc2,$tc3 # User array set user_req {} set user_req(cluster) $tc1,$tc2,$tc3 set user_req(account) $ta1,$ta2,$ta3 # Mod User 1 array set user_mod_info {} set user_mod_info(cluster) $tc1,$tc2,$tc3 array set user_mod_acct { adminlevel Operator } set user_mod_acct(defaultaccount) $ta2 array set user_mod_assoc {} # Mod User 2 array set user_mod_info2 {} set user_mod_info2(cluster) $tc1,$tc2,$tc3 array set user_mod_acct2 { adminlevel Administrator } set user_mod_acct2(defaultaccount) "'$ta3'" array set user_mod_assoc2 {} # Mod User 3 array set user_mod_info3 {} set user_mod_info3(cluster) $tc1,$tc2 array set user_mod_acct3 {} array set user_mod_assoc3 { fairshare 1700 maxcpumin 700000 maxjob 70 maxnode 700 maxwall 00:07:00 } # Mod User 4 array set user_mod_info4 {} set user_mod_info4(cluster) $tc1,$tc2 array set user_mod_acct4 {} array set user_mod_assoc4 { fairshare 1 maxcpumin 1 maxjob 1 maxnode 1 maxwall 00:01:00 } set timeout 60 # # Check accounting config and bail if not found. # if { [test_account_storage] == 0 } { skip "This test can't be run without a usable AccountStorageType" } if { [string compare [check_accounting_admin_level] "Administrator"] } { skip "This test can't be run without being an Accounting administrator.\nUse: sacctmgr mod user \$USER set admin=admin" } #make sure we have a clean system and permission to do this work remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" if {$access_err != 0} { skip "Not authorized to perform this test" } #add cluster incr exit_code [add_cluster "$tc1,$tc2,$tc3" [array get clus_req]] if { $exit_code } { remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" fail "Unable to add cluster ($tc1,$tc2,$tc3)" } #add accounts incr exit_code [add_acct "$ta1,$ta2,$ta3" [array get acct_req]] if { $exit_code } { remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" fail "Unable to add account ($ta1,$ta2,$ta3)" } #add users incr exit_code [add_user "$tu1,$tu2,$tu3" [array get user_req]] if { $exit_code } { remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" fail "Unable to add user ($tu1,$tu2,$tu3)" } # First test change the AdminLevel and DefaultAccount of the accounts incr exit_code [mod_user "$tu1,$tu2,$tu3" [array get user_mod_info] [array get user_mod_acct] [array get user_mod_assoc]] if { $exit_code } { remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" fail "Unable to modify user ($tu1,$tu2,$tu3)" } # # Use sacctmgr to list the test account modifications # set matches 0 set my_pid [spawn $sacctmgr -n -p list user names=$tu1,$tu2,$tu3 format="User,DefaultA,Admin" cluster=$tc1] expect { -re "There was a problem" { log_error "There was a problem with the sacctmgr command" incr exit_code 1 } -re "($tu1|$tu2|$tu3).$ta2.$user_mod_acct(adminlevel)." { incr matches exp_continue } timeout { log_error "sacctmgr list associations not responding" slow_kill $my_pid incr exit_code 1 } eof { wait } } if {$matches != 3} { log_error "Account modification 3 incorrect with only $matches" incr exit_code 1 } # Test change the AdminLevel and DefaultAccount of two accounts incr exit_code [mod_user "$tu1,$tu3" [array get user_mod_info2] [array get user_mod_acct2] [array get user_mod_assoc2]] if { $exit_code } { remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" fail "Unable to modify user ($tu1,$tu3)" } # # Use sacctmgr to list the test account modifications # set matches 0 set my_pid [spawn $sacctmgr -n -p list user names=$tu1,$tu2,$tu3 format="User,DefaultA,Admin" cluster=$tc1] expect { -re "There was a problem" { log_error "There was a problem with the sacctmgr command" incr exit_code 1 } -re "(($tu1|$tu3).$ta3.$user_mod_acct2(adminlevel).|$tu2.$ta2.$user_mod_acct(adminlevel).)" { incr matches exp_continue } timeout { log_error "sacctmgr list associations not responding" slow_kill $my_pid incr exit_code 1 } eof { wait } } if {$matches != 3} { log_error "Account modification 3 incorrect with only $matches" incr exit_code 1 } # Next, test change the limits of the users incr exit_code [mod_user "$tu1,$tu2,$tu3" [array get user_mod_info3] [array get user_mod_acct3] [array get user_mod_assoc3]] if { $exit_code } { remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" fail "Unable to modify user ($tu1,$tu2,$tu3)" } # # Use sacctmgr to list the test user modifications # set matches 0 set my_pid [spawn $sacctmgr -n -p list assoc users=$tu1,$tu2,$tu3 format="User,Cluster,Fairshare,Maxcpum,MaxJ,MaxN,MaxW"] expect { -re "There was a problem" { log_error "There was a problem with the sacctmgr command" incr exit_code 1 } -re "(($tu1|$tu2|$tu3).($tc1|$tc2).$user_mod_assoc3(fairshare).$user_mod_assoc3(maxcpumin).$user_mod_assoc3(maxjob).$user_mod_assoc3(maxnode).$user_mod_assoc3(maxwall).)" { incr matches exp_continue } timeout { log_error "sacctmgr list associations not responding" slow_kill $my_pid incr exit_code 1 } eof { wait } } if {$matches != 18} { log_error "User modification 18 incorrect with only $matches" incr exit_code 1 } # Next, test change the limits of two users incr exit_code [mod_user "$tu1,$tu3" [array get user_mod_info4] [array get user_mod_acct4] [array get user_mod_assoc4]] if { $exit_code } { remove_user "" "" "$tu1,$tu2,$tu3" remove_acct "" "$ta1,$ta2,$ta3" remove_cluster "$tc1,$tc2,$tc3" fail "Unable to modify user ($tu1,$tu3)" } # # Use sacctmgr to list the test user modifications # set matches 0 set my_pid [eval spawn $sacctmgr -n -p list assoc user=$tu1,$tu2,$tu3 format="User,Cluster,Fairshare,Maxcpum,MaxJ,MaxN,MaxW"] expect { -re "There was a problem" { log_error "There was a problem with the sacctmgr command" incr exit_code 1 } # Any time you use () around something you need to combine all # those things together since you can miss some and they be thrown away -re "(($tu1|$tu3).($tc1|$tc2).$user_mod_assoc4(fairshare).$user_mod_assoc4(maxcpumin).$user_mod_assoc4(maxjob).$user_mod_assoc4(maxnode).$user_mod_assoc4(maxwall).|$tu2.($tc1|$tc2).$user_mod_assoc3(fairshare).$user_mod_assoc3(maxcpumin).$user_mod_assoc3(maxjob).$user_mod_assoc3(maxnode).$user_mod_assoc3(maxwall).)" { incr matches exp_continue } timeout { log_error "sacctmgr list associations not responding" slow_kill $my_pid incr exit_code 1 } eof { wait } } if {$matches != 18} { log_error "User modification 18 incorrect with $matches" incr exit_code 1 } # This is the end below here incr exit_code [remove_user "" "" "$tu1,$tu2,$tu3"] incr exit_code [remove_acct "" "$ta1,$ta2,$ta3"] incr exit_code [remove_cluster "$tc1,$tc2,$tc3"] if {$exit_code != 0} { fail "Test failed due to previous errors" }