Fixes Python 3 unit tests for nova.compute

Partially implements blueprint: nova-python3-mitaka

Change-Id: I603ac853505d86afcbce42938f664e402f1e343b
This commit is contained in:
Claudiu Belu 2015-11-19 12:18:37 +02:00
parent 0ac278ab88
commit e5269b3a8f
7 changed files with 32 additions and 26 deletions

View File

@ -677,8 +677,8 @@ class API(base.Base):
image_defined_bdms = block_device.from_legacy_mapping(
image_defined_bdms, None, root_device_name)
else:
image_defined_bdms = map(block_device.BlockDeviceDict,
image_defined_bdms)
image_defined_bdms = list(map(block_device.BlockDeviceDict,
image_defined_bdms))
if image_mapping:
image_mapping = self._prepare_image_mapping(instance_type,

View File

@ -804,8 +804,10 @@ class ResourceTracker(object):
# filter to most recently updated migration for each instance:
other_migration = filtered.get(uuid, None)
if (not other_migration or
migration.updated_at >= other_migration.updated_at):
# NOTE(claudiub): In Python 3, you cannot compare NoneTypes.
if (not other_migration or (
migration.updated_at and other_migration.updated_at and
migration.updated_at >= other_migration.updated_at)):
filtered[uuid] = migration
for migration in filtered.values():

View File

@ -7609,9 +7609,9 @@ class ComputeAPITestCase(BaseTestCase):
bdms = block_device_obj.BlockDeviceMappingList.get_by_instance_uuid(
self.context, instance_uuid)
ephemeral = filter(block_device.new_format_is_ephemeral, bdms)
ephemeral = list(filter(block_device.new_format_is_ephemeral, bdms))
self.assertEqual(1, len(ephemeral))
swap = filter(block_device.new_format_is_swap, bdms)
swap = list(filter(block_device.new_format_is_swap, bdms))
self.assertEqual(1, len(swap))
self.assertEqual(1024, swap[0].volume_size)
@ -7735,7 +7735,7 @@ class ComputeAPITestCase(BaseTestCase):
self.assertRaises(exception.InstanceUserDataTooLarge,
self.compute_api.create, self.context, inst_type,
self.fake_image['id'], user_data=('1' * 65536))
self.fake_image['id'], user_data=(b'1' * 65536))
def test_create_with_malformed_user_data(self):
# Test an instance type with malformed user data.
@ -7747,7 +7747,7 @@ class ComputeAPITestCase(BaseTestCase):
self.assertRaises(exception.InstanceUserDataMalformed,
self.compute_api.create, self.context, inst_type,
self.fake_image['id'], user_data='banana')
self.fake_image['id'], user_data=b'banana')
def test_create_with_base64_user_data(self):
# Test an instance type with ok much user data.
@ -7761,7 +7761,7 @@ class ComputeAPITestCase(BaseTestCase):
# base64
(refs, resv_id) = self.compute_api.create(
self.context, inst_type, self.fake_image['id'],
user_data=base64.encodestring('1' * 48510))
user_data=base64.encodestring(b'1' * 48510))
def test_populate_instance_for_create(self):
base_options = {'image_ref': self.fake_image['id'],
@ -11687,8 +11687,8 @@ class ComputeInjectedFilesTestCase(BaseTestCase):
def test_injected_success(self):
# test with valid b64 encoded content.
injected_files = [
('/a/b/c', base64.b64encode('foobarbaz')),
('/d/e/f', base64.b64encode('seespotrun')),
('/a/b/c', base64.b64encode(b'foobarbaz')),
('/d/e/f', base64.b64encode(b'seespotrun')),
]
decoded_files = [
@ -11700,7 +11700,7 @@ class ComputeInjectedFilesTestCase(BaseTestCase):
def test_injected_invalid(self):
# test with invalid b64 encoded content
injected_files = [
('/a/b/c', base64.b64encode('foobarbaz')),
('/a/b/c', base64.b64encode(b'foobarbaz')),
('/d/e/f', 'seespotrun'),
]

View File

@ -3233,6 +3233,7 @@ class SecurityGroupAPITest(test.NoDBTestCase):
mock_get.return_value = groups
names = self.secgroup_api.get_instance_security_groups(self.context,
uuids.instance)
self.assertEqual([{'name': 'bar'}, {'name': 'foo'}], sorted(names))
self.assertEqual(sorted([{'name': 'bar'}, {'name': 'foo'}], key=str),
sorted(names, key=str))
self.assertEqual(1, mock_get.call_count)
self.assertEqual(uuids.instance, mock_get.call_args_list[0][0][1].uuid)

View File

@ -202,8 +202,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
get_rt.side_effect = _get_rt_side_effect
self.compute.update_available_resource(ctxt)
get_db_nodes.assert_called_once_with(ctxt, use_slave=True)
self.assertEqual([mock.call(node) for node in avail_nodes],
get_rt.call_args_list)
self.assertEqual(sorted([mock.call(node) for node in avail_nodes]),
sorted(get_rt.call_args_list))
for rt in rts:
rt.update_available_resource.assert_called_once_with(ctxt)
self.assertEqual(expected_rt_dict,
@ -1077,7 +1077,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
@mock.patch(
'nova.compute.manager.ComputeManager._get_instance_block_device_info')
@mock.patch('nova.virt.driver.ComputeDriver.destroy')
@mock.patch('nova.virt.driver.ComputeDriver.get_volume_connector')
@mock.patch('nova.virt.fake.FakeDriver.get_volume_connector')
def _test_shutdown_instance_exception(self, exc, mock_connector,
mock_destroy, mock_blk_device_info, mock_nw_info, mock_elevated):
mock_connector.side_effect = exc
@ -1097,15 +1097,15 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self._test_shutdown_instance_exception(exc)
def test_shutdown_instance_client_exception(self):
exc = cinder_exception.ClientException
exc = cinder_exception.ClientException(code=9001)
self._test_shutdown_instance_exception(exc)
def test_shutdown_instance_volume_not_found(self):
exc = exception.VolumeNotFound
exc = exception.VolumeNotFound(volume_id=42)
self._test_shutdown_instance_exception(exc)
def test_shutdown_instance_disk_not_found(self):
exc = exception.DiskNotFound
exc = exception.DiskNotFound(location="not\\here")
self._test_shutdown_instance_exception(exc)
def _test_init_instance_retries_reboot(self, instance, reboot_type,

View File

@ -240,8 +240,8 @@ class BaseTestCase(test.NoDBTestCase):
self._initialize_used_res_counter()
result = self.r_handler.test_resources(flavor, limits)
expected = ['Free 4 < requested 5 ', None]
self.assertEqual(sorted(expected),
sorted(result))
self.assertEqual(sorted(expected, key=str),
sorted(result, key=str))
def test_empty_resource_handler(self):
"""An empty resource handler has no resource extensions,

View File

@ -70,12 +70,15 @@ nova.tests.unit.cells.test_cells_scheduler.CellsSchedulerTestCase
nova.tests.unit.cells.test_cells_state_manager.TestCellsGetCapacity
nova.tests.unit.cells.test_cells_state_manager.TestCellsStateManager
nova.tests.unit.cells.test_cells_state_manager.TestCellsStateManagerNToOne
nova.tests.unit.compute.test_compute.ComputeAPITestCase
nova.tests.unit.compute.test_compute.ComputeInjectedFilesTestCase
nova.tests.unit.compute.test_compute.ComputeAPITestCase.test_create_with_base64_user_data
nova.tests.unit.compute.test_compute.ComputeInjectedFilesTestCase.test_injected_invalid
nova.tests.unit.compute.test_compute.ComputeTestCase.test_finish_resize_with_volumes
nova.tests.unit.compute.test_compute.ComputeVolumeTestCase
nova.tests.unit.compute.test_compute_api.SecurityGroupAPITest
nova.tests.unit.compute.test_compute_cells.CellsComputeAPITestCase
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
nova.tests.unit.compute.test_resources.BaseTestCase
nova.tests.unit.compute.test_tracker.TestMoveClaim