Replaces longs with ints

The long type no longer exists in Python 3.

Partially implements blueprint: nova-python3-mitaka

Change-Id: I1c6eef299bd0abe77f715e7788dc22c92edde14c
This commit is contained in:
Claudiu Belu 2015-10-21 23:17:52 +03:00
parent 3f8c69b2ef
commit 28585bb368
10 changed files with 26 additions and 22 deletions

View File

@ -61,7 +61,8 @@ class FlavorExtraSpecsController(object):
# NOTE(dims): The following check was added for backwards
# compatibility.
if (isinstance(value, (int, long, float))):
if (isinstance(value, float) or
type(value) in six.integer_types):
value = six.text_type(value)
utils.check_string_length(value, 'extra_specs value',
max_length=255)

View File

@ -199,7 +199,9 @@ class BaseRequestHandler(object):
if isinstance(value, six.string_types):
parts.append(utils.xhtml_escape(value))
elif isinstance(value, int) or isinstance(value, long):
elif type(value) in six.integer_types:
parts.append(str(value))
elif isinstance(value, bool):
parts.append(str(value))
elif isinstance(value, datetime.datetime):
parts.append(value.strftime("%Y-%m-%dT%H:%M:%S.000Z"))

View File

@ -35,7 +35,7 @@ class APIRequestTestCase(test.NoDBTestCase):
self.resp = {
'string': 'foo',
'int': 1,
'long': long(1),
'long': int(1),
'bool': False,
'dict': {
'string': 'foo',

View File

@ -109,7 +109,7 @@ class TestString(TestField):
self.field = fields.StringField()
self.coerce_good_values = [('foo', 'foo'), (1, '1'), (True, 'True')]
if six.PY2:
self.coerce_good_values.append((long(1), '1'))
self.coerce_good_values.append((int(1), '1'))
self.coerce_bad_values = [None]
self.to_primitive_values = self.coerce_good_values[0:1]
self.from_primitive_values = self.coerce_good_values[0:1]
@ -150,7 +150,7 @@ class TestEnum(TestField):
valid_values=['foo', 'bar', 1, 1, True])
self.coerce_good_values = [('foo', 'foo'), (1, '1'), (True, 'True')]
if six.PY2:
self.coerce_good_values.append((long(1), '1'))
self.coerce_good_values.append((int(1), '1'))
self.coerce_bad_values = ['boo', 2, False]
self.to_primitive_values = self.coerce_good_values[0:1]
self.from_primitive_values = self.coerce_good_values[0:1]

View File

@ -572,8 +572,8 @@ class Domain(object):
def info(self):
return [self._state,
long(self._def['memory']),
long(self._def['memory']),
int(self._def['memory']),
int(self._def['memory']),
self._def['vcpu'],
123456789]

View File

@ -15,6 +15,7 @@
from nova import test
from lxml import etree
import six
from nova.compute import arch
import nova.tests.unit.virt.libvirt.fakelibvirt as libvirt
@ -140,7 +141,7 @@ class FakeLibvirtTests(test.NoDBTestCase):
blockstats = dom.blockStats('vda')
self.assertEqual(len(blockstats), 5)
for x in blockstats:
self.assertIn(type(x), [int, long])
self.assertIn(type(x), six.integer_types)
def test_attach_detach(self):
conn = self.get_openAuth_curry_func()('qemu:///system')
@ -163,7 +164,7 @@ class FakeLibvirtTests(test.NoDBTestCase):
self.assertEqual(info[1], 128000)
self.assertTrue(info[2] <= 128000)
self.assertEqual(info[3], 1)
self.assertIn(type(info[4]), [int, long])
self.assertIn(type(info[4]), six.integer_types)
def test_createXML_runs_domain(self):
conn = self.get_openAuth_curry_func()('qemu:///system')

View File

@ -135,13 +135,13 @@ class GuestTestCase(test.NoDBTestCase):
self.domain.resume.assert_called_once_with()
def test_get_vcpus_info(self):
self.domain.vcpus.return_value = ([(0, 1, long(10290000000), 2)],
self.domain.vcpus.return_value = ([(0, 1, int(10290000000), 2)],
[(True, True)])
vcpus = list(self.guest.get_vcpus_info())
self.assertEqual(0, vcpus[0].id)
self.assertEqual(2, vcpus[0].cpu)
self.assertEqual(1, vcpus[0].state)
self.assertEqual(long(10290000000), vcpus[0].time)
self.assertEqual(int(10290000000), vcpus[0].time)
def test_delete_configuration(self):
self.guest.delete_configuration()

View File

@ -399,7 +399,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
vm = self._get_vm_record()
# Check that m1.large above turned into the right thing.
mem_kib = long(self.type_data['memory_mb']) << 10
mem_kib = int(self.type_data['memory_mb']) << 10
vcpus = self.type_data['vcpus']
self.assertEqual(vm_info.max_mem_kb, mem_kib)
self.assertEqual(vm_info.mem_kb, mem_kib)
@ -439,7 +439,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
"""Check if the get_info returned values correspond to the instance
object in the db.
"""
mem_kib = long(self.type_data['memory_mb']) << 10
mem_kib = int(self.type_data['memory_mb']) << 10
self.assertEqual(info.state, pwr_state)
self.assertEqual(info.max_mem_kb, mem_kib)
self.assertEqual(info.mem_kb, mem_kib)

View File

@ -608,7 +608,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
def check_vm_record(self, conn, instance_type_id, check_injection):
flavor = db.flavor_get(conn, instance_type_id)
mem_kib = long(flavor['memory_mb']) << 10
mem_kib = int(flavor['memory_mb']) << 10
mem_bytes = str(mem_kib << 10)
vcpus = flavor['vcpus']
vcpu_weight = flavor['vcpu_weight']

View File

@ -233,7 +233,7 @@ def create_vm(session, instance, name_label, kernel, ramdisk,
3. Using hardware virtualization
"""
flavor = instance.get_flavor()
mem = str(long(flavor.memory_mb) * units.Mi)
mem = str(int(flavor.memory_mb) * units.Mi)
vcpus = str(flavor.vcpus)
vcpu_weight = flavor.vcpu_weight
@ -363,9 +363,9 @@ def is_vm_shutdown(session, vm_ref):
def is_enough_free_mem(session, instance):
flavor = instance.get_flavor()
mem = long(flavor.memory_mb) * units.Mi
host_free_mem = long(session.call_xenapi("host.compute_free_memory",
session.host_ref))
mem = int(flavor.memory_mb) * units.Mi
host_free_mem = int(session.call_xenapi("host.compute_free_memory",
session.host_ref))
return host_free_mem >= mem
@ -1752,8 +1752,8 @@ def compile_info(session, vm_ref):
num_cpu = session.call_xenapi("VM.get_VCPUs_max", vm_ref)
return hardware.InstanceInfo(state=power_state,
max_mem_kb=long(max_mem) >> 10,
mem_kb=long(mem) >> 10,
max_mem_kb=int(max_mem) >> 10,
mem_kb=int(mem) >> 10,
num_cpu=num_cpu)
@ -1766,7 +1766,7 @@ def compile_instance_diagnostics(instance, vm_rec):
driver='xenapi',
config_drive=config_drive)
for cpu_num in range(0, long(vm_rec['VCPUs_max'])):
for cpu_num in range(0, int(vm_rec['VCPUs_max'])):
diags.add_cpu()
for vif in vm_rec['VIFs']:
@ -1775,7 +1775,7 @@ def compile_instance_diagnostics(instance, vm_rec):
for vbd in vm_rec['VBDs']:
diags.add_disk()
max_mem_bytes = long(vm_rec['memory_dynamic_max'])
max_mem_bytes = int(vm_rec['memory_dynamic_max'])
diags.memory_details.maximum = max_mem_bytes / units.Mi
return diags