From e6593d3a4b21c563fbca4cff76a925216ae4c900 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Fri, 1 Apr 2016 03:22:39 +0300 Subject: [PATCH] compute: fixes python 3 related unit tests Fixes volume related unit tests. Fixes non-sortable None items. Fixes __getattr__ infinite recursion. Fixes is_dict_like method. Dicts in python 3.4 do not have the 'has_key' method. Partially Implements: blueprint goal-python35 Change-Id: I97efc09f7657436f706b08e0b2795f0e59ac1dcd --- nova/block_device.py | 4 +++- nova/cells/utils.py | 4 +++- nova/utils.py | 2 +- nova/virt/block_device.py | 3 ++- tests-py3.txt | 5 ----- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nova/block_device.py b/nova/block_device.py index ecb78efb6ac4..c6f1d1c773dd 100644 --- a/nova/block_device.py +++ b/nova/block_device.py @@ -541,7 +541,9 @@ def instance_block_mapping(instance, bdms): # Right now sort by device name for deterministic # result. if ebs_devices: - ebs_devices.sort() + # NOTE(claudiub): python2.7 sort places None values first. + # this sort will maintain the same behaviour for both py27 and py34. + ebs_devices = sorted(ebs_devices, key=lambda x: (x is not None, x)) for nebs, ebs in enumerate(ebs_devices): mappings['ebs%d' % nebs] = ebs diff --git a/nova/cells/utils.py b/nova/cells/utils.py index e196470e1393..f3d2619c6d37 100644 --- a/nova/cells/utils.py +++ b/nova/cells/utils.py @@ -123,7 +123,9 @@ class ServiceProxy(_CellProxy): # ComputeNode object that consumers of this Proxy don't use, we can # safely remove it from what's returned raise AttributeError - return getattr(self._obj, key) + # NOTE(claudiub): needed for py34 compatiblity. + # get self._obj first, without ending into an infinite recursion. + return getattr(self.__getattribute__("_obj"), key) def get_instances_to_sync(context, updated_since=None, project_id=None, diff --git a/nova/utils.py b/nova/utils.py index 6a34b2cfd791..d775e579aa2f 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -732,7 +732,7 @@ def temporary_mutation(obj, **kwargs): do_something_that_needed_deleted_objects() """ def is_dict_like(thing): - return hasattr(thing, 'has_key') + return hasattr(thing, 'has_key') or isinstance(thing, dict) def get(thing, attr, default): if is_dict_like(thing): diff --git a/nova/virt/block_device.py b/nova/virt/block_device.py index 41eef7a9d028..b68f61544ea8 100644 --- a/nova/virt/block_device.py +++ b/nova/virt/block_device.py @@ -508,7 +508,8 @@ def attach_block_devices(block_device_mapping, *attach_args, **attach_kwargs): bdm.attach(*attach_args, **attach_kwargs) - map(_log_and_attach, block_device_mapping) + for device in block_device_mapping: + _log_and_attach(device) return block_device_mapping diff --git a/tests-py3.txt b/tests-py3.txt index e31c6a992784..540247a46483 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -32,11 +32,6 @@ nova.tests.unit.api.openstack.compute.test_volumes.BootFromVolumeTest nova.tests.unit.api.openstack.compute.test_volumes.VolumeApiTestV21 nova.tests.unit.api.test_compute_req_id.RequestIdTest nova.tests.unit.compute.test_compute.ComputeAPITestCase.test_create_with_base64_user_data -nova.tests.unit.compute.test_compute.ComputeTestCase.test_finish_resize_with_volumes -nova.tests.unit.compute.test_compute.ComputeVolumeTestCase.test_boot_volume_serial -nova.tests.unit.compute.test_compute.ComputeVolumeTestCase.test_poll_bandwidth_usage_not_implemented -nova.tests.unit.compute.test_compute.ComputeVolumeTestCase.test_prep_block_device_over_quota_failure -nova.tests.unit.compute.test_compute.ComputeVolumeTestCase.test_prep_block_device_with_blanks nova.tests.unit.compute.test_compute_cells.CellsComputeAPITestCase.test_create_with_base64_user_data nova.tests.unit.compute.test_compute_mgr.ComputeManagerUnitTestCase.test_run_pending_deletes nova.tests.unit.compute.test_host_api.ComputeHostAPICellsTestCase