System test refinement
[anna.git] / example / diameter / launcher / deployments / st-client / configure.sh
index 383c21a..3073050 100755 (executable)
@@ -9,6 +9,9 @@ ADML_INSTANCES__ST_CONF_FILE=.st_conf_adml_instances
 ADML_CONNECTIONS__ST_CONF_FILE=.st_conf_adml_connections
 CYCLE_REPEATS__ST_CONF_FILE=.st_conf_cycle_repeats
 N_TESTCASES__ST_CONF_FILE=.st_conf_n_testcases
+ADML_RATE_PER_INSTANCE__ST_CONF_FILE=.st_conf_rate_per_instance
+ADML_DESIRED_RATE__ST_CONF_FILE=.st_conf_desired_rate
+N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE=.st_conf_n_testcases_program_layout
 
 #############
 # FUNCTIONS #
@@ -22,7 +25,10 @@ _exit () {
 
 # ceil of division $1/$2
 ceil() {
-  echo "$1 $2" | awk '{print int( ($1/$2) + 1 )}'
+  #echo "$1 $2" | awk '{print int( ($1/$2) + 1 )}'
+  awk -vnumber="$1" -vdiv="$2" '
+  function ceiling(x){return x%1 ? int(x)+1 : x}
+  BEGIN{ print ceiling(number/div) }'
 }
 
 # Calculates the number of ADML instances and their client connections
@@ -70,9 +76,20 @@ calculate_deployment_layout() {
   read G_ADML_CONNECTIONS
   [ -z "$G_ADML_CONNECTIONS" ] && G_ADML_CONNECTIONS=1
   [ $G_ADML_CONNECTIONS -lt 1 ] && G_ADML_CONNECTIONS=1
-  [ $G_ADML_CONNECTIONS -gt $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE ] && G_ADML_CONNECTIONS=$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE
+  if [ $G_ADML_CONNECTIONS -gt 1 ]
+  then
+    echo "Remember to add 'diameterServerSessions="$G_ADML_CONNECTIONS"' on servers services.xml file (node tag)"
+    echo " in case that you are testing against ADML servers."
+    echo
+    echo "Press ENTER to continue, CTRL-C to abort ..."
+    read dummy
+  fi
+  if [ $G_ADML_CONNECTIONS -gt $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE ]
+  then
+    G_ADML_CONNECTIONS=$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE
+  fi
   
-  G_ADML_INSTANCES=$((max_connections/G_ADML_CONNECTIONS))
+  G_ADML_INSTANCES=$(ceil $max_connections $G_ADML_CONNECTIONS)
 }
 
 #############
@@ -86,6 +103,8 @@ echo "====================================="
 echo "ADML SYSTEM TEST CONFIGURATION WIZARD"
 echo "====================================="
 echo
+[ -d ADMLS ] && _exit "ADMLS directory still exists. Please remove it to continue (perhaps you have to 'pkill ADML' before) !"
+[ ! -d realms ] && _exit "Missing realms configuration (expecting '$PWD/realms' directory). Try with 'realms-example' and see README inside it !"
 
 calculate_deployment_layout
 
@@ -93,6 +112,13 @@ calculate_deployment_layout
 echo $G_ADML_INSTANCES > $ADML_INSTANCES__ST_CONF_FILE
 echo $G_ADML_CONNECTIONS > $ADML_CONNECTIONS__ST_CONF_FILE
 
+# Rate per instance:
+#rate_per_instance=$(ceil $desired_rate $G_ADML_INSTANCES)
+rate_per_instance=$((desired_rate/$G_ADML_INSTANCES))
+[ $rate_per_instance -lt 1 ] && rate_per_instance=1
+echo $rate_per_instance > $ADML_RATE_PER_INSTANCE__ST_CONF_FILE
+echo $desired_rate > $ADML_DESIRED_RATE__ST_CONF_FILE
+
 echo
 echo "Suggested layout:"
 echo " - $G_ADML_INSTANCES ADML instances"
@@ -104,6 +130,7 @@ echo "Usually, you will program a test case per subscriber. Input the number of
 read N_TESTCASES
 while [ -z "$N_TESTCASES" ]; do read N_TESTCASES; done
 echo $N_TESTCASES > $N_TESTCASES__ST_CONF_FILE
+testcase_per_adml_instance=$N_TESTCASES
 echo
 time_covered_1=$(ceil $N_TESTCASES $maximum_rate)
 time_covered=$(ceil $N_TESTCASES $((maximum_rate*G_ADML_INSTANCES)))
@@ -111,10 +138,19 @@ echo "That amount covers $time_covered_1 seconds for one running ADML instance."
 if [ $G_ADML_INSTANCES -gt 1 ]
 then
   echo "But you will have $G_ADML_INSTANCES instances running in parallel, then the total covered time is: $time_covered seconds"
-  testcase_per_adml_instance=$(ceil $N_TESTCASES $G_ADML_INSTANCES)
+  testcase_per_adml_instance=$((N_TESTCASES/G_ADML_INSTANCES))
   echo "(aproximately, $testcase_per_adml_instance test cases will be programmed on each ADML instance)"
 fi
 
+0>$N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
+for instance in `seq 1 $G_ADML_INSTANCES`
+do
+  offset=$((testcase_per_adml_instance * (instance-1)))
+  ini=$((offset + 1))
+  fin=$((offset + testcase_per_adml_instance))
+  echo "$instance $ini $fin" >> $N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
+done
+
 echo
 if [ $time_covered -lt 300 ]
 then
@@ -130,28 +166,37 @@ while [ -z "$minutes" ]; do read minutes; done
 seconds=$((minutes*60))
 repeats=$(ceil $seconds $time_covered)
 echo $repeats > $CYCLE_REPEATS__ST_CONF_FILE
-[ $repeats -gt 0 ] && echo "Configured $repeats cycle repeats ($repeats x $time_covered seconds = $seconds seconds (desired $minutes minutes)"
+[ $repeats -gt 0 ] && echo "Configured $repeats cycle repeats ($repeats x $time_covered seconds ~ $seconds seconds (desired $minutes minutes)"
 echo
 echo "System test configuration completed."
 echo
 echo "Ready to clone/start the ADML instances: press ENTER to continue, CTRL+C to abort ..."
 read dummy
-[ ! -d realms ] && _exit "Missing realms configuration (expecting '$PWD/realms' directory). Try with 'realms.example' and see README inside it !"
 
 # Update services.xml regarding the number of client connections:
-cp realms/services.msk realms/services.xml
-sed -i 's/__CLIENT_CONNECTIONS__/'$G_ADML_CONNECTIONS'/g' realms/services.xml
+cd realms
+cp services.msk services.xml
+sed -i 's/__CLIENT_CONNECTIONS__/'$G_ADML_CONNECTIONS'/g' services.xml
+cd - >/dev/null
+
 
-rm -rf ADMLS
 for instance in `seq 1 $G_ADML_INSTANCES`
 do
+  echo "Creating ADMLS/$instance ..."
   mkdir -p ADMLS/$instance
   cd ADMLS/$instance
   # Create resources:
-  ln -s ../../ADML-launcher
-  ln -s ../../operation.sh
-  ln -s ../../realms/services.xml
-  for cer in `ls ../../realms/cer*xml`; do ln -s $cer; done
+  ln -s ../../.operation-one.sh operation.sh
+  ln -s ../../pre-start.sh
+  cp ../../.run-one.sh run.sh
+  sed -i 's/^EXE=.*/EXE=ADML-'$instance'/' run.sh
+  ln -s ../../ADML-launcher ADML-$instance
+  for xml in `ls ../../realms/*xml`; do ln -s $xml; done
   cd - >/dev/null
 done
 
+echo
+echo "Now you can run all the instances deployed: ./run.sh"
+echo
+echo "Done!"
+