Add ct automation
[anna.git] / example / diameter / launcher / resources / rest_api / ct / ct.sh
diff --git a/example/diameter/launcher/resources/rest_api/ct/ct.sh b/example/diameter/launcher/resources/rest_api/ct/ct.sh
new file mode 100755 (executable)
index 0000000..4d485df
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+#############
+# VARIABLES #
+#############
+
+REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
+[ -z "$REPO_DIR" ] && { echo "You must execute under a valid git repository !" ; exit 1 ; }
+
+SERVICES=${REPO_DIR}/example/diameter/launcher/resources/rest_api/ct/resources/servicesJson-request.json
+ENDPOINT=http://localhost:8074
+PORT=$(echo ${ENDPOINT} | cut -d: -f3)
+C_NAME=adml-http
+
+#############
+# EXECUTION #
+#############
+cd $(dirname $0)
+
+# Basic requirement:
+nghttp --version 2>/dev/null
+[ $? -ne 0 ] && { echo -e "\nThe HTTP2 client 'nghttp' is required. Install with: sudo apt install nghttp\n" ; exit 1 ; }
+echo "Requirement found !"
+
+echo
+echo "Rebuild ADML HTTP service image (y/n) [y]:"
+read opt
+[ -z "${opt}" ] && opt=y
+[ "${opt}" = "y" ] && ${REPO_DIR}/tools/build-adml-http
+
+version=$(${REPO_DIR}/tools/version)
+echo "Restart ADML HTTP service image (version '${version}') ..."
+docker kill ${C_NAME} >/dev/null
+cid=$(docker run --rm -d -p ${PORT}:${PORT} --name ${C_NAME} anna-adml-http:${version})
+echo "Container id: ${cid} (deployed as '${C_NAME}')"
+
+echo
+echo "Configuring services (${SERVICES}) ..."
+sleep 4 # wait for docker running
+nghttp -H ":method: POST" -d ${SERVICES} ${ENDPOINT}/services
+echo
+
+echo
+echo -n "Waiting for server-client connection ..."
+while true
+do
+  docker exec -it ${C_NAME} bash -c "netstat -p $(pgrep ADML) --numeric-ports | grep -w 3868 | grep -w ESTABLISHED" >/dev/null
+  [ $? -eq 0 ] && break
+  echo -n .
+done
+echo "Ready !"
+
+echo
+echo "Press ENTER to start component test, CTRL-C to abort ..."
+read dummy
+
+pytest
+