Replace py2 xrange with six.moves.range

Func 'xrange' is absent in py3. So, use six.moves.range instead for py34
compatibility.

Change-Id: I76217598ae08849c2a93746392fc552dc0a51de1
Partially-Implements: bp py3-compatibility
This commit is contained in:
Valeriy Ponomaryov 2015-08-03 14:47:17 +03:00
parent 83107dd849
commit 130b0df508
3 changed files with 15 additions and 14 deletions

View File

@ -156,7 +156,7 @@ class HostManagerTestCase(test.TestCase):
self.assertEqual(4, len(host_state_map))
# Check that service is up
for i in xrange(4):
for i in moves.range(4):
share_node = fakes.SHARE_SERVICES_WITH_POOLS[i]
host = share_node['host']
self.assertEqual(share_node, host_state_map[host].service)

View File

@ -22,6 +22,7 @@ import mock
from oslo_config import cfg
from oslo_serialization import jsonutils as json
from oslo_utils import units
from six import moves
from manila import context
from manila import exception
@ -217,10 +218,9 @@ class SopShareDriverTestCase(test.TestCase):
},
}
self.assertEqual(expectedresult, fsadd)
httpcalls = [mock.call('fakeuri',
'GET',
body='',
headers=fake_authorization) for x in xrange(2)]
httpcalls = [
mock.call('fakeuri', 'GET', body='', headers=fake_authorization)
for x in moves.range(2)]
self.assertEqual(httpcalls, httpclient.request.call_args_list)
def test_wait_for_job_completion_notimeout(self):
@ -244,7 +244,7 @@ class SopShareDriverTestCase(test.TestCase):
'esource-action":"ADD","percent-complete":75,"resource'
'-id":"fakeuuid","target-node-name":"Node005","target-'
'node-id":"fakeuuid","spawned-jobs":false,"spawned-job'
's-list-uri":""}}') for x in xrange(200)
's-list-uri":""}}') for x in moves.range(200)
]
httpreturn.append(({'status': '200',
@ -297,9 +297,9 @@ class SopShareDriverTestCase(test.TestCase):
'GET',
body='',
headers=fake_authorization)
for x in xrange(201)]
for x in moves.range(201)]
self.assertEqual(httpcalls, httpclient.request.call_args_list)
timecalls = [mock.call(1) for x in xrange(200)]
timecalls = [mock.call(1) for x in moves.range(200)]
self.assertEqual(timecalls, time.sleep.call_args_list)
def test_wait_for_job_completion_timeout(self):
@ -324,7 +324,7 @@ class SopShareDriverTestCase(test.TestCase):
':75,"resource-id":"fakeuuid"'
',"target-node-name":"Node005","target-node-id":"fakeuuid'
'","spawned-jobs":false,"spawned-jobs-list-uri":""}}')
for x in xrange(301)]
for x in moves.range(301)]
httpret.append(({'status': '200',
'content-location':
@ -356,9 +356,9 @@ class SopShareDriverTestCase(test.TestCase):
'GET',
body='',
headers=fake_authorization)
for x in xrange(301)]
for x in moves.range(301)]
self.assertEqual(httpcalls, httpclient.request.call_args_list)
timecalls = [mock.call(1) for x in xrange(301)]
timecalls = [mock.call(1) for x in moves.range(301)]
self.assertEqual(timecalls, time.sleep.call_args_list)
def test_add_share_sopapi(self):

View File

@ -23,6 +23,7 @@ import ddt
import mock
from oslo_concurrency import processutils
from oslo_config import cfg
from six import moves
from manila.common import constants as const
from manila import compute
@ -302,17 +303,17 @@ class GenericShareDriverTestCase(test.TestCase):
self.assertEqual(1, time.sleep.call_count)
self.assertEqual(self._driver._get_mount_path.mock_calls,
[mock.call(self.share) for i in xrange(2)])
[mock.call(self.share) for i in moves.range(2)])
self.assertEqual(self._driver._is_device_mounted.mock_calls,
[mock.call(mount_path,
self.server) for i in xrange(2)])
self.server) for i in moves.range(2)])
self._driver._sync_mount_temp_and_perm_files.assert_called_once_with(
self.server)
self.assertEqual(
self._driver._ssh_exec.mock_calls,
[mock.call(self.server, ['sudo umount', mount_path,
'&& sudo rmdir', mount_path])
for i in xrange(2)]
for i in moves.range(2)]
)
def test_unmount_device_not_present(self):