summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py (renamed from openstackclient/tests/unit/volume/v2/test_transfer_request.py)46
-rw-r--r--openstackclient/volume/v2/volume_transfer_request.py36
2 files changed, 82 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/volume/v2/test_transfer_request.py b/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py
index c9dce3ca..1a1f220f 100644
--- a/openstackclient/tests/unit/volume/v2/test_transfer_request.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py
@@ -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):
diff --git a/openstackclient/volume/v2/volume_transfer_request.py b/openstackclient/volume/v2/volume_transfer_request.py
index 2a1ace1f..89199336 100644
--- a/openstackclient/volume/v2/volume_transfer_request.py
+++ b/openstackclient/volume/v2/volume_transfer_request.py
@@ -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
@@ -77,6 +78,25 @@ class CreateTransferRequest(command.ShowOne):
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>",
help=_('Volume to transfer (name or ID)'),
@@ -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)