Fix stacklight-pytest install

Install stacklight-pytest into virtualenv to not broke system
libraries.

Change-Id: I89f9f00a2aacb1c86d7bbc7c047527b963f90024
diff --git a/tcp_tests/managers/sl_manager.py b/tcp_tests/managers/sl_manager.py
index 4eb6228..a1ee3a7 100644
--- a/tcp_tests/managers/sl_manager.py
+++ b/tcp_tests/managers/sl_manager.py
@@ -93,15 +93,14 @@
         target_node_name = [node_name for node_name
                             in self.__underlay.node_names()
                             if node_to_run in node_name]
-        if skip_tests:
-            cmd = ("cd {0}; "
-                   "export VOLUME_STATUS='available'; "
-                   "pytest -k 'not {1}' {2}".format(
-                       tests_path, skip_tests, test_to_run))
-        else:
-            cmd = ("cd {0}; "
-                   "export VOLUME_STATUS='available'; "
-                   "pytest -k {1}".format(tests_path, test_to_run))
+        cmd = ("cd {0}; "
+               ". venv-stacklight-pytest/bin/activate;"
+               "export VOLUME_STATUS='available';"
+               "pytest -k {1} {2}".format(
+                   tests_path,
+                   "'not " + skip_tests + "'" if skip_tests else '',
+                   test_to_run))
+
         with self.__underlay.remote(node_name=target_node_name[0]) \
                 as node_remote:
             LOG.debug("Run {0} on the node {1}".format(
@@ -115,21 +114,19 @@
         target_node_name = [node_name for node_name
                             in self.__underlay.node_names()
                             if node_to_run in node_name]
-        if skip_tests:
-            cmd = ("cd {0}; "
-                   "export VOLUME_STATUS='available'; "
-                   "pytest  --json=report.json -k 'not {1}' {2}".format(
-                       tests_path, skip_tests, test_to_run))
-        else:
-            cmd = ("cd {0}; "
-                   "export VOLUME_STATUS='available'; "
-                   "pytest --json=report.json -k {1}".format(
-                       tests_path, test_to_run))
+        cmd = ("cd {0}; "
+               ". venv-stacklight-pytest/bin/activate;"
+               "export VOLUME_STATUS='available';"
+               "pip install pytest-json;"
+               "pytest --json=report.json -k {1} {2}".format(
+                   tests_path,
+                   "'not " + skip_tests + "'" if skip_tests else '',
+                   test_to_run))
+
         with self.__underlay.remote(node_name=target_node_name[0]) \
                 as node_remote:
             LOG.debug("Run {0} on the node {1}".format(
                 cmd, target_node_name[0]))
-            node_remote.execute('pip install pytest-json')
             node_remote.execute(cmd)
             res = node_remote.execute('cd {0}; cat report.json'.format(
                 tests_path))
diff --git a/tcp_tests/templates/shared-sl-tests.yaml b/tcp_tests/templates/shared-sl-tests.yaml
index e0f7823..fe7a98a 100644
--- a/tcp_tests/templates/shared-sl-tests.yaml
+++ b/tcp_tests/templates/shared-sl-tests.yaml
@@ -6,13 +6,14 @@
 
 {%- macro MACRO_CLONE_SL_TESTS() %}
 {############################################################}
-- description: Clone repo and install tests on cfg node
+- description: Install stacklight-pytest into virlual environemnt
   cmd: |
     set -e;
+    apt-get -y install python-virtualenv;
+    virtualenv venv-stacklight-pytest;
+    . venv-stacklight-pytest/bin/activate;
     git clone -b {{ SL_TEST_BRANCH }} {{ SL_TEST_REPO }} /root/stacklight-pytest;
-    cd /root/stacklight-pytest;
-    python setup.py sdist;
-    pip install dist/stacklight_tests-1.0.tar.gz --process-dependency-links
+    pip install /root/stacklight-pytest;
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 1}
   skip_fail: false
@@ -24,11 +25,10 @@
 - description: Configure tests
   cmd: |
     set -e;
+    . venv-stacklight-pytest/bin/activate;
     stl-tests gen-config-mk;
-    cp /usr/local/lib/python2.7/dist-packages/stacklight_tests/fixtures/config.yaml /root/stacklight-pytest/stacklight_tests/fixtures/config.yaml;
+    cp venv-stacklight-pytest/lib/python2.7/site-packages/stacklight_tests/fixtures/config.yaml /root/stacklight-pytest/stacklight_tests/fixtures/config.yaml;
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 1}
   skip_fail: false
 {%- endmacro %}
-
-