Update run_tests.sh

Actualize run_tests.sh according to other formulas

Change-Id: If946ab8d9a3e8a8c34f5523bc72159324d526728
diff --git a/debian/control b/debian/control
index 404b76c..daff960 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,12 @@
 Maintainer: Jan Kaufman <jan.kaufman@tcpcloud.eu>
 Section: admin
 Priority: optional
-Build-Depends: debhelper (>= 9), salt-master, python, python-yaml, python-virtualenv
+Build-Depends: debhelper (>= 9),
+               openstack-pkg-tools,
+Build-Depends-Indep: python-all,
+                     python-yaml,
+                     python-virtualenv,
+                     salt-master,
 Standards-Version: 3.9.6
 Homepage: http://www.tcpcloud.eu
 Vcs-Browser: https://github.com/tcpcloud/salt-formula-tftpd-hpa
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 1f1316f..3f42101 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -69,6 +69,7 @@
   base:
   - ${SALT_FILE_DIR}
   - ${CURDIR}/..
+  - /usr/share/salt-formulas/env
 
 pillar_roots:
   base:
@@ -78,16 +79,17 @@
 }
 
 fetch_dependency() {
-    dep_root="${DEPSDIR}/$(basename $1 .git)"
+    dep_name="$(echo $1|cut -d : -f 1)"
+    dep_source="$(echo $1|cut -d : -f 2-)"
+    dep_root="${DEPSDIR}/$(basename $dep_source .git)"
     dep_metadata="${dep_root}/metadata.yml"
 
-    [ -d $dep_root ] && log_info "Dependency $1 already fetched" && return 0
+    [ -d /usr/share/salt-formulas/env/${dep_name} ] && log_info "Dependency $dep_name already present in system-wide salt env" && return 0
+    [ -d $dep_root ] && log_info "Dependency $dep_name already fetched" && return 0
 
-    log_info "Fetching dependency $1"
+    log_info "Fetching dependency $dep_name"
     [ ! -d ${DEPSDIR} ] && mkdir -p ${DEPSDIR}
-    git clone $1 ${DEPSDIR}/$(basename $1 .git)
-
-    dep_name=$(cat $dep_metadata | python -c "import sys,yaml; print yaml.load(sys.stdin)['name']")
+    git clone $dep_source ${DEPSDIR}/$(basename $dep_source .git)
     ln -s ${dep_root}/${dep_name} ${SALT_FILE_DIR}/${dep_name}
 
     METADATA="${dep_metadata}" install_dependencies
@@ -98,7 +100,7 @@
     (python - | while read dep; do fetch_dependency "$dep"; done) << EOF
 import sys,yaml
 for dep in yaml.load(open('${METADATA}', 'ro'))['dependencies']:
-    print dep["source"]
+    print '%s:%s' % (dep["name"], dep["source"])
 EOF
 }
 
@@ -108,14 +110,14 @@
 }
 
 salt_run() {
-    source ${VENV_DIR}/bin/activate
+    [ -e ${VEN_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
     salt-call ${SALT_OPTS} $*
 }
 
 prepare() {
     [ -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR}
 
-    setup_virtualenv
+    which salt-call || setup_virtualenv
     setup_pillar
     setup_salt
     install_dependencies