mik-laj commented on a change in pull request #10329:
URL: https://github.com/apache/airflow/pull/10329#discussion_r470921708



##########
File path: scripts/ci/in_container/check_environment.sh
##########
@@ -23,142 +23,95 @@ EXIT_CODE=0
 
 DISABLED_INTEGRATIONS=""
 
-function check_integration {
+function check_service {
     INTEGRATION_NAME=$1
     CALL=$2
     MAX_CHECK=${3:=1}
 
-    ENV_VAR_NAME=INTEGRATION_${INTEGRATION_NAME^^}
-    if [[ ${!ENV_VAR_NAME:=} != "true" ]]; then
-        DISABLED_INTEGRATIONS="${DISABLED_INTEGRATIONS} ${INTEGRATION_NAME}"
-        return
-    fi
-
-    echo 
"-----------------------------------------------------------------------------------------------"
-    echo "             Checking integration ${INTEGRATION_NAME}"
-    echo 
"-----------------------------------------------------------------------------------------------"
+    echo -n "${INTEGRATION_NAME}: "
     while true
     do
         set +e
         LAST_CHECK_RESULT=$(eval "${CALL}" 2>&1)
         RES=$?
         set -e
         if [[ ${RES} == 0 ]]; then
-            echo
-            echo "             Integration ${INTEGRATION_NAME} OK!"
-            echo
+            echo -e " \e[32mOK.\e[0m"
             break
         else
             echo -n "."
             MAX_CHECK=$((MAX_CHECK-1))
         fi
         if [[ ${MAX_CHECK} == 0 ]]; then
-            echo
-            echo "ERROR! Maximum number of retries while checking 
${INTEGRATION_NAME} integration. Exiting"
-            echo
+            echo -e " \e[31mERROR!\e[30m"
+            echo "Maximum number of retries while checking service. Exiting"
             break
         else
             sleep 1
         fi
     done
     if [[ ${RES} != 0 ]]; then
-        echo "        ERROR: Integration ${INTEGRATION_NAME} could not be 
started!"
+        echo "Service could not be started!"
         echo
         echo "${LAST_CHECK_RESULT}"
         echo
         EXIT_CODE=${RES}
     fi
-    echo 
"-----------------------------------------------------------------------------------------------"
 }
 
-function check_db_connection {
-    MAX_CHECK=${1:=3}
+function check_integration {
+    INTEGRATION_NAME=$1
+
+    ENV_VAR_NAME=INTEGRATION_${INTEGRATION_NAME^^}
+    if [[ ${!ENV_VAR_NAME:=} != "true" ]]; then
+        DISABLED_INTEGRATIONS="${DISABLED_INTEGRATIONS} ${INTEGRATION_NAME}"
+        return
+    fi
+    check_service "${@}"
+}
+
+function check_db_backend {
+    MAX_CHECK=${1:=1}
 
     if [[ ${BACKEND} == "postgres" ]]; then
-        HOSTNAME=postgres
-        PORT=5432
+        check_service "postgres" "nc -zvv postgres 5432" "${MAX_CHECK}"
     elif [[ ${BACKEND} == "mysql" ]]; then
-        HOSTNAME=mysql
-        PORT=3306
-    else
+        check_service "mysql" "nc -zvv mysql 3306" "${MAX_CHECK}"
+    elif [[ ${BACKEND} == "sqlite" ]]; then
         return
+    else
+        echo "Unknown backend. Supported values: [postgres,mysql,sqlite]. 
Current value: [${BACKEND}]"
+        exit 1
     fi
-    echo 
"-----------------------------------------------------------------------------------------------"
-    echo "             Checking DB ${BACKEND}"
-    echo 
"-----------------------------------------------------------------------------------------------"
-    while true
-    do
-        set +e
-        LAST_CHECK_RESULT=$(nc -zvv ${HOSTNAME} ${PORT} 2>&1)
-        RES=$?
-        set -e
-        if [[ ${RES} == 0 ]]; then
-            echo
-            echo "             Backend ${BACKEND} OK!"
-            echo
-            break
-        else
-            echo -n "."
-            MAX_CHECK=$((MAX_CHECK-1))
-        fi
-        if [[ ${MAX_CHECK} == 0 ]]; then
-            echo
-            echo "ERROR! Maximum number of retries while checking ${BACKEND} 
db. Exiting"
-            echo
-            break
-        else
-            sleep 1
-        fi
-    done
-    if [[ ${RES} != 0 ]]; then
-        echo "        ERROR: ${BACKEND} db could not be reached!"
-        echo
-        echo "${LAST_CHECK_RESULT}"
-        echo
-        EXIT_CODE=${RES}
-    fi
-    echo 
"-----------------------------------------------------------------------------------------------"
 }
 
 function resetdb_if_requested() {
     if [[ ${DB_RESET:="false"} == "true" ]]; then
         if [[ ${RUN_AIRFLOW_1_10} == "true" ]]; then
-                airflow resetdb -y
+            airflow resetdb -y
         else
-                airflow db reset -y
+            airflow db reset -y
         fi
     fi
     return $?
 }
 
-if [[ -n ${BACKEND:=} ]]; then
-    echo 
"==============================================================================================="
-    echo "             Checking backend: ${BACKEND}"
-    echo 
"==============================================================================================="
-
-    set +e
-    check_db_connection 20
-    set -e
 
-    if [[ ${EXIT_CODE} == 0 ]]; then
-        echo 
"==============================================================================================="
-        echo "             Backend database is sane"
-        echo 
"==============================================================================================="
-        echo
-    fi
-else
-    echo 
"==============================================================================================="
-    echo "             Skip checking backend - BACKEND not set"
-    echo 
"==============================================================================================="
-    echo
+echo 
"==============================================================================================="
+echo "             Checking integrations and backends"
+echo 
"==============================================================================================="
+if [[ -n ${BACKEND:=} ]]; then
+    check_db_backend 20
+    echo 
"-----------------------------------------------------------------------------------------------"
 fi
-
 check_integration kerberos "nc -zvv kerberos 88" 30
 check_integration mongo "nc -zvv mongo 27017" 20
 check_integration redis "nc -zvv redis 6379" 20
 check_integration rabbitmq "nc -zvv rabbitmq 5672" 20
 check_integration cassandra "nc -zvv cassandra 9042" 20
 check_integration openldap "nc -zvv openldap 389" 20
+check_integration presto "nc -zvv presto 8080" 40

Review comment:
       Presto is a very slow service. For me, it takes 25 dots to start.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to