#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
#          lsid wrapper test
############################################################################
# Copyright (C) 2011-2016 SchedMD LLC
# Written by Alejandro Sanchez <alex@schedmd.com>
#
# 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 exit_code   0

if {[file executable $lsid] == 0} {
	skip "$lsid does not exist"
}

set cluster_name [get_config_param "ClusterName"]
regsub {\(.*} [get_config_param {SlurmctldHost[0]}] {} control_machine
set lsid_cluster_name ""
set lsid_control_machine ""
set cluster_name_ok 0
set control_machine_ok 0

spawn $lsid
expect {
	-re "My cluster name is ($re_word_str)" {
		set lsid_cluster_name $expect_out(1,string)
		exp_continue
	}
	-re "My master name is ($re_word_str)" {
		set lsid_control_machine $expect_out(1,string)
		exp_continue
	}
	timeout {
		fail "lsid not responding"
	}
	eof {
		wait
	}
}

if {[string compare $cluster_name $lsid_cluster_name]} {
	log_error "lsid's cluster name does not match the configured parameter ($cluster_name != $lsid_cluster_name)"
	set exit_code 1
}

if {[string compare $control_machine $lsid_control_machine]} {
	log_error "lsid's master name does not match the configured parameter ($control_machine != $lsid_control_machine)"
	set exit_code 1
}

if {$exit_code} {
	fail "Test failed due to previous errors (\$exit_code = $exit_code)"
}
