Fixes dict keys and items references for Python 3
Python 3 does not support indexing keys or items iterators. Removes unit tests from tests-py3.txt blacklist. Partially implements blueprint: nova-python3-mitaka Change-Id: I3ec1e775d91e7f56356f744fd80f5d9df36cae1d
This commit is contained in:
parent
28585bb368
commit
db9b47a0c7
|
@ -577,7 +577,7 @@ def ec2_error_ex(ex, req, code=None, message=None, unexpected=False):
|
|||
if unexpected:
|
||||
# Log filtered environment for unexpected errors.
|
||||
env = req.environ.copy()
|
||||
for k in env.keys():
|
||||
for k in list(env.keys()):
|
||||
if not isinstance(env[k], six.string_types):
|
||||
env.pop(k)
|
||||
log_fun(_LE('Environment: %s'), jsonutils.dumps(env))
|
||||
|
|
|
@ -72,7 +72,7 @@ class APIRequest(object):
|
|||
for key in args.keys():
|
||||
# NOTE(vish): Turn numeric dict keys into lists
|
||||
if isinstance(args[key], dict):
|
||||
if args[key] != {} and args[key].keys()[0].isdigit():
|
||||
if args[key] != {} and list(args[key].keys())[0].isdigit():
|
||||
s = args[key].items()
|
||||
s.sort()
|
||||
args[key] = [v for k, v in s]
|
||||
|
|
|
@ -136,7 +136,8 @@ class HostController(object):
|
|||
# Validate the request
|
||||
if len(params) > 0:
|
||||
# Some extra param was passed. Fail.
|
||||
explanation = _("Invalid update setting: '%s'") % params.keys()[0]
|
||||
explanation = _("Invalid update setting: '%s'") % list(
|
||||
params.keys())[0]
|
||||
raise webob.exc.HTTPBadRequest(explanation=explanation)
|
||||
if orig_status is not None:
|
||||
status = read_enabled(orig_status, _("Invalid status: '%s'"))
|
||||
|
|
|
@ -262,7 +262,7 @@ class SimpleTenantUsageController(object):
|
|||
tenant_id=tenant_id,
|
||||
detailed=True)
|
||||
if len(usage):
|
||||
usage = usage[0]
|
||||
usage = list(usage)[0]
|
||||
else:
|
||||
usage = {}
|
||||
return {'tenant_usage': usage}
|
||||
|
|
|
@ -263,7 +263,7 @@ class SimpleTenantUsageController(wsgi.Controller):
|
|||
tenant_id=tenant_id,
|
||||
detailed=True)
|
||||
if len(usage):
|
||||
usage = usage[0]
|
||||
usage = list(usage)[0]
|
||||
else:
|
||||
usage = {}
|
||||
return {'tenant_usage': usage}
|
||||
|
|
|
@ -495,7 +495,7 @@ def action_peek_json(body):
|
|||
raise exception.MalformedRequestBody(reason=msg)
|
||||
|
||||
# Return the action and the decoded body...
|
||||
return decoded.keys()[0]
|
||||
return list(decoded.keys())[0]
|
||||
|
||||
|
||||
class ResourceExceptionHandler(object):
|
||||
|
|
|
@ -2443,7 +2443,7 @@ class API(base.Base):
|
|||
|
||||
orig_sys_metadata = dict(instance.system_metadata)
|
||||
# Remove the old keys
|
||||
for key in instance.system_metadata.keys():
|
||||
for key in list(instance.system_metadata.keys()):
|
||||
if key.startswith(utils.SM_IMAGE_PROP_PREFIX):
|
||||
del instance.system_metadata[key]
|
||||
|
||||
|
|
|
@ -2202,7 +2202,7 @@ def _exact_instance_filter(query, filters, legal_keys):
|
|||
column_attr = getattr(model, key)
|
||||
if isinstance(value, list):
|
||||
for item in value:
|
||||
for k, v in item.iteritems():
|
||||
for k, v in item.items():
|
||||
query = query.filter(column_attr.any(key=k))
|
||||
query = query.filter(column_attr.any(value=v))
|
||||
|
||||
|
|
|
@ -561,7 +561,7 @@ class IptablesManager(object):
|
|||
# if no duplicates, use original rule
|
||||
if dup_filter:
|
||||
# grab the last entry, if there is one
|
||||
dup = dup_filter[-1]
|
||||
dup = list(dup_filter)[-1]
|
||||
rule_str = str(dup)
|
||||
else:
|
||||
rule_str = str(rule)
|
||||
|
@ -573,6 +573,7 @@ class IptablesManager(object):
|
|||
|
||||
our_rules += bot_rules
|
||||
|
||||
new_filter = list(new_filter)
|
||||
new_filter[rules_index:rules_index] = our_rules
|
||||
|
||||
new_filter[rules_index:rules_index] = [':%s - [0:0]' % (name,)
|
||||
|
|
|
@ -184,11 +184,11 @@ class BaseRequestHandler(object):
|
|||
def render_xml(self, value):
|
||||
assert isinstance(value, dict) and len(value) == 1
|
||||
self.set_header("Content-Type", "application/xml; charset=UTF-8")
|
||||
name = value.keys()[0]
|
||||
name = list(value.keys())[0]
|
||||
parts = []
|
||||
parts.append('<' + utils.utf8(name) +
|
||||
' xmlns="http://doc.s3.amazonaws.com/2006-03-01">')
|
||||
self._render_parts(value.values()[0], parts)
|
||||
self._render_parts(list(value.values())[0], parts)
|
||||
parts.append('</' + utils.utf8(name) + '>')
|
||||
self.finish('<?xml version="1.0" encoding="UTF-8"?>\n' +
|
||||
''.join(parts))
|
||||
|
|
|
@ -606,7 +606,7 @@ class BaseTrackerTestCase(BaseTestCase):
|
|||
|
||||
def _fake_migration_update(self, ctxt, migration_id, values):
|
||||
# cheat and assume there's only 1 migration present
|
||||
migration = self._migrations.values()[0]
|
||||
migration = list(self._migrations.values())[0]
|
||||
migration.update(values)
|
||||
return migration
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ class InstanceTypeToolsTest(test.TestCase):
|
|||
_instance_type_p = obj_base.obj_to_primitive(_instance_type)
|
||||
|
||||
props = flavors.system_metadata_flavor_props.keys()
|
||||
for key in instance_type_p.keys():
|
||||
for key in list(instance_type_p.keys()):
|
||||
if key not in props:
|
||||
del instance_type_p[key]
|
||||
|
||||
|
|
|
@ -868,7 +868,7 @@ class Connection(object):
|
|||
return len(self._running_vms)
|
||||
|
||||
def listDomainsID(self):
|
||||
return self._running_vms.keys()
|
||||
return list(self._running_vms.keys())
|
||||
|
||||
def lookupByID(self, id):
|
||||
if id in self._running_vms:
|
||||
|
|
|
@ -582,7 +582,7 @@ class DatastoreHostMount(DataObject):
|
|||
def __init__(self, value='host-100'):
|
||||
super(DatastoreHostMount, self).__init__()
|
||||
host_ref = (_db_content["HostSystem"]
|
||||
[_db_content["HostSystem"].keys()[0]].obj)
|
||||
[list(_db_content["HostSystem"].keys())[0]].obj)
|
||||
host_system = DataObject()
|
||||
host_system.ManagedObjectReference = [host_ref]
|
||||
host_system.value = value
|
||||
|
@ -709,7 +709,7 @@ class HostSystem(ManagedObject):
|
|||
create_host_network_system()
|
||||
if not _get_object_refs('HostStorageSystem'):
|
||||
create_host_storage_system()
|
||||
host_net_key = _db_content["HostNetworkSystem"].keys()[0]
|
||||
host_net_key = list(_db_content["HostNetworkSystem"].keys())[0]
|
||||
host_net_sys = _db_content["HostNetworkSystem"][host_net_key].obj
|
||||
self.set("configManager.networkSystem", host_net_sys)
|
||||
host_storage_sys_key = _get_object_refs('HostStorageSystem')[0]
|
||||
|
@ -767,7 +767,8 @@ class HostSystem(ManagedObject):
|
|||
|
||||
if _db_content.get("Network", None) is None:
|
||||
create_network()
|
||||
net_ref = _db_content["Network"][_db_content["Network"].keys()[0]].obj
|
||||
net_ref = _db_content["Network"][
|
||||
list(_db_content["Network"].keys())[0]].obj
|
||||
network_do = DataObject()
|
||||
network_do.ManagedObjectReference = [net_ref]
|
||||
self.set("network", network_do)
|
||||
|
@ -870,7 +871,8 @@ class Datacenter(ManagedObject):
|
|||
self.set("vmFolder", "vm_folder_ref")
|
||||
if _db_content.get("Network", None) is None:
|
||||
create_network()
|
||||
net_ref = _db_content["Network"][_db_content["Network"].keys()[0]].obj
|
||||
net_ref = _db_content["Network"][
|
||||
list(_db_content["Network"].keys())[0]].obj
|
||||
network_do = DataObject()
|
||||
network_do.ManagedObjectReference = [net_ref]
|
||||
self.set("network", network_do)
|
||||
|
@ -965,15 +967,16 @@ def create_vm(uuid=None, name=None,
|
|||
devices = []
|
||||
|
||||
if vmPathName is None:
|
||||
vm_path = ds_obj.DatastorePath(_db_content['Datastore'].values()[0])
|
||||
vm_path = ds_obj.DatastorePath(
|
||||
list(_db_content['Datastore'].values())[0])
|
||||
else:
|
||||
vm_path = ds_obj.DatastorePath.parse(vmPathName)
|
||||
|
||||
if res_pool_ref is None:
|
||||
res_pool_ref = _db_content['ResourcePool'].keys()[0]
|
||||
res_pool_ref = list(_db_content['ResourcePool'].keys())[0]
|
||||
|
||||
if host_ref is None:
|
||||
host_ref = _db_content["HostSystem"].keys()[0]
|
||||
host_ref = list(_db_content["HostSystem"].keys())[0]
|
||||
|
||||
# Fill in the default path to the vmx file if we were only given a
|
||||
# datastore. Note that if you create a VM with vmPathName '[foo]', when you
|
||||
|
@ -1525,7 +1528,7 @@ class FakeVim(object):
|
|||
|
||||
def _add_port_group(self, method, *args, **kwargs):
|
||||
"""Adds a port group to the host system."""
|
||||
_host_sk = _db_content["HostSystem"].keys()[0]
|
||||
_host_sk = list(_db_content["HostSystem"].keys())[0]
|
||||
host_mdo = _db_content["HostSystem"][_host_sk]
|
||||
host_mdo._add_port_group(kwargs.get("portgrp"))
|
||||
|
||||
|
|
|
@ -1564,7 +1564,7 @@ class VMwareVMUtilGetHostRefTestCase(test.NoDBTestCase):
|
|||
self.session = driver.VMwareAPISession()
|
||||
|
||||
# Create a fake VirtualMachine running on a known host
|
||||
self.host_ref = fake._db_content['HostSystem'].keys()[0]
|
||||
self.host_ref = list(fake._db_content['HostSystem'].keys())[0]
|
||||
self.vm_ref = fake.create_vm(host_ref=self.host_ref)
|
||||
|
||||
@mock.patch.object(vm_util, 'get_vm_ref')
|
||||
|
|
|
@ -3204,7 +3204,7 @@ class XenAPIAggregateTestCase(stubs.XenAPITestBase):
|
|||
def test_remove_host_from_aggregate_error(self):
|
||||
# Ensure we can remove a host from an aggregate even if in error.
|
||||
values = _create_service_entries(self.context)
|
||||
fake_zone = values.keys()[0]
|
||||
fake_zone = list(values.keys())[0]
|
||||
aggr = self.api.create_aggregate(self.context,
|
||||
'fake_aggregate', fake_zone)
|
||||
# let's mock the fact that the aggregate is ready!
|
||||
|
|
|
@ -371,7 +371,7 @@ def _create_vlan(pif_ref, vlan_num, network_ref):
|
|||
|
||||
|
||||
def get_all(table):
|
||||
return _db_content[table].keys()
|
||||
return list(_db_content[table].keys())
|
||||
|
||||
|
||||
def get_all_records(table):
|
||||
|
@ -482,7 +482,7 @@ class SessionBase(object):
|
|||
xenapi_session.apply_session_helpers(self)
|
||||
|
||||
def pool_get_default_SR(self, _1, pool_ref):
|
||||
return _db_content['pool'].values()[0]['default-SR']
|
||||
return list(_db_content['pool'].values())[0]['default-SR']
|
||||
|
||||
def VBD_insert(self, _1, vbd_ref, vdi_ref):
|
||||
vbd_rec = get_record('VBD', vbd_ref)
|
||||
|
|
|
@ -43,7 +43,7 @@ def find_network_with_bridge(session, bridge):
|
|||
(bridge, bridge))
|
||||
networks = session.network.get_all_records_where(expr)
|
||||
if len(networks) == 1:
|
||||
return networks.keys()[0]
|
||||
return list(networks.keys())[0]
|
||||
elif len(networks) > 1:
|
||||
raise exception.NovaException(
|
||||
_('Found non-unique network for bridge %s') % bridge)
|
||||
|
|
|
@ -758,7 +758,7 @@ def get_sr_path(session, sr_ref=None):
|
|||
|
||||
# NOTE(bobball): There can only be one PBD for a host/SR pair, but path is
|
||||
# not always present - older versions of XS do not set it.
|
||||
pbd_ref = pbd_rec.keys()[0]
|
||||
pbd_ref = list(pbd_rec.keys())[0]
|
||||
device_config = pbd_rec[pbd_ref]['device_config']
|
||||
if 'path' in device_config:
|
||||
return device_config['path']
|
||||
|
@ -847,7 +847,7 @@ def _find_cached_image(session, image_id, sr_ref):
|
|||
if number_found > 0:
|
||||
if number_found > 1:
|
||||
LOG.warning(_LW("Multiple base images for image: %s"), image_id)
|
||||
return recs.keys()[0]
|
||||
return list(recs.keys())[0]
|
||||
|
||||
|
||||
def _get_resize_func_name(session):
|
||||
|
@ -2222,7 +2222,7 @@ def get_this_vm_uuid(session):
|
|||
'field "is_control_domain"="true" and '
|
||||
'field "resident_on"="%s"' %
|
||||
session.host_ref)
|
||||
return vms[vms.keys()[0]]['uuid']
|
||||
return vms[list(vms.keys())[0]]['uuid']
|
||||
try:
|
||||
return _get_sys_hypervisor_uuid()
|
||||
except IOError:
|
||||
|
|
|
@ -2089,14 +2089,14 @@ class VMOps(object):
|
|||
msg = _('No suitable network for migrate')
|
||||
raise exception.MigrationPreCheckError(reason=msg)
|
||||
|
||||
pifkey = pifs.keys()[0]
|
||||
pifkey = list(pifs.keys())[0]
|
||||
if not (netutils.is_valid_ipv4(pifs[pifkey]['IP']) or
|
||||
netutils.is_valid_ipv6(pifs[pifkey]['IPv6'])):
|
||||
msg = (_('PIF %s does not contain IP address')
|
||||
% pifs[pifkey]['uuid'])
|
||||
raise exception.MigrationPreCheckError(reason=msg)
|
||||
|
||||
nwref = pifs[pifs.keys()[0]]['network']
|
||||
nwref = pifs[list(pifs.keys())[0]]['network']
|
||||
try:
|
||||
options = {}
|
||||
migrate_data = self._session.call_xenapi("host.migrate_receive",
|
||||
|
|
|
@ -77,7 +77,6 @@ nova.tests.unit.api.openstack.compute.test_floating_ips.FloatingIpTestV2
|
|||
nova.tests.unit.api.openstack.compute.test_floating_ips.FloatingIpTestV21
|
||||
nova.tests.unit.api.openstack.compute.test_hide_server_addresses.HideServerAddressesTestV2
|
||||
nova.tests.unit.api.openstack.compute.test_hide_server_addresses.HideServerAddressesTestV21
|
||||
nova.tests.unit.api.openstack.compute.test_hosts.HostTestCaseV20
|
||||
nova.tests.unit.api.openstack.compute.test_image_metadata.ImageMetaDataTestV2
|
||||
nova.tests.unit.api.openstack.compute.test_image_metadata.ImageMetaDataTestV21
|
||||
nova.tests.unit.api.openstack.compute.test_image_size.ImageSizeTestV2
|
||||
|
@ -218,7 +217,6 @@ nova.tests.unit.test_cinder.CinderTestCase
|
|||
nova.tests.unit.test_cinder.CinderV2TestCase
|
||||
nova.tests.unit.test_configdrive2.ConfigDriveTestCase
|
||||
nova.tests.unit.test_fixtures.TestOSAPIFixture
|
||||
nova.tests.unit.test_flavors.InstanceTypeToolsTest
|
||||
nova.tests.unit.test_hacking.HackingTestCase
|
||||
nova.tests.unit.test_iptables_network.IptablesManagerTestCase
|
||||
nova.tests.unit.test_ipv6.IPv6AccountIdentiferTestCase
|
||||
|
@ -282,7 +280,7 @@ nova.tests.unit.virt.libvirt.test_config.LibvirtConfigTest
|
|||
nova.tests.unit.virt.libvirt.test_driver.LibvirtConnTestCase
|
||||
nova.tests.unit.virt.libvirt.test_driver.LibvirtDriverTestCase
|
||||
nova.tests.unit.virt.libvirt.test_driver.LibvirtVolumeSnapshotTestCase
|
||||
nova.tests.unit.virt.libvirt.test_fakelibvirt.FakeLibvirtTests
|
||||
nova.tests.unit.virt.libvirt.test_fakelibvirt.FakeLibvirtTests.test_numa_topology_generation
|
||||
nova.tests.unit.virt.libvirt.test_firewall.IptablesFirewallTestCase
|
||||
nova.tests.unit.virt.libvirt.test_imagebackend.EncryptedLvmTestCase
|
||||
nova.tests.unit.virt.libvirt.test_imagebackend.LvmTestCase
|
||||
|
@ -307,7 +305,6 @@ nova.tests.unit.virt.vmwareapi.test_images.VMwareImagesTestCase
|
|||
nova.tests.unit.virt.vmwareapi.test_network_util.GetNetworkWithTheNameTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_read_write_util.ReadWriteUtilTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_vim_util.VMwareVIMUtilTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_vm_util.VMwareVMUtilGetHostRefTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_vm_util.VMwareVMUtilTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_vmops.VMwareVMOpsTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_volumeops.VMwareVolumeOpsTestCase
|
||||
|
@ -319,7 +316,6 @@ nova.tests.unit.virt.xenapi.image.test_vdi_through_dev.TestTarGzProducer
|
|||
nova.tests.unit.virt.xenapi.image.test_vdi_through_dev.TestUploadToGlanceAsRawTgz
|
||||
nova.tests.unit.virt.xenapi.test_agent.FileInjectionTestCase
|
||||
nova.tests.unit.virt.xenapi.test_driver.XenAPIDriverTestCase
|
||||
nova.tests.unit.virt.xenapi.test_network_utils.NetworkUtilsTestCase
|
||||
nova.tests.unit.virt.xenapi.test_vm_utils.CreateCachedImageTestCase
|
||||
nova.tests.unit.virt.xenapi.test_vm_utils.CreateVmRecordTestCase
|
||||
nova.tests.unit.virt.xenapi.test_vm_utils.CreateVmTestCase
|
||||
|
@ -343,7 +339,6 @@ nova.tests.unit.virt.xenapi.test_xenapi.XenAPILiveMigrateTestCase
|
|||
nova.tests.unit.virt.xenapi.test_xenapi.XenAPIMigrateInstance
|
||||
nova.tests.unit.virt.xenapi.test_xenapi.XenAPISRSelectionTestCase
|
||||
nova.tests.unit.virt.xenapi.test_xenapi.XenAPIVMTestCase
|
||||
nova.tests.unit.virt.xenapi.test_xenapi.XenAPIVolumeTestCase
|
||||
nova.tests.unit.volume.encryptors.test_cryptsetup.CryptsetupEncryptorTestCase
|
||||
nova.tests.unit.volume.encryptors.test_luks.LuksEncryptorTestCase
|
||||
nova.tests.unit.volume.test_cinder.CinderApiTestCase
|
||||
|
|
Loading…
Reference in New Issue