Fix: transfer-delete command

All of the cinder resource delete commands accept multiple
resources as arguments but in case of transfer-delete, we
can only pass one transfer.
This patch fixes the issue and allows multiple transfers to
be supplied to the transfer-delete command.

Closes-Bug: #2069992
Change-Id: Iaccb5dc72e8648b628ff6f1ca2594644b6682c8a
This commit is contained in:
Rajat Dhasmana 2024-06-21 10:53:32 +05:30
parent a58bb92b28
commit 8e5fae8102
4 changed files with 37 additions and 3 deletions

View File

@ -1032,6 +1032,14 @@ class FakeHTTPClient(base_client.HTTPClient):
# VolumeTransfers
#
def get_os_volume_transfer_1234(self, **kw):
base_uri = 'http://localhost:8776'
tenant_id = '0fa851f6668144cf9cd8c8419c1646c1'
transfer1 = '1234'
return (200, {},
{'transfer':
_stub_transfer_full(transfer1, base_uri, tenant_id)})
def get_os_volume_transfer_5678(self, **kw):
base_uri = 'http://localhost:8776'
tenant_id = '0fa851f6668144cf9cd8c8419c1646c1'
@ -1050,6 +1058,9 @@ class FakeHTTPClient(base_client.HTTPClient):
_stub_transfer_full(transfer1, base_uri, tenant_id),
_stub_transfer_full(transfer2, base_uri, tenant_id)]})
def delete_os_volume_transfer_1234(self, **kw):
return (202, {}, None)
def delete_os_volume_transfer_5678(self, **kw):
return (202, {}, None)

View File

@ -1653,6 +1653,15 @@ class ShellTest(utils.TestCase):
url = ('/volume-transfers/detail')
self.assert_called('GET', url)
def test_delete_transfer(self):
self.run_command('transfer-delete 1234')
self.assert_called('DELETE', '/os-volume-transfer/1234')
def test_delete_transfers(self):
self.run_command('transfer-delete 1234 5678')
self.assert_called_anytime('DELETE', '/os-volume-transfer/1234')
self.assert_called_anytime('DELETE', '/os-volume-transfer/5678')
def test_subcommand_parser(self):
"""Ensure that all the expected commands show up.

View File

@ -1348,12 +1348,21 @@ def do_transfer_create(cs, args):
shell_utils.print_dict(info)
@utils.arg('transfer', metavar='<transfer>',
@utils.arg('transfer', metavar='<transfer>', nargs='+',
help='Name or ID of transfer to delete.')
def do_transfer_delete(cs, args):
"""Undoes a transfer."""
transfer = shell_utils.find_transfer(cs, args.transfer)
transfer.delete()
failure_count = 0
for t in args.transfer:
try:
transfer = shell_utils.find_transfer(cs, t)
transfer.delete()
except Exception as e:
failure_count += 1
print("Delete for volume transfer %s failed: %s" % (t, e))
if failure_count == len(args.transfer):
raise exceptions.CommandError("Unable to delete any of the specified "
"volume transfers.")
@utils.arg('transfer', metavar='<transfer>',

View File

@ -0,0 +1,5 @@
---
fixes:
- |
`Bug #2069992 <https://bugs.launchpad.net/python-cinderclient/+bug/2069992>`_:
Fixed transfer-delete command to accept multiple transfers.