From af81a92c373a5c4e1bec751b282eda8081cb3063 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Tue, 23 Aug 2016 16:09:52 +0800 Subject: Support error handling for delete commands in volume v1 Some delete commands in volume v1 support multi delete but do not support error handling, this patch fixes them, and this patch also refactor (or add new) unit tests for some delete commands in volume v1. Change-Id: Ia8177698f8733cfe75ea0ff00eee8fdc0820f62e --- openstackclient/volume/v1/backup.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'openstackclient/volume/v1/backup.py') diff --git a/openstackclient/volume/v1/backup.py b/openstackclient/volume/v1/backup.py index 539ed369..c9d0ca0d 100644 --- a/openstackclient/volume/v1/backup.py +++ b/openstackclient/volume/v1/backup.py @@ -19,12 +19,16 @@ import copy import logging from osc_lib.command import command +from osc_lib import exceptions from osc_lib import utils import six from openstackclient.i18n import _ +LOG = logging.getLogger(__name__) + + class CreateVolumeBackup(command.ShowOne): """Create new volume backup""" @@ -100,10 +104,24 @@ class DeleteVolumeBackup(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - for backup in parsed_args.backups: - backup_id = utils.find_resource(volume_client.backups, - backup).id - volume_client.backups.delete(backup_id) + result = 0 + + for i in parsed_args.backups: + try: + backup_id = utils.find_resource( + volume_client.backups, i).id + volume_client.backups.delete(backup_id) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete backup with " + "name or ID '%(backup)s': %(e)s"), + {'backup': i, 'e': e}) + + if result > 0: + total = len(parsed_args.backups) + msg = (_("%(result)s of %(total)s backups failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class DeleteBackup(DeleteVolumeBackup): -- cgit v1.2.1