Add ct automation
[anna.git] / example / diameter / launcher / resources / rest_api / ct / ct.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6
7 REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
8 [ -z "$REPO_DIR" ] && { echo "You must execute under a valid git repository !" ; exit 1 ; }
9
10 SERVICES=${REPO_DIR}/example/diameter/launcher/resources/rest_api/ct/resources/servicesJson-request.json
11 ENDPOINT=http://localhost:8074
12 PORT=$(echo ${ENDPOINT} | cut -d: -f3)
13 C_NAME=adml-http
14
15 #############
16 # EXECUTION #
17 #############
18 cd $(dirname $0)
19
20 # Basic requirement:
21 nghttp --version 2>/dev/null
22 [ $? -ne 0 ] && { echo -e "\nThe HTTP2 client 'nghttp' is required. Install with: sudo apt install nghttp\n" ; exit 1 ; }
23 echo "Requirement found !"
24
25 echo
26 echo "Rebuild ADML HTTP service image (y/n) [y]:"
27 read opt
28 [ -z "${opt}" ] && opt=y
29 [ "${opt}" = "y" ] && ${REPO_DIR}/tools/build-adml-http
30
31 version=$(${REPO_DIR}/tools/version)
32 echo "Restart ADML HTTP service image (version '${version}') ..."
33 docker kill ${C_NAME} >/dev/null
34 cid=$(docker run --rm -d -p ${PORT}:${PORT} --name ${C_NAME} anna-adml-http:${version})
35 echo "Container id: ${cid} (deployed as '${C_NAME}')"
36
37 echo
38 echo "Configuring services (${SERVICES}) ..."
39 sleep 4 # wait for docker running
40 nghttp -H ":method: POST" -d ${SERVICES} ${ENDPOINT}/services
41 echo
42
43 echo
44 echo -n "Waiting for server-client connection ..."
45 while true
46 do
47   docker exec -it ${C_NAME} bash -c "netstat -p $(pgrep ADML) --numeric-ports | grep -w 3868 | grep -w ESTABLISHED" >/dev/null
48   [ $? -eq 0 ] && break
49   echo -n .
50 done
51 echo "Ready !"
52
53 echo
54 echo "Press ENTER to start component test, CTRL-C to abort ..."
55 read dummy
56
57 pytest
58