replace basetring/xrange

basetring --> six.string_types
xrange --> six.moves.xrange

Partial Implement: blueprint tempest-py33-support

Change-Id: Ia7ae4415d6d4ca9ee04e6735b2c6a6131c05a04f
diff --git a/tempest/api/compute/servers/test_list_servers_negative.py b/tempest/api/compute/servers/test_list_servers_negative.py
index a0aefd8..72af51b 100644
--- a/tempest/api/compute/servers/test_list_servers_negative.py
+++ b/tempest/api/compute/servers/test_list_servers_negative.py
@@ -15,6 +15,8 @@
 
 import datetime
 
+from six import moves
+
 from tempest.api.compute import base
 from tempest import exceptions
 from tempest.test import attr
@@ -36,7 +38,7 @@
         cls.existing_fixtures = []
         cls.deleted_fixtures = []
         cls.start_time = datetime.datetime.utcnow()
-        for x in xrange(2):
+        for x in moves.xrange(2):
             resp, srv = cls.create_test_server()
             cls.existing_fixtures.append(srv)
 
diff --git a/tempest/api/compute/v3/servers/test_list_servers_negative.py b/tempest/api/compute/v3/servers/test_list_servers_negative.py
index 9a46193..92f44fe 100644
--- a/tempest/api/compute/v3/servers/test_list_servers_negative.py
+++ b/tempest/api/compute/v3/servers/test_list_servers_negative.py
@@ -15,6 +15,8 @@
 
 import datetime
 
+from six import moves
+
 from tempest.api.compute import base
 from tempest import exceptions
 from tempest.test import attr
@@ -35,7 +37,7 @@
         cls.existing_fixtures = []
         cls.deleted_fixtures = []
         cls.start_time = datetime.datetime.utcnow()
-        for x in xrange(2):
+        for x in moves.xrange(2):
             resp, srv = cls.create_test_server()
             cls.existing_fixtures.append(srv)
 
diff --git a/tempest/api/identity/admin/test_roles.py b/tempest/api/identity/admin/test_roles.py
index aa64969..5e78cce 100644
--- a/tempest/api/identity/admin/test_roles.py
+++ b/tempest/api/identity/admin/test_roles.py
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from six import moves
+
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
 from tempest.test import attr
@@ -24,7 +26,7 @@
     @classmethod
     def setUpClass(cls):
         super(RolesTestJSON, cls).setUpClass()
-        for _ in xrange(5):
+        for _ in moves.xrange(5):
             role_name = data_utils.rand_name(name='role-')
             resp, role = cls.client.create_role(role_name)
             cls.data.roles.append(role)
diff --git a/tempest/api/identity/admin/test_services.py b/tempest/api/identity/admin/test_services.py
index cbf6b58..459c44c 100644
--- a/tempest/api/identity/admin/test_services.py
+++ b/tempest/api/identity/admin/test_services.py
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from six import moves
 
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
@@ -69,7 +70,7 @@
     def test_list_services(self):
         # Create, List, Verify and Delete Services
         services = []
-        for _ in xrange(3):
+        for _ in moves.xrange(3):
             name = data_utils.rand_name('service-')
             type = data_utils.rand_name('type--')
             description = data_utils.rand_name('description-')
diff --git a/tempest/api/identity/admin/test_tenants.py b/tempest/api/identity/admin/test_tenants.py
index c7cacb4..257a6d7 100644
--- a/tempest/api/identity/admin/test_tenants.py
+++ b/tempest/api/identity/admin/test_tenants.py
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from six import moves
+
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
 from tempest.test import attr
@@ -25,7 +27,7 @@
     def test_tenant_list_delete(self):
         # Create several tenants and delete them
         tenants = []
-        for _ in xrange(3):
+        for _ in moves.xrange(3):
             tenant_name = data_utils.rand_name(name='tenant-new')
             resp, tenant = self.client.create_tenant(tenant_name)
             self.assertEqual(200, resp.status)
diff --git a/tempest/api/identity/admin/v3/test_projects.py b/tempest/api/identity/admin/v3/test_projects.py
index be03a03..31a0ddd 100644
--- a/tempest/api/identity/admin/v3/test_projects.py
+++ b/tempest/api/identity/admin/v3/test_projects.py
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from six import moves
+
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
 from tempest import exceptions
@@ -31,7 +33,7 @@
     @test.attr(type='gate')
     def test_project_list_delete(self):
         # Create several projects and delete them
-        for _ in xrange(3):
+        for _ in moves.xrange(3):
             resp, project = self.client.create_project(
                 data_utils.rand_name('project-new'))
             self.addCleanup(self._delete_project, project['id'])
diff --git a/tempest/api/object_storage/test_account_services.py b/tempest/api/object_storage/test_account_services.py
index 5456768..7542ea1 100644
--- a/tempest/api/object_storage/test_account_services.py
+++ b/tempest/api/object_storage/test_account_services.py
@@ -15,6 +15,8 @@
 
 import random
 
+from six import moves
+
 from tempest.api.object_storage import base
 from tempest.common import custom_matchers
 from tempest.common.utils import data_utils
@@ -26,7 +28,7 @@
     def setUpClass(cls):
         super(AccountTest, cls).setUpClass()
         cls.containers = []
-        for i in xrange(ord('a'), ord('f') + 1):
+        for i in moves.xrange(ord('a'), ord('f') + 1):
             name = data_utils.rand_name(name='%s-' % chr(i))
             cls.container_client.create_container(name)
             cls.containers.append(name)
diff --git a/tempest/api/object_storage/test_object_services.py b/tempest/api/object_storage/test_object_services.py
index 33f3299..91df292 100644
--- a/tempest/api/object_storage/test_object_services.py
+++ b/tempest/api/object_storage/test_object_services.py
@@ -14,6 +14,7 @@
 #    under the License.
 
 import hashlib
+from six import moves
 
 from tempest.api.object_storage import base
 from tempest.common import custom_matchers
@@ -242,9 +243,9 @@
         object_name = data_utils.rand_name(name='LObject')
         data = data_utils.arbitrary_string()
         segments = 10
-        data_segments = [data + str(i) for i in xrange(segments)]
+        data_segments = [data + str(i) for i in moves.xrange(segments)]
         # uploading segments
-        for i in xrange(segments):
+        for i in moves.xrange(segments):
             resp, _ = self.object_client.create_object_segments(
                 self.container_name, object_name, i, data_segments[i])
             self.assertEqual(resp['status'], '201')
diff --git a/tempest/common/glance_http.py b/tempest/common/glance_http.py
index 4503f13..b4ba933 100644
--- a/tempest/common/glance_http.py
+++ b/tempest/common/glance_http.py
@@ -21,6 +21,7 @@
 import json
 import posixpath
 import re
+from six import moves
 import socket
 import StringIO
 import struct
@@ -264,7 +265,7 @@
 
         # Also try Subject Alternative Names for a match
         san_list = None
-        for i in xrange(x509.get_extension_count()):
+        for i in moves.xrange(x509.get_extension_count()):
             ext = x509.get_extension(i)
             if ext.get_short_name() == 'subjectAltName':
                 san_list = str(ext)
diff --git a/tempest/common/ssh.py b/tempest/common/ssh.py
index b6fa0a0..531887c 100644
--- a/tempest/common/ssh.py
+++ b/tempest/common/ssh.py
@@ -16,6 +16,7 @@
 
 import cStringIO
 import select
+import six
 import socket
 import time
 import warnings
@@ -39,7 +40,7 @@
         self.host = host
         self.username = username
         self.password = password
-        if isinstance(pkey, basestring):
+        if isinstance(pkey, six.string_types):
             pkey = paramiko.RSAKey.from_private_key(
                 cStringIO.StringIO(str(pkey)))
         self.pkey = pkey
diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py
index 94fc23c..b833ee7 100644
--- a/tempest/common/utils/linux/remote_client.py
+++ b/tempest/common/utils/linux/remote_client.py
@@ -11,6 +11,7 @@
 #    under the License.
 
 import re
+import six
 import time
 
 from tempest.common import ssh
@@ -28,7 +29,7 @@
         network = CONF.compute.network_for_ssh
         ip_version = CONF.compute.ip_version_for_ssh
         ssh_channel_timeout = CONF.compute.ssh_channel_timeout
-        if isinstance(server, basestring):
+        if isinstance(server, six.string_types):
             ip_address = server
         else:
             addresses = server['addresses'][network]
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 1b1ddab..ca8ac3b 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -16,6 +16,7 @@
 
 import logging
 import os
+import six
 import subprocess
 
 import netaddr
@@ -371,7 +372,7 @@
         return keypair
 
     def get_remote_client(self, server_or_ip, username=None, private_key=None):
-        if isinstance(server_or_ip, basestring):
+        if isinstance(server_or_ip, six.string_types):
             ip = server_or_ip
         else:
             network_name_for_ssh = CONF.compute.network_for_ssh
diff --git a/tempest/stress/driver.py b/tempest/stress/driver.py
index 3715636..9660081 100644
--- a/tempest/stress/driver.py
+++ b/tempest/stress/driver.py
@@ -17,6 +17,8 @@
 import signal
 import time
 
+from six import moves
+
 from tempest import clients
 from tempest.common import ssh
 from tempest.common.utils import data_utils
@@ -128,7 +130,7 @@
             manager = admin_manager
         else:
             manager = clients.Manager()
-        for p_number in xrange(test.get('threads', default_thread_num)):
+        for p_number in moves.xrange(test.get('threads', default_thread_num)):
             if test.get('use_isolated_tenants', False):
                 username = data_utils.rand_name("stress_user")
                 tenant_name = data_utils.rand_name("stress_tenant")
diff --git a/tempest/thirdparty/boto/test.py b/tempest/thirdparty/boto/test.py
index 6a9836b..10d421e 100644
--- a/tempest/thirdparty/boto/test.py
+++ b/tempest/thirdparty/boto/test.py
@@ -17,6 +17,7 @@
 import logging as orig_logging
 import os
 import re
+import six
 import urlparse
 
 import boto
@@ -134,7 +135,7 @@
         The not leaf elements does wildcard match
     """
     # in error_code just literal and '.' characters expected
-    if not isinstance(error_data, basestring):
+    if not isinstance(error_data, six.string_types):
         (error_code, status_code) = map(str, error_data)
     else:
         status_code = None
@@ -144,7 +145,7 @@
     num_parts = len(parts)
     max_index = num_parts - 1
     add_cls = error_cls
-    for i_part in xrange(num_parts):
+    for i_part in six.moves.xrange(num_parts):
         part = parts[i_part]
         leaf = i_part == max_index
         if not leaf: