Update run_tests.sh

There are issues with interpreter path lenth, and they are
fixed in new version of run_test.sh from [1]

https://raw.githubusercontent.com/salt-formulas/cookiecutter-salt-formula/

Change-Id: I4cdb02c31f82f4a06ec035a69ba9bc4fa00e6c8f
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 742688b..d7f2242 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -2,7 +2,8 @@
 
 ###
 # Script requirments:
-#  apt-get install -y python-yaml virtualenv git
+#apt-get install -y python-yaml virtualenv git
+
 set -e
 [ -n "$DEBUG" ] && set -x
 
@@ -27,11 +28,10 @@
 
 SALT_OPTS="${SALT_OPTS} --retcode-passthrough --local -c ${SALT_CONFIG_DIR} --log-file=/dev/null"
 
-if [[ "x${SALT_VERSION}" != "x" ]]; then
+if [ "x${SALT_VERSION}" != "x" ]; then
     PIP_SALT_VERSION="==${SALT_VERSION}"
 fi
 
-
 ## Functions
 log_info() {
     echo -e "[INFO] $*"
@@ -43,11 +43,13 @@
 
 setup_virtualenv() {
     log_info "Setting up Python virtualenv"
+    dependency_check virtualenv
     virtualenv $VENV_DIR
     source ${VENV_DIR}/bin/activate
-    pip install salt${PIP_SALT_VERSION}
+    python -m pip install salt${PIP_SALT_VERSION}
+    python -m pip install jsonschema
     if [[ -f ${CURDIR}/pip_requirements.txt ]]; then
-       pip install -r ${CURDIR}/pip_requirements.txt
+       python -m pip install -r ${CURDIR}/pip_requirements.txt
     fi
 }
 
@@ -109,6 +111,7 @@
     dep_root="${DEPSDIR}/$(basename $dep_source .git)"
     dep_metadata="${dep_root}/metadata.yml"
 
+    dependency_check git
     [ -d $dep_root ] && { log_info "Dependency $dep_name already fetched"; return 0; }
 
     log_info "Fetching dependency $dep_name"
@@ -148,7 +151,7 @@
 
 salt_run() {
     [ -e ${VENV_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
-    salt-call ${SALT_OPTS} $*
+    python $(which salt-call) ${SALT_OPTS} $*
 }
 
 prepare() {
@@ -164,7 +167,7 @@
 lint_releasenotes() {
     [[ ! -f "${VENV_DIR}/bin/activate" ]] && setup_virtualenv
     source ${VENV_DIR}/bin/activate
-    pip install reno
+    python -m pip install reno
     reno lint ${CURDIR}/../
 }
 
@@ -201,19 +204,30 @@
 }
 
 run_model_validate(){
-    [[ -d ${SCHEMARDIR} ]] || { log_err "${SCHEMARDIR} not found!"; return 1; }
-    # model validator require py modules
-    fetch_dependency "salt:https://github.com/salt-formulas/salt-formula-salt"
-    link_modules
-    # Rendered Example:
-    # salt-call --local -c /test1/maas/tests/build/salt --id=maas_cluster modelschema.model_validate maas cluster
-    for role in ${SCHEMARDIR}/*.yaml; do
-        state_name=$(basename "${role%*.yaml}")
-        minion_id="${state_name}"
-        # in case debug-reruns, usefull to make cleanup
-        [ -n "$DEBUG" ] && { salt_run saltutil.clear_cache; salt_run saltutil.refresh_pillar; salt_run saltutil.sync_all; }
-        salt_run --id=${minion_id} modelschema.model_validate ${FORMULA_NAME} ${state_name} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1 ; }
-    done
+    if [ -d ${SCHEMARDIR} ]; then
+      # model validator require py modules
+      fetch_dependency "salt:https://github.com/salt-formulas/salt-formula-salt"
+      link_modules
+      # Rendered Example:
+      # python $(which salt-call) --local -c /test1/maas/tests/build/salt --id=maas_cluster modelschema.model_validate maas cluster
+      for role in ${SCHEMARDIR}/*.yaml; do
+          state_name=$(basename "${role%*.yaml}")
+          minion_id="${state_name}"
+          # in case debug-reruns, usefull to make cleanup
+          [ -n "$DEBUG" ] && { salt_run saltutil.clear_cache; salt_run saltutil.refresh_pillar; salt_run saltutil.sync_all; }
+          salt_run -m ${DEPSDIR}/salt-formula-salt --id=${minion_id} modelschema.model_validate ${FORMULA_NAME} ${state_name} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1 ; }
+      done
+    else
+      log_info "${SCHEMARDIR} not found!";
+    fi
+}
+
+dependency_check() {
+  local DEPENDENCY_COMMANDS=$*
+
+  for DEPENDENCY_COMMAND in $DEPENDENCY_COMMANDS; do
+    which $DEPENDENCY_COMMAND > /dev/null || ( log_err "Command \"$DEPENDENCY_COMMAND\" can not be found in default path."; exit 1; )
+  done
 }
 
 _atexit() {
@@ -257,4 +271,4 @@
         run
 #        run_model_validate
         ;;
-esac
+esac
\ No newline at end of file