From b8d3a1d525a552cbe417ce8a95132fc2605dc9a8 Mon Sep 17 00:00:00 2001 From: zhangyangyang Date: Thu, 30 Aug 2018 15:49:09 +0800 Subject: [PATCH] Python 3 compatibility: fix xrange/range issues xrange is not defined in python3. Rename xrange() to range(). Story: 2003433 Task: 24920 Signed-off-by: zhangyangyang Change-Id: I1f18c87b4dbb4855b3afce88f0abd6e84aa0eb53 --- .../controllerconfig/configassistant.py | 10 +++++----- .../controllerconfig/controllerconfig/openstack.py | 4 ++-- .../controllerconfig/controllerconfig/utils.py | 2 +- .../cgtsclient/common/wrapping_formatters.py | 2 +- sysinv/sysinv/sysinv/sysinv/common/utils.py | 4 ++-- .../sysinv/sysinv/sysinv/tests/api/test_invservers.py | 6 +++--- .../sysinv/sysinv/sysinv/tests/api/test_sensorgroup.py | 10 +++++----- sysinv/sysinv/sysinv/sysinv/tests/db/test_sysinv.py | 2 +- .../sysinv/sysinv/tests/test_sysinv_deploy_helper.py | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/controllerconfig/controllerconfig/controllerconfig/configassistant.py b/controllerconfig/controllerconfig/controllerconfig/configassistant.py index 6a82a537e4..55486527b1 100644 --- a/controllerconfig/controllerconfig/controllerconfig/configassistant.py +++ b/controllerconfig/controllerconfig/controllerconfig/configassistant.py @@ -3529,7 +3529,7 @@ class ConfigAssistant(): cmd = 'test $(sm-dump | grep -E %s | wc -l) -eq %d' % (egrep, count) interval = 10 - for _ in xrange(0, constants.SERVICE_ENABLE_TIMEOUT, interval): + for _ in range(0, constants.SERVICE_ENABLE_TIMEOUT, interval): try: subprocess.check_call(cmd, shell=True, stderr=subprocess.STDOUT) @@ -3624,7 +3624,7 @@ class ConfigAssistant(): return True def _wait_system_config(self, client): - for _ in xrange(constants.SYSTEM_CONFIG_TIMEOUT): + for _ in range(constants.SYSTEM_CONFIG_TIMEOUT): try: systems = client.sysinv.isystem.list() if systems: @@ -3639,7 +3639,7 @@ class ConfigAssistant(): def _wait_ethernet_port_config(self, client, host): count = 0 - for _ in xrange(constants.SYSTEM_CONFIG_TIMEOUT / 10): + for _ in range(constants.SYSTEM_CONFIG_TIMEOUT / 10): try: ports = client.sysinv.ethernet_port.list(host.uuid) if ports and count == len(ports): @@ -3654,7 +3654,7 @@ class ConfigAssistant(): def _wait_disk_config(self, client, host): count = 0 - for _ in xrange(constants.SYSTEM_CONFIG_TIMEOUT / 10): + for _ in range(constants.SYSTEM_CONFIG_TIMEOUT / 10): try: disks = client.sysinv.idisk.list(host.uuid) if disks and count == len(disks): @@ -3672,7 +3672,7 @@ class ConfigAssistant(): def _wait_pv_config(self, client, host): count = 0 - for _ in xrange(constants.SYSTEM_CONFIG_TIMEOUT / 10): + for _ in range(constants.SYSTEM_CONFIG_TIMEOUT / 10): try: pvs = client.sysinv.ipv.list(host.uuid) if pvs and count == len(pvs): diff --git a/controllerconfig/controllerconfig/controllerconfig/openstack.py b/controllerconfig/controllerconfig/controllerconfig/openstack.py index 52bf62693c..0a7ec944d1 100755 --- a/controllerconfig/controllerconfig/controllerconfig/openstack.py +++ b/controllerconfig/controllerconfig/controllerconfig/openstack.py @@ -75,7 +75,7 @@ class OpenStack(object): self._disconnect() # Try to obtain an admin token from keystone - for _ in xrange(KEYSTONE_AUTH_SERVER_RETRY_CNT): + for _ in range(KEYSTONE_AUTH_SERVER_RETRY_CNT): self.admin_token = get_token(self.conf['auth_url'], self.conf['admin_tenant'], self.conf['admin_user'], @@ -245,7 +245,7 @@ class OpenStack(object): if exempt_hostnames is None: exempt_hostnames = [] - for _ in xrange(timeout / interval_step): + for _ in range(timeout / interval_step): hosts = sysinv.get_hosts(self.admin_token, self.conf['region_name']) if not hosts: diff --git a/controllerconfig/controllerconfig/controllerconfig/utils.py b/controllerconfig/controllerconfig/controllerconfig/utils.py index 11b0c01212..50015d84de 100644 --- a/controllerconfig/controllerconfig/controllerconfig/utils.py +++ b/controllerconfig/controllerconfig/controllerconfig/utils.py @@ -219,7 +219,7 @@ def wait_sm_service(service, timeout=180): :param timeout: timeout in seconds :return True if the service is enabled, False otherwise """ - for _ in xrange(timeout): + for _ in range(timeout): if check_sm_service(service, 'enabled-active'): return True time.sleep(1) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py b/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py index 8cc95343e7..05e75d90d5 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py @@ -784,7 +784,7 @@ def _simpleTestHarness(no_wrap): formatterSpec[f] = buildFormatter(f, formatterSpecX[f]) logs = [] - for i in xrange(0, 30): + for i in range(0, 30): log = {} for f in fields: if f == 'number': diff --git a/sysinv/sysinv/sysinv/sysinv/common/utils.py b/sysinv/sysinv/sysinv/sysinv/common/utils.py index dc6abba38f..e2066e875b 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/utils.py +++ b/sysinv/sysinv/sysinv/sysinv/common/utils.py @@ -286,13 +286,13 @@ def trycmd(*args, **kwargs): def generate_uid(topic, size=8): characters = '01234567890abcdefghijklmnopqrstuvwxyz' - choices = [random.choice(characters) for _x in xrange(size)] + choices = [random.choice(characters) for _x in range(size)] return '%s-%s' % (topic, ''.join(choices)) def random_alnum(size=32): characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' - return ''.join(random.choice(characters) for _ in xrange(size)) + return ''.join(random.choice(characters) for _ in range(size)) class LazyPluggable(object): diff --git a/sysinv/sysinv/sysinv/sysinv/tests/api/test_invservers.py b/sysinv/sysinv/sysinv/sysinv/tests/api/test_invservers.py index 529a16e746..2d8e84b328 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/api/test_invservers.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/api/test_invservers.py @@ -146,7 +146,7 @@ class TestListServers(base.FunctionalTest): def test_many(self): ihosts = [] - for id in xrange(1000): # there is a limit of 1000 returned by json + for id in range(1000): # there is a limit of 1000 returned by json ndict = dbutils.get_test_ihost(id=id, hostname=id, mgmt_mac=id, forisystemid=self.system.id, mgmt_ip="%s.%s.%s.%s" % (id, id, id, id), @@ -171,7 +171,7 @@ class TestListServers(base.FunctionalTest): def test_collection_links(self): ihosts = [] - for id in xrange(100): + for id in range(100): ndict = dbutils.get_test_ihost(id=id, hostname=id, mgmt_mac=id, forisystemid=self.system.id, mgmt_ip="%s.%s.%s.%s" % (id, id, id, id), @@ -195,7 +195,7 @@ class TestListServers(base.FunctionalTest): ndict = dbutils.get_test_ihost(forisystemid=self.system.id) self.dbapi.ihost_create(ndict) - for id in xrange(2): + for id in range(2): pdict = dbutils.get_test_port(id=id, host_id=ndict['id'], pciaddr=id, diff --git a/sysinv/sysinv/sysinv/sysinv/tests/api/test_sensorgroup.py b/sysinv/sysinv/sysinv/sysinv/tests/api/test_sensorgroup.py index df1fb90e8c..02ced481ef 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/api/test_sensorgroup.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/api/test_sensorgroup.py @@ -116,14 +116,14 @@ class sensorgroupTestCase(base.FunctionalTest): 'sensortype': 'testsensortype', 'sensorname': 'defaultSensorName', } - for i in xrange(numOfSensors): + for i in range(numOfSensors): sensor.append(self.post_json('/isensors', sensorVals, headers={'User-Agent': 'hwmon'})) self.patch_dict_json('/isensors/%s/' % sensor[i].json['uuid'], headers={'User-Agent': 'hwmon'}, sensorgroup_uuid=sensorgroup.json['uuid']) # Assert sensors created properly in DB - for i in xrange(numOfSensors): + for i in range(numOfSensors): self.assertEqual('defaultSensorName', # Expected self.get_json('/isensors/%s/' % sensor[i].json['uuid'])['sensorname']) # Result self.assertEqual(sensorgroup.json['uuid'], # Expected @@ -151,7 +151,7 @@ class sensorgroupTestCase(base.FunctionalTest): self.get_json('/isensorgroups/%s/' % sensorgroup.json['uuid'])['suppress']) # Result # Assert values got propagated to sensor - for i in xrange(numOfSensors): + for i in range(numOfSensors): self.assertEqual(42, # Expected self.get_json('/isensors/%s/' % sensor[i].json['uuid'])['audit_interval']) # Result self.assertEqual('action minor', # Expected @@ -165,12 +165,12 @@ class sensorgroupTestCase(base.FunctionalTest): # Delete sensorgroup and sensors self.delete('/isensorgroups/%s/' % sensorgroup.json['uuid']) - for i in xrange(numOfSensors): + for i in range(numOfSensors): self.delete('/isensors/%s/' % sensor[i].json['uuid']) # Assert deletion of sensorgroup and sensors self.assertDeleted('/isensorgroups/%s/' % sensorgroup.json['uuid']) - for i in xrange(numOfSensors): + for i in range(numOfSensors): self.assertDeleted('/isensors/%s/' % sensor[i].json['uuid']) def test_sensorgroup_post(self): diff --git a/sysinv/sysinv/sysinv/sysinv/tests/db/test_sysinv.py b/sysinv/sysinv/sysinv/sysinv/tests/db/test_sysinv.py index 892d21f292..73e5ad8f10 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/db/test_sysinv.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/db/test_sysinv.py @@ -34,7 +34,7 @@ class DbNodeTestCase(base.DbTestCase): def _create_many_test_ihosts(self): uuids = [] - for i in xrange(1, 6): + for i in range(1, 6): n = self._create_test_ihost(id=i, uuid=uuidutils.generate_uuid()) uuids.append(n['uuid']) uuids.sort() diff --git a/sysinv/sysinv/sysinv/sysinv/tests/test_sysinv_deploy_helper.py b/sysinv/sysinv/sysinv/sysinv/tests/test_sysinv_deploy_helper.py index 8b53b00ad2..e9af1a0008 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/test_sysinv_deploy_helper.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/test_sysinv_deploy_helper.py @@ -76,7 +76,7 @@ class WorkerTestCase(base.DbTestCase): # super(WorkerTestCase, self).tearDown() def wait_queue_empty(self, timeout): - for _ in xrange(int(timeout / 0.1)): + for _ in range(int(timeout / 0.1)): if bmdh.QUEUE.empty(): break time.sleep(0.1)