From ea5f6394857e2abd0418942e5d43ace097119e47 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Tue, 25 Feb 2020 13:47:59 -0700 Subject: [PATCH] qa/workunits/cephadm/test_cephadm.sh: consolidate wait loop logic into an `is_available` function Signed-off-by: Michael Fritch --- qa/workunits/cephadm/test_cephadm.sh | 66 +++++++++++----------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/qa/workunits/cephadm/test_cephadm.sh b/qa/workunits/cephadm/test_cephadm.sh index 9618d5241f4..08529cafc1a 100755 --- a/qa/workunits/cephadm/test_cephadm.sh +++ b/qa/workunits/cephadm/test_cephadm.sh @@ -86,6 +86,26 @@ function expect_false() if "$@"; then return 1; else return 0; fi } +function is_available() +{ + local name="$1" + local condition="$2" + local tries="$3" + + local num=0 + while ! eval "$condition"; do + num=$(($num + 1)) + if [ "$num" -ge $tries ]; then + echo "$name is not available" + false + fi + sleep 5 + done + + echo "$name is available" + true +} + ## prepare + check host $SUDO $CEPHADM check-host @@ -208,58 +228,24 @@ done # add node-exporter $CEPHADM --image 'prom/node-exporter:latest' \ deploy --name node-exporter.a --fsid $FSID -TRIES=0 -while true; do - if curl 'http://localhost:9100' | grep -q 'Node Exporter'; then - break - fi - TRIES=$(($TRIES + 1)) - if [ "$TRIES" -eq 5 ]; then - echo "node exporter did not come up" - exit 1 - fi - sleep 5 -done -echo "node exporter ok" +cond="curl 'http://localhost:9100' | grep -q 'Node Exporter'" +is_available "node-exporter" "$cond" 5 # add prometheus cat ${CEPHADM_SAMPLES_DIR}/prometheus.json | \ $CEPHADM --image 'prom/prometheus:latest' \ deploy --name prometheus.a --fsid $FSID \ --config-json - -TRIES=0 -while true; do - if curl 'localhost:9095/api/v1/query?query=up' | \ - jq -e '.["status"] == "success"'; then - break - fi - TRIES=$(($TRIES + 1)) - if [ "$TRIES" -eq 5 ]; then - echo "prom did not come up" - exit 1 - fi - sleep 5 -done -echo "prom ok" +cond="curl 'localhost:9095/api/v1/query?query=up'" +is_available "prometheus" "$cond" 5 # add grafana cat ${CEPHADM_SAMPLES_DIR}/grafana.json | \ $CEPHADM --image 'pcuzner/ceph-grafana-el8:latest' \ deploy --name grafana.a --fsid $FSID \ --config-json - -TRIES=0 -while true; do - if curl --insecure 'https://localhost:3000' | grep -q 'grafana'; then - break - fi - TRIES=$(($TRIES + 1)) - if [ "$TRIES" -eq 30 ]; then - echo "grafana did not come up" - exit 1 - fi - sleep 5 -done -echo "grafana ok" +cond="curl --insecure 'https://localhost:3000' | grep -q 'grafana'" +is_available "grafana" "$cond" 30 ## run # WRITE ME -- 2.39.5