diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 1d17ce1c9fd8..694e7a48beea 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -700,9 +700,9 @@ def expected_errors(errors): LOG.exception("Unexpected exception in API method") msg = _("Unexpected API Error. " - "%(support)s\n%(exc)s" % { - 'support': version.support_string(), - 'exc': type(exc)}) + "{support}\n{exc}").format( + support=version.support_string(), + exc=type(exc)) raise webob.exc.HTTPInternalServerError(explanation=msg) return wrapped diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 45ae678ab4c1..5857a33d8724 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -2604,7 +2604,7 @@ class PlacementCommands(object): # By default we suspect the orphaned allocation was for a # migration... consumer_type = 'migration' - if not(consumer_uuid in inst_uuids): + if consumer_uuid not in inst_uuids: # ... but if we can't find it either for an instance, # that means it was for this. consumer_type = 'instance' @@ -2778,8 +2778,8 @@ class LibvirtCommands(object): print(mtype) return 0 else: - print(_('No machine type registered for instance %s' % - instance_uuid)) + print(_('No machine type registered for instance %s') % + instance_uuid) return 3 except (exception.InstanceNotFound, exception.InstanceMappingNotFound) as e: diff --git a/nova/compute/provider_config.py b/nova/compute/provider_config.py index 956a4beb8679..f12b6d2709d4 100644 --- a/nova/compute/provider_config.py +++ b/nova/compute/provider_config.py @@ -229,8 +229,9 @@ def _load_yaml_file(path): if hasattr(ex, 'problem_mark'): pos = ex.problem_mark message += _("File: %s ") % open_file.name - message += _("Error position: (%s:%s)") % ( - pos.line + 1, pos.column + 1) + message += _("Error position: " + "({line}:{column})").format( + line=pos.line + 1, column=pos.column + 1) raise nova_exc.ProviderConfigException(error=message) except OSError: message = _("Unable to read yaml config file: %s") % path diff --git a/nova/console/rfb/authvencrypt.py b/nova/console/rfb/authvencrypt.py index dc09693fc2ea..8ad1c2aab4a1 100644 --- a/nova/console/rfb/authvencrypt.py +++ b/nova/console/rfb/authvencrypt.py @@ -110,10 +110,10 @@ class RFBAuthSchemeVeNCrypt(auth.RFBAuthScheme): # MITM'd Anonymous Diffie Hellmann (DH) cyphers) if AuthVeNCryptSubtype.X509NONE not in sub_types: reason = _( - "Server does not support the %d (%s) VeNCrypt auth subtype" - ) % ( - AuthVeNCryptSubtype.X509NONE.value, - AuthVeNCryptSubtype.X509NONE.name) + "Server does not support the {value} ({name}) " + "VeNCrypt auth subtype" + ).format(value=AuthVeNCryptSubtype.X509NONE.value, + name=AuthVeNCryptSubtype.X509NONE.name) raise exception.RFBAuthHandshakeFailed(reason=reason) LOG.debug( diff --git a/nova/console/securityproxy/rfb.py b/nova/console/securityproxy/rfb.py index d8972fbc9557..34911c3f8cdd 100644 --- a/nova/console/securityproxy/rfb.py +++ b/nova/console/securityproxy/rfb.py @@ -164,19 +164,17 @@ class RFBSecurityProxy(base.SecurityProxy): if client_auth != auth.AuthType.NONE: self._fail( tenant_sock, compute_sock, - _("Only the security type %d (%s) is supported") % ( - auth.AuthType.NONE.value, auth.AuthType.NONE.name, - )) + _("Only the security type {value} ({name}) " + "is supported").format(value=auth.AuthType.NONE.value, + name=auth.AuthType.NONE.name)) reason = _( - "Client requested a security type other than %d (%s): " - "%d (%s)" - ) % ( - auth.AuthType.NONE.value, - auth.AuthType.NONE.name, - auth.AuthType(client_auth).value, - auth.AuthType(client_auth).name, - ) + "Client requested a security type other than " + "{value} ({name}): {client_value} ({client_name})" + ).format(value=auth.AuthType.NONE.value, + name=auth.AuthType.NONE.name, + client_value=auth.AuthType(client_auth).value, + client_name=auth.AuthType(client_auth).name) raise exception.SecurityProxyNegotiationFailed(reason=reason) try: diff --git a/nova/image/glance.py b/nova/image/glance.py index 0ceb3b4b8fe2..f524618a8beb 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -389,7 +389,8 @@ class GlanceImageServiceV2(object): def _verify_and_write(self, context, image_id, trusted_certs, image_chunks, data, dst_path): - """Perform image signature verification and save the image file if needed. + """Perform image signature verification and save the image file if + needed. This function writes the content of the image_chunks iterator either to a file object provided by the data parameter or to a filepath provided diff --git a/nova/objects/aggregate.py b/nova/objects/aggregate.py index 1d6597965c0f..98005edea361 100644 --- a/nova/objects/aggregate.py +++ b/nova/objects/aggregate.py @@ -437,7 +437,7 @@ def _get_by_host_from_db(context, host, key=None): @api_db_api.context_manager.reader def _get_by_metadata_from_db(context, key=None, value=None): - assert(key is not None or value is not None) + assert key is not None or value is not None query = context.session.query(api_models.Aggregate) query = query.join(api_models.Aggregate._metadata) if key is not None: diff --git a/nova/objects/block_device.py b/nova/objects/block_device.py index 82ce1c680697..80bf9ab4c783 100644 --- a/nova/objects/block_device.py +++ b/nova/objects/block_device.py @@ -168,7 +168,7 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject, # gave this bdm a uuid result = query.one() uuid = result['uuid'] - assert(uuid is not None) + assert uuid is not None return uuid diff --git a/nova/objects/instance_numa.py b/nova/objects/instance_numa.py index 28e877574d09..61c35e2a6e33 100644 --- a/nova/objects/instance_numa.py +++ b/nova/objects/instance_numa.py @@ -49,8 +49,10 @@ class InstanceNUMACell(base.NovaEphemeralObject, raise exception.ObjectActionError( action='obj_make_compatible', reason=_( - '%s policy is not supported in version %s' - ) % (primitive['cpu_policy'], target_version)) + '{policy} policy is not supported in ' + 'version {version}' + ).format(policy=primitive['cpu_policy'], + version=target_version)) # NOTE(huaqiang): Since version 1.5, 'cpuset' is modified to track the # unpinned CPUs only, with pinned CPUs tracked via 'pcpuset' instead. diff --git a/nova/scheduler/filters/image_props_filter.py b/nova/scheduler/filters/image_props_filter.py index e6598a19a890..e1084902372a 100644 --- a/nova/scheduler/filters/image_props_filter.py +++ b/nova/scheduler/filters/image_props_filter.py @@ -82,7 +82,7 @@ class ImagePropertiesFilter(filters.BaseHostFilter): def _compare_product_version(hyper_version, image_props): version_required = image_props.get('img_hv_requested_version') - if not(hypervisor_version and version_required): + if not (hypervisor_version and version_required): return True img_prop_predicate = versionpredicate.VersionPredicate( 'image_prop (%s)' % version_required) diff --git a/nova/tests/fixtures/__init__.py b/nova/tests/fixtures/__init__.py index 9ff4a2a601de..ff3dc92f023e 100644 --- a/nova/tests/fixtures/__init__.py +++ b/nova/tests/fixtures/__init__.py @@ -10,22 +10,23 @@ # License for the specific language governing permissions and limitations # under the License. -from .api_paste import ApiPasteNoProjectId # noqa: F401 -from .api_paste import ApiPasteV21Fixture # noqa: F401 -from .cast_as_call import CastAsCallFixture # noqa: F401 -from .cinder import CinderFixture # noqa: F401 -from .conf import ConfFixture # noqa: F401, F403 -from .cyborg import CyborgFixture # noqa: F401 -from .filesystem import SysFileSystemFixture # noqa: F401 -from .filesystem import TempFileSystemFixture # noqa: F401 -from .glance import GlanceFixture # noqa: F401 -from .libvirt import LibvirtFixture # noqa: F401 -from .libvirt_imagebackend import LibvirtImageBackendFixture # noqa: F401 -from .neutron import NeutronFixture # noqa: F401 -from .notifications import NotificationFixture # noqa: F401 -from .nova import * # noqa: F401, F403 -from .os_brick import OSBrickFixture # noqa: F401 -from .policy import OverridePolicyFixture # noqa: F401 -from .policy import PolicyFixture # noqa: F401 -from .policy import RealPolicyFixture # noqa: F401 -from .policy import RoleBasedPolicyFixture # noqa: F401 +from .api_paste import ApiPasteNoProjectId # noqa: F401, H304 +from .api_paste import ApiPasteV21Fixture # noqa: F401, H304 +from .cast_as_call import CastAsCallFixture # noqa: F401, H304 +from .cinder import CinderFixture # noqa: F401, H304 +from .conf import ConfFixture # noqa: F401, H304, F403 +from .cyborg import CyborgFixture # noqa: F401, H304 +from .filesystem import SysFileSystemFixture # noqa: F401, H304 +from .filesystem import TempFileSystemFixture # noqa: F401, H304 +from .glance import GlanceFixture # noqa: F401, H304 +from .libvirt import LibvirtFixture # noqa: F401, H304 +from .libvirt_imagebackend import \ + LibvirtImageBackendFixture # noqa: F401, H304 +from .neutron import NeutronFixture # noqa: F401, H304 +from .notifications import NotificationFixture # noqa: F401, H304 +from .nova import * # noqa: F401, F403, H303, H304 +from .os_brick import OSBrickFixture # noqa: F401, H304 +from .policy import OverridePolicyFixture # noqa: F401, H304 +from .policy import PolicyFixture # noqa: F401, H304 +from .policy import RealPolicyFixture # noqa: F401, H304 +from .policy import RoleBasedPolicyFixture # noqa: F401, H304 diff --git a/nova/tests/unit/api/openstack/compute/test_instance_actions.py b/nova/tests/unit/api/openstack/compute/test_instance_actions.py index df13e1d89d98..b91efbcfd85d 100644 --- a/nova/tests/unit/api/openstack/compute/test_instance_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_instance_actions.py @@ -49,7 +49,7 @@ def format_action(action, expect_traceback=True, expect_host=False, 'deleted') for key in to_delete: if key in action: - del(action[key]) + del action[key] if 'start_time' in action: # NOTE(danms): Without WSGI above us, these will be just stringified action['start_time'] = str(action['start_time'].replace(tzinfo=None)) @@ -73,7 +73,7 @@ def format_event(event, project_id, expect_traceback=True, expect_host=False, to_delete.append('hostId') for key in to_delete: if key in event: - del(event[key]) + del event[key] if 'start_time' in event: # NOTE(danms): Without WSGI above us, these will be just stringified event['start_time'] = str(event['start_time'].replace(tzinfo=None)) diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 16de724a42d1..def21bb05964 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -5612,7 +5612,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase, '_get_instance_block_device_info', return_value='fake-bdminfo'), mock.patch.object(self.compute, '_check_trusted_certs'), - ) as( + ) as ( mock_notify_usage, mock_setup, mock_setup_inst, @@ -5712,7 +5712,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase, return_value=is_vol_backed), mock.patch.object(self.compute, '_rebuild_volume_backed_instance'), mock.patch.object(compute_utils, 'get_root_bdm') - ) as( + ) as ( mock_destroy, mock_spawn, mock_save, @@ -5844,7 +5844,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase, return_value=root_bdm), mock.patch.object(self.compute, 'volume_api'), mock.patch.object(self.compute.image_api, 'get'), - ) as( + ) as ( mock_save, mock_get_root_bdm, mock_vol_api, diff --git a/nova/tests/unit/policies/test_rescue.py b/nova/tests/unit/policies/test_rescue.py index 120809877c79..2b8f94c5e396 100644 --- a/nova/tests/unit/policies/test_rescue.py +++ b/nova/tests/unit/policies/test_rescue.py @@ -100,8 +100,8 @@ class RescueServerPolicyTest(base.BasePolicyTest): class RescueServerNoLegacyNoScopePolicyTest(RescueServerPolicyTest): - """Test rescue/unrescue server APIs policies with no legacy deprecated rules - and no scope checks which means new defaults only. + """Test rescue/unrescue server APIs policies with no legacy deprecated + rules and no scope checks which means new defaults only. """ diff --git a/nova/tests/unit/virt/libvirt/volume/test_mount.py b/nova/tests/unit/virt/libvirt/volume/test_mount.py index 8ecb117f050e..aaa6db3b2a3b 100644 --- a/nova/tests/unit/virt/libvirt/volume/test_mount.py +++ b/nova/tests/unit/virt/libvirt/volume/test_mount.py @@ -117,7 +117,7 @@ class ThreadController(object): self.waiting = True self.wait_lock.notify_all() self.wait_lock.wait(1) - assert(time.time() - wait_since < MAX_WAIT) + assert time.time() - wait_since < MAX_WAIT self.epoch += 1 self.waiting = False @@ -141,7 +141,7 @@ class ThreadController(object): wait_since = time.time() while self.epoch == self.last_epoch or not self.waiting: self.wait_lock.wait(1) - assert(time.time() - wait_since < MAX_WAIT) + assert time.time() - wait_since < MAX_WAIT self.last_epoch = self.epoch @@ -164,7 +164,7 @@ class ThreadController(object): self.wait_lock.notify_all() while not self.complete: self.wait_lock.wait(1) - assert(time.time() - wait_since < MAX_WAIT) + assert time.time() - wait_since < MAX_WAIT self.thread.wait() diff --git a/nova/virt/disk/mount/api.py b/nova/virt/disk/mount/api.py index a8585a0c9f51..20a9653eaf49 100644 --- a/nova/virt/disk/mount/api.py +++ b/nova/virt/disk/mount/api.py @@ -184,7 +184,7 @@ class Mount(object): def map_dev(self): """Map partitions of the device to the file system namespace.""" - assert(os.path.exists(self.device)) + assert os.path.exists(self.device) LOG.debug("Map dev %s", self.device) automapped_path = '/dev/%sp%s' % (os.path.basename(self.device), self.partition) @@ -194,7 +194,7 @@ class Mount(object): elif self.partition and not os.path.exists(automapped_path): map_path = '/dev/mapper/%sp%s' % (os.path.basename(self.device), self.partition) - assert(not os.path.exists(map_path)) + assert not os.path.exists(map_path) # Note kpartx can output warnings to stderr and succeed # Also it can output failures to stderr and "succeed" diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 869996f615fa..c23d2c5bf963 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1837,7 +1837,7 @@ class LibvirtDriver(driver.ComputeDriver): # Set maximum attempt as 5, most test can remove the directory # for the second time. attempts = 0 - while(os.path.exists(target) and attempts < 5): + while os.path.exists(target) and attempts < 5: shutil.rmtree(target, ignore_errors=True) if os.path.exists(target): time.sleep(random.randint(20, 200) / 100.0) @@ -11103,7 +11103,7 @@ class LibvirtDriver(driver.ComputeDriver): announce_pause = ( CONF.workarounds.qemu_monitor_announce_self_interval) - while(current_attempt < max_attempts): + while current_attempt < max_attempts: # Increment attempt current_attempt += 1 diff --git a/test-requirements.txt b/test-requirements.txt index bbf04f5a1aac..a5238bb96d96 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking>=3.1.0,<3.2.0 # Apache-2.0 +hacking>=6.0.1,<=6.0.1 # Apache-2.0 mypy>=0.761 # MIT types-paramiko>=0.1.3 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0