Support to run cord-tester with a virtual environment where pip python packages are installed with prerequisites.sh
Run prerequisites with: --venv option.
Then use cord-tester bash script instead of using cord-test.py directly that wraps the invocation of cord-test.py by activating the virtual environment before running cord-tester.

In order to use cord-test.py directly as before with venv, just:
source setup/venv/bin/activate
before running cord-test.py.

On the cord or on CiaB, its recommended to install the pip packages on the host if one wants to use the MAAS/fabric test cases.
For cord/CiaB, just run the prerequisites with the --cord option as before.

Change-Id: I65e64e376540124165731da30a90152f559a5299
diff --git a/src/test/setup/cord-tester b/src/test/setup/cord-tester
new file mode 100755
index 0000000..786517e
--- /dev/null
+++ b/src/test/setup/cord-tester
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+setup_path=$(dirname $(realpath $0))
+source $setup_path/venv/bin/activate
+$setup_path/cord-test.py $*
+
diff --git a/src/test/setup/prerequisites.sh b/src/test/setup/prerequisites.sh
index 8a3c06d..2cf2c2b 100755
--- a/src/test/setup/prerequisites.sh
+++ b/src/test/setup/prerequisites.sh
@@ -1,11 +1,50 @@
 #!/usr/bin/env bash
-apt-get update
+
+function usage {
+    echo "usage: ${0#*/} [-h |--help] [--cord] [--venv]"
+    exit 1
+}
+
 on_cord=0
-release=$(lsb_release -cs)
-if [ "$1" = "--cord" ]; then
-    echo "Skipping installation of Docker and ONOS"
-    on_cord=1
+venv=0
+optspec=":h-:"
+while getopts "$optspec" optchar; do
+    case "${optchar}" in
+        -)
+            case "${OPTARG}" in
+                cord)
+                    on_cord=1
+                    OPTIND=$(( $OPTIND + 1 ))
+                    ;;
+                venv)
+                    venv=1
+                    OPTIND=$(( $OPTIND + 1))
+                    ;;
+                help)
+                    usage
+                    ;;
+                *)
+                    echo "Unknown option --${OPTARG}"
+                    usage
+                    ;;
+            esac
+            ;;
+        h)
+            usage
+            ;;
+        *)
+            usage
+            ;;
+    esac
+done
+
+shift $((OPTIND-1))
+if [ $# -gt 0 ]; then
+    usage
 fi
+
+apt-get update
+release=$(lsb_release -cs)
 if [ $on_cord -eq 0 ]; then
     apt-get -y install apt-transport-https ca-certificates
     apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
@@ -25,32 +64,26 @@
     docker rmi hello-world
     echo "Pulling ONOS latest"
     docker pull onosproject/onos:latest || exit 127
+else
+    echo "Skipping installation of Docker and ONOS"
 fi
-apt-get -y install openvswitch-common openvswitch-switch
-apt-get -y install wget git python python-dev python-pip python-setuptools python-scapy python-pexpect python-maas-client tcpdump arping libssl-dev libffi-dev realpath
-easy_install nose
-pip install scapy==2.3.2
-pip install monotonic
-pip install configObj
-pip install docker-py==1.9.0
-pip install -U pyyaml
-pip install -U nsenter
-pip install -U pyroute2
-pip install -U netaddr
-pip install -U python-daemon
-pip install scapy-ssl_tls==1.2.2
-pip install -U robotframework
-pip install -U robotframework-requests
-pip install -U robotframework-sshlibrary
-pip install paramiko==1.10.1
-( cd /tmp && git clone https://github.com/jpetazzo/pipework.git && cp -v pipework/pipework /usr/bin && rm -rf pipework )
 
-## Special mode to pull cord-tester repo in case prereqs was installed by hand instead of repo
-if [ "$1" = "--test" ]; then
-    rm -rf cord-tester
-    git clone https://github.com/opencord/cord-tester.git
+apt-get -y install openvswitch-common openvswitch-switch
+apt-get -y install wget git python python-dev python-pip python-setuptools python-scapy python-pexpect python-maas-client tcpdump arping libssl-dev libffi-dev realpath python-virtualenv
+
+setup_path=$(dirname $(realpath $0))
+if [ $venv -eq 1 ]; then
+    echo "Making a virtual cord-tester pip installation environment"
+    mkdir -p $setup_path/venv
+    echo "Installing cord-tester pip packages on the virtual environment"
+    $setup_path/venv/bin/pip install -r $setup_path/requirements.txt
+else
+    echo "Installing cord-tester pip packages on the host"
+    pip install -r $setup_path/requirements.txt
 fi
 
+( cd /tmp && git clone https://github.com/jpetazzo/pipework.git && cp -v pipework/pipework /usr/bin && rm -rf pipework )
+
 install_ovs() {
     mkdir -p /root/ovs
     wget http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz -O /root/ovs/openvswitch-2.5.0.tar.gz && \
diff --git a/src/test/setup/requirements.txt b/src/test/setup/requirements.txt
new file mode 100644
index 0000000..490bd61
--- /dev/null
+++ b/src/test/setup/requirements.txt
@@ -0,0 +1,21 @@
+nose
+scapy==2.3.2
+monotonic
+configObj
+docker-py==1.9.0
+pyyaml
+nsenter
+pyroute2
+netaddr
+python-daemon
+scapy-ssl_tls==1.2.2
+robotframework
+robotframework-requests
+robotframework-sshlibrary
+paramiko==1.10.1
+twisted
+pexpect
+apiclient
+python-libmaas
+maasclient
+maasutil