Keep python 3.X compatibility for xrange

Use six.move.xrange instead of  xrange. xrange is replaced
by range in python3.

closes-bug: #1291191

Change-Id: I15454421d3c120ba828efe1947437bba87d7357f
This commit is contained in:
Fengqian Gao 2014-03-19 16:08:29 +08:00
parent b28c7703a3
commit 56d084cdef
4 changed files with 11 additions and 6 deletions

View File

@ -15,6 +15,8 @@
import os
import six
from sahara import context
from sahara.openstack.common import timeutils
from sahara.plugins.general import utils
@ -87,7 +89,7 @@ def parse_dfs_report(cmd_output):
res = []
datanode_info = {}
for i in xrange(0, len(array)):
for i in six.moves.xrange(0, len(array)):
if array[i]:
idx = str.find(array[i], ':')
name = array[i][0:idx]

View File

@ -15,6 +15,7 @@
from novaclient import exceptions as nova_exceptions
from oslo.config import cfg
import six
from sahara import conductor as c
from sahara import context
@ -154,7 +155,7 @@ class DirectEngine(e.Engine):
for node_group in cluster.node_groups:
count = node_group.count
conductor.node_group_update(ctx, node_group, {'count': 0})
for idx in xrange(1, count + 1):
for idx in six.moves.xrange(1, count + 1):
self._run_instance(cluster, node_group, idx, aa_groups)
def _scale_cluster_instances(self, cluster, node_group_id_map):
@ -189,7 +190,7 @@ class DirectEngine(e.Engine):
LOG.info(g.format_cluster_status(cluster))
for node_group in node_groups_to_enlarge:
count = node_group_id_map[node_group.id]
for idx in xrange(node_group.count + 1, count + 1):
for idx in six.moves.xrange(node_group.count + 1, count + 1):
instance_id = self._run_instance(cluster, node_group, idx,
aa_groups)
instances_to_add.append(instance_id)

View File

@ -16,6 +16,7 @@
import mock
from novaclient import exceptions as nova_exceptions
import six
from sahara import conductor as cond
from sahara import context
@ -149,7 +150,7 @@ class NodePlacementTest(AbstractInstanceTest):
create.
"""
different_hosts = []
for instance_id in xrange(1, idx):
for instance_id in six.moves.xrange(1, idx):
different_hosts.append(str(instance_id))
scheduler_hints = ({'different_host': different_hosts}
if different_hosts else None)
@ -163,7 +164,7 @@ class NodePlacementTest(AbstractInstanceTest):
# find instance names in instance create calls
instance_names = []
for idx in xrange(1, 4):
for idx in six.moves.xrange(1, 4):
instance_name = _find_created_at(idx)
if instance_name in instance_names:
self.fail("Create instance was called twice with the same "

View File

@ -15,6 +15,7 @@
import xml.dom.minidom as xml
import six
import unittest2
from sahara.utils import patches
@ -32,7 +33,7 @@ class MinidomPatchesTest(unittest2.TestCase):
doc.insertBefore(pi, doc.firstChild)
configuration = doc.createElement("root")
doc.appendChild(configuration)
for idx in xrange(0, 5):
for idx in six.moves.xrange(0, 5):
elem = doc.createElement("element")
configuration.appendChild(elem)
name = doc.createElement("name")