Added CSIT for Macroflow with HEAT
[integration/csit.git] / plans / so / integration-etsi-testing / config / apply-workarounds.sh
index f6bf906..4ecf880 100755 (executable)
@@ -27,7 +27,9 @@ NORTH_BOUND_TABLE_NAME="northbound_request_ref_lookup"
 TABLE_EXISTS_QUERY="select count(*) from information_schema.tables WHERE table_schema='$CATALOG_DB' AND table_name='$BUIDLING_BLOCK_TABLE_NAME';"
 BUILDING_BLOCK_COUNT_QUERY="select count(*) from $BUIDLING_BLOCK_TABLE_NAME;"
 FLY_WAY_MIGRATION_QUERY="SELECT COUNT(*) FROM flyway_schema_history WHERE script LIKE '%R__MacroData%' AND installed_on IS NOT NULL;"
-
+SLEEP_TIME=5
+TIME_OUT_DEFAULT_VALUE_SEC=1200 #20 mins
+SCRIPT_NAME=$(basename $0)
 
 current_timestamp()
 {
@@ -36,51 +38,58 @@ current_timestamp()
 
 wait_for_database_availability()
 {
- echo "$(current_timestamp): Checking for database availability"
+ echo "$SCRIPT_NAME $(current_timestamp): Checking for database availability"
  until echo '\q' | mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB; do
-     >&2 echo "$(current_timestamp): Database is unavailable - sleeping for 5 seconds"
-     sleep 5
+     >&2 echo "$SCRIPT_NAME $(current_timestamp): Database is unavailable - sleeping for ${SLEEP_TIME} seconds"
+     isTimeOut
+     sleep ${SLEEP_TIME}
  done
 
- echo "$(current_timestamp): Database is available now"
+ echo "$SCRIPT_NAME $(current_timestamp): Database is available now"
 }
 
 wait_container_to_create_table()
 {
  while [ $(mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB -sse "$TABLE_EXISTS_QUERY") -eq "0" ] ; do
-     echo "$(current_timestamp): Waiting for so-catalog container to create tables - sleeping for 5 seconds"
-     sleep 5
+     echo "$SCRIPT_NAME $(current_timestamp): Waiting for so-catalog container to create tables - sleeping for ${SLEEP_TIME} seconds"
+     isTimeOut
+     sleep ${SLEEP_TIME}
  done
 
  while [ $(mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB -sse "$BUILDING_BLOCK_COUNT_QUERY") -eq "0" ] ; do
-     echo "$(current_timestamp): Waiting for so-catalog container to insert records in $BUIDLING_BLOCK_TABLE_NAME - sleeping for 5 seconds"
-     sleep 5
+     echo "$SCRIPT_NAME $(current_timestamp): Waiting for so-catalog container to insert records in $BUIDLING_BLOCK_TABLE_NAME - sleeping for ${SLEEP_TIME} seconds"
+     isTimeOut
+     sleep ${SLEEP_TIME}
  done
 
- echo "$(current_timestamp): $CATALOG_DB tables available now . . ."
+ echo "$SCRIPT_NAME $(current_timestamp): $CATALOG_DB tables available now . . ."
 }
 
 wait_for_flyway_migration_to_finish()
 {
  while [ $(mysql -h $DB_HOST -P $DB_PORT -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB -sse "$FLY_WAY_MIGRATION_QUERY") -ne "1" ] ; do
-     echo "$(current_timestamp): Waiting for flyway migration sql statement to finish with success - sleeping for 5 seconds"
-     sleep 5
+     echo "$SCRIPT_NAME $(current_timestamp): Waiting for flyway migration sql statement to finish with success - sleeping for ${SLEEP_TIME} seconds"
+     isTimeOut
+     sleep ${SLEEP_TIME}
  done
- echo "$(current_timestamp): flyway migration finished . . . "
+ echo "$SCRIPT_NAME $(current_timestamp): flyway migration finished . . . "
 }
 
 
 apply_workaround()
 {
- echo "$(current_timestamp): Applying workaround . . ."
+ echo "$SCRIPT_NAME $(current_timestamp): Applying workaround . . ."
 
  wait_for_database_availability
  wait_container_to_create_table
  wait_for_flyway_migration_to_finish
 
- echo "$(current_timestamp): Will insert data into $CATALOG_DB"
+ echo "$SCRIPT_NAME $(current_timestamp): Will insert data into $CATALOG_DB"
 mysql -h $DB_HOST -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB << EOF
   BEGIN;
+  
+  UPDATE $NORTH_BOUND_TABLE_NAME SET SERVICE_TYPE="*";
+
   INSERT INTO $BUIDLING_BLOCK_TABLE_NAME (BUILDING_BLOCK_NAME,RESOURCE_TYPE,TARGET_ACTION) values ("EtsiVnfInstantiateBB", "VNF", "ACTIVATE");
   INSERT INTO $BUIDLING_BLOCK_TABLE_NAME (BUILDING_BLOCK_NAME,RESOURCE_TYPE,TARGET_ACTION) values ("EtsiVnfDeleteBB", "VNF", "DEACTIVATE");
  
@@ -100,17 +109,42 @@ mysql -h $DB_HOST -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB << EOF
 
  UPDATE orchestration_status_state_transition_directive SET FLOW_DIRECTIVE='CONTINUE' WHERE RESOURCE_TYPE='VNF' AND ORCHESTRATION_STATUS='CREATED' AND TARGET_ACTION='ACTIVATE' AND FLOW_DIRECTIVE='FAIL';
 
+ insert into cloud_sites(ID, REGION_ID, IDENTITY_SERVICE_ID, CLOUD_VERSION, CLLI, ORCHESTRATOR) values("EtsiCloudRegion", "EtsiCloudRegion", "DEFAULT_KEYSTONE", "2.5", "clli2", "multicloud");
+
  COMMIT;
 EOF
 
  if [ $? -ne 0 ]; then
-    echo "$(current_timestamp): Failed to execute workaround . . ."
+    echo "$SCRIPT_NAME $(current_timestamp): Failed to execute workaround . . ."
     exit 1
  fi
 
- echo "$(current_timestamp): Finished applying workaround . . ."
+ echo "$SCRIPT_NAME $(current_timestamp): Finished applying workaround . . ."
+}
+
+isTimeOut()
+{
+ if [ `date +%s` -gt $TIME_OUT_END_TIME_IN_SECONDS ]; then
+    echo "$SCRIPT_NAME $(current_timestamp): workaround script timed out . . ."
+    exit 1;
+ fi
 }
 
 # main body
+if [ -z "$TIME_OUT_IN_SECONDS"]; then
+    echo "$SCRIPT_NAME $(current_timestamp): TIME_OUT_IN_SECONDS attribute is empty will use default val: $TIME_OUT_DEFAULT_VALUE_SEC"
+    TIME_OUT_IN_SECONDS=$TIME_OUT_DEFAULT_VALUE_SEC
+fi
+
+DIGITS_REGEX='^[0-9]+$'
+if ! [[ $TIME_OUT_IN_SECONDS =~ $DIGIT_REGEX ]] ; then
+    echo "$SCRIPT_NAME $(current_timestamp): TIME_OUT_IN_SECONDS attribute Must be number: $TIME_OUT_IN_SECONDS, will use default val: $TIME_OUT_DEFAULT_VALUE_SEC"
+    TIME_OUT_IN_SECONDS=$TIME_OUT_DEFAULT_VALUE_SEC
+fi
+
+START_TIME_IN_SECONDS=`date +%s`
+TIME_OUT_END_TIME_IN_SECONDS=$(($START_TIME_IN_SECONDS+$TIME_OUT_IN_SECONDS));
+echo "$SCRIPT_NAME $(current_timestamp): Workaround script will time out at `date -d @$TIME_OUT_END_TIME_IN_SECONDS`"
+
 apply_workaround