Skip to contentSkip to conversation

add script to launch t_client.sh against a VM

PATCH In review Jens Neuhalfen 1 participant 1 message Apr 23, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 add script to launch t_client.sh against a VM

This script will prepare (compile and start openvpn) a vm, run t_client.sh against it, and then halt the VM.

From 4cc7877a0d1678d1ac3994d169ee81537b945146 Mon Sep 17 00:00:00 2001
From: Jens Neuhalfen <[email protected]...>
Date: Sat, 23 Apr 2016 17:33:47 +0200
Subject: [PATCH 2/2] add script to launch t_client.sh against a VM

This script will prepare (compile and start openvpn) a vm, run t_client.sh against it, and then halts the VM.

---
 tests/server/run_integration.sh | 118 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 118 insertions(+)
 create mode 100755 tests/server/run_integration.sh
tests/server/run_integration.sh new file +118 -0
new file mode 100755
index 0000000..a74020c
@@ -0,0 +1,118 @@
+#!/bin/bash
+
+if [ $# -ne 1 ]; then
+    echo $0 vm_folder
+    exit -1
+fi
+
+
+VM_FOLDER=$1
+if [ ! -d  "$VM_FOLDER" ]; then
+    echo $0 vm_folder
+    echo "-- '${VM_FOLDER}' is no directory"
+    exit -1
+fi
+
+cd "${VM_FOLDER}"
+
+# Path is relative to the pth of the folder containing Vagrantfile
+TEST_PROGRAM=./launch_t_client.sh
+
+# result 99: test not run bc. server could not be started
+test_result=99
+
+start_vm() {
+  vagrant halt
+  vagrant up
+  vagrant ssh -c '/scripts/sync_codebase.sh && /scripts/compile.sh'
+}
+
+START_TEST_ON="Initialization Sequence Completed"
+
+colorize() {
+  local BLACK=$(tput setaf 0)
+  local RED=$(tput setaf 1)
+  local GREEN=$(tput setaf 2)
+  local YELLOW=$(tput setaf 3)
+  local LIME_YELLOW=$(tput setaf 190)
+  local POWDER_BLUE=$(tput setaf 153)
+  local BLUE=$(tput setaf 4)
+  local MAGENTA=$(tput setaf 5)
+  local CYAN=$(tput setaf 6)
+  local WHITE=$(tput setaf 7)
+  local BRIGHT=$(tput bold)
+  local NORMAL=$(tput sgr0)
+  local BLINK=$(tput blink)
+  local REVERSE=$(tput smso)
+  local UNDERLINE=$(tput smul)
+
+  local ERROR="$RED"
+
+  local msg="$2"
+  local color=""
+
+  case "$1" in
+    "S")
+      color="${POWDER_BLUE}"
+    ;;
+    "C")
+      color="${YELLOW}"
+    ;;
+    *)
+  esac
+
+  msg="${color}${msg}${NORMAL}"
+
+  msg=${msg/FATAL/${ERROR}FATAL${color}}
+  msg=${msg/FAIL/${ERROR}FAIL${color}}
+  echo $msg
+}
+
+print_log() {
+  local src="$1"
+  local line="$2"
+
+  local sanitized=$(echo "$line" |  tr -cd '\40-\176' | sed -e 's/^[ ]+//' -e 's/[ ]+$//')
+  sanitized=$(colorize $src "$sanitized")
+
+  printf "%s: %s\n" "$src" "$sanitized"
+}
+
+
+
+# Run the test command defined in $TEST_PROGRAM and halt the VM afterwards
+run_test() {
+        echo Starting Client
+        $TEST_PROGRAM 2>&1 | while read client_line
+        do 
+          print_log "C" "$client_line"
+        done  
+
+        local result=${PIPESTATUS[0]}
+        vagrant halt
+        return $result
+}
+
+
+start_vm
+
+while read server_line
+do
+  # At least on my Mac this is needed. Else the code only prints LF, but no CR
+  reset -I
+  # Remove non-ascii. Esp. remove CR/LF because they break the processing logic
+  
+  print_log "S"  "$server_line"
+
+  if [[ "$server_line" == *$START_TEST_ON* ]] ; then
+      run_test &
+  fi
+done < <(vagrant ssh -c 'sudo /scripts/start_server.sh' &)
+
+echo "Waiting for all jobs to terminate ...."
+
+wait %run_test
+test_result=$?
+wait
+
+exit $test_result
Signature · 1 line
2.6.4 (Apple Git-63)