-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.sh
executable file
·158 lines (145 loc) · 4.06 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash -leE
# Setup paths
BASE_DIR=`pwd`
print_usage()
{
echo "Usage:"
echo -e "$0 --prepare [force] <SLURM_HOST_PREFIX>"
echo -e "\tSLURM will be compiled and installed in SLURM_HOST_PREFIX"
echo -e "\t\"force\" will force replacement of images and SLURM installation"
echo -e "$0 --test <SLURM_HOST_PREFIX> <SLURM_SOURCES> <NUM_NODES>"
echo -e "\tSLURM_HOST_PREFIX - path where SLURM host intallation can be found"
echo -e "\t should be the same as for \"--prepare\""
echo -e "\tSLURM_SOURCES - path to the cloned repo that should be tested"
echo -e "\tNUM_NODES - number of virtual machines to boot"
}
prepare_host()
{
PREFIX_DIR=$1
cd $HOST_DIR
# Sanity check
if [ -f "$PREFIX_DIR/bin/srun" ] || [ -f "$PREFIX_DIR/bin/munge" ]; then
if [ "$FORCE" != "1" ]; then
echo "WARNING: SLURM installation found in $PREFIX_DIR"
echo "Use --force to overwrite it"
exit 1
else
rm --preserve-root -fR $PREFIX_DIR
fi
fi
./prepare_host.sh $PREFIX_DIR
cd $BASE_DIR
}
prepare_dev_image()
{
# NOTE: we need to use <pipeline> || true to
# hide error exit code = 1 from grep
STR=`docker images | awk '{ print $1 }' | grep $DEV_IMG_NAME || true`
if [ -n "$STR" ] && [ "$FORCE" != "1" ]; then
echo "WARNING: developer image was found"
echo "Use --force to remove it"
exit 1
else
if [ -n "$STR" ]; then
docker rmi -f $DEV_IMG_NAME
fi
cd $DEV_IMG_DIR
./dev_img.sh
cd $BASE_DIR
fi
STR=`docker images | awk '{ print $1 }' | grep $NODE_IMG_NAME || true`
if [ -n "$STR" ] && [ "$FORCE" != "1" ]; then
echo "WARNING: node image was found"
echo "Use --force to remove it"
exit 1
else
if [ -n "$STR" ]; then
docker rmi -f $NODE_IMG_NAME
fi
cd $NODE_IMG_DIR
./node_img.sh
cd $BASE_DIR
fi
}
build_all()
{
if [ -f $FINAL_DIR/$ROOT_TAR_NAME ]; then
#already build root fs
return
fi
mkdir -p $BUILD_SRC
cp -R $SLURM_SOURCES $BUILD_SRC/slurm
cd $BUILD_DIR
tmp_file=`mktemp`
tmp_image=`basename $tmp_file | tr '[:upper:]' '[:lower:]'`
./prepare.sh $tmp_image
rm $tmp_file
mv $BUILD_DIR/$ROOT_TAR_NAME $FINAL_DIR
cd $BASE_DIR
}
create_node_image()
{
cd $FINAL_DIR
docker build --no-cache=true -t "$CLUSTER_IMG" .
cd $BASE_DIR
}
run_cluster()
{
cd $RUNNING_DIR
./run_cluster.sh $CLUSTER_IMG $NODES
cd $BASE_DIR
docker rmi $CLUSTER_IMG
}
case "$1" in
"--prepare")
FORCE=0
if [ "$2" == "force" ]; then
FORCE=1
shift
fi
HOST_DIR=$BASE_DIR/prepare_host
DEV_IMG_DIR=$BASE_DIR/dev_img
DEV_IMG_NAME="dev_img"
NODE_IMG_DIR=$BASE_DIR/node_img
NODE_IMG_NAME="node_img"
prepare_host $2
prepare_dev_image
;;
"--test")
#Skip first param
shift
# Enable bash trace
ROOT_TAR_NAME="root.tar.bz2"
BUILD_DIR=$BASE_DIR/compile_img
BUILD_SRC=$BUILD_DIR/src
FINAL_DIR=$BASE_DIR/cluster_img
CLUSTER_IMG_NAME_FILE=`mktemp`
CLUSTER_IMG=`basename $CLUSTER_IMG_NAME_FILE | tr '[:upper:]' '[:lower:]'`
RUNNING_DIR=$BASE_DIR/run_cluster
# Path to the host installation
export SLURM_HOST_PREFIX=$1
SLURM_SOURCES=$2
NODES=$3
if [ ! -f $SLURM_HOST_PREFIX/bin/sbatch ] || \
[ ! -f $SLURM_HOST_PREFIX/bin/squeue ]; then
echo "ERROR: No slurm host installation found."
print_usage
exit 1
fi
if [ ! -d $SLURM_SOURCES ]; then
echo "ERROR: No slurm sources found. Nothing to check"
print_usage
exit 1
fi
set -x
build_all
create_node_image
run_cluster
# Cleanup temp filename
rm $CLUSTER_IMG_NAME_FILE
;;
*)
print_usage
exit 1
;;
esac