install test-reqs when TESTONLY packages are installed

INSTALL_TESTONLY_PACKAGES in devstack only impacts .deb/.rpm files
even though most of our test requirements are actually specified
in python. This will do an explicit install of test-requirements.txt
if pip_install is called with args that look like a directory,
and test-requirements.txt exists in that directory.

Change-Id: Id21e282ddc945c819c9c8c4d724658e28bfde785
diff --git a/functions-common b/functions-common
index 5284056..494914a 100644
--- a/functions-common
+++ b/functions-common
@@ -1386,6 +1386,19 @@
         $cmd_pip install --build=${pip_build_tmp} \
         $pip_mirror_opt $@ \
         && $sudo_pip rm -rf ${pip_build_tmp}
+
+    if [[ "$INSTALL_TESTONLY_PACKAGES" == "True" ]]; then
+        local test_req="$@/test-requirements.txt"
+        if [[ -e "$test_req" ]]; then
+            $sudo_pip PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-/var/cache/pip} \
+                http_proxy=$http_proxy \
+                https_proxy=$https_proxy \
+                no_proxy=$no_proxy \
+                $cmd_pip install --build=${pip_build_tmp} \
+                $pip_mirror_opt -r $test_req \
+                && $sudo_pip rm -rf ${pip_build_tmp}
+        fi
+    fi
 }
 
 # this should be used if you want to install globally, all libraries should