scripts/common.zsh

102 lines
2.0 KiB
Bash

#!/bin/zsh
##############################
# #
# NFS client configuration #
# #
##############################
CLIENT=(client)
MOUNTPOINT=(/mnt/test)
SCRATCHMNT=(/mnt/scratch)
##############################
# #
# NFS server configuration #
# #
##############################
SERVER=(server)
EXPORT=(/srv/xfs/test)
SCRATCH=(/srv/xfs/scratch)
NO_SERVER_ACCESS=()
###########################
# #
# General configuration #
# #
###########################
BIN=$HOME/.local/bin
COLORS=$BIN/colors
DMESG=()
PROTO=(tcp)
SRVDMESG=()
USER=$(whoami)
VERSION=(3 4)
######################
# #
# Shared functions #
# #
######################
function client_run()
{
zparseopts -D -K t=TERMINAL
[[ ! -z $TERMINAL ]] && SSH_OPT="-t"
ssh $SSH_OPT ${CLIENT[-1]} sudo run.zsh $*
}
function client_setup()
{
ssh ${CLIENT[-1]} sudo setup.zsh $*
}
function setup_client_func()
{
client_setup testdirs.zsh ${SERVER[-1]} ${EXPORT[-1]} \
${MOUNTPOINT[-1]} $USER
}
function prepare_to_test()
{
$BIN/vm.zsh boot ${CLIENT[-1]} ${SERVER[-1]}
$BIN/install-scripts.zsh ${CLIENT[-1]}
if [ ${#DMESG} -gt 0 ]; then
ssh ${CLIENT[-1]} "sudo dmesg --clear"
fi
if [ ${#SRVDMESG} -gt 0 ]; then
ssh ${SERVER[-1]} "sudo dmesg --clear"
fi
if [ ${#RDMA} -gt 0 ]; then
PROTO+=(rdma)
if [ ${#NO_SERVER_ACCESS} -gt 0 ]; then
$BIN/rdma.zsh ${RDMA[-1]} ${CLIENT[-1]}
else
$BIN/rping.zsh ${RDMA[-1]} ${CLIENT[-1]} ${SERVER[-1]}
fi
fi
setup_client_func
check_versions
echo
}
function check_versions()
{
valid=(3 4.0 4.1 4.2)
if [[ ${VERSION[(ie)4]} -le ${#VERSION} ]]; then
VERSION+=(4.0 4.1 4.2)
fi
VERSION=(${(ou)VERSION})
VERSION=(${VERSION:*valid})
}
TRAPEXIT()
{
if [ ${#DMESG} -gt 0 ]; then
ssh ${CLIENT[-1]} "sudo dmesg --color=always"
fi
if [ ${#SRVDMESG} -gt 0 ]; then
ssh ${SERVER[-1]} "sudo dmesg --color=always"
fi
}