blob: c6ffaef2c284834ac857e71c539b4138d1e18713 [file]
#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
# Validate that scontrol show assoc_mgr shows the data cached in
# the slurmctld
############################################################################
# Copyright (C) SchedMD LLC.
#
# 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
set test_acct "${test_name}_acct"
set test_user ""
if {![is_super_user]} {
skip "This test can't be run except as SlurmUser or root"
} elseif {![param_contains [get_config_param "AccountingStorageEnforce"] "limits"]} {
skip "AccountingStorageEnforce limits must be set"
}
if {[get_config_param "AccountingStorageType"] ne "accounting_storage/slurmdbd"} {
skip "Test requires accounting_storage/slurmdbd"
}
proc mod_assoc_vals { } {
global sacctmgr test_acct test_user
set modified 0
spawn $sacctmgr mod -i account $test_acct where user=$test_user set \
GrpCpus=3 MaxJobs=2 MaxCPUs=6 Priority=9
expect {
-re "Modified account associations" {
set modified 1
exp_continue
}
timeout {
fail "sacctmgr is not responding"
}
eof {
wait
}
}
if {!$modified} {
fail "Account limits were not modified"
}
}
proc clear_assoc_vals { } {
global sacctmgr test_acct test_user
set modified 0
spawn $sacctmgr mod -i account $test_acct where user=$test_user set \
GrpCpus=-1 MaxJobs=-1 MaxCPUs=-1 Priority=-1
expect {
-re "Modified account associations" {
set modified 1
exp_continue
}
timeout {
fail "sacctmgr is not responding"
}
eof {
wait
}
}
if {!$modified} {
fail "Account limits were not modified"
}
}
proc cleanup { } {
global test_acct sacctmgr
set deleted 0
spawn $sacctmgr delete -i account $test_acct
expect {
-re "Deleting accounts..." {
set deleted 1
exp_continue
}
timeout {
fail "sacctmgr is not responding"
}
eof {
wait
}
}
}
# Remove any vestigial accounts
cleanup
# Get username
set test_user [get_my_user_name]
# Add test Account
set acct_added 0
set cluster [get_config_param "ClusterName"]
spawn $sacctmgr add -i account $test_acct cluster=$cluster
expect {
-re "Adding Account" {
set acct_added 1
exp_continue
}
timeout {
fail "sacctmgr is not responding"
}
eof {
wait
}
}
if {!$acct_added} {
fail "Could not add test account ($test_acct)"
}
# Add user to test account
set user_added 0
spawn $sacctmgr add -i user $test_user account=$test_acct
expect {
-re "Associations" {
set user_added 1
exp_continue
}
timeout {
fail "sacctmgr is not responding"
}
eof {
wait
}
}
if {!$user_added} {
fail "Could not add user to test account"
}
set match 0
wait_for {$match == 5} {
set output [run_command -fail "$scontrol -o show assoc_mgr | $bin_grep Account=$test_acct| $bin_grep UserName=$test_user"]
set match 0
incr match [regexp " Account=$test_acct" $output]
incr match [regexp " UserName=$test_user" $output]
incr match [regexp -all " GrpTRES=" $output]
incr match [regexp -all " MaxJobs=" $output]
incr match [regexp -all " MaxTRESPJ=" $output]
}
subtest {$match == 5} "1. Verify scontrol show assoc_mgr shows correct information" "$match != 5"
# Set association limits and check that controller is updated
mod_assoc_vals
set match 0
wait_for {$match == 6} {
set output [run_command -fail "$scontrol -o show assoc_mgr | $bin_grep Account=$test_acct| $bin_grep UserName=$test_user"]
set match 0
incr match [regexp " Account=$test_acct" $output]
incr match [regexp " UserName=$test_user" $output]
incr match [regexp -all " Priority=9" $output]
incr match [regexp -all " GrpTRES=cpu=3" $output]
incr match [regexp -all " MaxJobs=2" $output]
incr match [regexp -all " MaxTRESPJ=cpu=6" $output]
}
subtest {$match == 6} "2. Verify scontrol show assoc_mgr shows correct information" "$match != 6"
# Clear associtation limits and check controller is updated
clear_assoc_vals
set match 0
set nmatch 0
wait_for {$match == 3 && $nmatch == 0} {
set output [run_command -fail "$scontrol -o show assoc_mgr | $bin_grep Account=$test_acct| $bin_grep UserName=$test_user"]
set match 0
incr match [regexp " Account=$test_acct" $output]
incr match [regexp " UserName=$test_user" $output]
incr match [regexp -all " Priority=0" $output]
incr nmatch [regexp -all " GrpTRES=" $output]
incr nmatch [regexp -all " MaxJobs=" $output]
incr nmatch [regexp -all " MaxTRESPJ=" $output]
set nmatch 0
incr nmatch [regexp -all " GrpTRES=cpu=3" $output]
incr nmatch [regexp -all " MaxJobs=2" $output]
incr nmatch [regexp -all " MaxTRESPJ=cpu=6" $output]
}
subtest {$match == 3 && $nmatch == 0} "3. Verify scontrol show assoc_mgr shows correct information" "$match != 3 || $nmatch != 0"