#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
#          sacctmgr load data file
############################################################################
# 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

set file_in     "$test_dir/input"
set file_in2    "$test_dir/input2"
set file_in3    "$test_dir/input3"
set lis         list
set as          assoc
set fmt         format
set cln         clean
set tre         tree
set was         withassoc
set wco         withcoordinator
set par         Parent
set roo         root
set clu         Cluster
set tc1         "${test_name}-cluster-1"
set acc         Account
set nams        ames
set ta1         "${test_name}-account.1"
set ta2         "${test_name}-account.2"
set ta3         "${test_name}-account.3"
set ta4         "${test_name}-account.4"
set dsc         Description
set ds1         scienceacct
set ds2         physicsacct
set ds3         theoryacct
set ds4         appliedacct
set org         Organization
set or1         scienceorg
set or2         physicsorg
set or3         theoryorg
set or4         appliedorg
set usr         user
set tu1         "${test_name}-user.1"
set tu2         "${test_name}-user.2"
set tu3         "${test_name}-user.3"
set tu4         "${test_name}-user.4"
set qs          QOS
set qs1         normal
set pat         parent
set al          AdminLevel
set aln         None
set ala         Administrator
set alo         Operator
set coo         Coordinator
set col         Coordinator
set dac         DefaultAccount
set pts         Partition
set pde         pdebug
set pba         pbatch
set fs          Fairshare
set gm          GrpCPUMins
set gc          GrpCPUs
set gj          GrpJobs
set gs          GrpSubmitJobs
set gn          GrpNodes
set gw          GrpWall
set mm          MaxCPUMins
set mc          MaxCPUs
set mj          MaxJobs
set ms          MaxSubmitJobs
set mn          MaxNodes
set mw          MaxWall
set class       Classification
set class1      Capacity
set class2      Capability
set class3      Capapacity
set fs1         1000
set fs2         2375
set fs3         3240
set fs4         4321
set fs5         5678
set fs6         6789
set gm1         1100
set gc1         10
set gj1         120
set gs1         130
set gn1         140
set gw1         60
set gt1         01:00:00
set mc1         150
set mm1         110000
set mj1         160
set ms1         170
set mn1         180
set mw1         70
set mt1         01:10:00
set gm2         2000
set gc2         20
set gj2         210
set gs2         220
set gn2         230
set gw2         120
set gt2         02:00:00
set mc2         240
set mm2         220000
set mj2         250
set ms2         260
set mn2         270
set mw2         140
set mt2         02:20:00
set gm3         3300
set gc3         30
set gj3         310
set gs3         320
set gn3         330
set gw3         180
set gt3         03:00:00
set mc3         340
set mm3         330000
set mj3         350
set ms3         360
set mn3         370
set mw3         210
set mt3         03:30:00
set gm4         4000
set gc4         40
set gj4         410
set gs4         420
set gn4         430
set gw4         240
set gt4         04:00:00
set mc4         440
set mm4         420000
set mj4         450
set ms4         460
set mn4         470
set mw4         280
set mt4         04:40:00
set gm5         5500
set gc5         50
set gj5         510
set gs5         520
set gn5         530
set gw5         300
set gt5         05:00:00
set mc5         540
set mm5         550000
set mj5         550
set ms5         560
set mn5         570
set mw5         350
set mt5         05:50:00
set gm6         6600
set gc6         60
set gj6         610
set gs6         620
set gn6         630
set gw6         1440
set gt6         1-00:00:00
set mc6         640
set mm6         660000
set mj6         650
set ms6         660
set mn6         670
set mw6         2880
set mt6         2-00:00:00
set access_err  0
set timeout     120

#
# 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"
}

#
# Use sacctmgr to remove the test cluster
#
proc _remove_cluster {name} {
        global access_err sacctmgr timeout

	set matches 0
	set nothing 0

	if { ![string length $name] } {
		fail "We need a name to remove"
	}

	spawn $sacctmgr -i delete cluster $name
	expect {
		-re "privilege to perform this action" {
			set access_err 1
			exp_continue
		}
		-re "(There was a problem|Unknown condition|Bad format on|Bad MaxWall|Unknown option)" {
			fail "There was a problem with the sacctmgr command"
		}
		-re "Problem getting" {
			fail "There was a problem getting information from the database"
		}
		-re "Problem adding" {
			fail "There was an unknown problem"
		}
		-re "No associations" {
			fail "Your command didn't return anything"
		}
		-re "Deleting clusters" {
			incr matches
			exp_continue
		}
		-re " Nothing deleted" {
			incr matches
			set nothing 1
			exp_continue
		}
		timeout {
			fail "sacctmgr delete not responding"
		}
		eof {
			wait
		}
	}
	if {$access_err != 0} {
		return 1
	}
	if {$matches != 1} {
		fail "sacctmgr had a problem deleting cluster ($matches != 1)"
	}
	if { !$nothing } {
		if {![check_acct_associations]} {
			fail "Our associations don't line up"
		}
	}
}

#
# Use sacctmgr to remove an account
#
proc _remove_acct { cluster name } {
        global sacctmgr timeout

	set matches 0
	set nothing 1
	set check "Deleting account"

	if { ![string length $name] } {
		fail "We need a name to remove"
	}

	set command "$name"

	if { [string length $cluster] } {
		set command "$command cluster=$cluster"
		set check "Deleting account associations"
	}

	eval spawn $sacctmgr -i delete account $command
	expect {
		-re "(There was a problem|Unknown condition|Bad format on|Bad MaxWall|Unknown option)" {
			fail "There was a problem with the sacctmgr command"
		}
		-re "Problem getting" {
			fail "There was a problem getting information from the database"
		}
		-re "Problem adding" {
			fail "There was an unknown problem"
		}
		-re "No associations" {
			fail "Your command didn't return anything"
		}
		-re "$check" {
			incr matches
			exp_continue
		}
		-re " Nothing deleted" {
			incr matches
			set nothing 1
			exp_continue
		}
		timeout {
			fail "sacctmgr add not responding"
		}
		eof {
			wait
		}
	}

	if {$matches != 1} {
		fail "sacctmgr had a problem deleting account ($matches != 1)"
	}

	if { !$nothing } {
		if {![check_acct_associations]} {
			fail "Our associations don't line up"
		}
	}
}

#
# Use sacctmgr to remove an user
#
proc _remove_user { acct user } {
        global sacctmgr timeout

	set matches 0
	set nothing 1
	set check "Deleting user"

	if { ![string length $user] } {
		fail "We need a name to remove"
	}

	set command "$user"

	if { [string length $acct] } {
		set command "$command account=$acct"
		set check "Deleting user associations"
	}

	eval spawn $sacctmgr -i delete user $command
	expect {
		-re "(There was a problem|Unknown condition|Bad format on|Bad MaxWall|Unknown option)" {
			fail "There was a problem with the sacctmgr command"
		}
		-re "Problem getting" {
			fail "There was a problem getting information from the database"
		}
		-re "Problem adding" {
			fail "There was an unknown problem"
		}
		-re "No associations" {
			fail "Your command didn't return anything"
		}
		-re "$check" {
			incr matches
			exp_continue
		}
		-re " Nothing deleted" {
			incr matches
			set nothing 1
			exp_continue
		}
		timeout {
			fail "sacctmgr delete not responding"
		}
		eof {
			wait
		}
	}

	if {$matches != 1} {
		fail "sacctmgr had a problem deleting user ($matches != 1)"
	}

	if { !$nothing } {
		if {![check_acct_associations]} {
			fail "Our associations don't line up"
		}
	}
}

proc cleanup {} {
	global tu1 tu2 tu3 tu4 ta1 ta2 ta3 ta4 tc1 file_in file_in2 file_in3

	_remove_user "" "$tu1,$tu2,$tu3,$tu4"
	_remove_acct "" "$ta1,$ta2,$ta3,$ta4"
	_remove_cluster "$tc1"

	#
	# Delete left-over input script files
	#
	file delete $file_in file_in2 file_in3
}

# 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"
}

#
# Build input script file - to create original associations
#
exec echo "$clu - '$tc1':$class=$class1:$fs=$fs6:$gm=$gm6:$gc=$gc6:$gj=$gj6:$gn=$gn6:$gs=$gs6:$gw=$gw6:$mm=$mm6:$mc=$mc6:$mj=$mj6:$mn=$mn6:$ms=$ms6:$mw=$mw6:$qs=$qs1"     >>$file_in
exec echo "$par - '$roo'"     >>$file_in
exec echo "$acc - '$ta1':$dsc=$ds1:$org=$or1:$fs=$fs5:$gm=$gm5:$gc=$gc5:$gj=$gj5:$gn=$gn5:$gs=$gs5:$gw=$gw5:$mm=$mm5:$mc=$mc5:$mj=$mj5:$mn=$mn5:$ms=$ms5:$mw=$mw5:$qs=$qs1"     >>$file_in
exec echo "$acc - '$ta2':$dsc=$ds2:$org=$or2:$fs=$fs4:$gm=$gm4:$gc=$gc4:$gj=$gj4:$gn=$gn4:$gs=$gs4:$gw=$gw4:$mm=$mm4:$mc=$mc4:$mj=$mj4:$mn=$mn4:$ms=$ms4:$mw=$mw4:$qs=$qs1"     >>$file_in
exec echo "$par - '$ta1'"     >>$file_in
exec echo "$acc - '$ta3':$dsc=$ds3:$org=$or3:$fs=$fs3:$gm=$gm3:$gc=$gc3:$gj=$gj3:$gn=$gn3:$gs=$gs3:$gw=$gw3:$mm=$mm3:$mc=$mc3:$mj=$mj3:$mn=$mn3:$ms=$ms3:$mw=$mw3:$qs=$qs1"     >>$file_in
exec echo "$par - '$ta2'"     >>$file_in
exec echo "$usr - '$tu1':$coo=$ta2:$dac=$ta2:$fs=$fs1:$mm=$mm2:$mc=$mc2:$mj=$mj2:$mn=$mn2:$ms=$ms2:$mw=$mw2:$qs=$qs1:$al=$alo"     >>$file_in
exec echo "$par - '$ta3'"     >>$file_in
exec echo "$usr - '$tu2':$coo=$ta3:$dac=$ta3:$fs=$fs2:$mm=$mm1:$mc=$mc1:$mj=$mj1:$mn=$mn1:$ms=$ms1:$mw=$mw1:$qs=$qs1:$al=$ala"     >>$file_in

#
# Second input file - to modify and add associations to the original
#
exec echo "$clu - '$tc1':$class=$class2"     >>$file_in2
exec echo "$par - '$roo'"     >>$file_in2
exec echo "$acc - '$ta1'"     >>$file_in2
exec echo "$acc - '$ta3':$dsc=$ds1:$org=$or1:$fs=$fs5:$gm=$gm5:$gc=$gc5:$gj=$gj5:$gn=$gn5:$gs=$gs5:$gw=$gw5:$mm=$mm5:$mc=$mc5:$mj=$mj5:$mn=$mn5:$ms=$ms5:$mw=$mw5:$qs=$qs1"     >>$file_in2
exec echo "$par - '$ta1'"     >>$file_in2
exec echo "$acc - '$ta2'"     >>$file_in2
exec echo "$par - '$ta2'"     >>$file_in2
exec echo "$usr - '$tu3':$coo=$ta1,$ta2,$ta3:$dac=$ta2:$fs=$fs2:$mm=$mm2:$mc=$mc2:$mj=$mj2:$mn=$mn2:$ms=$ms2:$mw=$mw2:$qs=$qs1:$al=$ala"     >>$file_in2
exec echo "$par - '$ta3'"     >>$file_in2
exec echo "$usr - '$tu2':$dac=$ta3:$fs=$fs3:$mm=$mm3:$mc=$mc3:$mj=$mj3:$mn=$mn3:$ms=$ms3:$mw=$mw3:$qs=$qs1:$al=$alo"     >>$file_in2
exec echo "$usr - '$tu3':$dac=$ta3:$fs=$fs3:$mm=$mm3:$mc=$mc3:$mj=$mj3:$mn=$mn3:$ms=$ms3:$mw=$mw3:$qs=$qs1"     >>$file_in2
exec echo "$par - '$ta1'"     >>$file_in2
exec echo "$usr - '$tu3':$dac=$ta1:$fs=$fs2:$mm=$mm1:$mc=$mc1:$mj=$mj1:$mn=$mn1:$ms=$ms1:$mw=$mw1:$qs=$qs1"     >>$file_in2

#
# Third input file - to replace all previous
#
exec echo "$clu - '$tc1':$class=$class3:$fs=$fs6:$gm=$gm6:$gc=$gc6:$gj=$gj6:$gn=$gn6:$gs=$gs6:$gw=$gw6:$mm=$mm6:$mc=$mc6:$mj=$mj6:$mn=$mn6:$ms=$ms6:$mw=$mw6:$qs=$qs1"    >>$file_in3
exec echo "$par - '$roo'"    >>$file_in3
exec echo "$acc - '$ta1':$dsc=$ds1:$org=$or1:$fs=$fs5:$gm=$gm5:$gc=$gc5:$gj=$gj5:$gn=$gn5:$gs=$gs5:$gw=$gw5:$mm=$mm5:$mc=$mc5:$mj=$mj5:$mn=$mn5:$ms=$ms5:$mw=$mw5:$qs=$qs1"    >>$file_in3
exec echo "$acc - '$ta3':$dsc=$ds3:$org=$or3:$fs=$fs5:$gm=$gm5:$gc=$gc5:$gj=$gj5:$gn=$gn5:$gs=$gs5:$gw=$gw5:$mm=$mm5:$mc=$mc5:$mj=$mj5:$mn=$mn5:$ms=$ms5:$mw=$mw5:$qs=$qs1"    >>$file_in3
exec echo "$par - '$ta1'"    >>$file_in3
exec echo "$acc - '$ta3':$dsc=$ds1:$org=$or1:$fs=$fs5:$gm=$gm5:$gc=$gc5:$gj=$gj5:$gn=$gn5:$gs=$gs5:$gw=$gw5:$mm=$mm5:$mc=$mc5:$mj=$mj5:$mn=$mn5:$ms=$ms5:$mw=$mw5:$qs=$qs1"    >>$file_in3
exec echo "$acc - '$ta2':$dsc=$ds2:$org=$or2:$fs=$fs4:$gm=$gm4:$gc=$gc4:$gj=$gj4:$gn=$gn4:$gs=$gs4:$gw=$gw4:$mm=$mm4:$mc=$mc4:$mj=$mj4:$mn=$mn4:$ms=$ms4:$mw=$mw4:$qs=$qs1:$al=$alo"    >>$file_in3
exec echo "$usr - '$tu3':$coo=$ta1,$ta2,$ta3:$dac=$ta1:$fs=$fs2:$mm=$mm1:$mc=$mc1:$mj=$mj1:$mn=$mn1:$ms=$ms1:$mw=$mw1:$qs=$qs1:$al=$ala"     >>$file_in3
exec echo "$par - '$ta2'"    >>$file_in3
exec echo "$usr - '$tu1':$coo=$ta2:$dac=$ta2:$fs=$fs1:$mm=$mm2:$mc=$mc2:$mj=$mj2:$mn=$mn2:$ms=$ms2:$mw=$mw2:$qs=$qs1:$al=$alo"    >>$file_in3
exec echo "$usr - '$tu3':$dac=$ta2:$fs=$fs2:$mm=$mm2:$mc=$mc2:$mj=$mj2:$mn=$mn2:$ms=$ms2:$mw=$mw2:$qs=$qs1"    >>$file_in3
exec echo "$par - '$ta3'"    >>$file_in3
exec echo "$usr - '$tu2':$coo=$ta3:$dac=$ta3:$fs=$fs3:$mm=$mm3:$mc=$mc3:$mj=$mj3:$mn=$mn3:$ms=$ms3:$mw=$mw3:$qs=$qs1"    >>$file_in3
exec echo "$usr - '$tu3':$dac=$ta3:$fs=$fs3:$mm=$mm3:$mc=$mc3:$mj=$mj3:$mn=$mn3:$ms=$ms3:$mw=$mw3:$qs=$qs1"    >>$file_in3

set matches 0
spawn $sacctmgr -i load $file_in
expect {
	-re "(Unable to read *.* * No such file or directory)" {
	        fail "There was a problem with the file"
	}
	-re "error" {
	        fail "There was a problem with the file"
	}
	-re "Problem with requests" {
	        fail "There was a problem with the request"
	}
	-re "For cluster $tc1" {
		incr matches
		exp_continue
	}
	"Classification: $class1" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 1"
	}
	eof {
		wait
	}
}

if {$matches != 2} {
	fail "File load 1 incorrect ($matches != 2)"
}

#
# Use sacctmgr to list the test original association additions
#
set matches 0
spawn $sacctmgr -n -p $lis $as $clu=$tc1 $fmt=$clu,$acc,$usr,$pts,$fs,$gm,$gc,$gj,$gn,$gs,$gw,$mc,$mm,$mj,$mn,$ms,$mw,$qs
expect {
	-re "There was a problem" {
	        fail "There was a problem with the sacctmgr command"
	}
	-re "($tc1.$roo...$fs6.$gm6.$gc6.$gj6.$gn6.$gs6.$gt6.$mc6.$mm6.$mj6.$mn6.$ms6.$mt6.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$roo.$roo..1.......$mc6.$mm6.$mj6.$mn6.$ms6.$mt6.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta1...$fs5.$gm5.$gc5.$gj5.$gn5.$gs5.$gt5.$mc5.$mm5.$mj5.$mn5.$ms5.$mt5.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta3...$fs3.$gm3.$gc3.$gj3.$gn3.$gs3.$gt3.$mc3.$mm3.$mj3.$mn3.$ms3.$mt3.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta3.$tu2..$fs2.......$mc1.$mm1.$mj1.$mn1.$ms1.$mt1.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta2...$fs4.$gm4.$gc4.$gj4.$gn4.$gs4.$gt4.$mc4.$mm4.$mj4.$mn4.$ms4.$mt4.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta2.$tu1..$fs1.......$mc2.$mm2.$mj2.$mn2.$ms2.$mt2.$qs1)" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 2"
	}
	eof {
		wait
	}
}

if {$matches != 7} {
	fail "Associations addition 7 incorrect ($matches != 7)"
}

#
# Use sacctmgr to list the test original Admin Levels and Account Coordinators
#
set matches 0
spawn $sacctmgr -n -p $lis $usr $fmt=$usr,$col,$al $wco
expect {
	-re "There was a problem" {
	    fail "There was a problem with the sacctmgr command"
	}
	-re "($tu1.$ta2.$alo)" {
		incr matches
		exp_continue
	}
	-re "($tu2.$ta3.$ala)" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 3"
	}
	eof {
		wait
	}
}

if {$matches != 2} {
	fail "Adminstrator and coordinator 2 incorrect ($matches != 2)"
}

set matches 0
spawn $sacctmgr -i load $file_in2
expect {
	-re "(Unable to read *.* * No such file or directory)" {
	    fail "There was a problem with the file"
	}
	-re "error" {
	    fail "There was a problem with the file"
	}
	-re "Problem with requests" {
	    fail "There was a problem with the request"
	}
	-re "For cluster $tc1" {
		incr matches
		exp_continue
	}

	"$class1 -> $class2" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr load not responding 4"
	}
	eof {
		wait
	}
}

if {$matches != 2} {
	fail "File load 2 incorrect ($matches != 2)"
}

#
# Use sacctmgr to list the test modifications to the original association
#
set matches 0

spawn $sacctmgr -n -P $lis $as $clu=$tc1 $fmt=$clu,$acc,$usr,$fs,$gm,$gc,$gj,$gn,$gs,$gw,$mc,$mm,$mj,$mn,$ms,$mw,$qs
expect {
	-re "There was a problem" {
	    fail "there was a problem with the sacctmgr command"
	}
	-re "($tc1.$roo..$fs6.$gm6.$gc6.$gj6.$gn6.$gs6.$gt6.$mc6.$mm6.$mj6.$mn6.$ms6.$mt6.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$roo.$roo.1.......$mc6.$mm6.$mj6.$mn6.$ms6.$mt6.$qs1)" {
		incr matches
		log_debug "2"
		exp_continue
	}
	-re "($tc1.$ta1..$fs5.$gm5.$gc5.$gj5.$gn5.$gs5.$gt5.$mc5.$mm5.$mj5.$mn5.$ms5.$mt5.$qs1)" {
		incr matches
		log_debug "3"
		exp_continue
	}
	-re "($tc1.$ta1.$tu3.$fs2.......$mc1.$mm1.$mj1.$mn1.$ms1.$mt1.$qs1)" {
		incr matches
		log_debug "4"
		exp_continue
	}
	-re "($tc1.$ta2..$fs4.$gm4.$gc4.$gj4.$gn4.$gs4.$gt4.$mc4.$mm4.$mj4.$mn4.$ms4.$mt4.$qs1)" {
		incr matches
		log_debug "5"
		exp_continue
	}
	-re "($tc1.$ta2.$tu1.$fs1.......$mc2.$mm2.$mj2.$mn2.$ms2.$mt2.$qs1)" {
		incr matches
		log_debug "6"
		exp_continue
	}
	-re "($tc1.$ta2.$tu3.$fs2.......$mc2.$mm2.$mj2.$mn2.$ms2.$mt2.$qs1)" {
		incr matches
		log_debug "7"
		exp_continue
	}
	-re "($tc1.$ta3..$fs5.$gm5.$gc5.$gj5.$gn5.$gs5.$gt5.$mc5.$mm5.$mj5.$mn5.$ms5.$mt5.$qs1)" {
		incr matches
		log_debug "8"
		exp_continue
	}
	-re "($tc1.$ta3.$tu2.$fs3.......$mc3.$mm3.$mj3.$mn3.$ms3.$mt3.$qs1)" {
		incr matches
		log_debug "9"
		exp_continue
	}
	-re "($tc1.$ta3.$tu3.$fs3.......$mc3.$mm3.$mj3.$mn3.$ms3.$mt3.$qs1)" {
		incr matches
		log_debug "10"
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 5"
	}
	eof {
		wait
	}
}

if {$matches != 10} {
	fail "Association modification 10 incorrect ($matches != 10)"
}

#
# Use sacctmgr to list the test modification Admin Levels and Account Coordinators
#
set matches 0
spawn $sacctmgr -n -p $lis $usr $fmt=$usr,$col,$al $wco
expect {
	-re "There was a problem" {
	    fail "There was a problem with the sacctmgr command"
	}
	-re "($tu1.$ta2.$alo)" {
		incr matches
		exp_continue
	}
	-re "($tu2.$ta3.$alo)" {
		incr matches
		exp_continue
	}
	-re "($tu3.$ta1,$ta2,$ta3.$ala)" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 6"
	}
	eof {
		wait
	}
}

if {$matches != 3} {
	fail "Adminstrator and coordinator 3 incorrect ($matches != 3)"
}

set matches 0
spawn $sacctmgr -i load $file_in3 clean
expect {
	-re "(Unable to read *.* * No such file or directory)" {
	    fail "There was a problem with the file"
	}
	-re "error" {
	    fail "There was a problem with the file"
	}
	-re "Problem with requests" {
	    fail "There was a problem with the request"
	}
	-re "For cluster $tc1" {
		incr matches
		exp_continue
	}
	"Classification: $class3" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 7"
	}
	eof {
		wait
	}
}

if {$matches != 2} {
	fail "File load 2 incorrect ($matches != 2)"
}

#
# Use sacctmgr to list the test modifications to the original association
#
set matches 0
spawn $sacctmgr -n -p $lis $as $clu=$tc1 $fmt=$clu,$acc,$usr,$pts,$fs,$gm,$gc,$gj,$gn,$gs,$gw,$mc,$mm,$mj,$mn,$ms,$mw,$qs
expect {
	-re "There was a problem" {
	    fail "there was a problem with the sacctmgr command"
	}
	-re "($tc1.$roo...$fs6.$gm6.$gc6.$gj6.$gn6.$gs6.$gt6.$mc6.$mm6.$mj6.$mn6.$ms6.$mt6.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$roo.$roo..1.......$mc6.$mm6.$mj6.$mn6.$ms6.$mt6.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta1...$fs5.$gm5.$gc5.$gj5.$gn5.$gs5.$gt5.$mc5.$mm5.$mj5.$mn5.$ms5.$mt5.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta1.$tu3..$fs2.......$mc1.$mm1.$mj1.$mn1.$ms1.$mt1.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta2...$fs4.$gm4.$gc4.$gj4.$gn4.$gs4.$gt4.$mc4.$mm4.$mj4.$mn4.$ms4.$mt4.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta2.$tu1..$fs1.......$mc2.$mm2.$mj2.$mn2.$ms2.$mt2.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta2.$tu3..$fs2.......$mc2.$mm2.$mj2.$mn2.$ms2.$mt2.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta3...$fs5.$gm5.$gc5.$gj5.$gn5.$gs5.$gt5.$mc5.$mm5.$mj5.$mn5.$ms5.$mt5.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta3.$tu2..$fs3.......$mc3.$mm3.$mj3.$mn3.$ms3.$mt3.$qs1)" {
		incr matches
		exp_continue
	}
	-re "($tc1.$ta3.$tu3..$fs3.......$mc3.$mm3.$mj3.$mn3.$ms3.$mt3.$qs1)" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 8"
	}
	eof {
		wait
	}
}

if {$matches != 10} {
	fail "Clean association addition 10 incorrect ($matches != 10)"
}

#
# Use sacctmgr to list the test modification Admin Levels and Account Coordinators
#
set matches 0
spawn $sacctmgr -n -p $lis $usr $fmt=$usr,$col,$al $wco
expect {
	-re "There was a problem" {
	    fail "There was a problem with the sacctmgr command"
	}
	-re "($tu1.$ta2.$alo)" {
		incr matches
		exp_continue
	}
	-re "($tu2.$ta3.$alo)" {
		incr matches
		exp_continue
	}
	-re "($tu3.$ta1,$ta2,$ta3.$ala)" {
		incr matches
		exp_continue
	}
	timeout {
		fail "sacctmgr list associations not responding 9"
	}
	eof {
		wait
	}
}

if {$matches != 3} {
	fail "Adminstrator and coordinator 3 incorrect ($matches != 3)"
}
