diff --git a/nova/api/openstack/compute/legacy_v2/contrib/flavorextraspecs.py b/nova/api/openstack/compute/legacy_v2/contrib/flavorextraspecs.py index 50c80dd66239..e38095459669 100644 --- a/nova/api/openstack/compute/legacy_v2/contrib/flavorextraspecs.py +++ b/nova/api/openstack/compute/legacy_v2/contrib/flavorextraspecs.py @@ -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) diff --git a/nova/objectstore/s3server.py b/nova/objectstore/s3server.py index 0b01d2423ffd..e2abfd1fcd63 100644 --- a/nova/objectstore/s3server.py +++ b/nova/objectstore/s3server.py @@ -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")) diff --git a/nova/tests/unit/api/ec2/test_apirequest.py b/nova/tests/unit/api/ec2/test_apirequest.py index c162f87518a6..e4e9414f804d 100644 --- a/nova/tests/unit/api/ec2/test_apirequest.py +++ b/nova/tests/unit/api/ec2/test_apirequest.py @@ -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', diff --git a/nova/tests/unit/objects/test_fields.py b/nova/tests/unit/objects/test_fields.py index af162c10a5b5..13f8d560ae22 100644 --- a/nova/tests/unit/objects/test_fields.py +++ b/nova/tests/unit/objects/test_fields.py @@ -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] diff --git a/nova/tests/unit/virt/libvirt/fakelibvirt.py b/nova/tests/unit/virt/libvirt/fakelibvirt.py index 001ae6f65c5b..7dd57662a923 100644 --- a/nova/tests/unit/virt/libvirt/fakelibvirt.py +++ b/nova/tests/unit/virt/libvirt/fakelibvirt.py @@ -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] diff --git a/nova/tests/unit/virt/libvirt/test_fakelibvirt.py b/nova/tests/unit/virt/libvirt/test_fakelibvirt.py index c7cbca3054d1..d3e14fe1522e 100644 --- a/nova/tests/unit/virt/libvirt/test_fakelibvirt.py +++ b/nova/tests/unit/virt/libvirt/test_fakelibvirt.py @@ -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') diff --git a/nova/tests/unit/virt/libvirt/test_guest.py b/nova/tests/unit/virt/libvirt/test_guest.py index c467b6c87a94..ed8309e466fd 100644 --- a/nova/tests/unit/virt/libvirt/test_guest.py +++ b/nova/tests/unit/virt/libvirt/test_guest.py @@ -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() diff --git a/nova/tests/unit/virt/vmwareapi/test_driver_api.py b/nova/tests/unit/virt/vmwareapi/test_driver_api.py index ee0e4f88b5b8..19a6a8f28cbb 100644 --- a/nova/tests/unit/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/unit/virt/vmwareapi/test_driver_api.py @@ -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) diff --git a/nova/tests/unit/virt/xenapi/test_xenapi.py b/nova/tests/unit/virt/xenapi/test_xenapi.py index c23d01bfa3c8..284fd7df30b7 100644 --- a/nova/tests/unit/virt/xenapi/test_xenapi.py +++ b/nova/tests/unit/virt/xenapi/test_xenapi.py @@ -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'] diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 0d7a300a1051..34eac9566b40 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -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