diff --git a/nova/pci/stats.py b/nova/pci/stats.py index 46bdc2a652..8c1c9d9c16 100644 --- a/nova/pci/stats.py +++ b/nova/pci/stats.py @@ -60,7 +60,7 @@ class PciDeviceStats(object): # NOTE(sbauza): Stats are a PCIDevicePoolList object self.pools = [pci_pool.to_dict() for pci_pool in stats] if stats else [] - self.pools.sort(self.pool_cmp) + self.pools.sort(key=lambda item: len(item)) def _equal_properties(self, dev, entry, matching_keys): return all(dev.get(prop) == entry.get(prop) @@ -102,7 +102,7 @@ class PciDeviceStats(object): dev_pool['count'] = 0 dev_pool['devices'] = [] self.pools.append(dev_pool) - self.pools.sort(self.pool_cmp) + self.pools.sort(key=lambda item: len(item)) pool = dev_pool pool['count'] += 1 pool['devices'].append(dev) @@ -235,10 +235,6 @@ class PciDeviceStats(object): for r in requests]): raise exception.PciDeviceRequestFailed(requests=requests) - @staticmethod - def pool_cmp(dev1, dev2): - return len(dev1) - len(dev2) - def __iter__(self): # 'devices' shouldn't be part of stats pools = [] diff --git a/nova/scheduler/filters/trusted_filter.py b/nova/scheduler/filters/trusted_filter.py index 4b1e44afe0..c69c7714a6 100644 --- a/nova/scheduler/filters/trusted_filter.py +++ b/nova/scheduler/filters/trusted_filter.py @@ -223,7 +223,8 @@ class ComputeAttestationCache(object): def _update_cache(self): self._invalidate_caches() - states = self.attestservice.do_attestation(self.compute_nodes.keys()) + states = self.attestservice.do_attestation( + list(self.compute_nodes.keys())) if states is None: return for state in states: diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index a2fb8aa2f1..b1c284663d 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -452,7 +452,7 @@ class HostManager(object): def _strip_ignore_hosts(host_map, hosts_to_ignore): ignored_hosts = [] for host in hosts_to_ignore: - for (hostname, nodename) in host_map.keys(): + for (hostname, nodename) in list(host_map.keys()): if host == hostname: del host_map[(hostname, nodename)] ignored_hosts.append(host) @@ -462,7 +462,7 @@ class HostManager(object): def _match_forced_hosts(host_map, hosts_to_force): forced_hosts = [] - for (hostname, nodename) in host_map.keys(): + for (hostname, nodename) in list(host_map.keys()): if hostname not in hosts_to_force: del host_map[(hostname, nodename)] else: @@ -478,7 +478,7 @@ class HostManager(object): def _match_forced_nodes(host_map, nodes_to_force): forced_nodes = [] - for (hostname, nodename) in host_map.keys(): + for (hostname, nodename) in list(host_map.keys()): if nodename not in nodes_to_force: del host_map[(hostname, nodename)] else: diff --git a/nova/test.py b/nova/test.py index 44dede65d2..e5944baf49 100644 --- a/nova/test.py +++ b/nova/test.py @@ -295,7 +295,7 @@ class TestCase(testtools.TestCase): observed = jsonutils.loads(observed) def sort_key(x): - if isinstance(x, set) or isinstance(x, datetime.datetime): + if isinstance(x, (set, list)) or isinstance(x, datetime.datetime): return str(x) if isinstance(x, dict): items = ((sort_key(key), sort_key(value)) diff --git a/nova/tests/unit/scheduler/test_filter_scheduler.py b/nova/tests/unit/scheduler/test_filter_scheduler.py index c92e79d217..02a09b902f 100644 --- a/nova/tests/unit/scheduler/test_filter_scheduler.py +++ b/nova/tests/unit/scheduler/test_filter_scheduler.py @@ -23,6 +23,7 @@ from nova.scheduler import filter_scheduler from nova.scheduler import host_manager from nova.scheduler import utils as scheduler_utils from nova.scheduler import weights +from nova import test # noqa from nova.tests.unit.scheduler import fakes from nova.tests.unit.scheduler import test_scheduler diff --git a/nova/tests/unit/scheduler/test_scheduler_options.py b/nova/tests/unit/scheduler/test_scheduler_options.py index af3437996c..8da46f2309 100644 --- a/nova/tests/unit/scheduler/test_scheduler_options.py +++ b/nova/tests/unit/scheduler/test_scheduler_options.py @@ -17,9 +17,9 @@ Tests For PickledScheduler. """ import datetime -import StringIO from oslo_serialization import jsonutils +import six from nova.scheduler import scheduler_options from nova import test @@ -45,7 +45,9 @@ class FakeSchedulerOptions(scheduler_options.SchedulerOptions): def _get_file_handle(self, filename): self.file_was_loaded = True - return StringIO.StringIO(self._file_data) + if six.PY3: + return six.BytesIO(self._file_data.encode('utf-8')) + return six.StringIO(self._file_data) def _get_time_now(self): return self._time_now diff --git a/nova/tests/unit/scheduler/test_scheduler_utils.py b/nova/tests/unit/scheduler/test_scheduler_utils.py index 3eaedf7984..ed7541f5ee 100644 --- a/nova/tests/unit/scheduler/test_scheduler_utils.py +++ b/nova/tests/unit/scheduler/test_scheduler_utils.py @@ -15,12 +15,12 @@ """ Tests For Scheduler Utils """ -import contextlib import uuid import mock from mox3 import mox from oslo_config import cfg +import six from nova.compute import flavors from nova.compute import utils as compute_utils @@ -197,7 +197,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): scheduler_utils.populate_retry, filter_properties, 'fake-uuid') # make sure 'msg' is a substring of the complete exception text - self.assertIn(msg, nvh.message) + self.assertIn(msg, six.text_type(nvh)) def _check_parse_options(self, opts, sep, converter, expected): good = scheduler_utils.parse_options(opts, @@ -248,7 +248,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): def _get_group_details(self, group, policy=None): group_hosts = ['hostB'] - with contextlib.nested( + with test.nested( mock.patch.object(objects.InstanceGroup, 'get_by_instance_uuid', return_value=group), mock.patch.object(objects.InstanceGroup, 'get_hosts', @@ -297,7 +297,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): group.members = [instance.uuid] group.policies = [policy] - with contextlib.nested( + with test.nested( mock.patch.object(objects.InstanceGroup, 'get_by_instance_uuid', return_value=group), mock.patch.object(objects.InstanceGroup, 'get_hosts', diff --git a/tox.ini b/tox.ini index dee68ebfbe..96d070f76a 100644 --- a/tox.ini +++ b/tox.ini @@ -38,6 +38,48 @@ commands = python -m testtools.run \ nova.tests.unit.compute.test_keypairs \ nova.tests.unit.db.test_db_api \ + nova.tests.unit.scheduler.filters.test_affinity_filters \ + nova.tests.unit.scheduler.filters.test_aggregate_image_properties_isolation_filters \ + nova.tests.unit.scheduler.filters.test_aggregate_instance_extra_specs_filters \ + nova.tests.unit.scheduler.filters.test_aggregate_multitenancy_isolation_filters \ + nova.tests.unit.scheduler.filters.test_availability_zone_filters \ + nova.tests.unit.scheduler.filters.test_compute_capabilities_filters \ + nova.tests.unit.scheduler.filters.test_compute_filters \ + nova.tests.unit.scheduler.filters.test_core_filters \ + nova.tests.unit.scheduler.filters.test_disk_filters \ + nova.tests.unit.scheduler.filters.test_exact_core_filter \ + nova.tests.unit.scheduler.filters.test_exact_disk_filter \ + nova.tests.unit.scheduler.filters.test_exact_ram_filter \ + nova.tests.unit.scheduler.filters.test_extra_specs_ops \ + nova.tests.unit.scheduler.filters.test_image_props_filters \ + nova.tests.unit.scheduler.filters.test_io_ops_filters \ + nova.tests.unit.scheduler.filters.test_isolated_hosts_filter \ + nova.tests.unit.scheduler.filters.test_json_filters \ + nova.tests.unit.scheduler.filters.test_metrics_filters \ + nova.tests.unit.scheduler.filters.test_num_instances_filters \ + nova.tests.unit.scheduler.filters.test_numa_topology_filters \ + nova.tests.unit.scheduler.filters.test_pci_passthrough_filters \ + nova.tests.unit.scheduler.filters.test_ram_filters \ + nova.tests.unit.scheduler.filters.test_retry_filters \ + nova.tests.unit.scheduler.filters.test_trusted_filters \ + nova.tests.unit.scheduler.filters.test_type_filters \ + nova.tests.unit.scheduler.filters.test_utils \ + nova.tests.unit.scheduler.test_caching_scheduler \ + nova.tests.unit.scheduler.test_chance_scheduler \ + nova.tests.unit.scheduler.test_client \ + nova.tests.unit.scheduler.test_filter_scheduler \ + nova.tests.unit.scheduler.test_filters \ + nova.tests.unit.scheduler.test_host_filters \ + nova.tests.unit.scheduler.test_host_manager \ + nova.tests.unit.scheduler.test_ironic_host_manager \ + nova.tests.unit.scheduler.test_rpcapi \ + nova.tests.unit.scheduler.test_scheduler \ + nova.tests.unit.scheduler.test_scheduler_options \ + nova.tests.unit.scheduler.test_scheduler_utils \ + nova.tests.unit.scheduler.weights.test_weights_hosts \ + nova.tests.unit.scheduler.weights.test_weights_ioopsweight \ + nova.tests.unit.scheduler.weights.test_weights_metrics \ + nova.tests.unit.scheduler.weights.test_weights_ram \ nova.tests.unit.objects.test_agent \ nova.tests.unit.objects.test_aggregate \ nova.tests.unit.objects.test_bandwidth_usage \