From 9b51127ecc85e9814b6256180ef612c857156559 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Tue, 12 Jul 2016 15:53:58 +0800 Subject: Support error handling for delete commands in volumev2 Some delete conmmands in volumev2 did not support error handling, this patch add them and also add the unit tests for bulk deletion Change-Id: I56ade6f9c7396c78fb989547476c4d94ccd76eae --- openstackclient/volume/v2/volume.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'openstackclient/volume/v2/volume.py') diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 0ee7bd8f..85f267ef 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -19,6 +19,7 @@ import logging from osc_lib.cli import parseractions from osc_lib.command import command +from osc_lib import exceptions from osc_lib import utils import six @@ -176,13 +177,27 @@ class DeleteVolume(command.Command): def take_action(self, parsed_args): volume_client = self.app.client_manager.volume - for volume in parsed_args.volumes: - volume_obj = utils.find_resource( - volume_client.volumes, volume) - if parsed_args.force: - volume_client.volumes.force_delete(volume_obj.id) - else: - volume_client.volumes.delete(volume_obj.id) + result = 0 + + for i in parsed_args.volumes: + try: + volume_obj = utils.find_resource( + volume_client.volumes, i) + if parsed_args.force: + volume_client.volumes.force_delete(volume_obj.id) + else: + volume_client.volumes.delete(volume_obj.id) + except Exception as e: + result += 1 + LOG.error(_("Failed to delete volume with " + "name or ID '%(volume)s': %(e)s") + % {'volume': i, 'e': e}) + + if result > 0: + total = len(parsed_args.volumes) + msg = (_("%(result)s of %(total)s volumes failed " + "to delete.") % {'result': result, 'total': total}) + raise exceptions.CommandError(msg) class ListVolume(command.Lister): -- cgit v1.2.1