blob: e5189610892b1e2aece22b591668b07dba26100f [file] [log] [blame]
#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
# sacctmgr modify accounts, descriptions, limits,
# and parents down and up the tree
############################################################################
# Copyright (C) 2008-2010 Lawrence Livermore National Security.
# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
# Written by Joseph Donaghy <donaghy1@llnl.gov>
# CODE-OCEC-09-009. All rights reserved.
#
# This file is part of Slurm, a resource management program.
# For details, see <https://slurm.schedmd.com/>.
# 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 tc1 "${test_name}-cluster-1"
set tc2 "${test_name}-cluster-2"
set ta1 "${test_name}-account.1"
set ta2 "${test_name}-account.2"
set ta3 "${test_name}-account.3"
set access_err 0
########## Account ##########
array set acct_req {}
set acct_req(cluster) $tc1,$tc2
########## Modify Accounts ##########
# Mod account 1
array set acct_mod_desc1 {}
array set acct_mod_acct_vals1 {
description testacct2
organization acttrg
}
array set acct_mod_assoc_vals1 {}
# Mod account 2
array set acct_mod_desc2 {}
array set acct_mod_acct_vals2 {}
array set acct_mod_assoc_vals2 {
fairshare 1700
maxcpumins 700000
maxjobs 70
maxnodes 700
maxwall 00:07:00
}
# Mod account 3
array set acct_mod_desc3 {}
array set acct_mod_acct_vals3 {
description testacct1
organization accountorga1
}
array set acct_mod_assoc_vals3 {
fairshare -1
maxcpumins -1
maxjobs -1
maxnodes -1
maxwall -1
}
# Mod account 4
array set acct_mod_desc4 {}
set acct_mod_desc4(cluster) $tc1
array set acct_mod_acct_vals4 {}
array set acct_mod_assoc_vals4 {}
set acct_mod_assoc_vals4(parent) $ta2
# Mod account 5
array set acct_mod_desc5 {}
set acct_mod_desc5(cluster) $tc1
array set acct_mod_acct_vals5 {}
array set acct_mod_assoc_vals5 {}
set acct_mod_assoc_vals5(parent) $ta3
# Mod account 5_1
array set acct_mod_desc5_1 {}
set acct_mod_desc5_1(cluster) $tc1
array set acct_mod_acct_vals5_1 {}
array set acct_mod_assoc_vals5_1 {}
set acct_mod_assoc_vals5_1(parent) "root"
# Mod account 6
array set acct_mod_desc6 {}
set acct_mod_desc6(cluster) $tc1
array set acct_mod_acct_vals6 {}
array set acct_mod_assoc_vals6 {}
set acct_mod_assoc_vals6(parent) $ta2
set timeout 60
#
# Check accounting config and bail if not found.
#
if {[get_config_param "AccountingStorageType"] ne "accounting_storage/slurmdbd"} {
skip "This test can't be run without a usable AccountStorageType"
}
if {[get_admin_level] ne "Administrator"} {
skip "This test can't be run without being an Accounting administrator.\nUse: sacctmgr mod user \$USER set admin=admin"
}
proc cleanup {} {
global ta1 ta2 ta3 tc1 tc2
remove_acct "$tc1,$tc2" "$ta1,$ta2,$ta3"
remove_acct "" "$ta1,$ta2,$ta3"
remove_cluster "$tc1,$tc2"
}
# Make sure we have a clean system and permission to do this work
cleanup
if {$access_err != 0} {
skip "Not authorized to perform this test"
}
# Add cluster
if [add_cluster "$tc1,$tc2" ""] {
fail "Unable to add clusters ($tc1,$tc2)"
}
# Add accounts
if [add_acct "$ta1,$ta2,$ta3" [array get acct_req]] {
fail "Unable to add accounts ($ta1,$ta2,$ta3)"
}
# OK This is the real test. First test change the desc and org of the accounts
if [mod_acct "$ta1,$ta2,$ta3" [array get acct_mod_desc1] [array get acct_mod_acct_vals1] [array get acct_mod_assoc_vals1]] {
fail "Unable to modify accounts ($ta1,$ta2,$ta3)"
}
#
# Use sacctmgr to list the test account modifications
#
set matches 0
spawn $sacctmgr -n -p list account account=$ta1,$ta2,$ta3 format="Account,Desc,Org"
expect {
-re "There was a problem" {
fail "There was a problem with the sacctmgr command"
}
-re "($ta1|$ta2|$ta3).$acct_mod_acct_vals1(description).$acct_mod_acct_vals1(organization)." {
incr matches
exp_continue
}
timeout {
fail "sacctmgr list associations not responding"
}
eof {
wait
}
}
if {$matches != 3} {
fail "Account modification 1 incorrect ($matches != 3)"
}
# Next, test change the limits of the accounts
if [mod_acct "$ta1,$ta2,$ta3" [array get acct_mod_desc2] [array get acct_mod_assoc_vals2] [array get acct_mod_acct_vals2]] {
fail "Unable to modify accounts ($ta1,$ta2,$ta3)"
}
#
# Use sacctmgr to list the test account modifications
#
set matches 0
spawn $sacctmgr -n -p list assoc account=$ta1,$ta2,$ta3 format="Account,Cluster,Fairshare,MaxCPUM,MaxJ,MaxN,MaxW"
expect {
-re "There was a problem" {
fail "There was a problem with the sacctmgr command"
}
-re "($ta1|$ta2|$ta3).($tc1|$tc2).$acct_mod_assoc_vals2(fairshare).$acct_mod_assoc_vals2(maxcpumins).$acct_mod_assoc_vals2(maxjobs).$acct_mod_assoc_vals2(maxnodes).$acct_mod_assoc_vals2(maxwall)." {
incr matches
exp_continue
}
timeout {
fail "sacctmgr list associations not responding"
}
eof {
wait
}
}
if {$matches != 6} {
fail "Account modification 2 incorrect ($matches != 6)"
}
# Next, test change the desc and limits of the accounts
if [mod_acct "$ta1,$ta3" [array get acct_mod_desc3] [array get acct_mod_acct_vals3] [array get acct_mod_assoc_vals3]] {
fail "Unable to modify accounts ($ta1,$ta2,$ta3)"
}
#
# Use sacctmgr to list the test account modifications
#
set matches 0
eval spawn $sacctmgr -n -p list account withassoc account=$ta1,$ta2,$ta3 format="Account,Desc,Org,Cluster,Fairshare,MaxCPUM,MaxJ,MaxN,MaxW"
expect {
-re "There was a problem" {
fail "There was a problem with the sacctmgr command"
}
# 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 "(($ta1|$ta3).$acct_mod_acct_vals3(description).$acct_mod_acct_vals3(organization).($tc1|$tc2).1.....|$ta2.$acct_mod_acct_vals1(description).$acct_mod_acct_vals1(organization).($tc1|$tc2).$acct_mod_assoc_vals2(fairshare).$acct_mod_assoc_vals2(maxcpumins).$acct_mod_assoc_vals2(maxjobs).$acct_mod_assoc_vals2(maxnodes).$acct_mod_assoc_vals2(maxwall).)" {
incr matches
exp_continue
}
timeout {
fail "sacctmgr list associations not responding"
}
eof {
wait
}
}
if {$matches != 6} {
fail "Account modification 6 incorrect (matches" != 6)
}
# Next, test change the parent of ta3 to be $ta2 on $tc1 sibling to be a child
if [mod_acct $ta3 [array get acct_mod_desc4] [array get acct_mod_assoc_vals4] [array get acct_mod_acct_vals4]] {
fail "Unable to modify account ($ta3)"
}
#
# Use sacctmgr to list the test account modifications
#
set matches 0
eval spawn $sacctmgr -n -p list assoc account=$ta3 format="Account,ParentN,Cluster,Fairshare,MaxCPUM,MaxJ,MaxN,MaxW"
expect {
-re "There was a problem" {
fail "There was a problem with the sacctmgr command"
}
-re "$ta3.$ta2.$tc1.1.$acct_mod_assoc_vals2(maxcpumins).$acct_mod_assoc_vals2(maxjobs).$acct_mod_assoc_vals2(maxnodes).$acct_mod_assoc_vals2(maxwall)." {
incr matches
exp_continue
}
-re "$ta3.root.$tc2.1....." {
incr matches
exp_continue
}
timeout {
fail "sacctmgr list associations not responding"
}
eof {
wait
}
}
if {$matches != 2} {
fail "Account modification 2 incorrect ($matches != 2)"
}
# Next, test change the parent of $ta2 to be $ta3 on $tc1
# making the child the parent - This should fail
if [mod_acct $ta2 [array get acct_mod_desc5] [array get acct_mod_assoc_vals5] [array get acct_mod_acct_vals5]] {
log_info "Assuming we weren't able to re-parent $ta2 to child $ta3, expected"
} else {
fail "The above was suppose to fail to re-parent, but it succeeded erroneously"
}
# Now do it correctly, reparent the child $ta3 to $ta1
if [mod_acct $ta3 [array get acct_mod_desc5_1] [array get acct_mod_assoc_vals5_1] [array get acct_mod_acct_vals5_1]] {
fail "Unable to modify account ($ta3)"
}
# Now this original request should work
if [mod_acct $ta2 [array get acct_mod_desc5] [array get acct_mod_assoc_vals5] [array get acct_mod_acct_vals5]] {
fail "Unable to modify account ($ta2)"
}
#
# Use sacctmgr to list the test account modifications
#
set matches 0
eval spawn $sacctmgr -n -p list assoc account=$ta3,$ta2 format="Account,ParentN,Cluster,Fairshare,MaxCPUM,MaxJ,MaxN,MaxW"
expect {
-re "There was a problem" {
fail "There was a problem with the sacctmgr command"
}
-re "($ta2.root.$tc2.$acct_mod_assoc_vals2(fairshare).$acct_mod_assoc_vals2(maxcpumins).$acct_mod_assoc_vals2(maxjobs).$acct_mod_assoc_vals2(maxnodes).$acct_mod_assoc_vals2(maxwall).|$ta2.$ta3.$tc1.$acct_mod_assoc_vals2(fairshare).$acct_mod_assoc_vals2(maxcpumins).$acct_mod_assoc_vals2(maxjobs).$acct_mod_assoc_vals2(maxnodes).$acct_mod_assoc_vals2(maxwall).|$ta3.root.($tc1|$tc2).1.....)" {
incr matches
exp_continue
}
timeout {
fail "sacctmgr list associations not responding"
}
eof {
wait
}
}
if {$matches != 4} {
fail "Account modification 4 incorrect ($matches != 4)"
}
# Next, test change the parent of $ta3 to be $ta2 on $tc1 again
# only this time the parent will become the child instead of it being a sibling.
if [mod_acct $ta3 [array get acct_mod_desc6] [array get acct_mod_assoc_vals6] [array get acct_mod_acct_vals6]] {
log_info "Assuming we weren't able to re-parent $ta3 to child $ta2, expected"
} else {
fail "The above was suppose to fail to re-parent, but it succeeded erroneously"
}
# Now do it correctly, reparent the child $ta2 to $ta1
if [mod_acct $ta2 [array get acct_mod_desc5_1] [array get acct_mod_assoc_vals5_1] [array get acct_mod_acct_vals5_1]] {
fail "Unable to modify account ($ta2)"
}
# Now this original request should work
if [mod_acct $ta3 [array get acct_mod_desc6] [array get acct_mod_assoc_vals6] [array get acct_mod_acct_vals6]] {
fail "Unable to modify account ($ta3)"
}
#
# Use sacctmgr to list the test account modifications
#
set matches 0
eval spawn $sacctmgr -n -p list assoc account=$ta3,$ta2 format="Account,ParentN,Cluster,Fairshare,MaxCPUM,MaxJ,MaxN,MaxW"
expect {
-re "There was a problem" {
fail "There was a problem with the sacctmgr command"
}
-re "($ta2.root.($tc1|$tc2).$acct_mod_assoc_vals2(fairshare).$acct_mod_assoc_vals2(maxcpumins).$acct_mod_assoc_vals2(maxjobs).$acct_mod_assoc_vals2(maxnodes).$acct_mod_assoc_vals2(maxwall).|$ta3.$ta2.$tc1.1.$acct_mod_assoc_vals2(maxcpumins).$acct_mod_assoc_vals2(maxjobs).$acct_mod_assoc_vals2(maxnodes).$acct_mod_assoc_vals2(maxwall).|$ta3.root.$tc2.1.....)" {
incr matches
exp_continue
}
timeout {
fail "sacctmgr list associations not responding"
}
eof {
wait
}
}
if {$matches != 4} {
fail "Account modification 4 incorrect ($matches != 4)"
}