Fix tox.ini to run unit tests on CI

Change-Id: I64a998b04e432397dcb34f70e7a0167374147eef
diff --git a/tcp_tests/helpers/oslo_cfg_types.py b/tcp_tests/helpers/oslo_cfg_types.py
index d9d091b..8b322b7 100644
--- a/tcp_tests/helpers/oslo_cfg_types.py
+++ b/tcp_tests/helpers/oslo_cfg_types.py
@@ -111,6 +111,6 @@
         super(Cfg, self).__init__(*args, **kwargs)
 
         # Print info about default environment variables to console
-        print ('{}={}  # {}'.format(env_var_name,
-                                    kwargs.get('default', ''),
-                                    kwargs.get('help', '')))
+        print('{}={}  # {}'.format(env_var_name,
+                                   kwargs.get('default', ''),
+                                   kwargs.get('help', '')))
diff --git a/tcp_tests/helpers/utils.py b/tcp_tests/helpers/utils.py
index 76641bd..e24c18b 100644
--- a/tcp_tests/helpers/utils.py
+++ b/tcp_tests/helpers/utils.py
@@ -168,7 +168,7 @@
 def dump_keyfile(file_path, key):
     key = paramiko.RSAKey(file_obj=StringIO.StringIO(key['private']))
     key.write_private_key_file(file_path)
-    os.chmod(file_path, 0644)
+    os.chmod(file_path, 0o644)
 
 
 def clean_dir(dirpath):
diff --git a/tcp_tests/managers/k8smanager.py b/tcp_tests/managers/k8smanager.py
index 12dd2dc..6394141 100644
--- a/tcp_tests/managers/k8smanager.py
+++ b/tcp_tests/managers/k8smanager.py
@@ -289,15 +289,17 @@
             ns = self.api.namespaces.get(name=name)
             LOG.info("Namespace '{0}' is already exists".format(ns.name))
         except ApiException as e:
-          if hasattr(e,"status") and 404 == e.status:
-            LOG.info("Creating Namespace in k8s cluster")
-            ns = self.api.namespaces.create(body={'metadata': {'name': name}})
-            LOG.info("Namespace '{0}' is created".format(ns.name))
-            # wait 10 seconds until a token for new service account is created
-            time.sleep(10)
-            ns = self.api.namespaces.get(name=ns.name)
-          else:
-            raise
+            if hasattr(e, "status") and 404 == e.status:
+                LOG.info("Creating Namespace in k8s cluster")
+                ns = self.api.namespaces.create(
+                    body={'metadata': {'name': name}})
+                LOG.info("Namespace '{0}' is created".format(ns.name))
+                # wait 10 seconds until a token for new service account
+                # is created
+                time.sleep(10)
+                ns = self.api.namespaces.get(name=ns.name)
+            else:
+                raise
         return ns
 
     def create_objects(self, path):
@@ -409,7 +411,6 @@
         cmd = "apt install jq -y"
         return self.__underlay.check_call(cmd, node_name=self.ctl_host)
 
-
     def git_clone(self, project, target):
         cmd = "git clone {0} {1}".format(project, target)
         return self.__underlay.check_call(cmd, node_name=self.ctl_host)
@@ -494,4 +495,4 @@
         cmd = ("~/virtlet/examples/virsh.sh domblklist {} | "
                "tail -n +3 | awk {{'print $2'}}".format(domain_id))
         result = self.__underlay.check_call(cmd, node_name=self.ctl_host)
-        return result['stdout'].strip()
\ No newline at end of file
+        return result['stdout'].strip()
diff --git a/tcp_tests/managers/sl_manager.py b/tcp_tests/managers/sl_manager.py
index 2f76306..d66ee67 100644
--- a/tcp_tests/managers/sl_manager.py
+++ b/tcp_tests/managers/sl_manager.py
@@ -90,7 +90,7 @@
             cmd = ("cd {0}; "
                    "export VOLUME_STATUS='available'; "
                    "pytest -k 'not {1}' {2}".format(
-                tests_path, skip_tests, test_to_run))
+                       tests_path, skip_tests, test_to_run))
         else:
             cmd = ("cd {0}; "
                    "export VOLUME_STATUS='available'; "
@@ -112,12 +112,12 @@
             cmd = ("cd {0}; "
                    "export VOLUME_STATUS='available'; "
                    "pytest  --json=report.json -k 'not {1}' {2}".format(
-                tests_path, skip_tests, test_to_run))
+                       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))
+                       tests_path, 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(
@@ -165,7 +165,7 @@
         prometheus_client = self.api
         try:
             current_targets = prometheus_client.get_targets()
-        except:
+        except Exception:
             LOG.info('Restarting keepalived service on mon nodes...')
             for node in nodes:
                 self._salt.local(tgt=node, fun='cmd.run',
diff --git a/tcp_tests/managers/underlay_ssh_manager.py b/tcp_tests/managers/underlay_ssh_manager.py
index ad3e4ad..8b3da06 100644
--- a/tcp_tests/managers/underlay_ssh_manager.py
+++ b/tcp_tests/managers/underlay_ssh_manager.py
@@ -418,27 +418,28 @@
         tar_cmd = ('tar --absolute-names'
                    ' --warning=no-file-changed '
                    '-czf {t} {d}'.format(
-            t='{0}_log.tar.gz'.format(artifact_name), d='/var/log'))
+                       t='{0}_log.tar.gz'.format(artifact_name), d='/var/log'))
         minion_nodes = [ssh for ssh in self.config_ssh
                         if node_role not in ssh['roles']]
         for node in minion_nodes:
             try:
                 with self.remote(host=node['host']) as r_node:
-                    r_node.check_call(('tar '
-                                       '--absolute-names '
-                                       '--warning=no-file-changed '
-                                       '-czf {t} {d}'.format(
-                        t='{0}.tar.gz'.format(node['node_name']),
-                        d='/var/log')),
-                        verbose=True, raise_on_err=False)
-            except:
+                    r_node.check_call((
+                        'tar '
+                        '--absolute-names '
+                        '--warning=no-file-changed '
+                        '-czf {t} {d}'.format(
+                            t='{0}.tar.gz'.format(node['node_name']),
+                            d='/var/log')),
+                            verbose=True, raise_on_err=False)
+            except Exception:
                 LOG.info("Can not ssh for node {}".format(node))
         with self.remote(master_node['node_name']) as r:
             for node in minion_nodes:
                 packages_minion_cmd = ("salt '{0}*' cmd.run "
                                        "'dpkg -l' > /var/log/"
                                        "{0}_packages.output".format(
-                    node['node_name']))
+                                           node['node_name']))
                 r.check_call(packages_minion_cmd)
                 r.check_call("rsync {0}:/root/*.tar.gz "
                              "/var/log/".format(node['node_name']),
diff --git a/tcp_tests/settings_oslo.py b/tcp_tests/settings_oslo.py
index 1092c8b..f8b3fb4 100644
--- a/tcp_tests/settings_oslo.py
+++ b/tcp_tests/settings_oslo.py
@@ -22,8 +22,8 @@
 from tcp_tests.helpers import oslo_cfg_types as ct
 from tcp_tests import settings
 
-print ("\n" + "-" * 10 + " Initialize oslo.config variables with defaults"
-       " from environment" + "-" * 10)
+print("\n" + "-" * 10 + " Initialize oslo.config variables with defaults"
+      " from environment" + "-" * 10)
 
 _default_conf = pkg_resources.resource_filename(
     __name__, 'templates/{0}/underlay.yaml'.format(settings.LAB_CONFIG_NAME))
diff --git a/tcp_tests/tests/system/test_failover.py b/tcp_tests/tests/system/test_failover.py
index 11173ce..9007eba 100644
--- a/tcp_tests/tests/system/test_failover.py
+++ b/tcp_tests/tests/system/test_failover.py
@@ -52,7 +52,7 @@
     @pytest.mark.grab_versions
     @pytest.mark.fail_snapshot
     def test_restart_ctl01_node(self, underlay, openstack_deployed,
-                                      openstack_actions, show_step):
+                                openstack_actions, show_step):
         """Test restart ctl01
 
         Scenario:
@@ -353,9 +353,9 @@
     @pytest.mark.grab_versions
     @pytest.mark.fail_snapshot
     def test_stop_influxdb_relay_mon_nodes(self, underlay,
-                                            openstack_deployed,
-                                            openstack_actions,
-                                            sl_deployed):
+                                           openstack_deployed,
+                                           openstack_actions,
+                                           sl_deployed):
         """Test stop influxdb relay on mon01 node
 
         Scenario:
@@ -412,9 +412,9 @@
     @pytest.mark.grab_versions
     @pytest.mark.fail_snapshot
     def test_stop_influxdb_mon_nodes(self, underlay,
-                                      openstack_deployed,
-                                      openstack_actions,
-                                      sl_deployed):
+                                     openstack_deployed,
+                                     openstack_actions,
+                                     sl_deployed):
         """Test stop influxdb on mon01 node
 
         Scenario:
@@ -458,7 +458,7 @@
         assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon01')
         assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon02')
         # STEP #10
-      
+
         after_result = sl_deployed.run_sl_tests_json(
             'cfg01', '/root/stacklight-pytest/stacklight_tests/',
             'tests/prometheus/', 'test_alerts.py')
diff --git a/tcp_tests/tests/system/test_install_k8s.py b/tcp_tests/tests/system/test_install_k8s.py
index 2294cf6..018f561 100644
--- a/tcp_tests/tests/system/test_install_k8s.py
+++ b/tcp_tests/tests/system/test_install_k8s.py
@@ -89,7 +89,7 @@
             current_targets = prometheus_client.get_targets()
             LOG.debug('Current targets after install {0}'
                       .format(current_targets))
-        except:
+        except Exception:
             LOG.warning('Restarting keepalived service on mon nodes...')
             sl_actions._salt.local(tgt='mon*', fun='cmd.run',
                                    args='systemctl restart keepalived')
@@ -151,7 +151,7 @@
             current_targets = prometheus_client.get_targets()
             LOG.debug('Current targets after install {0}'
                       .format(current_targets))
-        except:
+        except Exception:
             LOG.warning('Restarting keepalived service on mon nodes...')
             sl_actions._salt.local(tgt='mon*', fun='cmd.run',
                                    args='systemctl restart keepalived')
diff --git a/tcp_tests/tests/system/test_virtlet_actions.py b/tcp_tests/tests/system/test_virtlet_actions.py
index 99d6389..775eb5b 100644
--- a/tcp_tests/tests/system/test_virtlet_actions.py
+++ b/tcp_tests/tests/system/test_virtlet_actions.py
@@ -67,8 +67,8 @@
         target_memory_kb = target_memory * 1024
         target_yaml = 'virtlet/examples/cirros-vm-exp.yaml'
         k8s_deployed.adjust_cirros_resources(cpu=target_cpu,
-                                                memory=target_memory,
-                                                target_yaml=target_yaml)
+                                             memory=target_memory,
+                                             target_yaml=target_yaml)
         show_step(2)
         vm_name = k8s_deployed.run_vm(target_yaml)
         k8s_deployed.wait_active_state(vm_name)
diff --git a/tox.ini b/tox.ini
index 379ee79..9014d59 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,17 +5,13 @@
 
 [tox]
 skipsdist = True
-envlist = py35,py34,py27,pypy,pep8
-
-[tox:travis]
-2.7 = py27
-3.4 = py34
-3.5 = py35
+#envlist = pep8, py{27,35}
+# requirement functools32 is not installed for py35
+envlist = pep8,py27
 
 [testenv]
-install_command = pip install --allow-external -U {opts} {packages}
+install_command = pip install -U {opts} {packages}
 deps =
-    setuptools
     -r{toxinidir}/tcp_tests/requirements.txt
 usedevelop = False
 commands = py.test -s -vvv tcp_tests/tests/unit