From 61dfdca2a015373c145cc6bfc90a654e0081a8de Mon Sep 17 00:00:00 2001 From: Sakala Venkata Krishna Rohit Date: Mon, 4 Sep 2017 16:59:05 +0530 Subject: Refactored docker watchdog code Removed start_containers fix as it was redundant. Checking jenkins job status for each module separately as deployment of one module doesn't depend on other module. Change-Id: I8ce34b9b7458ac56c9b866b5add539ad304095ed Signed-off-by: Sakala Venkata Krishna Rohit --- testapi/tools/watchdog/docker_watch.sh | 63 ++++++++++++++-------------------- 1 file changed, 25 insertions(+), 38 deletions(-) (limited to 'testapi/tools') diff --git a/testapi/tools/watchdog/docker_watch.sh b/testapi/tools/watchdog/docker_watch.sh index d67e4b3..786fc10 100644 --- a/testapi/tools/watchdog/docker_watch.sh +++ b/testapi/tools/watchdog/docker_watch.sh @@ -21,33 +21,19 @@ modules=(testapi reporting) declare -A ports=( ["testapi"]="8082" ["reporting"]="8084") ## Urls to check if the modules are deployed or not ? -#declare -A urls=( ["testapi"]="http://testresults.opnfv.org/test/" \ -# ["reporting"]="http://testresults.opnfv.org/reporting2/reporting/index.html") - -declare -A urls=( ["testapi"]="http://localhost:8082/" \ +declare -A urls=( ["testapi"]="http://testresults.opnfv.org/test/" \ ["reporting"]="http://testresults.opnfv.org/reporting2/reporting/index.html") - ### Functions related to checking. function is_deploying() { - echo -e "Checking job statuses" - for module in "${modules[@]}" - do - if get_status $module; then - exit 0 - fi - done -} - -function get_status() { xml=$(curl -m10 "https://build.opnfv.org/ci/job/${1}-automate-master/lastBuild/api/xml?depth=1") building=$(grep -oPm1 "(?<=)[^<]+" <<< "$xml") if [[ $building == "false" ]] then - return 1 - else return 0 + else + return 1 fi } @@ -78,6 +64,9 @@ function check_modules() { failed_modules=() for module in "${modules[@]}" do + if is_deploying $module; then + continue + fi if ! check_connectivity $module "${urls[$module]}"; then echo -e "$module failed" failed_modules+=($module) @@ -110,27 +99,30 @@ function docker_proxy_fix() { echo $pid if [ ! -z "$pid" ]; then kill $pid - start_containers_fix $module + start_container_fix $module fi done } function start_containers_fix() { - echo "Runnning start_containers_fix" start_modules=("${@}") for module in "${start_modules[@]}" do - echo -e "Starting a container $module" + start_container_fix $module + done +} + +function start_container_fix() { + echo -e "Starting a container $module" + sudo docker stop $module + sudo docker start $module + sleep 5 + if ! check_connectivity $module "${urls[$module]}"; then + echo -e "Starting an old container $module_old" sudo docker stop $module - sudo docker start $module + sudo docker start $module"_old" sleep 5 - if ! check_connectivity $module "${urls[$module]}"; then - echo -e "Starting an old container $module_old" - sudo docker stop $module - sudo docker start $module"_old" - sleep 5 - fi - done + fi } ### Main Flow @@ -141,11 +133,6 @@ echo -e echo -e `date "+%Y-%m-%d %H:%M:%S.%N"` echo -e -if ! is_deploying; then - echo -e "Jenkins Jobs running" - exit -fi - ## If the problem is related to docker daemon if get_docker_status; then @@ -156,16 +143,16 @@ if get_docker_status; then exit fi -## If the problem is related to docker containers +## If the problem is related to docker proxy if ! check_modules; then - start_containers_fix "${failed_modules[@]}" + docker_proxy_fix "${failed_modules[@]}" fi -## If the problem is related to docker proxy +## If any other problem : restart docker if ! check_modules; then - docker_proxy_fix "${failed_modules[@]}" + restart_docker_fix fi ## If nothing works out @@ -175,4 +162,4 @@ if ! check_modules; then fi sudo docker ps -sudo docker images \ No newline at end of file +sudo docker images -- cgit 1.2.3-korg