Skip to content

Commit cb6c11b

Browse files
author
Huanxuan Ao
committed
Multi REST API calls error handling of "volume unset" command
Support multi REST API calls error handling for "volume unset" command follow the rule in doc/source/command-errors.rst. Also add a unit test for testing the error handling Change-Id: I2de7a7bd5a7a5e39817ed5cf6952abf4afba75e4
1 parent 676a0e9 commit cb6c11b

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,3 +964,30 @@ def test_volume_unset_image_property(self):
964964

965965
self.volumes_mock.delete_image_metadata.assert_called_with(
966966
self.new_volume.id, parsed_args_unset.image_property)
967+
968+
def test_volume_unset_image_property_fail(self):
969+
self.volumes_mock.delete_image_metadata.side_effect = (
970+
exceptions.CommandError())
971+
arglist = [
972+
'--image-property', 'Alpha',
973+
'--property', 'Beta',
974+
self.new_volume.id,
975+
]
976+
verifylist = [
977+
('image_property', ['Alpha']),
978+
('property', ['Beta']),
979+
('volume', self.new_volume.id),
980+
]
981+
parsed_args = self.check_parser(
982+
self.cmd_unset, arglist, verifylist)
983+
984+
try:
985+
self.cmd_unset.take_action(parsed_args)
986+
self.fail('CommandError should be raised.')
987+
except exceptions.CommandError as e:
988+
self.assertEqual('One or more of the unset operations failed',
989+
str(e))
990+
self.volumes_mock.delete_image_metadata.assert_called_with(
991+
self.new_volume.id, parsed_args.image_property)
992+
self.volumes_mock.delete_metadata.assert_called_with(
993+
self.new_volume.id, parsed_args.property)

openstackclient/volume/v2/volume.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,23 @@ def take_action(self, parsed_args):
511511
volume = utils.find_resource(
512512
volume_client.volumes, parsed_args.volume)
513513

514+
result = 0
514515
if parsed_args.property:
515-
volume_client.volumes.delete_metadata(
516-
volume.id, parsed_args.property)
516+
try:
517+
volume_client.volumes.delete_metadata(
518+
volume.id, parsed_args.property)
519+
except Exception as e:
520+
LOG.error(_("Failed to unset volume property: %s"), e)
521+
result += 1
522+
517523
if parsed_args.image_property:
518-
volume_client.volumes.delete_image_metadata(
519-
volume.id, parsed_args.image_property)
524+
try:
525+
volume_client.volumes.delete_image_metadata(
526+
volume.id, parsed_args.image_property)
527+
except Exception as e:
528+
LOG.error(_("Failed to unset image property: %s"), e)
529+
result += 1
530+
531+
if result > 0:
532+
raise exceptions.CommandError(_("One or more of the "
533+
"unset operations failed"))

0 commit comments

Comments
 (0)