Merge "volume: Add 'volume transfer request create --(no-)snapshots' option"

This commit is contained in:
Zuul 2021-08-26 08:03:53 +00:00 committed by Gerrit Code Review
commit eca51342c3
3 changed files with 88 additions and 0 deletions

View File

@ -15,6 +15,7 @@
from unittest import mock
from unittest.mock import call
from cinderclient import api_versions
from osc_lib import exceptions
from osc_lib import utils
@ -172,6 +173,51 @@ class TestTransferCreate(TestTransfer):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
def test_transfer_create_with_no_snapshots(self):
self.app.client_manager.volume.api_version = \
api_versions.APIVersion('3.55')
arglist = [
'--no-snapshots',
self.volume.id,
]
verifylist = [
('name', None),
('snapshots', False),
('volume', self.volume.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.transfer_mock.create.assert_called_once_with(
self.volume.id, None, no_snapshots=True)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
def test_transfer_create_pre_v355(self):
self.app.client_manager.volume.api_version = \
api_versions.APIVersion('3.54')
arglist = [
'--no-snapshots',
self.volume.id,
]
verifylist = [
('name', None),
('snapshots', False),
('volume', self.volume.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
exc = self.assertRaises(
exceptions.CommandError,
self.cmd.take_action,
parsed_args)
self.assertIn(
'--os-volume-api-version 3.55 or greater is required',
str(exc))
class TestTransferDelete(TestTransfer):

View File

@ -16,6 +16,7 @@
import logging
from cinderclient import api_versions
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
@ -76,6 +77,25 @@ class CreateTransferRequest(command.ShowOne):
metavar="<name>",
help=_('New transfer request name (default to None)'),
)
parser.add_argument(
'--snapshots',
action='store_true',
dest='snapshots',
help=_(
'Allow transfer volumes without snapshots (default) '
'(supported by --os-volume-api-version 3.55 or later)'
),
default=None,
)
parser.add_argument(
'--no-snapshots',
action='store_false',
dest='snapshots',
help=_(
'Disallow transfer volumes without snapshots '
'(supported by --os-volume-api-version 3.55 or later)'
),
)
parser.add_argument(
'volume',
metavar="<volume>",
@ -85,6 +105,21 @@ class CreateTransferRequest(command.ShowOne):
def take_action(self, parsed_args):
volume_client = self.app.client_manager.volume
kwargs = {}
if parsed_args.snapshots is not None:
if volume_client.api_version < api_versions.APIVersion('3.55'):
msg = _(
"--os-volume-api-version 3.55 or greater is required to "
"support the '--(no-)snapshots' option"
)
raise exceptions.CommandError(msg)
# unfortunately this option is negative so we have to reverse
# things
kwargs['no_snapshots'] = not parsed_args.snapshots
volume_id = utils.find_resource(
volume_client.volumes,
parsed_args.volume,
@ -92,6 +127,7 @@ class CreateTransferRequest(command.ShowOne):
volume_transfer_request = volume_client.transfers.create(
volume_id,
parsed_args.name,
**kwargs,
)
volume_transfer_request._info.pop("links", None)

View File

@ -0,0 +1,6 @@
---
features:
- |
The ``volume transfer request create`` command now accepts the
``--snapshots`` / ``--no-snapshots`` option to configure whether to
create a transfer request for a volume without snapshots or not.