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 <zhangyangyang@unionpay.com> Change-Id: I1f18c87b4dbb4855b3afce88f0abd6e84aa0eb53
This commit is contained in:
parent
cb6b0fbde2
commit
b8d3a1d525
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue