Fix outstanding hacking issues
Change-Id: I920dc4922056a807b4d25728560fb4f58cbf14c2 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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="<share-server>",
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user