System test refinement
[anna.git] / example / diameter / launcher / deployments / st-client / configure.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6 MAXIMUM_ADML_ASYNC_RATE=50
7 MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE=10
8 ADML_INSTANCES__ST_CONF_FILE=.st_conf_adml_instances
9 ADML_CONNECTIONS__ST_CONF_FILE=.st_conf_adml_connections
10 CYCLE_REPEATS__ST_CONF_FILE=.st_conf_cycle_repeats
11 N_TESTCASES__ST_CONF_FILE=.st_conf_n_testcases
12 ADML_RATE_PER_INSTANCE__ST_CONF_FILE=.st_conf_rate_per_instance
13 ADML_DESIRED_RATE__ST_CONF_FILE=.st_conf_desired_rate
14 N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE=.st_conf_n_testcases_program_layout
15
16 #############
17 # FUNCTIONS #
18 #############
19 _exit () {
20   echo
21   echo $1
22   echo
23   exit 1
24 }
25
26 # ceil of division $1/$2
27 ceil() {
28   #echo "$1 $2" | awk '{print int( ($1/$2) + 1 )}'
29   awk -vnumber="$1" -vdiv="$2" '
30   function ceiling(x){return x%1 ? int(x)+1 : x}
31   BEGIN{ print ceiling(number/div) }'
32 }
33
34 # Calculates the number of ADML instances and their client connections
35 calculate_deployment_layout() {
36   echo "Input the maximum client connections accepted by the server to be tested [5000]:"
37   read max_server_accepted_connections
38   [ "$max_server_accepted_connections" = "" ] && max_server_accepted_connections=5000
39
40   echo "Input the maximum test case rate per second:"
41   read desired_rate
42   while [ -z "$desired_rate" ]; do read desired_rate; done
43
44   max_connections=$((desired_rate/MAXIMUM_ADML_ASYNC_RATE))
45   if [ $max_connections -eq 0 ]
46   then
47     G_ADML_CONNECTIONS=1
48     G_ADML_INSTANCES=1
49     return
50   fi
51   max_adml_instances=$((max_server_accepted_connections/MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE))
52   if [ $max_connections -gt $max_server_accepted_connections ]
53   then
54     echo
55     echo "Maximum rate reached for $max_server_accepted_connections server connections:"
56     G_ADML_CONNECTIONS=$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE
57     G_ADML_INSTANCES=$max_adml_instances
58     return
59   fi
60
61   echo
62   echo "==========================================================================================================="
63   echo "Orientative table"
64   echo "-----------------------------------------------------------------------------------------------------------"
65   echo -e "Connects per instance:\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10"
66   echo -n "Number of instances:  "
67   for conn in `seq 1 $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE`
68   do
69     instances=$(ceil $max_connections $conn)
70     echo -n -e "\t$instances"
71   done
72   echo
73   echo "==========================================================================================================="
74   echo
75   echo "Input selection (connections per instance 1..$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE) [1]:"
76   read G_ADML_CONNECTIONS
77   [ -z "$G_ADML_CONNECTIONS" ] && G_ADML_CONNECTIONS=1
78   [ $G_ADML_CONNECTIONS -lt 1 ] && G_ADML_CONNECTIONS=1
79   if [ $G_ADML_CONNECTIONS -gt 1 ]
80   then
81     echo "Remember to add 'diameterServerSessions="$G_ADML_CONNECTIONS"' on servers services.xml file (node tag)"
82     echo " in case that you are testing against ADML servers."
83     echo
84     echo "Press ENTER to continue, CTRL-C to abort ..."
85     read dummy
86   fi
87   if [ $G_ADML_CONNECTIONS -gt $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE ]
88   then
89     G_ADML_CONNECTIONS=$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE
90   fi
91   
92   G_ADML_INSTANCES=$(ceil $max_connections $G_ADML_CONNECTIONS)
93 }
94
95 #############
96 # EXECUTION #
97 #############
98
99 cd `dirname $0`
100
101 echo
102 echo "====================================="
103 echo "ADML SYSTEM TEST CONFIGURATION WIZARD"
104 echo "====================================="
105 echo
106 [ -d ADMLS ] && _exit "ADMLS directory still exists. Please remove it to continue (perhaps you have to 'pkill ADML' before) !"
107 [ ! -d realms ] && _exit "Missing realms configuration (expecting '$PWD/realms' directory). Try with 'realms-example' and see README inside it !"
108
109 calculate_deployment_layout
110
111 # Dump persintently:
112 echo $G_ADML_INSTANCES > $ADML_INSTANCES__ST_CONF_FILE
113 echo $G_ADML_CONNECTIONS > $ADML_CONNECTIONS__ST_CONF_FILE
114
115 # Rate per instance:
116 #rate_per_instance=$(ceil $desired_rate $G_ADML_INSTANCES)
117 rate_per_instance=$((desired_rate/$G_ADML_INSTANCES))
118 [ $rate_per_instance -lt 1 ] && rate_per_instance=1
119 echo $rate_per_instance > $ADML_RATE_PER_INSTANCE__ST_CONF_FILE
120 echo $desired_rate > $ADML_DESIRED_RATE__ST_CONF_FILE
121
122 echo
123 echo "Suggested layout:"
124 echo " - $G_ADML_INSTANCES ADML instances"
125 echo " - $G_ADML_CONNECTIONS client connections per ADML instance"
126 maximum_rate=$((G_ADML_INSTANCES*G_ADML_CONNECTIONS*MAXIMUM_ADML_ASYNC_RATE))
127 echo " - Maximum rate: $maximum_rate test cases per second"
128 echo
129 echo "Usually, you will program a test case per subscriber. Input the number of test cases to program:"
130 read N_TESTCASES
131 while [ -z "$N_TESTCASES" ]; do read N_TESTCASES; done
132 echo $N_TESTCASES > $N_TESTCASES__ST_CONF_FILE
133 testcase_per_adml_instance=$N_TESTCASES
134 echo
135 time_covered_1=$(ceil $N_TESTCASES $maximum_rate)
136 time_covered=$(ceil $N_TESTCASES $((maximum_rate*G_ADML_INSTANCES)))
137 echo "That amount covers $time_covered_1 seconds for one running ADML instance."
138 if [ $G_ADML_INSTANCES -gt 1 ]
139 then
140   echo "But you will have $G_ADML_INSTANCES instances running in parallel, then the total covered time is: $time_covered seconds"
141   testcase_per_adml_instance=$((N_TESTCASES/G_ADML_INSTANCES))
142   echo "(aproximately, $testcase_per_adml_instance test cases will be programmed on each ADML instance)"
143 fi
144
145 0>$N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
146 for instance in `seq 1 $G_ADML_INSTANCES`
147 do
148   offset=$((testcase_per_adml_instance * (instance-1)))
149   ini=$((offset + 1))
150   fin=$((offset + testcase_per_adml_instance))
151   echo "$instance $ini $fin" >> $N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
152 done
153
154 echo
155 if [ $time_covered -lt 300 ]
156 then
157   echo "$time_covered seconds is under 5 minutes, you should add more test cases to the pool except if you are sure"
158   echo " they will take less time that cycle completion. You could ensure that with a first timeout step."
159   echo "Configuring such timeout slightly under $((1000*time_covered)) milliseconds, you could repeat the cycle safely to"
160   echo " obtain a greater total time of testing."
161 fi
162 echo
163 echo "How many total time do you want to cover (in minutes):"
164 read minutes
165 while [ -z "$minutes" ]; do read minutes; done
166 seconds=$((minutes*60))
167 repeats=$(ceil $seconds $time_covered)
168 echo $repeats > $CYCLE_REPEATS__ST_CONF_FILE
169 [ $repeats -gt 0 ] && echo "Configured $repeats cycle repeats ($repeats x $time_covered seconds ~ $seconds seconds (desired $minutes minutes)"
170 echo
171 echo "System test configuration completed."
172 echo
173 echo "Ready to clone/start the ADML instances: press ENTER to continue, CTRL+C to abort ..."
174 read dummy
175
176 # Update services.xml regarding the number of client connections:
177 cd realms
178 cp services.msk services.xml
179 sed -i 's/__CLIENT_CONNECTIONS__/'$G_ADML_CONNECTIONS'/g' services.xml
180 cd - >/dev/null
181
182
183 for instance in `seq 1 $G_ADML_INSTANCES`
184 do
185   echo "Creating ADMLS/$instance ..."
186   mkdir -p ADMLS/$instance
187   cd ADMLS/$instance
188   # Create resources:
189   ln -s ../../.operation-one.sh operation.sh
190   ln -s ../../pre-start.sh
191   cp ../../.run-one.sh run.sh
192   sed -i 's/^EXE=.*/EXE=ADML-'$instance'/' run.sh
193   ln -s ../../ADML-launcher ADML-$instance
194   for xml in `ls ../../realms/*xml`; do ln -s $xml; done
195   cd - >/dev/null
196 done
197
198 echo
199 echo "Now you can run all the instances deployed: ./run.sh"
200 echo
201 echo "Done!"
202