From 130b0df5086dbe4a7326961acf86fa9e882eb8de Mon Sep 17 00:00:00 2001 From: Valeriy Ponomaryov Date: Mon, 3 Aug 2015 14:47:17 +0300 Subject: [PATCH] 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 --- manila/tests/scheduler/test_host_manager.py | 2 +- manila/tests/share/drivers/hds/test_sop.py | 20 ++++++++++---------- manila/tests/share/drivers/test_generic.py | 7 ++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/manila/tests/scheduler/test_host_manager.py b/manila/tests/scheduler/test_host_manager.py index 4526a06e23..cfd15599c7 100644 --- a/manila/tests/scheduler/test_host_manager.py +++ b/manila/tests/scheduler/test_host_manager.py @@ -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) diff --git a/manila/tests/share/drivers/hds/test_sop.py b/manila/tests/share/drivers/hds/test_sop.py index dd93ba04c8..a9d7e4b4aa 100644 --- a/manila/tests/share/drivers/hds/test_sop.py +++ b/manila/tests/share/drivers/hds/test_sop.py @@ -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): diff --git a/manila/tests/share/drivers/test_generic.py b/manila/tests/share/drivers/test_generic.py index 11fd57198e..1995d0b9e8 100644 --- a/manila/tests/share/drivers/test_generic.py +++ b/manila/tests/share/drivers/test_generic.py @@ -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):