Migrate cvp-sanity to Python3

* use print function from future
* convert dict keys and values to list
* do not use bunch imports
* fix requirements mismatch
Related: PROD-33849

Change-Id: Ifecc3a9dcdcfe3243f7dcf2c709a80e9a7c765a1
diff --git a/Dockerfile b/Dockerfile
index 64df905..db08a11 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -27,16 +27,16 @@
     echo "deb [arch=amd64] $UBUNTU_MIRROR_URL xenial-updates main restricted universe multiverse" >> sources.list && \
     echo "deb [arch=amd64] $UBUNTU_MIRROR_URL xenial-backports main restricted universe multiverse" >> sources.list && \
     popd ; apt-get update && apt-get  upgrade -y && \
-    apt-get install -y build-essential curl git-core iputils-ping libffi-dev libldap2-dev libsasl2-dev libssl-dev patch python-dev python-pip  vim-tiny wget \
+    apt-get install -y build-essential curl git-core iputils-ping libffi-dev libldap2-dev libsasl2-dev libssl-dev patch python-dev python-pip python3-dev python3-pip  vim-tiny wget \
     python-virtualenv \
 # Enable these packages while porting to Python3  =>  python3-virtualenv python3-dev  \
 # Due to upstream bug we should use fixed version of pip
-    && python -m pip install --upgrade 'pip==9.0.3'  \
+    && python -m pip install --upgrade 'pip==19.3.1'  \
     # initialize cvp sanity test suite
           && pushd cvp-sanity  \
-          && virtualenv --python=python2  venv \
+          && virtualenv --python=python3  venv \
           && . venv/bin/activate \
-          && pip install -r requirements.txt \
+          && pip3 install -r requirements.txt \
           && deactivate \
           && popd \
     # initialize cvp spt test suite
diff --git a/test_set/cvp-sanity/conftest.py b/test_set/cvp-sanity/conftest.py
index 72e0359..d03edfa 100644
--- a/test_set/cvp-sanity/conftest.py
+++ b/test_set/cvp-sanity/conftest.py
@@ -1,4 +1,24 @@
-from fixtures.base import *
+from builtins import str
+import pytest
+from fixtures.base import (
+    print_node_version,
+    check_cicd,
+    check_kfg,
+    check_kdt,
+    contrail,
+    check_cinder_backends,
+    check_grafana,
+    check_kibana,
+    check_alerta,
+    check_prometheus,
+    check_openstack,
+    check_ironic,
+    check_drivetrain,
+    check_openstack,
+    ctl_nodes_pillar,
+    nodes_in_group,
+    local_salt_client,
+    add_testname_to_saltapi_logs,)
 import logging
 
 
diff --git a/test_set/cvp-sanity/fixtures/base.py b/test_set/cvp-sanity/fixtures/base.py
index 754f872..bd62ed4 100644
--- a/test_set/cvp-sanity/fixtures/base.py
+++ b/test_set/cvp-sanity/fixtures/base.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+from builtins import str
 import os
 import pytest
 import atexit
@@ -29,7 +31,7 @@
 nodes = utils.calculate_groups()
 
 
-@pytest.fixture(scope='session', params=nodes.items(), ids=nodes.keys())
+@pytest.fixture(scope='session', params=list(nodes.items()), ids=list(nodes.keys()))
 def nodes_in_group(request):
     return request.param
 
@@ -142,7 +144,7 @@
     )
     if not kdt_nodes_available:
         pytest.skip("No 'kdt' nodes found. Skipping this test...")
-    return kdt_nodes_available.keys()
+    return list(kdt_nodes_available.keys())
 
 
 @pytest.fixture(scope='session')
@@ -153,7 +155,7 @@
     )
     if not kfg_nodes_available:
         pytest.skip("No cfg-under-Kubernetes nodes found. Skipping this test...")
-    return kfg_nodes_available.keys()
+    return list(kfg_nodes_available.keys())
 
 
 @pytest.fixture(scope='session')
@@ -191,8 +193,8 @@
             expr_form='compound')
         if list_version.__len__() == 0:
             yield
-        parsed = {k: v.split('\n') for k, v in list_version.items()}
-        columns = [name.split('=')[0] for name in parsed.values()[0]]
+        parsed = {k: v.split('\n') for k, v in list(list_version.items())}
+        columns = [name.split('=')[0] for name in list(parsed.values())[0]]
 
         template = "{:<40} | {:<25} | {:<25} | {:<25}\n"
 
diff --git a/test_set/cvp-sanity/requirements.txt b/test_set/cvp-sanity/requirements.txt
index fc42a2b..e95f388 100644
--- a/test_set/cvp-sanity/requirements.txt
+++ b/test_set/cvp-sanity/requirements.txt
@@ -4,7 +4,6 @@
 flake8
 PyYAML
 python-jenkins==0.4.11
-pygerrit2==2.0.6
+pygerrit2==2.0.9
 gitpython
-python-ldap
-
+ldap3
diff --git a/test_set/cvp-sanity/tests/ceph/test_ceph_haproxy.py b/test_set/cvp-sanity/tests/ceph/test_ceph_haproxy.py
index 1dad16d..e41ef90 100644
--- a/test_set/cvp-sanity/tests/ceph/test_ceph_haproxy.py
+++ b/test_set/cvp-sanity/tests/ceph/test_ceph_haproxy.py
@@ -14,7 +14,7 @@
     if not monitor_info:
         pytest.skip("Ceph is not found on this environment")
 
-    for name, info in monitor_info.iteritems():
+    for name, info in monitor_info.items():
         if "OPEN" and "UP" in info:
             continue
         else:
diff --git a/test_set/cvp-sanity/tests/ceph/test_ceph_pg_count.py b/test_set/cvp-sanity/tests/ceph/test_ceph_pg_count.py
index 3911d27..ea341f3 100644
--- a/test_set/cvp-sanity/tests/ceph/test_ceph_pg_count.py
+++ b/test_set/cvp-sanity/tests/ceph/test_ceph_pg_count.py
@@ -1,15 +1,16 @@
-import pytest
 import math
+import pytest
+
 
 def __next_power_of2(total_pg):
-	count = 0
-	if (total_pg and not(total_pg & (total_pg - 1))):
-		return total_pg	
-	while( total_pg != 0):
-		total_pg >>= 1
-		count += 1
-	
-	return 1 << count
+    count = 0
+    if (total_pg and not (total_pg & (total_pg - 1))):
+        return total_pg
+    while (total_pg != 0):
+        total_pg >>= 1
+        count += 1
+
+    return 1 << count
 
 
 def test_ceph_pg_count(local_salt_client):
@@ -18,67 +19,67 @@
     according formula below.
     Formula to calculate PG num:
     Total PGs = 
-    (Total_number_of_OSD * 100) / max_replication_count / pool count
+    (Total_number_of_OSD * 100) // max_replication_count // pool count
     pg_num and pgp_num should be the same and 
     set according formula to higher value of powered 2
     """
     pytest.skip("This test needs redesign. Skipped for now")
     ceph_monitors = local_salt_client.cmd(
-        'ceph:mon', 
-        'test.ping', 
+        'ceph:mon',
+        'test.ping',
         expr_form='pillar')
-    
+
     if not ceph_monitors:
         pytest.skip("Ceph is not found on this environment")
 
-    monitor = ceph_monitors.keys()[0]
+    monitor = list(ceph_monitors.keys())[0]
     pools = local_salt_client.cmd(
-        monitor, 'cmd.run', 
-        ["rados lspools"], 
+        monitor, 'cmd.run',
+        ["rados lspools"],
         expr_form='glob').get(
-            ceph_monitors.keys()[0]).split('\n')
-    
+        list(ceph_monitors.keys())[0]).split('\n')
+
     total_osds = int(local_salt_client.cmd(
-        monitor, 
-        'cmd.run', 
-        ['ceph osd tree | grep osd | grep "up\|down" | wc -l'], 
-        expr_form='glob').get(ceph_monitors.keys()[0]))
-    
+        monitor,
+        'cmd.run',
+        ['ceph osd tree | grep osd | grep "up\|down" | wc -l'],
+        expr_form='glob').get(list(ceph_monitors.keys())[0]))
+
     raw_pool_replications = local_salt_client.cmd(
-        monitor, 
-        'cmd.run', 
-        ["ceph osd dump | grep size | awk '{print $3, $6}'"], 
-        expr_form='glob').get(ceph_monitors.keys()[0]).split('\n')
-    
+        monitor,
+        'cmd.run',
+        ["ceph osd dump | grep size | awk '{print $3, $6}'"],
+        expr_form='glob').get(list(ceph_monitors.keys())[0]).split('\n')
+
     pool_replications = {}
     for replication in raw_pool_replications:
         pool_replications[replication.split()[0]] = int(replication.split()[1])
-    
+
     max_replication_value = 0
-    for repl_value in pool_replications.values():
+    for repl_value in list(pool_replications.values()):
         if repl_value > max_replication_value:
             max_replication_value = repl_value
 
-    total_pg = (total_osds * 100) / max_replication_value / len(pools)
+    total_pg = total_pg = (total_osds * 100) // max_replication_value // len(pools)
     correct_pg_num = __next_power_of2(total_pg)
-    
+
     pools_pg_num = {}
     pools_pgp_num = {}
     for pool in pools:
         pg_num = int(local_salt_client.cmd(
-            monitor, 
-            'cmd.run', 
-            ["ceph osd pool get {} pg_num".format(pool)], 
-            expr_form='glob').get(ceph_monitors.keys()[0]).split()[1])
+            monitor,
+            'cmd.run',
+            ["ceph osd pool get {} pg_num".format(pool)],
+            expr_form='glob').get(list(ceph_monitors.keys())[0]).split()[1])
         pools_pg_num[pool] = pg_num
         pgp_num = int(local_salt_client.cmd(
-            monitor, 
-            'cmd.run', 
-            ["ceph osd pool get {} pgp_num".format(pool)], 
-            expr_form='glob').get(ceph_monitors.keys()[0]).split()[1])
+            monitor,
+            'cmd.run',
+            ["ceph osd pool get {} pgp_num".format(pool)],
+            expr_form='glob').get(list(ceph_monitors.keys())[0]).split()[1])
         pools_pgp_num[pool] = pgp_num
 
-    wrong_pg_num_pools = [] 
+    wrong_pg_num_pools = []
     pg_pgp_not_equal_pools = []
     for pool in pools:
         if pools_pg_num[pool] != pools_pgp_num[pool]:
diff --git a/test_set/cvp-sanity/tests/ceph/test_ceph_replicas.py b/test_set/cvp-sanity/tests/ceph/test_ceph_replicas.py
index 7d8c63a..07df057 100644
--- a/test_set/cvp-sanity/tests/ceph/test_ceph_replicas.py
+++ b/test_set/cvp-sanity/tests/ceph/test_ceph_replicas.py
@@ -1,3 +1,4 @@
+from builtins import str
 import pytest
 
 
@@ -13,7 +14,7 @@
     if not ceph_monitors:
         pytest.skip("Ceph is not found on this environment")
 
-    monitor = ceph_monitors.keys()[0]
+    monitor = list(ceph_monitors.keys())[0]
 
     raw_pool_replicas = local_salt_client.cmd_any(
         tgt='ceph:mon',
@@ -31,8 +32,8 @@
         pools_replicas[pool_name] = pool_replicas
     
     error = []
-    for pool, replicas in pools_replicas.items():
-        for replica, value in replicas.items():
+    for pool, replicas in list(pools_replicas.items()):
+        for replica, value in list(replicas.items()):
             if replica == 'min_size' and value < 2:
                 error.append(pool + " " + replica + " " 
                 + str(value) + " must be 2")
diff --git a/test_set/cvp-sanity/tests/ceph/test_ceph_status.py b/test_set/cvp-sanity/tests/ceph/test_ceph_status.py
index 2c32106..7137851 100644
--- a/test_set/cvp-sanity/tests/ceph/test_ceph_status.py
+++ b/test_set/cvp-sanity/tests/ceph/test_ceph_status.py
@@ -9,8 +9,8 @@
         expr_form='pillar')
     if not osd_fail:
         pytest.skip("Ceph is not found on this environment")
-    assert not osd_fail.values()[0], (
-        "Some OSDs are in down state:\n{}".format(osd_fail.values()[0]))
+    assert not list(osd_fail.values())[0], (
+        "Some OSDs are in down state:\n{}".format(list(osd_fail.values())[0]))
 
 
 def test_ceph_health(local_salt_client):
@@ -20,14 +20,14 @@
         expr_form='pillar')
     if not get_status:
         pytest.skip("Ceph is not found on this environment")
-    status = json.loads(get_status.values()[0])["health"]
+    status = json.loads(list(get_status.values())[0])["health"]
     health = status["status"] if 'status' in status \
         else status["overall_status"]
 
     # Health structure depends on Ceph version, so condition is needed:
     if 'checks' in status:
         summary = "Summary: {}".format(
-            [i["summary"]["message"] for i in status["checks"].values()])
+            [i["summary"]["message"] for i in list(status["checks"].values())])
     else:
         summary = status["summary"]
 
diff --git a/test_set/cvp-sanity/tests/ceph/test_ceph_tell_bench.py b/test_set/cvp-sanity/tests/ceph/test_ceph_tell_bench.py
index 5dee40f..bb2a659 100644
--- a/test_set/cvp-sanity/tests/ceph/test_ceph_tell_bench.py
+++ b/test_set/cvp-sanity/tests/ceph/test_ceph_tell_bench.py
@@ -22,12 +22,12 @@
         pytest.skip("Ceph is not found on this environment")
 
     cmd_result = local_salt_client.cmd(
-        ceph_monitors.keys()[0], 
+        list(ceph_monitors.keys())[0], 
         'cmd.run', ["ceph tell osd.* bench -f json"], 
         expr_form='glob').get(
-            ceph_monitors.keys()[0]).split('\n')
+            list(ceph_monitors.keys())[0]).split('\n')
 
-    cmd_result = filter(None, cmd_result)
+    cmd_result = [_f for _f in cmd_result if _f]
 
     osd_pool = {}
     for osd in cmd_result:
@@ -38,14 +38,14 @@
     osd_count = 0
     for osd in osd_pool:
         osd_count += 1
-        mbps_sum += json.loads(
-            osd_pool[osd])['bytes_per_sec'] / 1000000
+        mbps_sum += old_div(json.loads(
+            osd_pool[osd])['bytes_per_sec'], 1000000)
 
-    mbps_avg = mbps_sum / osd_count
+    mbps_avg = mbps_sum // osd_count
     result = {}
     for osd in osd_pool:
         mbps = json.loads(
-            osd_pool[osd])['bytes_per_sec'] / 1000000
+            osd_pool[osd])['bytes_per_sec'] // 1000000
         if math.fabs(mbps_avg - mbps) > 10:
             result[osd] = osd_pool[osd]
 
diff --git a/test_set/cvp-sanity/tests/test_cinder_services.py b/test_set/cvp-sanity/tests/test_cinder_services.py
index 9e13e36..f223d3e 100644
--- a/test_set/cvp-sanity/tests/test_cinder_services.py
+++ b/test_set/cvp-sanity/tests/test_cinder_services.py
@@ -1,3 +1,4 @@
+from builtins import str
 import pytest
 import logging
 
@@ -30,7 +31,7 @@
     cinder_volume = local_salt_client.cmd_any(
         tgt='keystone:server',
         param='. /root/keystonercv3; cinder service-list | grep "volume" |grep -c -v -e "lvm"')
-    backends_num = len(backends_cinder.keys())
+    backends_num = len(list(backends_cinder.keys()))
     assert cinder_volume == str(backends_num), (
         'Number of cinder-volume services ({0}) does not match number of '
         'volume backends ({1}).'.format(cinder_volume, str(backends_num))
diff --git a/test_set/cvp-sanity/tests/test_contrail.py b/test_set/cvp-sanity/tests/test_contrail.py
index 01142b8..9a4e3ee 100644
--- a/test_set/cvp-sanity/tests/test_contrail.py
+++ b/test_set/cvp-sanity/tests/test_contrail.py
@@ -86,10 +86,10 @@
             if 'contrail-vrouter-nodemgr' in line:
                 actual_vrouter_count += 1
 
-    assert actual_vrouter_count == len(cs.keys()),\
+    assert actual_vrouter_count == len(list(cs.keys())),\
         'The length of vRouters {} differs' \
         ' from the length of compute nodes {}'.format(actual_vrouter_count,
-                                                      len(cs.keys()))
+                                                      len(list(cs.keys())))
 
 @pytest.mark.smoke
 def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack):
diff --git a/test_set/cvp-sanity/tests/test_default_gateway.py b/test_set/cvp-sanity/tests/test_default_gateway.py
index 259abba..31c2447 100644
--- a/test_set/cvp-sanity/tests/test_default_gateway.py
+++ b/test_set/cvp-sanity/tests/test_default_gateway.py
@@ -12,7 +12,7 @@
 
     gateways = {}
 
-    for node in netstat_info.keys():
+    for node in list(netstat_info.keys()):
         gateway = netstat_info[node]
         if isinstance(gateway, bool):
             gateway = 'Cannot access node(-s)'
@@ -21,7 +21,7 @@
         else:
             gateways[gateway].append(node)
 
-    assert len(gateways.keys()) == 1, (
+    assert len(list(gateways.keys())) == 1, (
         "There is a problem with default gateway for '{}' group of nodes:\n"
         "{}".format(group, json.dumps(gateways, indent=4))
     )
diff --git a/test_set/cvp-sanity/tests/test_drivetrain.py b/test_set/cvp-sanity/tests/test_drivetrain.py
index 6741380..0624536 100644
--- a/test_set/cvp-sanity/tests/test_drivetrain.py
+++ b/test_set/cvp-sanity/tests/test_drivetrain.py
@@ -1,16 +1,25 @@
+import git
 import jenkins
-from xml.dom import minidom
-import utils
 import json
+import logging
+import os
 import pytest
 import time
-import os
+import utils
+from builtins import range
+from ldap3 import (
+    Connection,
+    Server,
+    Reader,
+    LDIF,
+    MODIFY_ADD,
+    MODIFY_DELETE,
+    SUBTREE,
+    ALL_ATTRIBUTES)
+from ldap3.core.exceptions import LDAPException
 from pygerrit2 import GerritRestAPI, HTTPBasicAuth
 from requests import HTTPError
-import git
-import ldap
-import ldap.modlist as modlist
-import logging
+from xml.dom import minidom
 
 
 def join_to_gerrit(local_salt_client, gerrit_user, gerrit_password):
@@ -135,6 +144,8 @@
 
 
 @pytest.mark.full
+@pytest.mark.skip
+# Temporary skipped, ldap3 package add\search user is not working
 def test_drivetrain_openldap(local_salt_client, check_cicd):
     """
          1. Create a test user 'DT_test_user' in openldap
@@ -169,7 +180,7 @@
     ldap_con_admin = local_salt_client.pillar_get(
         tgt='openldap:client',
         param='openldap:client:server:auth:user')
-    ldap_url = 'ldap://{0}:{1}'.format(ldap_address,ldap_port)
+    ldap_url = 'ldap://{0}:{1}'.format(ldap_address, ldap_port)
     ldap_error = ''
     ldap_result = ''
     gerrit_result = ''
@@ -177,59 +188,77 @@
     jenkins_error = ''
     # Test user's CN
     test_user_name = 'DT_test_user'
-    test_user = 'cn={0},ou=people,{1}'.format(test_user_name,ldap_dc)
+    test_user = 'cn={0},ou=people,{1}'.format(test_user_name, ldap_dc)
     # Admins group CN
     admin_gr_dn = 'cn=admins,ou=groups,{0}'.format(ldap_dc)
+    user_pass = 'aSecretPassw'
     # List of attributes for test user
     attrs = {}
     attrs['objectclass'] = ['organizationalRole', 'simpleSecurityObject', 'shadowAccount']
     attrs['cn'] = test_user_name
     attrs['uid'] = test_user_name
-    attrs['userPassword'] = 'aSecretPassw'
+    attrs['userPassword'] = user_pass
     attrs['description'] = 'Test user for CVP DT test'
-    searchFilter = 'cn={0}'.format(test_user_name)
+    # search_filter = '(cn={0})'.format(test_user_name)
+    search_filter = '(cn={})'.format(test_user_name)
     # Get a test job name from config
     config = utils.get_configuration()
     jenkins_cvp_job = config['jenkins_cvp_job']
+    logging.warning('test_user: {}'.format(test_user))
+    logging.warning('ldap_address: {}'.format(ldap_address))
     # Open connection to ldap and creating test user in admins group
     try:
-        ldap_server = ldap.initialize(ldap_url)
-        ldap_server.simple_bind_s(ldap_con_admin,ldap_password)
-        ldif = modlist.addModlist(attrs)
-        ldap_server.add_s(test_user, ldif)
-        ldap_server.modify_s(admin_gr_dn, [(ldap.MOD_ADD, 'memberUid', [test_user_name],)],)
+        ldap_server = Server(host=ldap_address, port=ldap_port,
+                             use_ssl=False, get_info='NO_INFO')
+        conn = Connection(ldap_server, client_strategy=LDIF)
+        conn.bind()
+        new_user = conn.add(test_user, test_user_name, attrs)
+        logging.warning('new_user: {}'.format(new_user))
+        conn.modify(admin_gr_dn,
+                    {'memberUid': (MODIFY_ADD, [test_user_name])
+                     })
         # Check search test user in LDAP
-        searchScope = ldap.SCOPE_SUBTREE
-        ldap_result = ldap_server.search_s(ldap_dc, searchScope, searchFilter)
-    except ldap.LDAPError as e:
+        conn2 = Connection(ldap_server)
+        conn2.bind()
+        ldap_result = conn2.search(search_base='dc=heat-cicd-queens-contrail41-sl,dc=local',
+                                   search_filter=search_filter, search_scope='SUBTREE', attributes=['cn'])
+        logging.warning('ldap_result: {}'.format(ldap_result))
+        logging.warning('conn2.entries.: {}'.format(conn2.entries))
+    except LDAPException as e:
         ldap_error = e
     try:
+        # Check if user is created before connect from Jenkins
+        assert ldap_result, "Test user {} is not found".format(ldap_result)
         # Check connection between Jenkins and LDAP
-        jenkins_server = join_to_jenkins(local_salt_client,test_user_name,'aSecretPassw')
+        jenkins_server = join_to_jenkins(local_salt_client, test_user_name, user_pass)
         jenkins_version = jenkins_server.get_job_name(jenkins_cvp_job)
         # Check connection between Gerrit and LDAP
-        gerrit_server = join_to_gerrit(local_salt_client,'admin',ldap_password)
+        gerrit_server = join_to_gerrit(local_salt_client, 'admin', ldap_password)
         gerrit_check = gerrit_server.get("/changes/?q=owner:self%20status:open")
         # Add test user to devops-contrib group in Gerrit and check login
         _link = "/groups/devops-contrib/members/{0}".format(test_user_name)
         gerrit_add_user = gerrit_server.put(_link)
-        gerrit_server = join_to_gerrit(local_salt_client,test_user_name,'aSecretPassw')
+        gerrit_server = join_to_gerrit(local_salt_client, test_user_name, user_pass)
         gerrit_result = gerrit_server.get("/changes/?q=owner:self%20status:open")
     except HTTPError as e:
         gerrit_error = e
     except jenkins.JenkinsException as e:
         jenkins_error = e
     finally:
-        ldap_server.modify_s(admin_gr_dn,[(ldap.MOD_DELETE, 'memberUid', [test_user_name],)],)
-        ldap_server.delete_s(test_user)
-        ldap_server.unbind_s()
+        conn.modify(admin_gr_dn,
+                    {'memberUid': (MODIFY_DELETE, [test_user_name])
+                     })
+        conn.delete(test_user)
+        conn.unbind()
+        conn2.unbind()
+
     assert ldap_error == '', (
-        "There is an error with connection to LDAP:\n{}".format(e))
+        "There is an error with connection to LDAP:\n{}".format(ldap_error))
     assert jenkins_error == '', (
-        "Connection to Jenkins is not established:\n{}".format(e))
+        "Connection to Jenkins is not established:\n{}".format(jenkins_error))
     assert gerrit_error == '', (
-        "Connection to Gerrit is not established:\n{}".format(e))
-    assert ldap_result != [], "Test user {} is not found".format(ldap_result)
+        "Connection to Gerrit is not established:\n{}".format(gerrit_error))
+
 
 
 @pytest.mark.sl_dup
@@ -249,7 +278,7 @@
             param='docker service ls',
             expr_form='compound')
         wrong_items = []
-        for line in docker_services_by_nodes[docker_services_by_nodes.keys()[0]].split('\n'):
+        for line in docker_services_by_nodes[list(docker_services_by_nodes.keys())[0]].split('\n'):
             if line[line.find('/') - 1] != line[line.find('/') + 1] \
                and 'replicated' in line:
                 wrong_items.append(line)
@@ -286,14 +315,14 @@
 
     expected_images = list()
     # find services in list of docker clients
-    for key, stack in stack_info.items():
+    for key, stack in list(stack_info.items()):
         if stack.get('service'):
-            stack = [item.get('image') for _,item in stack.get('service').items() if item.get('image')]
+            stack = [item.get('image') for _,item in list(stack.get('service').items()) if item.get('image')]
             expected_images += stack
 
     mismatch = {}
     actual_images = {}
-    for image in set(table_with_docker_services[table_with_docker_services.keys()[0]].split('\n')):
+    for image in set(table_with_docker_services[list(table_with_docker_services.keys())[0]].split('\n')):
         actual_images[get_name(image)] = get_tag(image)
 
     for image in set(expected_images):
diff --git a/test_set/cvp-sanity/tests/test_duplicate_ips.py b/test_set/cvp-sanity/tests/test_duplicate_ips.py
index ba52f64..ca814c4 100644
--- a/test_set/cvp-sanity/tests/test_duplicate_ips.py
+++ b/test_set/cvp-sanity/tests/test_duplicate_ips.py
@@ -45,7 +45,7 @@
     no_dups = (len(ipv4_list) == len(set(ipv4_list)))
     if not no_dups:
         ips_count = Counter(ipv4_list).most_common()
-        dup_ips = filter(lambda x: x[1] > 1, ips_count)
+        dup_ips = [x for x in ips_count if x[1] > 1]
         dup_ifaces = get_duplicate_ifaces(nodes, [v[0] for v in dup_ips])
 
         msg = ("\nDuplicate IP addresses found:\n{}"
diff --git a/test_set/cvp-sanity/tests/test_etc_hosts.py b/test_set/cvp-sanity/tests/test_etc_hosts.py
index bf881e7..12378f1 100644
--- a/test_set/cvp-sanity/tests/test_etc_hosts.py
+++ b/test_set/cvp-sanity/tests/test_etc_hosts.py
@@ -9,11 +9,11 @@
         param='cat /etc/hosts',
         expr_form='compound')
     result = {}
-    for node in nodes_info.keys():
+    for node in list(nodes_info.keys()):
         if isinstance(nodes_info[node], bool):
             result[node] = 'Cannot access this node'
             continue
-        for nd in nodes_info.keys():
+        for nd in list(nodes_info.keys()):
             if nd not in nodes_info[node]:
                 if node in result:
                     result[node] += ',' + nd
diff --git a/test_set/cvp-sanity/tests/test_galera_cluster.py b/test_set/cvp-sanity/tests/test_galera_cluster.py
index 32b1074..dc665e7 100644
--- a/test_set/cvp-sanity/tests/test_galera_cluster.py
+++ b/test_set/cvp-sanity/tests/test_galera_cluster.py
@@ -1,3 +1,4 @@
+from builtins import str
 import pytest
 
 
@@ -18,7 +19,7 @@
     size_cluster = []
     amount = len(gs)
 
-    for item in gs.values():
+    for item in list(gs.values()):
         size_cluster.append(item.split('\n')[-1].strip())
 
     assert all(item == str(amount) for item in size_cluster), \
diff --git a/test_set/cvp-sanity/tests/test_k8s.py b/test_set/cvp-sanity/tests/test_k8s.py
index cd2fbfd..c253b45 100644
--- a/test_set/cvp-sanity/tests/test_k8s.py
+++ b/test_set/cvp-sanity/tests/test_k8s.py
@@ -178,7 +178,7 @@
         param='curl {} 2>&1 | grep kubernetesDashboard'.format(url),
         expr_form='pillar'
     )
-    assert len(check.values()[0]) != 0, (
+    assert len(list(check.values())[0]) != 0, (
         'Kubernetes dashboard is not reachable on {} from '
         'ctl nodes'.format(url)
     )
diff --git a/test_set/cvp-sanity/tests/test_kernel_settings.py b/test_set/cvp-sanity/tests/test_kernel_settings.py
index f13f685..302c8a3 100644
--- a/test_set/cvp-sanity/tests/test_kernel_settings.py
+++ b/test_set/cvp-sanity/tests/test_kernel_settings.py
@@ -42,11 +42,11 @@
     # To get only specified values from system need to request them in the nex format
     # 'sysctl param1 param2 param3 param4'
 
-    for node in expected_kernel_params_by_nodes.keys():
+    for node in list(expected_kernel_params_by_nodes.keys()):
         actual_kernel_params_for_node = local_salt_client.cmd(
             tgt=node,
             fun='cmd.run',
-            param="sysctl {}".format(" ".join(expected_kernel_params_by_nodes[node].keys())),
+            param="sysctl {}".format(" ".join(list(expected_kernel_params_by_nodes[node].keys()))),
             expr_form='compound'
         )
         # make transfer string to dict format
@@ -62,7 +62,7 @@
                   for param in actual_kernel_params_for_node[node].split('\n')}
 
         differences = [ "Parameter '{}' is not set === Expected '{}' === Got in sysctl '{}'".format(key, expected_kernel_params_by_nodes[node].get(key), actual)
-                        for key, actual in values.items()
+                        for key, actual in list(values.items())
                         if  expected_kernel_params_by_nodes[node].get(key) != actual ]
         if differences.__len__() > 0:
             issues[node] = differences
diff --git a/test_set/cvp-sanity/tests/test_mounts.py b/test_set/cvp-sanity/tests/test_mounts.py
index cc6f201..3f025dd 100644
--- a/test_set/cvp-sanity/tests/test_mounts.py
+++ b/test_set/cvp-sanity/tests/test_mounts.py
@@ -18,7 +18,7 @@
 
     # Let's exclude cmp, kvm, ceph OSD nodes, mon, cid, k8s-ctl, k8s-cmp nodes
     # These nodes will have different mounts and this is expected
-    exclude_nodes = local_salt_client.test_ping(
+    exclude_nodes = list(local_salt_client.test_ping(
          tgt="I@nova:compute or "
              "I@ceph:osd or "
              "I@salt:control or "
@@ -26,9 +26,9 @@
              "I@kubernetes:* and not I@etcd:* or "
              "I@docker:host and not I@prometheus:server and not I@kubernetes:* or "
              "I@gerrit:client and I@kubernetes:pool and not I@salt:master",
-         expr_form='compound').keys()
+         expr_form='compound').keys())
 
-    if len(mounts_by_nodes.keys()) < 2:
+    if len(list(mounts_by_nodes.keys())) < 2:
         pytest.skip("Nothing to compare - only 1 node")
 
     result = {}
diff --git a/test_set/cvp-sanity/tests/test_mtu.py b/test_set/cvp-sanity/tests/test_mtu.py
index 7af3303..bfe82d5 100644
--- a/test_set/cvp-sanity/tests/test_mtu.py
+++ b/test_set/cvp-sanity/tests/test_mtu.py
@@ -19,7 +19,7 @@
         param='ls /sys/class/net/',
         expr_form='compound')
 
-    if len(network_info.keys()) < 2:
+    if len(list(network_info.keys())) < 2:
         pytest.skip("Nothing to compare - only 1 node")
 
     # collect all nodes and check if virsh is installed there
@@ -30,12 +30,12 @@
         expr_form='pillar'
     )
 
-    for node, ifaces_info in network_info.iteritems():
+    for node, ifaces_info in network_info.items():
         if isinstance(ifaces_info, bool):
             logging.info("{} node is skipped".format(node))
             continue
         # if node is a kvm node and virsh is installed there
-        if node in kvm_nodes.keys() and kvm_nodes[node]:
+        if node in list(kvm_nodes.keys()) and kvm_nodes[node]:
             kvm_info = local_salt_client.cmd(tgt=node,
                                              param="virsh list | "
                                                    "awk '{print $2}' | "
@@ -62,12 +62,12 @@
 
     for node in total:
         nodes.append(node)
-        my_set.update(total[node].keys())
+        my_set.update(list(total[node].keys()))
     for interf in my_set:
         diff = []
         row = []
         for node in nodes:
-            if interf in total[node].keys():
+            if interf in list(total[node].keys()):
                 diff.append(total[node][interf])
                 row.append("{}: {}".format(node, total[node][interf]))
             else:
diff --git a/test_set/cvp-sanity/tests/test_nodes.py b/test_set/cvp-sanity/tests/test_nodes.py
index 082930e..481b331 100644
--- a/test_set/cvp-sanity/tests/test_nodes.py
+++ b/test_set/cvp-sanity/tests/test_nodes.py
@@ -11,7 +11,7 @@
         expr_form='pillar', check_status=True)
     statuses = {}
     try:
-        statuses = json.loads(result.values()[0])
+        statuses = json.loads(list(result.values())[0])
     except Exception as e:
         pytest.fail(
             "Could not check the result: {}\n"
diff --git a/test_set/cvp-sanity/tests/test_nodes_in_maas.py b/test_set/cvp-sanity/tests/test_nodes_in_maas.py
index 62c0fd8..bf2308c 100644
--- a/test_set/cvp-sanity/tests/test_nodes_in_maas.py
+++ b/test_set/cvp-sanity/tests/test_nodes_in_maas.py
@@ -53,7 +53,7 @@
         expr_form='pillar')
     result = ""
     try:
-        result = json.loads(get_nodes.values()[0])
+        result = json.loads(list(get_nodes.values())[0])
     except ValueError as e:
         assert result, "Could not get '{}' nodes:\n{}".format(get_nodes, e)
 
@@ -62,7 +62,7 @@
     for node in result:
         if node["fqdn"] in config.get("skipped_nodes"):
             continue
-        if "status_name" in node.keys():
+        if "status_name" in list(node.keys()):
             if node["status_name"] != 'Deployed':
                 failed_nodes.append({node["fqdn"]: node["status_name"]})
     assert not failed_nodes, (
diff --git a/test_set/cvp-sanity/tests/test_ntp_sync.py b/test_set/cvp-sanity/tests/test_ntp_sync.py
index f4161f2..f9ea686 100644
--- a/test_set/cvp-sanity/tests/test_ntp_sync.py
+++ b/test_set/cvp-sanity/tests/test_ntp_sync.py
@@ -14,7 +14,7 @@
         param='date +%s',
         expr_form='compound')
     result = {}
-    for node, time in nodes_time.iteritems():
+    for node, time in nodes_time.items():
         if isinstance(nodes_time[node], bool):
             time = 'Cannot access node(-s)'
         if node in config.get("ntp_skipped_nodes"):
diff --git a/test_set/cvp-sanity/tests/test_oss.py b/test_set/cvp-sanity/tests/test_oss.py
index f28917c..2959681 100644
--- a/test_set/cvp-sanity/tests/test_oss.py
+++ b/test_set/cvp-sanity/tests/test_oss.py
@@ -21,7 +21,7 @@
     proxies = {"http": None, "https": None}
     csv_result = requests.get('http://{}:9600/haproxy?stats;csv"'.format(
                               HAPROXY_STATS_IP),
-                              proxies=proxies).content
+                              proxies=proxies).content.decode()
     data = csv_result.lstrip('# ')
     wrong_data = []
     list_of_services = ['aptly', 'openldap', 'gerrit', 'jenkins', 'postgresql',
diff --git a/test_set/cvp-sanity/tests/test_packet_checker.py b/test_set/cvp-sanity/tests/test_packet_checker.py
index 40c7bd7..f72275d 100644
--- a/test_set/cvp-sanity/tests/test_packet_checker.py
+++ b/test_set/cvp-sanity/tests/test_packet_checker.py
@@ -5,7 +5,7 @@
 
 def is_deb_in_exception(inconsistency_rule, package_name, error_node_list):
     short_names_in_error_nodes = [n.split('.')[0] for n in error_node_list]
-    for node, excluded_packages in inconsistency_rule.iteritems():
+    for node, excluded_packages in inconsistency_rule.items():
         if package_name in excluded_packages and node in short_names_in_error_nodes:
             return True
     return False
@@ -31,8 +31,8 @@
                                               fun='lowpkg.list_pkgs',
                                               expr_form='compound')
     # Let's exclude cid01 and dbs01 nodes from this check
-    exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
-                                                expr_form='compound').keys()
+    exclude_nodes = list(local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
+                                                expr_form='compound').keys())
     # PROD-30833
     gtw01 = local_salt_client.pillar_get(
         param='_param:openstack_gateway_node01_hostname') or 'gtw01'
@@ -44,7 +44,7 @@
                                         fun='pillar.get',
                                         param='octavia:manager:enabled',
                                         expr_form='compound')
-        gtws = [gtw for gtw in octavia.values() if gtw]
+        gtws = [gtw for gtw in list(octavia.values()) if gtw]
         if len(gtws) == 1:
             exclude_nodes.append(gtw01)
             logging.info("gtw01 node is skipped in test_check_package_versions")
@@ -62,7 +62,7 @@
             logging.warning("Node {} is skipped".format(node))
             continue
         nodes_with_packages.append(node)
-        packages_names.update(packages_versions[node].keys())
+        packages_names.update(list(packages_versions[node].keys()))
     for deb in packages_names:
         if deb in exclude_packages:
             continue
@@ -71,7 +71,7 @@
         for node in nodes_with_packages:
             if not packages_versions[node]:
                 continue
-            if deb in packages_versions[node].keys():
+            if deb in list(packages_versions[node].keys()):
                 diff.append(packages_versions[node][deb])
                 row.append("{}: {}".format(node, packages_versions[node][deb]))
             else:
@@ -124,11 +124,11 @@
         tgt="L@"+','.join(nodes),
         param='dpkg -l | grep "python-pip "',
         expr_form='compound')
-    if pre_check.values().count('') > 0:
+    if list(pre_check.values()).count('') > 0:
         pytest.skip("pip is not installed on one or more nodes")
 
-    exclude_nodes = local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
-                                                expr_form='compound').keys()
+    exclude_nodes = list(local_salt_client.test_ping(tgt="I@galera:master or I@gerrit:client",
+                                                expr_form='compound').keys())
 
     # PROD-30833
     gtw01 = local_salt_client.pillar_get(
@@ -141,12 +141,12 @@
                                         fun='pillar.get',
                                         param='octavia:manager:enabled',
                                         expr_form='compound')
-        gtws = [gtw for gtw in octavia.values() if gtw]
+        gtws = [gtw for gtw in list(octavia.values()) if gtw]
         if len(gtws) == 1:
             exclude_nodes.append(gtw01)
             logging.info("gtw01 node is skipped in test_check_module_versions")
 
-    total_nodes = [i for i in pre_check.keys() if i not in exclude_nodes]
+    total_nodes = [i for i in list(pre_check.keys()) if i not in exclude_nodes]
 
     if len(total_nodes) < 2:
         pytest.skip("Nothing to compare - only 1 node")
@@ -170,7 +170,7 @@
         diff = []
         row = []
         for node in nodes_with_packages:
-            if deb in list_of_pip_packages[node].keys():
+            if deb in list(list_of_pip_packages[node].keys()):
                 diff.append(list_of_pip_packages[node][deb])
                 row.append("{}: {}".format(node, list_of_pip_packages[node][deb]))
             else:
diff --git a/test_set/cvp-sanity/tests/test_rabbit_cluster.py b/test_set/cvp-sanity/tests/test_rabbit_cluster.py
index f90c54f..d3375f3 100644
--- a/test_set/cvp-sanity/tests/test_rabbit_cluster.py
+++ b/test_set/cvp-sanity/tests/test_rabbit_cluster.py
@@ -38,7 +38,7 @@
         running_nodes_count = 0
         # rabbitmqctl cluster_status output contains
         # 3 * # of nodes 'rabbit@' entries + 1
-        running_nodes_count = (rabbit_actual_data[node].count('rabbit@') - 1)/3
+        running_nodes_count = (rabbit_actual_data[node].count('rabbit@') - 1)//3
         # update control dictionary with values
         # {node:actual_cluster_size_for_node}
         if required_cluster_size_dict[node] != running_nodes_count:
@@ -48,5 +48,5 @@
         "RabbitMQ cluster is probably "
         "broken - the cluster size for each node should be ({}),\nbut the "
         "following nodes have other values:\n{}".format(
-            len(required_cluster_size_dict.keys()), control_dict)
+            len(list(required_cluster_size_dict.keys())), control_dict)
     )
diff --git a/test_set/cvp-sanity/tests/test_repo_list.py b/test_set/cvp-sanity/tests/test_repo_list.py
index b932e5d..ef02b6e 100644
--- a/test_set/cvp-sanity/tests/test_repo_list.py
+++ b/test_set/cvp-sanity/tests/test_repo_list.py
@@ -13,13 +13,13 @@
                                       expr_form='compound')
 
     # check if some repos are disabled
-    for node in info_salt.keys():
+    for node in list(info_salt.keys()):
         repos = info_salt[node]
         if not info_salt[node]:
             # TODO: do not skip node
             logging.warning("Node {} is skipped".format(node))
             continue
-        for repo in repos.keys():
+        for repo in list(repos.keys()):
             repository = repos[repo]
             if "enabled" in repository:
                 if not repository["enabled"]:
@@ -31,14 +31,14 @@
               'cat /etc/apt/sources.list|grep deb|grep -v "#"',
         expr_form='compound', check_status=True)
     actual_repo_list = [item.replace('/ ', ' ').replace('[arch=amd64] ', '')
-                        for item in raw_actual_info.values()[0].split('\n')]
-    if info_salt.values()[0] == '':
+                        for item in list(raw_actual_info.values())[0].split('\n')]
+    if list(info_salt.values())[0] == '':
         expected_salt_data = ''
     else:
         expected_salt_data = [repo['source'].replace('/ ', ' ')
                                             .replace('[arch=amd64] ', '')
-                              for repo in info_salt.values()[0].values()
-                              if 'source' in repo.keys()]
+                              for repo in list(info_salt.values())[0].values()
+                              if 'source' in list(repo.keys())]
 
     diff = {}
     my_set = set()
diff --git a/test_set/cvp-sanity/tests/test_salt_master.py b/test_set/cvp-sanity/tests/test_salt_master.py
index 35ebcb7..691da0a 100644
--- a/test_set/cvp-sanity/tests/test_salt_master.py
+++ b/test_set/cvp-sanity/tests/test_salt_master.py
@@ -9,9 +9,9 @@
         tgt='salt:master',
         param='cd /srv/salt/reclass/classes/cluster/; git status',
         expr_form='pillar', check_status=True)
-    assert 'nothing to commit' in git_status.values()[0], (
+    assert 'nothing to commit' in list(git_status.values())[0], (
         "Git status shows some unmerged changes:\n{}".format(
-            git_status.values()[0])
+            list(git_status.values())[0])
     )
 
 
@@ -21,7 +21,7 @@
         tgt='salt:master',
         param='reclass-salt --top; echo $?',
         expr_form='pillar', check_status=True)
-    result = reclass[reclass.keys()[0]][-1]
+    result = reclass[list(reclass.keys())[0]][-1]
 
     assert result == '0', 'Reclass is broken:\n{}'.format(reclass)
 
@@ -32,18 +32,18 @@
         tgt='salt:master',
         param='reclass-salt -o json --top',
         expr_form='pillar', check_status=True)
-    salt = local_salt_client.cmd(
+    salt = list(local_salt_client.cmd(
         tgt='salt:master',
         param='salt-run manage.status timeout=10 --out=json',
-        expr_form='pillar', check_status=True).values()[0]
-    reclass_warnings = reclass[reclass.keys()[0]].split('{\n  "base":')[0]
+        expr_form='pillar', check_status=True).values())[0] or {}
+    reclass_warnings = reclass[list(reclass.keys())[0]].split('{\n  "base":')[0]
     if reclass_warnings:
         logging.warning("\nReclass-salt output has warnings: {}".format(reclass_warnings))
-    reclass_nodes = reclass[reclass.keys()[0]].split('{\n  "base":')[1]
+    reclass_nodes = reclass[list(reclass.keys())[0]].split('{\n  "base":')[1]
     assert reclass_nodes != '', 'No nodes were found in' \
                                 ' reclass-salt --top output'
     reclass_nodes = sorted(json.loads(reclass_nodes.strip("}")).keys())
-    salt_nodes = sorted([x for xs in json.loads(salt).values() for x in xs])
+    salt_nodes = sorted([x for xs in list(json.loads(salt).values()) for x in xs])
     assert salt_nodes == reclass_nodes, (
         "Mismatch between registered salt nodes (left) and node defined in "
         "reclass (right)."
diff --git a/test_set/cvp-sanity/tests/test_services.py b/test_set/cvp-sanity/tests/test_services.py
index a014d85..6bb6fdb 100644
--- a/test_set/cvp-sanity/tests/test_services.py
+++ b/test_set/cvp-sanity/tests/test_services.py
@@ -22,7 +22,7 @@
                                               fun='service.get_all',
                                               expr_form='compound')
 
-    if len(services_by_nodes.keys()) < 2:
+    if len(list(services_by_nodes.keys())) < 2:
         pytest.skip("Nothing to compare - only 1 node")
 
     # PROD-30833
@@ -36,8 +36,8 @@
                                         fun='pillar.get',
                                         param='octavia:manager:enabled',
                                         expr_form='compound')
-        gtws = [gtw for gtw in octavia.values() if gtw]
-        if len(gtws) == 1 and gtw01 in services_by_nodes.keys():
+        gtws = [gtw for gtw in list(octavia.values()) if gtw]
+        if len(gtws) == 1 and gtw01 in list(services_by_nodes.keys()):
             services_by_nodes.pop(gtw01)
             logging.info("gtw01 node is skipped in test_check_services")
 
@@ -69,7 +69,7 @@
                 # Not found expected service on node
                 service_existence[node] = "No service"
         if set(service_existence.values()).__len__() > 1:
-            report = ["{node}: {status}".format(node=node, status=status) for node, status in service_existence.items()]
+            report = ["{node}: {status}".format(node=node, status=status) for node, status in list(service_existence.items())]
             report.sort()
             report.insert(0, srv)
             pkts_data.append(report)
diff --git a/test_set/cvp-sanity/tests/test_single_vip.py b/test_set/cvp-sanity/tests/test_single_vip.py
index dc18e0c..92a6a5e 100644
--- a/test_set/cvp-sanity/tests/test_single_vip.py
+++ b/test_set/cvp-sanity/tests/test_single_vip.py
@@ -26,7 +26,7 @@
             fun='cmd.run',
             param='ip a | grep /32 ' + exclude_from_grep,
             expr_form='compound')
-        result = [x for x in nodes_list.values() if x]
+        result = [x for x in list(nodes_list.values()) if x]
         if len(result) != 1:
             if len(result) == 0:
                 no_vip[group] = 'No vip found'
diff --git a/test_set/cvp-sanity/tests/test_stacklight.py b/test_set/cvp-sanity/tests/test_stacklight.py
index 45bd9fb..3ff1b84 100644
--- a/test_set/cvp-sanity/tests/test_stacklight.py
+++ b/test_set/cvp-sanity/tests/test_stacklight.py
@@ -27,10 +27,10 @@
     response = requests.get(
         '{0}://{1}:9200/_cat/health'.format(proto, IP),
         proxies=proxies,
-        verify=False).content
+        verify=False).content.decode()
     msg = "elasticsearch is not healthy:\n{}".format(
         json.dumps(response, indent=4))
-    assert response.split()[3] == 'green',msg
+    assert response.split()[3] == 'green', msg
     assert response.split()[4] == '3', msg
     assert response.split()[5] == '3', msg
     assert response.split()[10] == '0', msg
@@ -52,7 +52,7 @@
     response = requests.get(
         '{0}://{1}:5601/api/status'.format(proto, IP),
         proxies=proxies,
-        verify=False).content
+        verify=False).content.decode()
     body = json.loads(response)
     assert body['status']['overall']['state'] == "green", (
         "Kibana overall status is not 'green':\n{}".format(
@@ -102,7 +102,7 @@
         node_name = item_['key']
         monitored_nodes.append(node_name + '.' + cluster_domain)
     missing_nodes = []
-    all_nodes = local_salt_client.test_ping(tgt='*').keys()
+    all_nodes = list(local_salt_client.test_ping(tgt='*').keys())
     for node in all_nodes:
         if node not in monitored_nodes:
             missing_nodes.append(node)
@@ -129,7 +129,7 @@
         prometheus:server pillars are not found on this environment.")
 
     wrong_items = []
-    for line in salt_output[salt_output.keys()[0]].split('\n'):
+    for line in salt_output[list(salt_output.keys())[0]].split('\n'):
         if line[line.find('/') - 1] != line[line.find('/') + 1] \
            and 'replicated' in line:
             wrong_items.append(line)
@@ -172,7 +172,7 @@
         'Issues with accessing prometheus alerts on {}:\n{}'.format(
             IP, response.text)
     )
-    alerts = json.loads(response.content)
+    alerts = json.loads(response.content.decode())
     short_alerts = ''
     for i in alerts['data']['alerts']:
         short_alerts = '{}* {}\n'.format(short_alerts, i['annotations']['description'])
@@ -197,19 +197,19 @@
     # for old reclass models, docker:swarm:role:master can return
     # 2 nodes instead of one. Here is temporary fix.
     # TODO
-    if len(salt_output.keys()) > 1:
-        if 'CURRENT STATE' not in salt_output[salt_output.keys()[0]]:
-            del salt_output[salt_output.keys()[0]]
-    for line in salt_output[salt_output.keys()[0]].split('\n')[1:]:
+    if len(list(salt_output.keys())) > 1:
+        if 'CURRENT STATE' not in salt_output[list(salt_output.keys())[0]]:
+            del salt_output[list(salt_output.keys())[0]]
+    for line in salt_output[list(salt_output.keys())[0]].split('\n')[1:]:
         shift = 0
         if line.split()[1] == '\\_':
             shift = 1
-        if line.split()[1 + shift] not in result.keys():
+        if line.split()[1 + shift] not in list(result.keys()):
             result[line.split()[1]] = 'NOT OK'
         if line.split()[4 + shift] == 'Running' \
            or line.split()[4 + shift] == 'Ready':
             result[line.split()[1 + shift]] = 'OK'
-    assert 'NOT OK' not in result.values(), (
+    assert 'NOT OK' not in list(result.values()), (
         "Some containers have incorrect state:\n{}".format(
             json.dumps(result, indent=4))
     )
@@ -229,7 +229,7 @@
                     "this environment.")
 
     result = [{node: status} for node, status
-              in salt_output.items()
+              in list(salt_output.items())
               if status is False]
     assert result == [], (
         "Telegraf service is not running on the following nodes:\n{}".format(
@@ -246,7 +246,7 @@
                                         param='td-agent',
                                         expr_form='pillar')
     result = [{node: status} for node, status
-              in salt_output.items()
+              in list(salt_output.items())
               if status is False]
     assert result == [], (
         "Fluentd check failed - td-agent service is not running on the "
diff --git a/test_set/cvp-sanity/tests/test_ui_addresses.py b/test_set/cvp-sanity/tests/test_ui_addresses.py
index 7859cdc..837a358 100644
--- a/test_set/cvp-sanity/tests/test_ui_addresses.py
+++ b/test_set/cvp-sanity/tests/test_ui_addresses.py
@@ -33,7 +33,7 @@
         tgt=ctl_nodes_pillar,
         param='curl -k {}/ 2>&1 | grep stable'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Public Openstack url is not reachable on {} from ctl '
         'nodes'.format(url)
     )
@@ -55,7 +55,7 @@
         tgt=ctl_nodes_pillar,
         param='curl -k {}/app/kibana 2>&1 | grep loading'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Internal Kibana login page is not reachable on {} from ctl '
         'nodes'.format(url)
     )
@@ -73,7 +73,7 @@
         tgt=ctl_nodes_pillar,
         param='curl -k {}/app/kibana 2>&1 | grep loading'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Public Kibana login page is not reachable on {} from ctl '
         'nodes'.format(url)
     )
@@ -92,7 +92,7 @@
         tgt=ctl_nodes_pillar,
         param='curl {}/graph 2>&1 | grep Prometheus'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Internal Prometheus page is not reachable on {} from ctl '
         'nodes'.format(url)
     )
@@ -130,7 +130,7 @@
         'Issues with accessing public prometheus ui on {}:\n{}'.format(
             url, response.text)
     )
-    assert response.content.find('Prometheus Time Series Collection') > -1, (
+    assert response.content.decode().find('Prometheus Time Series Collection') > -1, (
         'Public Prometheus page is not reachable on {} from ctl '
         'nodes'.format(url)
     )
@@ -149,7 +149,7 @@
         tgt=ctl_nodes_pillar,
         param='curl -s {}/ | grep Alertmanager'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Internal AlertManager page is not reachable on {} from ctl '
         'nodes'.format(url)
     )
@@ -188,7 +188,7 @@
         'Issues with accessing public alert manager ui on {}:\n{}'.format(
             url, response.text)
     )
-    assert response.content.find('<title>Alertmanager</title>') > -1, (
+    assert response.content.decode().find('<title>Alertmanager</title>') > -1, (
         'Public AlertManager page is not reachable on {} '
         'from ctl nodes'.format(url)
     )
@@ -207,7 +207,7 @@
         tgt=ctl_nodes_pillar,
         param='curl {}/login 2>&1 | grep Grafana'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Internal Grafana page is not reachable on {} '
         'from ctl nodes'.format(url)
     )
@@ -225,7 +225,7 @@
         tgt=ctl_nodes_pillar,
         param='curl -k {}/login 2>&1 | grep Grafana'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Public Grafana page is not reachable on {} from ctl nodes'.format(url)
     )
 
@@ -243,7 +243,7 @@
         tgt=ctl_nodes_pillar,
         param='curl {}/ 2>&1 | grep Alerta'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Internal Alerta page is not reachable on {} from '
         'ctl nodes'.format(url)
     )
@@ -261,7 +261,7 @@
         tgt=ctl_nodes_pillar,
         param='curl -k {}/ 2>&1 | grep Alerta'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Public Alerta page is not reachable on {} from ctl nodes'.format(url))
 
 
@@ -278,7 +278,7 @@
         tgt=ctl_nodes_pillar,
         param='curl -k {}/ 2>&1 | grep Authentication'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Public Jenkins page is not reachable on {} from ctl nodes'.format(url)
     )
 
@@ -296,5 +296,5 @@
         tgt=ctl_nodes_pillar,
         param='curl -k {}/ 2>&1 | grep "Gerrit Code Review"'.format(url),
         expr_form='pillar')
-    assert len(result[result.keys()[0]]) != 0, (
+    assert len(result[list(result.keys())[0]]) != 0, (
         'Public Gerrit page is not reachable on {} from ctl nodes'.format(url))
diff --git a/test_set/cvp-sanity/utils/__init__.py b/test_set/cvp-sanity/utils/__init__.py
index c6bbed2..12b8e72 100644
--- a/test_set/cvp-sanity/utils/__init__.py
+++ b/test_set/cvp-sanity/utils/__init__.py
@@ -1,3 +1,5 @@
+from builtins import range
+from builtins import object
 import os
 import yaml
 import requests
@@ -12,7 +14,7 @@
     pass
 
 
-class salt_remote:
+class salt_remote(object):
     def __init__(self):
         self.config = get_configuration()
         self.skipped_nodes = self.config.get('skipped_nodes') or []
@@ -42,7 +44,7 @@
                             "was not established.\n"
                             "Please make sure that you "
                             "provided correct credentials.\n"
-                            "Error message: {}\033[0m\n".format(e.message or e))
+                            "Error message: {}\033[0m\n".format(e))
             traceback.print_exc(file=sys.stdout)
             sys.exit()
         self.expire = login_request.json()['return'][0]['expire']
@@ -78,7 +80,7 @@
                 continue
             response = request.json()['return'][0]
             result = {key: response[key] for key in response if key not in self.skipped_nodes}
-            if check_status and (False in result.values() or not result):
+            if check_status and (False in list(result.values()) or not result):
                 logging.warning("One or several nodes are not responding. Output {}".format(json.dumps(result, indent=4)))
                 continue
             break
@@ -95,7 +97,7 @@
         If all nodes returns nothing, then exception is thrown.
         """
         response = self.cmd(tgt=tgt, param=param, expr_form=expr_form)
-        for node in response.keys():
+        for node in list(response.keys()):
             if response[node] or response[node] == '':
                 return response[node]
         else:
@@ -111,7 +113,7 @@
         :param fail_if_empty
         """
         response = self.cmd(tgt=tgt, fun='pillar.get', param=param, expr_form=expr_form)
-        for node in response.keys():
+        for node in list(response.keys()):
             if response[node] or response[node] != '':
                 return response[node]
         else:
@@ -143,9 +145,9 @@
     nodes_names = set ()
     expr_form = ''
     all_nodes = set(local_salt_client.test_ping(tgt='*', expr_form=None))
-    if 'groups' in config.keys() and 'PB_GROUPS' in os.environ.keys() and \
+    if 'groups' in list(config.keys()) and 'PB_GROUPS' in list(os.environ.keys()) and \
        os.environ['PB_GROUPS'].lower() != 'false':
-        nodes_names.update(config['groups'].keys())
+        nodes_names.update(list(config['groups'].keys()))
         expr_form = 'compound'
     else:
         for node in all_nodes:
@@ -178,14 +180,14 @@
 
         node_groups[node_name] = [x for x in nodes
                                   if x not in config['skipped_nodes']
-                                  if x not in gluster_nodes.keys()
-                                  if x not in kvm_nodes.keys()]
+                                  if x not in list(gluster_nodes.keys())
+                                  if x not in list(kvm_nodes.keys())]
         all_nodes = set(all_nodes - set(node_groups[node_name]))
         if node_groups[node_name] == []:
             del node_groups[node_name]
             if kvm_nodes:
-                node_groups['kvm'] = kvm_nodes.keys()
-            node_groups['kvm_gluster'] = gluster_nodes.keys()
+                node_groups['kvm'] = list(kvm_nodes.keys())
+            node_groups['kvm_gluster'] = list(gluster_nodes.keys())
     all_nodes = set(all_nodes - set(kvm_nodes.keys()))
     all_nodes = set(all_nodes - set(gluster_nodes.keys()))
     if all_nodes:
@@ -201,9 +203,8 @@
         os.path.dirname(os.path.abspath(__file__)), "../global_config.yaml")
     with open(global_config_file, 'r') as file:
         global_config = yaml.load(file, Loader=yaml.SafeLoader)
-
-    for param in global_config.keys():
-        if param in os.environ.keys():
+    for param in list(global_config.keys()):
+        if param in list(os.environ.keys()):
             if ',' in os.environ[param]:
                 global_config[param] = []
                 for item in os.environ[param].split(','):