From 16aaa8e7439bb8441c7a9ceff8d398fda276c553 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 10 Oct 2025 12:04:17 +0100 Subject: [PATCH] Fix outstanding hacking issues Change-Id: I920dc4922056a807b4d25728560fb4f58cbf14c2 Signed-off-by: Stephen Finucane --- manilaclient/osc/utils.py | 2 +- manilaclient/osc/v2/quotas.py | 12 ++++-- manilaclient/osc/v2/services.py | 15 +++---- manilaclient/osc/v2/share.py | 31 ++++++++------ manilaclient/osc/v2/share_access_rules.py | 17 ++++---- manilaclient/osc/v2/share_group_types.py | 41 +++++++++---------- manilaclient/osc/v2/share_groups.py | 5 ++- manilaclient/osc/v2/share_replicas.py | 10 ++--- manilaclient/osc/v2/share_servers.py | 19 +++++---- .../osc/v2/share_snapshot_instances.py | 4 +- manilaclient/osc/v2/share_snapshots.py | 18 ++++---- tox.ini | 4 +- 12 files changed, 89 insertions(+), 89 deletions(-) diff --git a/manilaclient/osc/utils.py b/manilaclient/osc/utils.py index 67583aabb..fe7d93db7 100644 --- a/manilaclient/osc/utils.py +++ b/manilaclient/osc/utils.py @@ -89,7 +89,7 @@ def extract_extra_specs( else: extra_specs[key] = value except ValueError: - msg = LOG.error(_("Wrong format: specs should be key=value pairs.")) + msg = _("Wrong format: specs should be key=value pairs.") raise exceptions.CommandError(msg) return extra_specs diff --git a/manilaclient/osc/v2/quotas.py b/manilaclient/osc/v2/quotas.py index b851f68d5..d8003757e 100644 --- a/manilaclient/osc/v2/quotas.py +++ b/manilaclient/osc/v2/quotas.py @@ -275,9 +275,11 @@ class QuotaSet(command.Command): try: share_client.quota_classes.update(**kwargs) except Exception as e: + msg = _( + "Failed to set quotas for class '%(project)s': '%(e)s'" + ) raise exceptions.CommandError( - _("Failed to set quotas for %s class: '%s'") - % (parsed_args.project, e) + msg % {'project': parsed_args.project, 'e': e} ) else: project_id = utils.find_resource( @@ -295,9 +297,11 @@ class QuotaSet(command.Command): try: share_client.quotas.update(**kwargs) except Exception as e: + msg = _( + "Failed to set quotas for project '%(project)s': '%(e)s'" + ) raise exceptions.CommandError( - _("Failed to set quotas for project '%s' : '%s'") - % (parsed_args.project, e) + msg % {'project': parsed_args.project, 'e': e} ) diff --git a/manilaclient/osc/v2/services.py b/manilaclient/osc/v2/services.py index dd4cab764..4206dcac9 100644 --- a/manilaclient/osc/v2/services.py +++ b/manilaclient/osc/v2/services.py @@ -74,9 +74,8 @@ class SetShareService(command.Command): parsed_args.host, parsed_args.binary ) except Exception as e: - raise exceptions.CommandError( - _(f"Failed to enable service: {e}") - ) + msg = _("Failed to enable service: %(e)s") + raise exceptions.CommandError(msg % {'e': e}) if parsed_args.disable: if parsed_args.disable_reason: @@ -97,9 +96,8 @@ class SetShareService(command.Command): parsed_args.host, parsed_args.binary ) except Exception as e: - raise exceptions.CommandError( - _(f"Failed to disable service: {e}") - ) + msg = _("Failed to disable service: %(e)s") + raise exceptions.CommandError(msg % {'e': e}) class ListShareService(command.Lister): @@ -205,6 +203,5 @@ class EnsureShareService(command.Command): try: share_client.services.ensure_shares(parsed_args.host) except Exception as e: - raise exceptions.CommandError( - _(f"Failed to run ensure shares: {e}") - ) + msg = _("Failed to ensure shares: %(e)s") + raise exceptions.CommandError(msg % {'e': e}) diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index 83454d068..9e09d8d80 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -1065,7 +1065,8 @@ class ResizeShare(command.Command): try: share_client.shares.shrink(share, new_size) except Exception as e: - raise exceptions.CommandError(_("Share resize failed: %s") % e) + msg = _("Share resize failed: %(e)s") + raise exceptions.CommandError(msg % {'e': e}) elif share_size < new_size: force = False if parsed_args.force: @@ -1081,11 +1082,11 @@ class ResizeShare(command.Command): else: share_client.shares.extend(share, new_size) except Exception as e: - raise exceptions.CommandError(_("Share resize failed: %s") % e) + msg = _("Share resize failed: %(e)s") + raise exceptions.CommandError(msg % {'e': e}) else: - raise exceptions.CommandError( - _("Share size is already at %s GiBs") % new_size - ) + msg = _("Share size is already at %(new_size)s GiBs") + raise exceptions.CommandError(msg % {'new_size': new_size}) if parsed_args.wait: if not oscutils.wait_for_status( status_f=share_client.shares.get, @@ -1544,9 +1545,8 @@ class RevertShare(command.Command): try: share.revert_to_snapshot(snapshot) except Exception as e: - raise exceptions.CommandError( - _("Failed to revert share to snapshot: %s") % e - ) + msg = _("Failed to revert share to snapshot: %(e)s") + raise exceptions.CommandError(msg % {'e': e}) if parsed_args.wait: if not oscutils.wait_for_status( status_f=share_client.shares.get, @@ -1784,12 +1784,17 @@ class RestoreShare(command.Command): {'share': share, 'e': e}, ) if failure_count > 0: - total = len(parsed_args.share) - msg = ( - f"Failed to restore {failure_count} out of {total} shares." + msg = _( + "Failed to restore %(failure_count)s out of %(total)s " + "shares." + ) + raise exceptions.CommandError( + msg + % { + 'failure_count': failure_count, + 'total': len(parsed_args.share), + }, ) - msg = _(msg) - raise exceptions.CommandError(msg) else: raise exceptions.CommandError( "Restoring a share from the recycle bin is only " diff --git a/manilaclient/osc/v2/share_access_rules.py b/manilaclient/osc/v2/share_access_rules.py index bb3c50761..422a2dad9 100644 --- a/manilaclient/osc/v2/share_access_rules.py +++ b/manilaclient/osc/v2/share_access_rules.py @@ -246,7 +246,6 @@ class ShareAccessDeny(command.Command): ) kwargs['unrestrict'] = True - error = None try: share.deny(parsed_args.id, **kwargs) if parsed_args.wait: @@ -254,17 +253,15 @@ class ShareAccessDeny(command.Command): manager=share_client.share_access_rules, res_id=parsed_args.id, ): - error = _( - f"Failed to delete share access rule with ID: {parsed_args.id}" - ) + raise Exception('timed out while waiting for deletion') except Exception as e: - error = e - if error: + msg = _( + "Failed to delete share access rule %(id)s for share " + "%(share)s: %(e)s" + ) raise exceptions.CommandError( - _( - "Failed to delete share access rule for share " - f"'{share}': {error}" - ) + msg + % {'id': parsed_args.id, 'share': parsed_args.share, 'e': e} ) diff --git a/manilaclient/osc/v2/share_group_types.py b/manilaclient/osc/v2/share_group_types.py index 71117adbd..6b756be4a 100644 --- a/manilaclient/osc/v2/share_group_types.py +++ b/manilaclient/osc/v2/share_group_types.py @@ -92,14 +92,13 @@ class CreateShareGroupType(command.ShowOne): share_types_list.append(share_type_obj.name) except Exception as e: - msg = LOG.error( - _( - "Failed to find the share type with " - "name or ID '%(share_type)s': %(e)s" - ), - {'share_type': share_type, 'e': e}, + msg = _( + "Failed to find the share type with name or ID " + "'%(share_type)s': %(e)s" + ) + raise exceptions.CommandError( + msg % {'share_type': share_type, 'e': e} ) - raise exceptions.CommandError(msg) kwargs['share_types'] = share_types_list @@ -310,14 +309,14 @@ class SetShareGroupType(command.Command): share_client.share_group_types, parsed_args.share_group_type ) except Exception as e: - msg = LOG.error( - _( - "Failed to find the share group type with " - "name or ID '%(share_group_type)s': %(e)s" - ), - {'share_group_type': parsed_args.share_group_type, 'e': e}, + msg = _( + "Failed to find the share group type with " + "name or ID '%(share_group_type)s': %(e)s" + ) + raise exceptions.CommandError( + msg + % {'share_group_type': parsed_args.share_group_type, 'e': e} ) - raise exceptions.CommandError(msg) kwargs = {} if kwargs: @@ -365,14 +364,14 @@ class UnsetShareGroupType(command.Command): share_client.share_group_types, parsed_args.share_group_type ) except Exception as e: - msg = LOG.error( - _( - "Failed to find the share group type with " - "name or ID '%(share_group_type)s': %(e)s" - ), - {'share_group_type': parsed_args.share_group_type, 'e': e}, + msg = _( + "Failed to find the share group type with " + "name or ID '%(share_group_type)s': %(e)s" + ) + raise exceptions.CommandError( + msg + % {'share_group_type': parsed_args.share_group_type, 'e': e} ) - raise exceptions.CommandError(msg) if parsed_args.group_specs: try: diff --git a/manilaclient/osc/v2/share_groups.py b/manilaclient/osc/v2/share_groups.py index 2b23bcb4f..175a29d93 100644 --- a/manilaclient/osc/v2/share_groups.py +++ b/manilaclient/osc/v2/share_groups.py @@ -577,6 +577,7 @@ class UnsetShareGroup(command.Command): try: share_client.share_groups.update(share_group, **kwargs) except Exception as e: - raise exceptions.CommandError( - _(f"Failed to unset share_group name or description : {e}") + msg = _( + "Failed to unset share_group name or description: %(e)s" ) + raise exceptions.CommandError(msg % {'e': e}) diff --git a/manilaclient/osc/v2/share_replicas.py b/manilaclient/osc/v2/share_replicas.py index ca77e1bb4..96e1aeb90 100644 --- a/manilaclient/osc/v2/share_replicas.py +++ b/manilaclient/osc/v2/share_replicas.py @@ -439,9 +439,8 @@ class PromoteShareReplica(command.Command): LOG.error(_("ERROR: Share replica is in error state.")) except Exception as e: - raise exceptions.CommandError( - _(f"Failed to promote replica to 'active': {e}") - ) + msg = "Failed to promote replica to 'active': %(e)s" + raise exceptions.CommandError(msg % {'e': e}) class ResyncShareReplica(command.Command): @@ -470,6 +469,5 @@ class ResyncShareReplica(command.Command): try: share_client.share_replicas.resync(replica) except Exception as e: - raise exceptions.CommandError( - _(f"Failed to resync share replica: {e}") - ) + msg = "Failed to resync share replica: %(e)s" + raise exceptions.CommandError(msg % {'e': e}) diff --git a/manilaclient/osc/v2/share_servers.py b/manilaclient/osc/v2/share_servers.py index dab754f85..7b17bf00c 100644 --- a/manilaclient/osc/v2/share_servers.py +++ b/manilaclient/osc/v2/share_servers.py @@ -77,9 +77,11 @@ class DeleteShareServer(command.Command): ) if result > 0: - total = len(parsed_args.share_servers) - msg = f'Failed to delete {result} servers out of {total}.' - raise exceptions.CommandError(_(msg)) + msg = "Failed to delete %(result)d servers out %(total)d" + raise exceptions.CommandError( + msg + % {'result': result, 'total': len(parsed_args.share_servers)}, + ) class ShowShareServer(command.ShowOne): @@ -433,9 +435,11 @@ class AbandonShareServer(command.Command): ) if result > 0: - total = len(parsed_args.share_server) - msg = f'Failed to abandon {result} of {total} servers.' - raise exceptions.CommandError(_(msg)) + msg = _('Failed to abandon %(result)s of %(total)s servers.') + raise exceptions.CommandError( + msg + % {'result': result, 'total': len(parsed_args.share_server)} + ) class SetShareServer(command.Command): @@ -444,7 +448,6 @@ class SetShareServer(command.Command): _description = _("Set share server properties (Admin only).") def get_parser(self, prog_name): - parser = super().get_parser(prog_name) allowed_update_choices = [ 'unmanage_starting', 'server_migrating_to', @@ -459,6 +462,8 @@ class SetShareServer(command.Command): 'network_change', ] allowed_update_choices_str = ', '.join(allowed_update_choices) + + parser = super().get_parser(prog_name) parser.add_argument( "share_server", metavar="", diff --git a/manilaclient/osc/v2/share_snapshot_instances.py b/manilaclient/osc/v2/share_snapshot_instances.py index a6ad8b60b..ccb94fe07 100644 --- a/manilaclient/osc/v2/share_snapshot_instances.py +++ b/manilaclient/osc/v2/share_snapshot_instances.py @@ -160,5 +160,5 @@ class SetShareSnapshotInstance(command.Command): parsed_args.snapshot_instance, parsed_args.status ) except Exception as e: - msg = _(f"Failed to update share snapshot instance status: {e}") - raise exceptions.CommandError(msg) + msg = _("Failed to update share snapshot instance status: %(e)s") + raise exceptions.CommandError(msg % {'e': e}) diff --git a/manilaclient/osc/v2/share_snapshots.py b/manilaclient/osc/v2/share_snapshots.py index 4f52164c4..88bc7396a 100644 --- a/manilaclient/osc/v2/share_snapshots.py +++ b/manilaclient/osc/v2/share_snapshots.py @@ -393,24 +393,20 @@ class UnsetShareSnapshot(command.Command): try: share_client.share_snapshots.update(share_snapshot, **kwargs) except Exception as e: - raise exceptions.CommandError( - _( - "Failed to unset snapshot display name " - f"or display description : {e}" - ) + msg = _( + "Failed to unset snapshot display name or display " + "description: %(e)s" ) + raise exceptions.CommandError(msg % {'e': e}) if parsed_args.property: for key in parsed_args.property: try: share_snapshot.delete_metadata([key]) except Exception as e: - raise exceptions.CommandError( - _( - "Failed to unset snapshot property " - "'%(key)s': %(e)s" - ), - {'key': key, 'e': e}, + msg = _( + "Failed to unset snapshot property '%(key)s': %(e)s" ) + raise exceptions.CommandError(msg % {'key': key, 'e': e}) class ListShareSnapshot(command.Lister): diff --git a/tox.ini b/tox.ini index ddaecb7c7..e787e52cd 100644 --- a/tox.ini +++ b/tox.ini @@ -97,9 +97,7 @@ exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,releasenotes # We only enable the hacking (H) checks select = H # H301 Black will put commas after imports that can't fit on one line -# H701 Hacking doesn't understand f-strings -# H703 Multiple placeholders are fine -ignore = H301,H701,H703 +ignore = H301 # H106 Don't put vim configuration in source files. # H203 Use assertIs(Not)None to check for None. # H904 Delay string interpolations at logging calls.