Skip to content

Commit a821d6b

Browse files
committed
volume: Add 'volume transfer request create --(no-)snapshots' option
This closes a gap with cinderclient's 'transfer-create' command. Change-Id: I7386a7be15c0e3ee87abbcfc2275ba8524c10ff8 Signed-off-by: Stephen Finucane <sfinucan@redhat.com> Story: 2009054 Task: 42831
1 parent 4891bb3 commit a821d6b

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

openstackclient/tests/unit/volume/v2/test_transfer_request.py renamed to openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from unittest import mock
1616
from unittest.mock import call
1717

18+
from cinderclient import api_versions
1819
from osc_lib import exceptions
1920
from osc_lib import utils
2021

@@ -172,6 +173,51 @@ def test_transfer_create_with_name(self):
172173
self.assertEqual(self.columns, columns)
173174
self.assertEqual(self.data, data)
174175

176+
def test_transfer_create_with_no_snapshots(self):
177+
self.app.client_manager.volume.api_version = \
178+
api_versions.APIVersion('3.55')
179+
180+
arglist = [
181+
'--no-snapshots',
182+
self.volume.id,
183+
]
184+
verifylist = [
185+
('name', None),
186+
('snapshots', False),
187+
('volume', self.volume.id),
188+
]
189+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
190+
191+
columns, data = self.cmd.take_action(parsed_args)
192+
193+
self.transfer_mock.create.assert_called_once_with(
194+
self.volume.id, None, no_snapshots=True)
195+
self.assertEqual(self.columns, columns)
196+
self.assertEqual(self.data, data)
197+
198+
def test_transfer_create_pre_v355(self):
199+
self.app.client_manager.volume.api_version = \
200+
api_versions.APIVersion('3.54')
201+
202+
arglist = [
203+
'--no-snapshots',
204+
self.volume.id,
205+
]
206+
verifylist = [
207+
('name', None),
208+
('snapshots', False),
209+
('volume', self.volume.id),
210+
]
211+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
212+
213+
exc = self.assertRaises(
214+
exceptions.CommandError,
215+
self.cmd.take_action,
216+
parsed_args)
217+
self.assertIn(
218+
'--os-volume-api-version 3.55 or greater is required',
219+
str(exc))
220+
175221

176222
class TestTransferDelete(TestTransfer):
177223

openstackclient/volume/v2/volume_transfer_request.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import logging
1818

19+
from cinderclient import api_versions
1920
from osc_lib.command import command
2021
from osc_lib import exceptions
2122
from osc_lib import utils
@@ -76,6 +77,25 @@ def get_parser(self, prog_name):
7677
metavar="<name>",
7778
help=_('New transfer request name (default to None)'),
7879
)
80+
parser.add_argument(
81+
'--snapshots',
82+
action='store_true',
83+
dest='snapshots',
84+
help=_(
85+
'Allow transfer volumes without snapshots (default) '
86+
'(supported by --os-volume-api-version 3.55 or later)'
87+
),
88+
default=None,
89+
)
90+
parser.add_argument(
91+
'--no-snapshots',
92+
action='store_false',
93+
dest='snapshots',
94+
help=_(
95+
'Disallow transfer volumes without snapshots '
96+
'(supported by --os-volume-api-version 3.55 or later)'
97+
),
98+
)
7999
parser.add_argument(
80100
'volume',
81101
metavar="<volume>",
@@ -85,13 +105,29 @@ def get_parser(self, prog_name):
85105

86106
def take_action(self, parsed_args):
87107
volume_client = self.app.client_manager.volume
108+
109+
kwargs = {}
110+
111+
if parsed_args.snapshots is not None:
112+
if volume_client.api_version < api_versions.APIVersion('3.55'):
113+
msg = _(
114+
"--os-volume-api-version 3.55 or greater is required to "
115+
"support the '--(no-)snapshots' option"
116+
)
117+
raise exceptions.CommandError(msg)
118+
119+
# unfortunately this option is negative so we have to reverse
120+
# things
121+
kwargs['no_snapshots'] = not parsed_args.snapshots
122+
88123
volume_id = utils.find_resource(
89124
volume_client.volumes,
90125
parsed_args.volume,
91126
).id
92127
volume_transfer_request = volume_client.transfers.create(
93128
volume_id,
94129
parsed_args.name,
130+
**kwargs,
95131
)
96132
volume_transfer_request._info.pop("links", None)
97133

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
The ``volume transfer request create`` command now accepts the
5+
``--snapshots`` / ``--no-snapshots`` option to configure whether to
6+
create a transfer request for a volume without snapshots or not.

0 commit comments

Comments
 (0)